PART TWO PREDICATE LOGIC. Chapter Seven Predicate Logic Symbolization.
First-Order Predicate Logic (1)frank/teaching/comp118/lecture3.pdf · Predicate Logic Predicate...
Transcript of First-Order Predicate Logic (1)frank/teaching/comp118/lecture3.pdf · Predicate Logic Predicate...
First-Order Predicate Logic (1)
Predicate Logic (1)
• Atomic sentences and ground sentences
• S-structure and truth relation for ground sentences
• Atomic formulas and quantifier-free formulas
• S-interpretation and truth relation for quantifier-free formulas
• First-order predicate logic formulas
• Truth relation for first-order predicate logic formulas
Illustrations from databases and arithmetic.
Logic in Computer Science 2012 2
Predicate Logic
Predicate logic is an extension of propositional logic with more expressive power.It is needed because in many applications propositional atomic formulas can-not be regarded as atoms but should carry additional structure. Consider:
• p0: my car is blue.
• p1: blue cars are fast.
• p2: my car is fast.
Then ‘my car is fast’ should be a logical consequence of ‘my car is blue’ and‘blue cars are fast’. However,
{p0, p1} 6|= p2.
We introduce predicate logic to represent those (and many more) sentences.
Logic in Computer Science 2012 3
Ground Sentences and theirSemantics
Individual Constants
Individual constants are symbols that denote a fixed individual object. For ex-ample,
• we could use Peter as an individual constant to denote a particular per-son;
• we could use 2 as an individual constant to denote the number 2;
• but we could also use 2, 3, or Peter as an individual constant to denotethe number 2;
• we could use Liverpool as an individual constant to denote Liverpool;
• but we could also use UK as an individual constant to denote France.
We use lower case letters c, d, e etc and c1, c2 . . . , d1, d2 . . . as individual con-stants.
Logic in Computer Science 2012 5
Predicate Symbols
Predicate Symbols are used to denote a property of objects or a relation be-tween objects. Every predicate symbol comes with an arity ≥ 1. For example,
• integer could be used as a predicate of arity 1 to denote the property ofbeing an integer.
• country could be used as a predicate of arity 1 to denote the property ofbeing a country.
• younger could be used as a predicate of arity 2 to denote the relation“younger than” between living beings.
• has birthday could be used as a predicate of arity 2 to denote a relationbetween humans and dates: Peter has birthday on the 7th of February1999.
We use upper case letters P,Q,R etc and P1, P2 . . . , Q1, Q2 . . . as predicatesymbols. Predicates of arity 1,2,3 are also called unary, binary, and ternarypredicates.Logic in Computer Science 2012 6
Atomic Sentences
In predicate logic, the simplest kinds of claims are those made with a singlepredicate symbol followed by the appropriate number of individual constants.
Definition If P is a predicate symbol of arity n and c1, . . . , cn are individual con-stants, then P (c1, . . . , cn) is an atomic sentence.
Examples:
• If integer is a unary predicate symbol and 3 an individual constant, theninteger(3) is an atomic sentence stating that 3 is an integer (more precisely,the predicate integer applies to the individual object denoted by 3).
• If integer is a unary predicate symbol and Peter an individual constant,then the expression integer(Peter) is an atomic sentence stating that Peteris an integer (more precisely, the predicate integer applies to the individualobject denoted by Peter).
Logic in Computer Science 2012 7
Atomic Sentences: more examples
• If younger is a binary predicate symbol and Sue and Tom are individualconstants, then younger(Sue,Tom) is an atomic sentence that states thatSue is younger than Tom (more precisely, the object denoted by Sue is inthe relation denoted by younger to the object denoted by Tom).
• If has birthday is a binary predicate symbol and Tom and 7.11.1999 are indi-vidual constants, then has birthday(Tom, 7.11.1999) is an atomic sentencestating that Tom was born 7.11.1999 (more precisely, the object denotedby Tom is in the relation denoted by has birthday to the object denote by7.11.1999).
• If sum is a ternary predicate symbol and 3, 4 and 7 are individual constants,then sum(3, 4, 7) is an atomic sentence stating that the sum of 3 and 4 is7 (more precisely, the objects denoted by 3, 4, and 7 are in the relationdenoted by sum).
Logic in Computer Science 2012 8
Signature and Ground Sentences
A signature S is a set of predicate symbols (with their arities) and individualconstants.
The set of all ground sentences over S is defined inductively as follows:
• all atomic sentences using symbols from S only are ground sentences overS;
• if F and G are ground sentences over S, then (F∧G) is a ground sentenceover S;
• if F and G are ground sentences over S, then (F∨G) is a ground sentenceover S;
• if F is a ground sentence over S, then ¬F is a ground sentence over S;
• nothing else is a ground sentence over S.
Logic in Computer Science 2012 9
A signature for kinship relations
Our (very incomplete) signature SK for kinship relations consists of
• unary predicate symbols male and female;
• a binary predicate symbol parent of;
• two binary predicate symbols father of and mother of;
• a binary predicate grandparent of;
• binary predicates brother of and sister of.
• a binary predicate ancestor of.
If we want to give small illustrating examples, we sometimes work with SK0 =
{father of,mother of}.
Logic in Computer Science 2012 10
Kinship Relations
Using individual constants a, b, c . . ., we can now use ground sentences over thesignature SK ∪ {a, b, c . . .} to express the relation between concrete people,e.g.,
• a is the father of b, but b is not father of c:
(father of(a, b) ∧ ¬father of(b, c))
• a is a brother of b or e is a sister of f :
(brother of(a, b) ∨ sister of(e, f))
Logic in Computer Science 2012 11
Signature for arithmetic
The signature SAR for arithmetic consists of:
• individual constants: 0, 1, 2, . . .;
• a binary predicate symbol smaller;
• a ternary predicate symbol sum;
• a ternary predicate symbol prod;
• a unary predicate symbol even.
The following are ground sentences over SAR:
• (smaller(3, 4) ∧ ¬smaller(5, 3));
• even(21);
• (¬sum(3, 4, 12) ∧ prod(3, 4, 12)).
Logic in Computer Science 2012 12
Semantics
So far, ground sentences are just words without any meaning.
To give an interpretation for ground sentences, we require more than just thetruth values “true” and “false”. In this case, we require a “domain of discourse”in which the individual constants and predicate symbols are interpreted.
Depending on the signature (and, therefore, application) the domain of dis-course can play very different roles:
• If we do arithmetic, it can be the natural, rational, or real numbers (withcorresponding operations);
• Our domain of discourse can be a database instance (which we query orpose integrity constraints on);
• When doing program verification, we can represent a run (or all runs) of aprogram we want to verify as a domain of discourse;
• If we specify a terminology for medicine or biology, the domain of dis-course can be gene products, medications, treatments, etc.
Logic in Computer Science 2012 13
Semantics: S-structures
Let S be a signature. An S-structure F is an object of the form
F = (DF , (sF | s ∈ S)),
where
• DF is a non-empty set (the domain of discourse);
• for all predicate symbols P ∈ S of arity n: PF is a n-ary relation on DF ;for example, if P is a unary predicate, then PF ⊆ DF and if P is a binarypredicate, then PF ⊆ DF ×DF ;
PF is called the extension of P in F or the interpretation of P in F .
• for all individual constant symbols c in S: cF is an element of DF (in otherwords, we have cF ∈ DF).
cF is called the object denoted by c in F or the interpretation of c in F .
Logic in Computer Science 2012 14
Examples of SK-structures (kinship relations)
For simplicity we use SK0 = {father of,mother of}. Note that any
F = (DF , father ofF ,mother ofF)
with DF a nonempty set, father ofF ⊆ DF ×DF and mother ofF ⊆ DF ×DF
is an SK0-structure.
For example,
• F1 with DF1 = {1}, father ofF1 = {(1, 1)}, and mother ofF1 = {(1, 1)}. Inthis structure 1 is a father of himself and a mother of herself.
• F2 with DF2 = {a, b}, father ofF2 = {(a, b)}, and mother ofF2 = {(b, a)}.In this structure a is a father of b and b is a mother of a.
• F3 with DF3 = {1, 2, . . .}, father ofF3 = {(n + 1, n) | n > 0}, andmother ofF3 = ∅. In this structure, 2 is father of 1, 3 is a father of 2, andso on.
Logic in Computer Science 2012 15
SK0-structures extended with individual constants
To use names for individuals we have to extend the signature. For example,define the signature S by setting S = SK0 ∪ {a, b, c, d}. Then S-structures areof the form
F = (DF , father ofF ,mother ofF , aF , bF , cF , dF),
where, in addition, aF , bF , cF , dF ∈ DF .
We can take, for example,
F1 = (DF1, father ofF1,mother ofF1, aF1, bF1, cF1, dF1)
defined by
• DF1 = {1, 2, 3, 4, 5};
• father ofF1 = ∅;
• mother ofF1 = {(1, 2), (2, 3)};
• aF1 = 1; bF1 = 1; cF1 = 3; dF1 = 4.
Logic in Computer Science 2012 16
Database Tables as structures
Database tables can be converted, without loss of information, into a structure.Consider, for example, the following table for father of:
Tom BillJohn KatePeter Sue
and the following table for mother of:
Sue BillKate Tim
We can represent both tables using the signature
S = SK0 ∪ {Tom,Bill, John,Kate,Peter, Sue,Tim}
Logic in Computer Science 2012 17
Database Tables continued
and the S-structure
F = (DF , father ofF ,mother ofF ,TomF ,BillF , JohnF ,KateF ,PeterF , SueF ,TimF),
where
• DF = {Tom,Bill, John,Kate,Peter, Sue,Tim};
• father ofF = {(Tom,Bill), (John,Kate), (Peter, Sue)};
• mother ofF = {(Sue,Bill), (Kate,Tim)};
• TomF = Tom, BillF = Bill, JohnF = John, KateF = Kate, PeterF = Peter,SueF = Sue, TimF = Tim.
Logic in Computer Science 2012 18
Examples: SAR-structures
Assume the signature of arithmetic, SAR = {smaller, sum, prod, even, 0, 1, 2, . . .}is given. The standard structure for SAR is given by
A = (DA, smallerA, sumA, productA, evenA, 0A, 1A, 2A, . . .),
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, 2A = 2, and so on
Logic in Computer Science 2012 19
Examples: SAR-structures
There are many (even interesting!) non-standard SAR-structures. We give a verysimple (not very interesting) one:
B = (DB, smallerB, sumB, productB, evenB, 0B, 1B, 2B, . . .),
where
• DB = {a};
• smallerA = ∅;
• sumA = {(a, a, a)};
• prodA = ∅;
• evenA = {a};
• 0A = a, 1A = a, 2A = a, and so on
Logic in Computer Science 2012 20
Truth relation for ground sentences
Let S be a signature. We define what it means for a ground sentence G over Sto be true in an S-structure F , in symbols
F |= G.
The definition is by structural induction:
• for every atomic sentence P (c1, . . . , cn),
F |= P (c1, . . . , cn) if (cF1 , . . . , cFn ) ∈ PF
• F |= G1 ∧G2 if F |= G1 and F |= G2;
• F |= G1 ∨G2 if F |= G1 or F |= G2;
• F |= ¬G if not F |= G.
Logic in Computer Science 2012 21
Comments
It is very important not to confuse the consequence relation “X |= P ” betweena set X of formulas and a formula P with the truth-relation between a structureand a formula:
• In the first case, X |= P means that P follows from X;
• in the second case, F |= G means that G is true in F .
We write F 6|= G if it is not the case that F |= G.
Logic in Computer Science 2012 22
Examples
Let for S = SK0 ∪ {a, b, c, d} the S-structure F be defined by
DF = {1, 2, 3, 4, 5}, father ofF = ∅, mother ofF = {(1, 2), (2, 3)},
aF = 1, bF = 2, cF = 3, dF = 4
Then
• F1 |= mother of(a, b) because (aF , bF) = (1, 2) and (1, 2) ∈ mother ofF ;
• F1 |= mother of(b, c) because (bF , cF) = (2, 3) and (2, 3) ∈ mother ofF ;
• F1 6|= mother of(a, c) because (aF , cF) = (1, 3) and (1, 3) 6∈ mother ofF ;
• F1 6|= father of(a, b) because (aF , bF) = (1, 2) and (1, 2) 6∈ father ofF .
Logic in Computer Science 2012 23
Standard structure for SAR
Assume the signature of arithmetic, SAR = {smaller, sum, prod, even, 0, 1, 2, . . .}is given and A is the standard SAR-structure. Then
• A |= smaller(1, 9) because (1A, 9A) = (1, 9) and 1 < 9.
• A 6|= sum(1, 9, 8) because (1A, 9A, 8A) = (1, 9, 8) and 1 + 9 6= 8.
• etc.
Logic in Computer Science 2012 24
Satisfiable ground sentences
Definition A ground sentence G over S is satisfiable if there exists an S-structureF such that
F |= G
Examples
(1) Every atomic sentence P (c1, . . . , cn) is satisfiable. Let S = {P, c1, . . . , cn}and define an S-structure
F = (DF , PF , cF1 , . . . , cFn )
by setting
• DF = {c1, . . . , cn};
• PF = {(c1, . . . , cn)};
• cF1 = c1, cF2 = c2, . . ..
Then F |= P (c1, . . . , cn).Logic in Computer Science 2012 25
Examples (continued)
Another S-structure G satisfying P (c1, . . . , cn) is given by setting for
G = (DG, P G, cG1 , . . . , cGn)
• DF = {0};
• PF = {(0, . . . , 0)};
• cF1 = 0, cF2 = 0, . . ..
Then G |= P (c1, . . . , cn).
Logic in Computer Science 2012 26
Examples (continued)
(2) Every sentence of the form¬P (c1, . . . , cn) is satisfiable. Let S = {P, c1, . . . , cn}and define an S-structure
F = (DF , PF , cF1 , . . . , cFn )
by setting
• DF = {c1, . . . , cn};
• PF = ∅;
• cF1 = c1, cF2 = c2, . . ..
Then F |= ¬P (c1, . . . , cn).
(3) The sentence P (c) ∧ ¬P (c) is not satisfiable.
Logic in Computer Science 2012 27
Reduction to propositional logic
Observation The problem of checking satisfiability of ground sentences can bereduced to checking satisfiability of propositional formulas.
To see this, associate with every atomic sentence A = P (c1, . . . , cn) a propo-sitional atomic formula pA. For any ground sentence G, denote by Gpro theresulting propositional formula when all atomic sentences A in G are replacedwith pA. For example:
((Q(a) ∧R(a, b)) ∨ ¬Q(b))pro = ((pQ(a) ∧ pR(a,b)) ∨ ¬pQ(b))
Logic in Computer Science 2012 28
If G is satisfiable, then Gpro is satisfiable
Let S be the set of predicate symbols and individual constants that occur in G.
Assume that G is satisfiable.
Take an S-structure F with F |= G.
Define a propositional interpretation IF by setting for all pA:
IF(pA) =
{1 if F |= A0 if F 6|= A
Then one can show by structural induction for all ground sentences E over S:
IF(Epro) = 1 ⇔ F |= E.
Thus IF(Gpro) = 1 and we have shown that Gpro is satisfiable.
Logic in Computer Science 2012 29
If Gpro is satisfiable, then G is satisfiable
Now assume that Gpro is satisfiable.
Take a propositional interpretation I with I(Gpro) = 1;
Define an S-structure FI = (DFI , sFI | s ∈ S)) by setting
• DFI = {c | c is an individual symbol in S};
• cFI = c, for all individual symbols c ∈ S;
• for all c1, . . . , cn ∈ DFI and all P ∈ S of arity n:
(c1, . . . , cn) ∈ PFI ⇔ I(pP (c1,...,cn)) = 1
Then one can show by structural induction for all ground sentences E over S:
I(Epro) = 1 ⇔ FI |= E.
Thus FI |= G and we have shown that G is satisfiable.
Logic in Computer Science 2012 30
Quantifier-free Sentences and theirSemantics
Ground sentences are not enough
It follows that satisfiability of ground sentences can be checked using the tableaualgorithm introduced above. It also follows that, with the exception of a moresophisticated semantics, ground sentences do not add much to propositionallogic.
Many things one would like to express cannot be expressed using ground sen-tences. For example,
• a grandfather is a father of a father (terminology)
• the sum of any two numbers x and y equals the sum of y and x
• for every number there exists a larger prime number;
• the system cannot reach a deadlock state (verification);
• there are no two students with the same ID (database constraint).
• the query: “all children of Sue”.
Logic in Computer Science 2012 32
Fundamental Idea: add individual variables and quantifiers
Individual variables are placeholders for arbitrary objects from the domain ofdiscourse. In the same way as constant symbols, they appear as arguments inthe list following a predicate. In contrast to individual constants, however, wecan quantify over the domain of discourse using variables. Individual variablesare denoted by lower case letters x1, x2, . . ., but also x, y, u, v etc.
Example: sum(x, y, 3) is formula with two individual variables, x, y and one in-dividual constant, 3. Whatever the structure F is, if we do not fix values for thevariables x, y, we cannot say whether
F |= sum(x, y, 3).
Thus, in contrast to ground sentences, in this case the truth relation cannot bedefined without an additional assignment that says what the individual vari-ables denote.
Logic in Computer Science 2012 33
Terms and Atomic Formulas
Definition Let S be a signature. Then
• every individual variable is an S-term;
• every individual constant from S is an S-term;
• nothing else is an S-term.
Terms are typically denoted by t, t1, t2, . . ..
Definition If P is a predicate symbol of arity n and t1, . . . , tn are S-terms, thenP (t1, . . . , tn) is an atomic formula over S.
Logic in Computer Science 2012 34
Examples of Atomic Formulas
• all atomic sentences over S are atomic formulas over S;
• if x, y, z are individual variables, then sum(x, y, z) is an atomic formulaover SAR;
• if x, y are individual variables, then sum(x, 2, y) is an atomic formula overSAR;
• if x is an individual variable, then sum(x, 2, 5) is an atomic formula overSAR.
If the signature S is not important (or clear from the context) we omit S andsimply talk about terms and atomic formulas.
Logic in Computer Science 2012 35
Variable assignments and truth relation for atomic formulas
Given an S-structure F , a variable assignment a into F is a function from someset of individual variables to DF . The pair (F , a) is called an S-interpretation.
For every term t, we set
tF ,a =
{a(t) if t is a variable in the domain of atF if t is an individual constant
An atomic formula P (t1, . . . , tn) is true in the S-interpretation (F , a), in symbols
(F , a) |= P (t1, . . . , tn),
if all variables in t1, . . . , tn are in the domain of a and
(tF ,a1 , . . . , tF ,a
n ) ∈ PF
Logic in Computer Science 2012 36
Examples
Assume the signature of arithmetic, SAR = {smaller, sum, prod, even, 0, 1, 2, . . .}is given and A is the standard SAR-structure.
Let a(x) = 5 and a(y) = 10. Then
• (A, a) |= smaller(1, x) because (1A, a(x)) = (1, 5) and 1 < 5.
• (A, a) |= sum(x, 5, y) because (a(x), 5A, a(y)) = (5, 5, 10) and 5+5 = 10.
• (A, a) 6|= sum(1, 5, x) because (1A, 5A, a(x)) = (1, 5, 5) and 1 + 5 6= 5.
List all variable assignments b with
• (A, b) |= prod(x, x, 4).
Answer: there is only one such assignment, namely b(x) = 2. (However, forthe “standard” SAR-structure over the integers (positive and negative numbers)there are two assignments: b(x) = 2 and b(x) = −2.)
Logic in Computer Science 2012 37
Finding assignments as database query answering
We have seen that finite structures correspond to database instances. Recallthe following table for father of:
Tom BillJohn KatePeter Sue
and the following table for mother of:
Sue BillKate Tim
Consider the queries:
• “who is the father of Sue?”
• “who are the children of Sue?”
Logic in Computer Science 2012 38
Finding assignments as database query answering
Recall the structure F representing the two tables.
• The assignments a with
(F , a) |= father of(x, Sue)
give the answers of F to the query q(x) = father of(x, Sue). There is onesuch assignment, namely a(x) = Peter.
• The assignments a with
(F , a) |= mother of(Sue, x)
give the answers of F to the query q(x) = mother of(Sue, x). There is onesuch assignment, namely a(x) = Bill.
Logic in Computer Science 2012 39
Quantifier-free formulas
Let S be a signature.
The set of all quantifier-free formulas over S is defined inductively as follows:
• all atomic formulas using symbols from S only are quantifier free formulasover S;
• if F and G are quantifier-free formulas over S, then (F ∧G) is a quantifier-free formula over S;
• if F and G are quantifier-free formulas over S, then (F ∨G) is a quantifier-free formula over S;
• if F is a quantifier-free formula over S, then ¬F is a quantifier-free formulaover S;
• nothing else is a quantifier-free formula over S.
Logic in Computer Science 2012 40
Truth relation for quantifier-free formulas
We define what it means for a quantifier-free formula G to be true in an S-interpretation (F , a), in symbols
(F , a) |= G
Of course, we have to assume that all individual variables in G are in the do-main of a. The definition is by structural induction:
• For atomic formulas P (t1, . . . , tn), the relation (F , a) |= P (t1, . . . , tn) hasbeen defined already.
• (F , a) |= G1 ∧G2 if (F , a) |= G1 and (F , a) |= G2;
• (F , a) |= G1 ∨G2 if (F , a) |= G1 or (F , a) |= G2;
• (F , a) |= ¬G if not (F , a) |= G.
Logic in Computer Science 2012 41
Finding assignments as database query answering
Recall the structure F corresponding to the following table for father of:
Tom BillJohn KatePeter Sue
and the following table for mother of:
Sue BillKate Tim
The query “the fathers of Sue or Kate” can be formalised as: give all variableassignments a with
• (F , a) |= father of(x, Sue) ∨ father of(x,Kate)
Answer: a1 with a1(x) = John and a2 with a2(x) = Peter.
Logic in Computer Science 2012 42
Full First-order Predicate Logic
The existential quantifier ∃: informal introduction
Using quantifier-free formulas alone, we cannot talk about the existence of ob-jects. For example:
• state that there exists a number x such that x2 = 4.
• state that there is no x such that x2 = 5.
• formulate the query: “those who have a father”.
To represent such statements, we require the existential quantifier ∃. In predi-cate logic, for any formula P and variable v, we can form the formula
∃v.P
which, intuitively, means that there exists some v with P , or, in more detail, thereexists an object d in the domain of discourse, such that if v denotes d, then P istrue.
Logic in Computer Science 2012 44
Examples from natural language
• “Something is large” can be represented by ∃x.large(x);
• “Something is a cube” can be represented by ∃x.cube(x);
• “Something is a large cube” can be represented by
∃x.(large(x) ∧ cube(x))
• “Some cube is large” can be represented by:
∃x.(cube(x) ∧ large(x))
Observe that this representation coincides with that of “Something is alarge cube”!
Here we use large, cube as unary predicate symbols. Note that the meaning ofthe formulas above does not change if we use another variable such y, v, z,etc. instead of x.
Logic in Computer Science 2012 45
Examples from natural language
Consider “Liverpool FC has a manager who is male”. To represent it, we useLiverpoolFC as an individual constant and male as a unary predicate. To repre-sent “has a manager” we require a binary predicate symbol, we call it manages,and obtain
∃x.(manages(x, LiverpoolFC) ∧male(x))
Note that if we know the manager we do not need quantifiers. To represent“Rodgers manages Liverpool FC and is male” we can use the ground sentence
manages(Rodgers, LiverpoolFC) ∧male(Rodgers)
Logic in Computer Science 2012 46
Example: arithmetic
In the signature SAR,
• ∃x.prod(x, x, 4) states that there is a number x with x2 = 4;
• ¬∃x.prod(x, x, 5) states that there is no number x with x2 = 5;
• ¬∃x.(smaller(3, x) ∧ smaller(x, 4)) states that there is no number between3 and 4.
Logic in Computer Science 2012 47
Example: arithmetic
We have for the standard SAR-structure A:
• A |= ∃x.prod(x, x, 4) because there exists a variable assignment a suchthat (A, a) |= prod(x, x, 4). Namely, we can take a(x) = 2.
• A |= ¬∃x.prod(x, x, 5) because there is no variable assigment a such that(A, a) |= prod(x, x, 5).
Although ∃x.prod(x, x, 4) contains the variable x , we do not require a variableassignment to determine whether ∃x.prod(x, x, 4) is true in a structure. This is incontrast to prod(x, x, 4): in this case a variable assignment is required. We saythat x is bound in ∃x.prod(x, x, 4), but x is free in prod(x, x, 4).
Logic in Computer Science 2012 48
Example: database queries
The query “those who have a father” is formulated as
• ∃y.father of(y, x).
The intuitive meaning as a query is: output all variable assigments a(x) thatmake ∃y.father of(y, x) true. For example, in the structure F determined bythe database tables above we have
• (F , a) |= ∃y.father of(y, x) for a(x) = Bill because we can extend a to anew variable assignment a′ giving a value a′(y) to y for which (F , a′) |=father of(y, x). Namely, we set a′(y) = Tom.
• This holds for a(x) = Kate and a(x) = Sue as well.
• However, (F , a) 6|= ∃y.father of(y, x) for a(x) = Tom because we cannotextend a to a new variable assignment a′ giving a value a′(y) to y forwhich (F , a′) |= father of(y, x).
Logic in Computer Science 2012 49
Bound and free variables
∃y.father of(y, x) contains two individual variables. To determine whether thisformula is true inF we require a variable assignment for x but we do not requirea variable assignment for y.
In contrast, to determine whether father of(y, x) is true in F , we require a vari-able assignment for x and y. We say that y is bound in ∃y.father of(y, x) and x
is free in ∃y.father of(y, x) Note that x and y are free in father of(y, x)
In the database context, x is also called an answer variable.
Logic in Computer Science 2012 50
The universal quantifier ∀: informal introduction
Using quantifier-free formulas alone, we cannot talk about all objects. For ex-ample:
• state the argument that if my car is blue and all blue cars are fast, thenmy car is fast.
• state that a relation is symmetric.
• state that every undergraduate student is a student.
To represent such statements, we require the universal quantifier ∀. In predicatelogic, for any formula P and variable v, we can form the formula
∀v.P
which, intuitively, means that P holds for all v, or, in more detail, for all objects dfrom the domain of discourse, if v denotes d, then P is true.
Logic in Computer Science 2012 51
→ and↔
Very often, the universal quantifier is used to express “All A’s are B’s”. The corre-sponding predicate logic sentence is
∀x.(A(x)→ B(x))
where we use→ as an abbreviation. For any two formulas P and Q:
(P → Q) = (¬P ∨Q)
Similarly,↔ is used as an abbreviation. For any two formulas P and Q:
(P ↔ Q) = ((P → Q) ∧ (Q→ P ))
Logic in Computer Science 2012 52
Examples from natural language
• “Every undergraduate student is a student” can be represented by
∀x.(undergraduatestudent(x)→ student(x))
• “All cubes are small” can be represented by ∀x.(cube(x)→ small(x));
• “Every player for Liverpool FC is a good player” can be represented by
∀x.(plays for(x, LiverpoolFC)→ good(x))
• “All blue cars are fast” can be represented by
∀x.((blue(x) ∧ car(x))→ fast(x)).
• “The binary relation R is symmetric” is represented by
∀x.∀y.(R(x, y)→ R(y, x)).
Logic in Computer Science 2012 53
Syntax of first-order predicate logic: formal definition
Let S be a signature. Then:
• every atomic formula over S is a formula over S;
• if F and G are formulas over S, then (F ∧G) is a formula over S;
• if F and G are formulas over S, then (F ∨G) is a formula over S;
• if F is a formula over S, then ¬F is a formula over S;
• if F is a formula over S and v an individual variable, then ∀v.F is a formulaover S and any occurrence of v in F is said to be bound;
• if F is a formula over S and v an individual variable, then ∃v.F is a formulaover S and any occurrence of v in F is said to be bound;
• nothing else is a formula over S.
Logic in Computer Science 2012 54
More Examples: The Four Aristotelian Forms
• “All P’s are Q’s”:∀x.(P (x)→ Q(x))
• “Some P’s are Q’s”:∃x.(P (x) ∧Q(x))
• “No P’s are Q’s”:¬∃x.(P (x) ∧Q(x))
• “Some P’s are not Q’s”:
∃x.(P (x) ∧ ¬Q(x))
Logic in Computer Science 2012 55
Examples
We represent “A grandfather is a father of a father”. First introduce a binarypredicate symbol father of and a unary predicate symbol grandfather. Then wecan represent this assertion by stating:
∀x.(grandfather(x)↔ ∃y.∃z.(father of(x, y) ∧ father of(y, z))
Alternatively, we could introduce a binary predicate symbol grandfather of andfirst “define” the relation grandfather as follows:
∀x∀y.(grandfather of(x, y)↔ ∃z.(father of(x, z) ∧ father of(z, y))
Afterwards we state that a grandfather is somebody who is a grandfather ofsomebody:
∀x.(grandfather(x)↔ ∃y.grandfather of(x, y))
Logic in Computer Science 2012 56
Example
To represent “for every number there exists a larger prime number” using thesignature SAR we first introduce an abbreviation for “prime number”: prime(y)
stands for
¬prod(y, y, y) ∧ ¬∃z1∃z2.(prod(z1, z2, y) ∧ smaller(z1, y) ∧ smaller(z2, y))
and then represent the assertion using:
∀x.∃y.(smaller(x, y) ∧ prime(y))
Logic in Computer Science 2012 57
Truth relation: formal definition
For an S-interpretation (F , a) and formula G over S we define what it meansfor G to be true in (F , a), in symbols
(F , a) |= G.
We assume that all unbound individual variables in G are in the domain of a.
The definition is by structural induction. First the boring part:
• For atomic formulas P (t1, . . . , tn), (F , a) |= P (t1, . . . , tn) has been de-fined already.
• (F , a) |= ¬G if and only if (F , a) 6|= G;
• (F , a) |= G1 ∧G2 if and only if (F , a) |= G1 and (F , a) |= G2;
• (F , a) |= G1 ∨G2 if and only if (F , a) |= G1 or (F , a) |= G2;
Logic in Computer Science 2012 58
the interesting part
• (F , a) |= ∀v.G if and only if (F , a′) |= G for every assignment a′ thatcoincides with a for all individual variables distinct from v.
Thus, we require G to be true for all possible values of v and we are notallowed to change the value of any variable distinct from v.
• (F , a) |= ∃v.G if and only if (F , a′) |= G for some assignment a′ thatcoincides with a for all individual variables distinct from v.
Thus, we require G to be true for at least one value of v and we are notallowed to change the value of any variable distinct from v.
Logic in Computer Science 2012 59