First-Order Predicate Logic (2)
Predicate Logic (2)
• Understanding first-order predicate logic formulas.
• Satisfiability and undecidability of satisfiability.
• Tautology, logical consequence, and logical equivalence.
• Completeness of first-order predicate logic
• Incompleteness of arithmetic and second-order logic.
Logic in Computer Science 2012 2
Translations into Predicate Logic
• “Every house is a physical object” is translated as
∀x.(house(x)→ physical object(x)),
where house and physical object are unary predicate symbols.
• “Some physical objects are houses”’ is translated as
∃x.(physical object(x) ∧ house(x))
• ”Every house has an owner” or, equivalently, “every house is owned bysomebody” is translated as
∀x(house(x)→ ∃y.owns(y, x)),
here owns is a binary predicate symbol.
• ”Everybody owns a house” is translated as
∀x.∃y.(owns(x, y) ∧ house(y))Logic in Computer Science 2012 3
Translations into Predicate Logic
• “Sue owns a house” is translated as
∃x.(owns(Sue, x) ∧ house(x))
where Sue is an individual constant symbol.
• “Peter does not own a house” is translated as
¬∃x.(owns(Peter, x) ∧ house(x))
• “Somebody does not own a house” is translated as
∃x.∀y.(owns(x, y)→ ¬house(y))
Logic in Computer Science 2012 4
The truth relation
Let S be the signature consisting of the unary predicates house and human, thebinary predicate owns, and the individual constant Sue. Give an S-interpretationF with F |= G for the following sentences G:
• there are houses: ∃x.house(x)
• there are human beings: ∃x.human(x)
• no house is a human being: ∀x.(house(x)→ ¬human(x))
• some humans own a house: ∃x.∃y.(human(x) ∧ house(y) ∧ owns(x, y))
• Sue is human: human(Sue)
• Sue does not own a house: ¬∃x.(owns(Sue, x) ∧ house(x))
• every house has an owner: ∀x.(house(x)→ ∃y.owns(y, x))
Logic in Computer Science 2012 5
The S-interpretation F
We can take, for example, F defined by
• DF = {a, b, c, d, e};
• humanF = {a, b, c};
• houseF = {d, e}
• ownsF = {(b, d), (c, e)};
• SueF = a.
Note that in this interpretation all owners are humans. We can also take humanF =
{a, b} and the sentences from the previous slide are still true in F .
(Note that this is not the case for humanF = {a}.)
Logic in Computer Science 2012 6
Satisfiability
Definition A first-order predicate logic sentence G over S is satisfiable if thereexists an S-structure F such that
F |= G
Examples
(a) ∃x.(P (x) ∧ ¬P (x)) is not satisfiable.
(b) ∀x.∃y.Q(x, y)∧¬∀u.∃v.Q(v, u) is satisfiable. (The sentence states that thedomain of Q is the whole domain of discourse and that the range of Q isnot the whole domain of discourse.)
(c) ∀x.P (x) ∧ ∃x.¬P (x) is not satisfiable.
Logic in Computer Science 2012 7
Proof for (b)
To show that ∀x.∃y.Q(x, y) ∧ ¬∀u.∃v.Q(v, u) is satisfiable we have to define a{Q}-structure F such that
F |= ∀x.∃y.Q(x, y) ∧ ¬∀u.∃v.Q(v, u)
Let
• DF = {a, b};
• QF = {(a, b), (b, b)}.
We have: for all d ∈ DF there exists d′ ∈ DF with (d, d′) ∈ QF . Thus, F |=∀x∃y.Q(x, y).
For d = a there does not exists d′ ∈ DF such that (d′, d) ∈ QF . Thus, F |=¬∀u.∃v.Q(v, u).
Logic in Computer Science 2012 8
Proof for (c)
To prove that ∀x.P (x)∧∃x.¬P (x) is not satisfiable, we have to show that for all{P}-structures F :
F 6|= ∀x.P (x) ∧ ∃x.¬P (x)
For a proof by contradiction assume there exists a {P}-structure F such that
F |= ∀x.P (x) ∧ ∃x.¬P (x)
Since F |= ∃x.¬P (x), there exists d ∈ DF such that d 6∈ PF . Take an assign-ment a with a(x) = d. Then (F , a) 6|= P (x). Hence F 6|= ∀x.P (x) and we havederived a contradiction to F |= ∀x.P (x) ∧ ∃x.¬P (x).
Logic in Computer Science 2012 9
Undecidability of satisfiability (very informal!)
We show that there does not exist any algorithm (no computer program) thatdecides whether a first-order predicate logic sentence is satisfiable; i.e., for in-put sentence G outputs “Yes” if G is satisfiable and “No” if G is not satisfiable.
To this end, we show that there is no computer program that decides whethera given computer program P halts for a given input number n. (Called unde-cidability of the halting problem.)
To formulate this a bit more precisely, let L be some standard programminglanguage. If a problem is decidable, then one can implement a program in L
solving it. With every program P in L we associate a unique number P ].
Logic in Computer Science 2012 10
Undecidability
Now we show: there is no program in L which outputs “yes” for input (P, n) (P aprogram in L and n a number) if program P terminates for input n, and outputs“no” otherwise.
For a proof by contradiction, assume there exists a program in L which outputs“yes” for input (P, n) if P terminates for input n and outputs “no” otherwise.
Then there exists a program Qterm that outputs “yes” for input P ] if P terminatesfor input P ]. Otherwise it outputs “no”.
Logic in Computer Science 2012 11
Undecidability
We can rewrite Qterm into a program Aterm that terminates for input P ] if Qterm
outputs “no” for input P ]. Otherwise it does not terminate. Then
• Aterm terminates for input A]term if, and only if (by def. of Aterm)
• Qterm outputs “no” for input A]term if, and only if (by def. of Qterm)
• Aterm does not terminate for input A]term.
We have derived a contradiction.
Now, for any (P, n), (P in a standard programming language L), one can writeup a first-order predicate logic sentence FP,n such that FP,n is satisfiable if, andonly if, P does not terminate for input n. FP,n describes the computation stepsof P .
Since the halting problem is undecidable, we obtain that satisfiablility of first-order predicate logic sentences is undecidable.Logic in Computer Science 2012 12
Tautology
Definition A first-order predicate logic sentence G over S is a tautology ifF |= G
holds for every S-structure F .
Examples of tautologies
(a) ∀x.P (x)→ ∃x.P (x);
(b) ∀x.P (x)→ P (c);
(c) P (c)→ ∃x.P (x);
(d) ∀x(P (x)↔ ¬¬P (x));
(e) ∀x(¬(P1(x) ∧ P2(x))↔ (¬P1(x) ∨ ¬P2(x))).
Logic in Computer Science 2012 13
Proof for (a)
To show that ∀x.P (x) → ∃x.P (x) is a tautology it is sufficient to prove that forevery {P}-structure F : if F |= ∀x.P (x), then F |= ∃x.P (x).
Assume F |= ∀x.P (x). Then PF coincides with the domain of discourse DF ;i.e., PF = DF . Note that DF is, by definition, always nonempty. Thus, thereexists d ∈ PF . Define a variable assignment a by setting a(x) = d. Then(F , a) |= P (x). Hence F |= ∃x.P (x).
Logic in Computer Science 2012 14
The relationship between satisfiability and tautologies
Observation
• A first-order predicate logic sentence G is a tautology if, and only if, ¬G isnot satisfiable.
• A first-order predicate logic sentence G is satisfiable if, and only if, ¬G isnot a tautology.
Consequence There is no algorithm that decides whether a first-order predi-cate logic sentence is a tautology.
Proof. Such an alogithm could be used to decide satisfiable of first-order pred-icate logic sentences. As satisfiability of first-order predicate logic sentences isundecidable, being a tautology is undecidable as well.
Logic in Computer Science 2012 15
Semantic consequence
Definition Let X be a set of sentences over a signature S and G be a sentenceover S. Then G follows from X (is a semantic consequence of X) if the followingimplication holds for every S-structure F :
If F |= E for all E ∈ X, then F |= G.
This is denoted byX |= G
Observations
• For any first-order sentence G: ∅ |= G if, and only if, G is a tautology. Since‘being a tautology’ is undecidable it follows that ‘being a logical con-sequence’ is undecidable: there is not algorithm that decides whetherX |= G.
• {G} |= F if, and only if, G→ F is a tautology.
Logic in Computer Science 2012 16
Examples
Let c be an individual constant and P,Q unary predicate symbols.
• We have:{P (c)} |= ∃xP (x).
• We have:{P (c), ∀x(P (x)→ Q(x))} |= ∃xQ(x).
• We have:{P (c), ∃x(P (x) ∧Q(x))} 6|= Q(c).
Logic in Computer Science 2012 17
Example
We can model the logical consequence “if my car is blue and all blue cars arefast, then my car is fast” as follows: take
• individual constant MyCar and
• unary predicates blue, fast, car.
Then
{blue(MyCar), car(MyCar), ∀x.((blue(x) ∧ car(x))→ fast(x))} |= fast(MyCar)
Logic in Computer Science 2012 18
F |= G versus X |= G
• Note that F |= G or F |= ¬G, for every sentence G. Thus, we havecomplete information about the domain of discourse. There are manyexamples where X 6|= G and X 6|= ¬G. We have incomplete information.
• F |= G means that G is true in the structure F . Checking whether this isthe case for finiteF coincides with querying relational database instancesand can be done very efficiently. It is also the underlying problem of modelchecking approaches to program verification: F is a representation of aprogram and one wants to know whether a property expressed by G istrue.
• X |= G means that G is true in every structure in which X is true. Thisis a much harder problem; in fact, it is undecidable. The research areaautomated reasoning develops methods which work in some cases. In-complete databases, ontologies, and theorem proving are applicationareas which are based on the problem of deciding X |= G.
Logic in Computer Science 2012 19
Logical equivalence
Definition Two first-order predicate logic sentences G1 and G2 over a signatureS are called logically equivalent if they are true in the same S-structures. Inother words, G1 and G2 are logically equivalent if the following holds for allS-structures F :
F |= G1 if and only if F |= G2.
This is denoted byG1 ≡ G2.
Observations
• G1 ≡ G2 if, and only if, {G1} |= G2 and {G2} |= G1;
• G1 ≡ G2 if, and only if, G1 ↔ G2 is a tautology.
Logic in Computer Science 2012 20
Examples
Let G and H be first-order predicate logic formulas.
• ¬∀x.G ≡ ∃x.¬G;
• ¬∃x.G ≡ ∀x.¬G;
• ∃x.G ≡ ¬∀x.¬G;
• ∀x.G ≡ ¬∃x.¬G;
• ∀x.G ∧ ∀x.H ≡ ∀x.(G ∧H);
• ∀x.G ∨ ∀x.H 6≡ ∀x.(G ∨H);
• ∃x.G ∨ ∃x.H ≡ ∃x(G ∨H);
• ∃x.G ∧ ∃x.H 6≡ ∃x.(G ∧H).
Logic in Computer Science 2012 21
Completeness of First-order Predicate Logic
Theorem There exists a computer program that outputs exactly the tautologiesof first-order predicate logic.
There are many distinct types of deduction systems that can be used to imple-ment such a program:
• Hilbert-style systems
• Natural deduction
• Sequent calculus
• Tableaux method
• Resolution
Logic in Computer Science 2012 22
Hilbert Style System
We assume that formulas are constructed using ∧, ¬, and ∀. We regard ∨,→,and ∃ as abbreviations:
• (G ∨D) = ¬(¬G ∧ ¬D);
• (G→ D) = (¬G ∨D);
• ∃x.G = ¬∀x.¬G.
We set(G→ D → F ) = (G→ (D → F ))
Intuitively, (G→ D → F ) means “If G and D are true, then F is true”.
We slightly generalise the notion of a tautology: a formula G is called a tautol-ogy if, and only if, the sentence ∀x1. . . . ∀xn.G is a tautology, where x1, . . . , xn
are the free varables of G.
Logic in Computer Science 2012 23
The Axioms (Part 1)
The following formulas are tautologies, for any first-order predicate logic formu-las D, G, and F :
(A1) ((G→ D → F )→ (G→ D)→ (G→ F ))
(A2) (G→ (D → G ∧D))
(A3) ((G ∧D)→ G)
(A4) ((G ∧D)→ D)
(A5) ((G→ ¬D)→ (D → ¬G))
Note that (A1)-(A5) “axiomatize the propositional part” of first-order predicatelogic.
Logic in Computer Science 2012 24
The Axioms (Part 2)
If t is a term, then we write G tx
for the formula obtained from G by replacingevery free occurrence of x in G by t. For example
• P (x) cx= P (c)
• ∀x.P (x) cx= ∀x.P (x)
The following formulas are tautologies for all first-order predicate logic formulasG and D:
(A6) ∀x.G→ G tx
(t not bound in G)
(A7) G→ ∀x.G (x not free in G)
(A8) (∀x.(G→ D)→ (∀x.G→ ∀x.D))
(A9) (∀y.Gyx→ ∀x.G) (y not in G)
Logic in Computer Science 2012 25
Two Rules
We take, in addition to the axioms (A1)-(A9), the following two rules:
(MP) G,G→ D/D;
(GE) G/∀x.G.
The first rules is called Modus Ponens. The second rule is called Generalisation.
Note
• if G and G→ D are tautologies, then D is a tautology
• if G is a tautology, then ∀x.G is a tautology.
Logic in Computer Science 2012 26
Completeness
We say that G is provable from (A1)-(A9) with (MP) and (GE) if, and only if, thereis a sequence G1, . . . , Gn such that for all Gi one of the following conditionsholds:
• Gi is of the form (A1) or (A2) or · · · or (A9);
• there exists j < i such that Gj = F and Gi = ∀x.F (for some F, x);
• there exist j, k < i such that Gj = F and Gk = F → Gi (for some F ).
Theorem A formula G is a tautology if, and only if, it is provable from (A1)-(A9)with (MP) and (GE).
Logic in Computer Science 2012 27
Arithmetic is incomplete
Recall thatSAR = {smaller, sum, prod, even, 0, 1, . . .}
The standard structure for SAR is given by
A = (DA, smallerA, sumA, prodA, evenA, 0A, 1A, . . .)
where
• DA is the set of natural numbers 0, 1, 2 . . .;
• smallerA = {(n,m) | n < m};
• sumA = {(n,m, k) | n + m = k};
• prodA = {(n,m, k) | n×m = k};
• evenA = {n | n is even };
• 0A = 0, 1A = 1, and so on.
Logic in Computer Science 2012 28
Incompleteness of Arithmetic
Theorem There does not exist an algorithm (computer program) that outputsexactly the first-order sentences G over SAR such that A |= G.
It follows, in particular, that there is no finitary calculus that captures the sen-tences that are true inA. Undecidability of arithmetic follows from incomplete-ness:
Theorem There does not exist an algorithm (computer program) that decideswhether for a first-order sentence G over SAR it holds that A |= G.
Logic in Computer Science 2012 29
Second-order Predicate Logic
Second-order predicate logic is an extension of first-order predicate logic whichhas, for every arity n > 0, variables X for relations of arity n. If X is a variableof arity n and t1, . . . , tn are terms, then
• X(t1, . . . , tn) is a second-order formula.
Then, if X is a variable and G is a second-order predicate logic formula,
• ∀X.G is a formula of second-order predicate logic.
Second-order logic is much more expressive than first-order logic. For example,one can formalise induction (we use, for simplicity, + instead of sum):
∀X.((X(0) ∧ (∀x.X(x)→ X(x + 1)))→ ∀y.X(y))
Theorem There does not exist an algorithm (computer program) that outputsexactly the tautologies of second-order logic.
Logic in Computer Science 2012 30