CMPS 217 – Logic in Computer Science Lecture #16

CMPS 217 – Logic in Computer Science
https://courses.soe.ucsc.edu/courses/cmps217/Spring13/01
Lecture #16
1
Prenex Normal Form
Definition:
A FO-formula is in prenex normal form if it is of the form
Q1x1 …Qnxn θ, where each Qi is a quantifier and θ is a quantifier-free
formula.
A Σn-formula, n ≥ 1, is a formula in prenex normal form with n
alternations of blocks of quantifiers starting with the existential
quantifier.
A Πn-formula, n ≥ 1, is a formula in prenex normal form with n
alternations of blocks of quantifiers starting with the universal
quantifier.
Σ = Π = Quantifier-free formulas
2
Hierarchies in Prenex Normal Form
Fact:
Σ ⊂ Σ ⊂ … ⊂ Σn ⊂ Σn+1 ⊂ …
Π ⊂ Π ⊂ … ⊂ Πn ⊂ Πn+1 ⊂ …
Example: The Σ-sentence ∃ x ∀ y (¬ E(x,y)) is not logically
equivalent to any Σ-sentence and to any Π-sentence.
Proof 1: Use Ehrenfeucht-Fraïssé games.
Proof 2: Use preservation properties
Σ-sentences are preserved under extensions.
Π-sentences are preserved under induced subgraphs.
3
Prenex Normal Form Theorem
Theorem:
Every FO-formula is logically equivalent to a FO-formula in prenex
normal form.
Moreover, there is a linear-time algorithm that, given a FO-formula
ϕ, returns a FO-formula ϕ* in prenex normal form that is logically
equivalent to ϕ.
Corollary:
For every FO-formula ϕ, there is some m ≥ 0 such that ϕ is logically
equivalent to some Σm-formula.
For every FO-formula ϕ, there is some n ≥ 0 such that ϕ is logically
equivalent to some Πn-formula.
Note:
The minimum such m may be different from the minimum such n.
4
Algorithmic Problems about First-Order Logic
Theorem (Gödel, Church, Tarski – 1930s):
Let S be a signature containing a relation symbol of arity at least 2.
The Validity Problem is undecidable, i.e., there is no algorithm to solve
the following problem: given a FO-sentence ψ over S, is it valid?
Theorem (Trakhtenbrot – 1949):
Let S be a signature containing a relation sumbol of arity at least 2.
The Finite Validity Problem is undecidable, i.e., there is no algorithm to
solve the following problem: given a FO-sentence ψ over S, is it finitely
valid?
5
Decidable Cases of the Validity Problem
The undecidability of the validity problem for FO-sentences
gave rise to the pursuit of restricted classes of FO-sentences
for which the validity problem is decidable.
A major direction of research in this area focused on the
quantifier pattern for FO-sentences in prenex normal forms
over relational signatures.
A complete classification delineating the boundary between
decidability and undecidability was obtained through research
that spanned several decades in the 20th Century.
6
Prefix Classes
Notation:
∀* denotes a block of zero or more consecutive universal quantifiers.
∃* denotes a block of zero or more consecutive existential quantifiers.
Definition:
A prefix class is a collection of FO-sentences in prenex normal form having
a particular quantifier pattern.
Examples:
1.
2.
∃* ∀ ∀ is the class of all Σ-sentences in prenex normal form with zero or
more existential quantifiers followed by two universal quantifier.
∀ ∃* ∀ is the class of all Π-sentences in prenex normal form starting
with one universal quantifier, followed by zero or more existential
quantifiers, followed by one universal quantifier.
7
Dual Prefix Classes
Notation: If C is a prefix class, then Cd denotes the dual
prefix class of C, that is, the collection of all formulas in
prenex normal form whose quantifier pattern is obtained
from that of C by replacing each quantifier Q by its dual Qd.
Example: If C is ∃*∀*∃, then Cd is ∀*∃*∀
Fact: Let C be a prefix class. Then the following statements
are equivalent:
1. The validity problem for C is decidable.
2. The satisfiability problem for Cd is decidable.
Proof: A sentence Q1x1 … Qmxm θ is valid if and only if the
sentence Qd1x1… Qdmxm (¬ θ) is unsatisfiable.
8
Decidable Cases of the Validity Problem
Theorem: Let S be a signature containing at least one relation
symbol of arity ≥ 2.
The validity problem for the prefix class ∀*∃* is decidable.
Equivalently, the satisfiability problem for the prefix class ∃*∀* is
decidable. This class is known as the Bernays-Schönfinkel Class.
The validity problem for the prefix class ∀*∃∀* is decidable.
Equivalently, the satisfiability problem for the prefix class ∃*∀∃* is
decidable. This class is known as the Ackermann Class.
If C is a prefix class that is not contained in one of the previous two prefix
classes, then the validity problem for C is undecidable.
In particular, the validity problem for the prefix class ∀*∃∃∀* is
undecidable.
Equivalently, the satisfiability problem for the prefix class ∃*∀∀∃* is
undecidable. This class is known as the Gödel Class.
9
Decidable Cases of the Validity Problem
Theorem: Let S be a signature containing at least one relation
symbol of arity ≥ 2.
The validity problem for the prefix class ∀*∃* is decidable.
Equivalently, the satisfiability problem for the prefix class ∃*∀*
is decidable. This is known as the Bernays-Schönfinkel Class.
Proof: It follows from a “bounded-model” property of the class∃*∀*.
Fact: Let ψ be a FO-sentence of the form ∃ x1…∃ xn ∀ y1 … ∀ ym θ,
where θ is quantifier-free. Then the following statements are
equivalent:
1. There is a structure A such that A ψ (i.e., ψ is satisfiable).
2. There is a structure A such that A ψ and |A| ≤ n
(i.e., ψ is satisfiable by a structure with at most n elements).
10
Decidable Cases of the Validity Problem
Historical Note: It took more than 50 years of research to
completely delineate the boundary between decidability and
undecidability of the validity problem for prefix classes over
relational signatures.
The decidability of the validity problem for ∀*∃* was established by Bernays
and Schönfinkel in 1928.
The decidability of the validity problem for ∀*∃∀* was established by
Ackermann in 1931.
The undecidability of the validity problem for ∀*∃∃∀* was established by
Goldfarb in 1984.
Back in 1932, Gödel had erroneously claimed that the validity problem
for the class ∀*∃∃∀* is decidable.
However, it is decidable for the class ∀*∃∃∀* without equality (Gödel).
11
The Complexity of FO-Truth on Infinite Structures
Theorem (Gödel - 1931):
Let N = (N, +, ×, 0, 1) be the structure of the natural numbers.
Then Th(N) is undecidable, i.e., there is no algorithm to solve
the following problem: given a FO-sentence ψ, does N ψ ?
Theorem (Tarski – 1949):
Let R = (R, +, ×, 0, 1) be the structure of the real numbers.
Then Th(R) is decidable, i.e., there is an algorithm to solve
the following problem: given a FO-sentence ψ, does R ψ ?
Note: The exact computational complexity of Th(R) is not known at present.
Lower bound: PSPACE-hard
Upper bound: in EXPSPACE.
12
The Complexity of FO-Truth on Finite Structures
Fact: If A is a fixed finite structure, then it is easy to see that Th(A)
is decidable
(Reason: for every FO-formula, there are only finitely many
assignments from the variables of the formula to the elements of
the universe of the structure).
Question: What can we say about the complexity of Th(A)?
More broadly, it is natural to consider the following algorithmic
problem about finite structures:
The Model Checking Problem:
Given a structure A and a FO-sentence ψ, does A ψ?
(equivalently, is ψ in Th(A)?)
13
The Complexity of FO-Truth on Finite Structures
Theorem: The Model Checking Problem is PSPACE-complete.
Proof: We have to show two different things:
The Model Checking Problem is in PSPACE.
For this, we need to give a polynomial-space algorithm for
solving the problem.
The Model Checking Problem is PSPACE-hard.
For this, we need to
either give a direct proof from Turing machines operating
in polynomial space
or
Give a polynomial-time reduction from a known PSPACEcomplete problem.
14
Complexity of the Model Checking Problem
Theorem: The Model Checking Problem is in PSPACE.
Proof (Hint): Let A be a given finite structure and ψ a FO-sentence, which
without loss of generality, we can assume it is of the form ∀x1∃x2 … ∀xmθ.
Exponential Time Algorithm: We can test whether A ψ by exhaustively
cycling over all possible interpretations of the xi’s over the universe A of A.
This algorithm runs in time O(nm), where n = |A| (size of the universe).
A more careful analysis shows that this algorithm can be implemented in
O(m·logn)-space.
Use m blocks of memory, each holding one of the n elements of A
written in binary (so O(logn) space is used in each block).
Maintain also m counters in binary to keep track of the number of
elements examined.
∀ x1
∃ x2
…
a1 in A
a2 in A
…
written in binary written in binary
∀ xm
am in A
written in binary
15
Quantified Boolean Formulas
Definition:
A quantified boolean formula is an expression of the form ∀ x1∃ x2 …. ∀ xkϕ,
where ϕ is a formula of propositional logic.
The Quantified Boolean Formulas Problem (QBF):
Given a quantified boolean formula ∀ x1∃ x2 …. ∀ xkϕ, is it true?
Examples:
∀ x1 ∃ x2 ((x1 Ç x2) Æ (¬ x1 Ç ¬ x2))
Is true.
If x1 = 1, then put x2 = 0.
If x1 = 0, then put x2 = 1.
∀ x1 ∃ x2 ((x1 Ç x2) Æ (x1 Ç ¬ x2))
Is false.
If x1 = 1, then we put x2 = 0.
If x1 = 0, then the formula evaluates to false, no matter what x2 is.
16
PSPACE-Complete Problems
Theorem (Stockmeyer – 1976)
QBF is PSPACE-complete.
Note: QBF was the first problem shown to be PSPACE-complete.
Complexity Class
Complete Problem
NLOGSPACE
2SAT
PTIME
Horn SAT
NP
SAT, 3SAT, 1-in-3-SAT
PSPACE
QBF
17
Complexity of the Model Checking Problem
Theorem: The Model Checking Problem is PSPACE-hard.
Proof: Show that QBF ≼p Model Checking Problem.
Given a quantified boolean formula ∀ x1∃ x2 …. ∀ xk ψ :
Introduce a single unary relation symbol P.
Obtain a FO-sentence ψ* from ψ by replacing xi by P(xi), and by
replacing ¬xi by (¬P(xi)).
Let A = (A, P’) be the finite structure with
A = {0,1}, and P’ = {1}.
Then the following statements are equivalent:
∀ x1∃ x2 …. ∀ xk ψ is true
A ∀ x1∃ x2 …. ∀ xk ψ*.
18
Complexity of the Model Checking Problem
The following theorem is an immediate consequence of the
preceding results.
Theorem: The Model Checking Problem is PSPACE-complete.
Moreover, the following result can be easily obtained via a
slight modification of the proof of the PSPACE-hardness of the
model checking problem.
Theorem: Let A = (A, R1,…,Rm) be a non-trivial finite relational
structure (i.e., for at least one of the relations Ri, we have that
Ri ≠ ∅ and Ri ≠ Ak). Then Th(A) is PSPACE-complete.
19
The Complexity of FO-Truth on a Structure
Structure A
Complexity of Th(A)
Structure of the natural numbers
N = (N, +, ×, 0, 1)
Undecidable
Structure of the real numbers
R = (R, +, ×, 0, 1)
Decidable in EXPSPACE;
PSPACE-hard
Non-trivial finite structure
PSPACE-complete
20
A Finer Analysis of Undecidability
Showing that an algorithmic problem of interest is undecidable is
not necessarily the end of the story, but, rather, the beginning of a
further investigation to understand the root causes of undecidability
for the problem at hand.
We have seen that:
the validity problem for FO-sentences is undecidable;
the finite validity problem for FO-sentences is undecidable.
As we will see in what follows, there are significant algorithmic
differences between these two undecidable problems.
To understand these differences, we need to introduce the notion of
a semi-decidable (a.k.a. recursively enumerable) algorithmic
problem.
21
Reminder: Decidable and Undecidable Problems
Definition: Let Q be a decision problem.
Q is decidable (solvable) if there is an algorithm (Turing
machine, via Church’s Thesis) for solving the membership
problem for the language associated with it.
Q is undecidable (unsolvable) if no such algorithm exists
1 (“yes”)
Input x
Q?
0 (“no”)
22
Semi-Decidable Problems
Definition: Let Q be a decision problem.
Q is semi-decidable (recursively enumerable) if there is an
algorithm (Turing machine, via Church’s Thesis) such that if
If x is a “yes” input to Q (i.e., a member of the language
associated with Q), then the algorithm halts and outputs 1.
If x is a “no” input to Q, then the algorithm does not halt.
1 (“yes”)
Input x
Q?
23
Semi-Decidable Problems
The Halting Problem:
Given a Turing machine M and an input x, does M halt on x?
Fact: The Halting Problem is semi-decidable.
Algorithm: Use a universal Turing machine to run M on x.
Hilbert’s 10th Problem:
Given a polynomial p(x1,…,xn) with integer coefficients, does it
have an all-integer solution?
th Problem is semi-decidable.
Fact: Hilbert’s 10
Algorithm: Evaluate p(x1,..,xn) on every tuple a1,…,an until
you find a tuple such that p(a1,…,an) = 0.
24
Semi-Decidable Problems
Theorem: Let Q be a decision problem. Then the following
statements are equivalent:
1. Q is semi-decidable.
2. There is an algorithm that enumerates all “yes” inputs of Q
(i.e., all members of the language associated with Q), and
nothing else.
Proof: (Sketch)
1. ⇒ 2. Run the algorithm for the semi-decidability of Q on
progressively more inputs and for progressively
increasing intervals of time.
2. ⇒ 1. Given an input, run the enumeration algorithm until the
input is produced by the enumeration algorithm.
25
Decidable vs. Semi-Decidable Problems
Theorem: Let Q be a decision problem. Then the following
statements are equivalent:
1. Q is decidable.
2. Both Q and the complement Qc of Q are semi-decidable
Proof: (Sketch)
1. ⇒ 2. Easy exercise.
2. ⇒ 1. Given an input, run the semi-decidability algorithm for Q
and the semi-decidability algorithm for Qc in parallel.
Exactly one of these two algorithms must terminate.
If the semi-decidability algorithm for Q terminates, return 1;
If the semi-decidability algorithm for Qc terminates, return 0.
26
Decidable vs. Semi-Decidable Problems
Theorem: Let Q be a decision problem. Then the following
statements are equivalent:
1. Q is decidable.
2. Both Q and the complement Qc of Q are semi-decidable
Corollary: If Q is an undecidable problem, then at least one of
Q and Qc is not semi-decidable.
Corollary:
1. The complement of the Halting problem is not semi-decidable.
2. The complement of Hilbert’s 10th Problem is not semi-decidable.
27
The Finer Structure of Undecidable Problems
Fact: Suppose that Q is an undecidable decision problem. Then
exactly one of the following three possibilities holds:
1. Q is semi-decidable, but its complement Qc is not.
2. Q is not semi-decidable, but its complement Qc is.
3. Neither Q nor its complement Qc is semi-decidable.
Examples:
The Halting Problem is semi-decidable, but its complement is not.
Total Turing Machine Problem: Given a Turing maching M, does it
halt on every input?
Neither the Total Turing Machine Problem nor its complement is
semi-decidable.
Neither Th(N) nor its complement is semi-decidable.
28
Validities and Finite Validities
Recall the two main undecidability results about FO-logic:
Theorem (Gödel, Church, Tarski – 1930s):
Let S be a signature containing a relation symbol of arity at least 2.
The Validity Problem is undecidable, i.e., there is no algorithm to solve
the following problem: given a FO-sentence ψ over S, is it valid?
Theorem (Trakhtenbrot – 1949):
Let S be a signature containing a relation sumbol of arity at least 2.
The Finite Validity Problem is undecidable, i.e., there is no algorithm to
solve the following problem: given a FO-sentence ψ over S, is it finitely
valid?
Question: What can we say about the semi-decidability of these two problems?
29
Finite Validities
Theorem: The Complement of the Finite Validity Problem is
semi-decidable.
Proof: Given a FO-sentence ψ, consider its negation (¬ ψ) and
search for a finite structure A such that A (¬ ψ). If such a
finite structure is found, then ψ is not finitely valid.
Corollary: The Finite Validity Problem is not semi-decidable.
Equivalently, there is no algorithm that enumerates all finitely
valid FO-sentences.
30
Validities
Theorem (Gödel’s Completeness Theorem): The Validity Problem
is semi-decidable. Equivalently, there is an algorithm that
enumerates all valid FO-sentences.
Note: The semi-decidability of the Validity Problem yields a proof
procedure for proving all valid FO-sentences (the proof of a valid
FO-sentence is the run of the algorithm for semi-decidability).
Corollary: The complement of the Validity Problem is not
semi-decidable.
31
The Undecidability of FO-Logic
Problem
Decidable
Semi-decidable
Semi-decidable
Complement
Validity
No
Yes
No
Finite Validity
No
No
Yes
Th(N)
No
No
No
32