# Artiﬁcial Intelligence

Artiﬁcial Intelligence 5. First-Order Logic

Lars Schmidt-Thieme

Information Systems and Machine Learning Lab (ISMLL) Institute of Economics and Information Systems & Institute of Computer Science University of Hildesheim http://www.ismll.uni-hildesheim.de
Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on Artiﬁcial Intelligence, summer term 2008

1/19

Artiﬁcial Intelligence

1. Introduction 2. Syntax 3. Semantics 4. Example 5. Conclusion

Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on Artiﬁcial Intelligence, summer term 2008

1/19

” How can we see that A. Course on Artiﬁcial Intelligence. as well as n-ary functions. Germany. – We can also use the connectives we already know from propositional logic. University of Hildesheim. Lars Schmidt-Thieme. Introduction What is ﬁrst-order logic? Think about expressing these phrases in propositional logic: A := “Socrates is human. Socrates is mortal. It is read “for all”. – H and M are unary relations.” B := “All humans are mortal. there are also relations with other arities. Course on Artiﬁcial Intelligence. In ﬁrst-order logic. and M for “is mortal”. Lars Schmidt-Thieme. Information Systems and Machine Learning Lab (ISMLL). Germany. summer term 2008 1/19 Artiﬁcial Intelligence / 1.” C := “Thus. there is the existential quantiﬁer.Artiﬁcial Intelligence / 1. C are related? First-order logic is richer than propositional logic: H (a) ∀xH (x) → M (x) M (a) where a stands for “Socrates”. – a is a constant. Constants denote speciﬁc elements of an underlying set. summer term 2008 2/19 . – ∀ is the all quantiﬁer. Introduction What is ﬁrst-order logic? H (a) ∀xH (x) → M (x) M (a) So what do we have here? – x is a variable. B. Variables denote arbitrary elements (objects) of an underlying set. H for “is human”. In addition to the all quantiﬁer. read “there exists”. Information Systems and Machine Learning Lab (ISMLL). University of Hildesheim.

} be the set of constant symbols. University of Hildesheim. . S. . – Let {a. . Constant symbols can be seen as 0-ary function symbols. Germany. – {x. Syntax 3. . } be the set of function symbols. Every function symbol has a given arity. . Course on Artiﬁcial Intelligence. c. Example 5. y. . . University of Hildesheim. Information Systems and Machine Learning Lab (ISMLL). } be the set of relation symbols. P2. a1. h. . z. Semantics 4. Conclusion Lars Schmidt-Thieme. b. summer term 2008 3/19 Artiﬁcial Intelligence / 2. Lars Schmidt-Thieme. f2. Introduction 2. Germany. . . . . R. Course on Artiﬁcial Intelligence.Artiﬁcial Intelligence 1. Sometimes we write P n to denote that P has arity n. summer term 2008 3/19 . g. . x1. . } be the set of variable symbols. . . Every relation symbol (predicate) has a given arity. . P1. – {P. . . . Syntax Syntax: Symbols – Let {f. . Sometimes we write f n to denote that f has arity n. . x2. f1. . . a2. Information Systems and Machine Learning Lab (ISMLL).

. ∃. b as well. (F1) If φ is a formula then so is (¬φ). tn are terms. soccer) ∧ Likes(stef f en. (T2) If f is an n-ary function symbol and t1. Examples: – a is a term. tn are terms. (F2) If φ and ψ are formulas then so is (φ ∧ ψ ). →. ∨. We deﬁne ∨. and ↔ the same way as in propositional logic. – f 1(f (f (a))) is a term. . . y ) is a formula and x(P (z )∃) is not. (F0) Every atomic formula is a formula. Syntax Syntax: Formulas An atomic formula has the form t1 = t2 or R(t1. – P (x) and P (x) ∨ Q(x) are not terms. tn) is an n-ary relation symbol and t1. Information Systems and Machine Learning Lab (ISMLL). kallias – succ(root) – Likes(zeno. tn) is also a term.Artiﬁcial Intelligence / 2. University of Hildesheim. Unnecessary brackets can be left out as in propositional logic. ↔ Examples: – P (x) and P (x) ∨ Q(x) are formulas if P and Q are unary. Germany. . Germany. . . ∀. Precedence: ¬. socrates. For any formula φ. . x) is not a term. . . Course on Artiﬁcial Intelligence. Course on Artiﬁcial Intelligence. More meaningful names for the symbols: – aristotle. (F3) If φ is a formula. . Likes(stef f en. – ∀yP (x. summer term 2008 5/19 . – succ(succ(succ(0))) = 3 is a formula. – f 3(a. (∀xφ) and (¬∃x¬φ) are interchangeable. . Information Systems and Machine Learning Lab (ISMLL). summer term 2008 4/19 Artiﬁcial Intelligence / 2. . then f (t1. →. . hockey ) – succ(succ(succ(0))) Lars Schmidt-Thieme. Lars Schmidt-Thieme. (T1) Every variable or constant symbol is a term. University of Hildesheim. Syntax Syntax: Terms A term is a logical expression that refers to an object. . then so is (∃xφ) for any variable x. hockey ). ∧. – f (a) is a term if f is unary. .

bnd(φ)? A sentence of ﬁrst-order logic is a formula having no free variables.Artiﬁcial Intelligence / 2. Course on Artiﬁcial Intelligence. Example: In ∀yR(x. Germany. y ). Syntax Syntax: Subformulas Let φ be a formula of ﬁrst-order logic. then f ree(φ) is the set of all variables occurring in φ. Lars Schmidt-Thieme. and – if φ = ∃xψ . or θ is a subformula of ψ2. summer term 2008 7/19 . We inductively deﬁne what it means for θ to be a subformula of φ as follows: – If φ is atomic. Germany. Lars Schmidt-Thieme. then f ree(φ) = f ree(ψ ). – If φ has the form ψ1 ∧ ψ2. University of Hildesheim. Information Systems and Machine Learning Lab (ISMLL). How would you deﬁne the set of bound variables of φ. then θ is a subformula of φ if and only if θ = φ. – if φ = ψ ∧ θ. Course on Artiﬁcial Intelligence. then θ is a subformula of φ if and only if θ = φ or θ is a subformula of ψ . then θ is a subformula of φ if and only if θ = φ or θ is a subformula of ψ . x is free. We deﬁne f ree(φ) inductively as follows: – If φ is atomic. then f ree(φ) = f ree(ψ ) ∪ f ree(θ). Information Systems and Machine Learning Lab (ISMLL). Syntax Syntax: Free variables The free variables of a formula are those variables occurring in it that are not quantiﬁed. University of Hildesheim. For any ﬁrst-order formula φ. summer term 2008 6/19 Artiﬁcial Intelligence / 2. – if φ = ¬ψ . then θ is a subformula of φ if and only if θ = φ or θ is a subformula of ψ1. – If φ has the form ∃xψ . – If φ has the form ¬ψ . let f ree(φ) denote the set of free variables of φ. but y is bound by ∀y . then f ree(φ) = f ree(ψ ) − {x}.

c}. relation. – V = {f 1. summer term 2008 8/19 Artiﬁcial Intelligence / 3. IN could interpret f (x) as x + 1. A V -structure M = (U. I ) consists of a nonempty underlying set U (the universe) along with an interpretation I of V . summer term 2008 8/19 . University of Hildesheim. R2. Introduction 2. IZ could interpret f (x) as x2. IN) The universe is the set of natural numbers N. y ) as x < y . Z = (Z. Information Systems and Machine Learning Lab (ISMLL). Course on Artiﬁcial Intelligence. and c as 0. Germany. Lars Schmidt-Thieme. Conclusion Lars Schmidt-Thieme. Semantics Semantics: Vocabularies. R(x. and c as 3. Example 5. y ) as x < y . and – a subset of U n to each n-ary relation in V . Semantics 4. Course on Artiﬁcial Intelligence. Let V be a vocabulary. and constant symbols. – a function from U n to U to each n-ary function in V . Germany. N = (N. Examples: – V = {f 1. R(x.Artiﬁcial Intelligence 1. Syntax 3. University of Hildesheim. Information Systems and Machine Learning Lab (ISMLL). c}. IZ) The universe is the set of integers Z. structures and interpretations A vocabulary is a set of function. R2. An interpretation I of V assigns: – an element of U to each constant symbol in V .

Germany. University of Hildesheim. ·. IN). University of Hildesheim. . Then R = (R. and – VM (t) = IM (f )(VM (t1). Course on Artiﬁcial Intelligence. Example: Var = {+. Example: V = {f 1. Course on Artiﬁcial Intelligence. Information Systems and Machine Learning Lab (ISMLL). . 1} is the vocabulary of arithmetic. tn). If M is a V -structure. R2. interpretation IN as before What is the value of the term t = f (f (c))? VN(f (f (c))) = IN(f )(VN(f (c))) = IN(f )(IN(f )(VN(c))) = IN(f )(IN(f )(IN(c))) = IN(f )(IN(f )(0)) = IN(f )(1) =2 Lars Schmidt-Thieme. 0. summer term 2008 9/19 Artiﬁcial Intelligence / 3. R |= ∀x∃y (1 + x · x = y ) What about ∀y ∃x(1 + x · x = y )? Lars Schmidt-Thieme. then we say M models φ and write M |= φ. .Artiﬁcial Intelligence / 3. . summer term 2008 10/19 . . if t = f n(t1. then each V -sentence φ is either true or false in M. If φ is true in M. IR) is an Var -structure if IR is a interpretation of Var . Semantics Semantics: The value of terms We deﬁne the value VM (t) ∈ U of a term t inductively as – VM (t) = IM (t). relation. . Semantics Semantics: V -formulas and V -sentences Let V be a vocabulary. VM (tn)). N = (N. c}. and constant symbol is in V . Germany. A V -formula is formula in which every function. A V -sentence is a V -formula that is a sentence. Information Systems and Machine Learning Lab (ISMLL). . if t is a constant symbol. .

0. Any structure is an expansion of itself. ·. I ) cannot be an expansion of M . tn) iff. Germany. University of Hildesheim. . then we say that M is a reduct of M . If M is an expansion of M . Semantics Semantics: The value of formulas We deﬁne M |= φ by induction: –M –M –M –M –M |= t1 = t2 if and only if V (t1) = V (t2). |= Rn(t1. Lars Schmidt-Thieme. |= φ1 ∧ φ2 iff. −. ·. . I ) if both I and I interpret the symbols +. summer term 2008 11/19 Artiﬁcial Intelligence / 3. Semantics Semantics: Vocabulary/structure expansions and reducts An expansion of a vocabulary V is a vocabulary containing V as a subset. . University of Hildesheim. . . MC |= φ(c) for some constant c ∈ V (M ) . <. IC ) is the expansion of M = (UM . <. Lars Schmidt-Thieme. (VM (t1). Course on Artiﬁcial Intelligence. |= ¬φ iff. and |= ∃xφ(x) iff. Germany. VM (tn)) ∈ IM (Rn). M does not model φ. Information Systems and Machine Learning Lab (ISMLL). Course on Artiﬁcial Intelligence. −. and 1 in the usual way. Examples: The {+. I ) is an expansion of the Var -structure M = (R. I ) to a V (M )-structure where IC interprets each cm as the element m. . 0. ·. summer term 2008 12/19 . Information Systems and Machine Learning Lab (ISMLL). . V (M ) = V ∪ {cm|m ∈ UM } MC = (UM . A structure M is an expansion of the V -structure M if M has the same universe and interprets the symbols of V in the same way as M . 1}-structure M = (Q. . 1}-structure M = (R.Artiﬁcial Intelligence / 3. 0. both M |= φ1 and M |= φ2. A {+.

unknown to the agent. summer term 2008 13/19 . Information Systems and Machine Learning Lab (ISMLL). unknown to the agent. – the agent starts in (1.4). Example Back to the Silly Example Toy example by Gregory Yob (1975). – some pits are located at random tiles. Germany.1) to (4. adapted by our textbook. – the beast Wumpus sits at a random tile. University of Hildesheim. summer term 2008 13/19 Artiﬁcial Intelligence / 4. he will be trapped. – if the agent enters the tile of the Wumpus. – a pile of gold sits at another random tile. Course on Artiﬁcial Intelligence. unknown to the agent. Conclusion Lars Schmidt-Thieme.Artiﬁcial Intelligence 1. Syntax 3. Information Systems and Machine Learning Lab (ISMLL). 4 Stench Bree z e PIT Bree z e 3 Stench Gold PIT Bree z e 2 Stench Bree z e 1 START Bree z e PIT Bree z e 1 2 3 4 Lars Schmidt-Thieme.1). Example 5. University of Hildesheim. tiles numbered (1. Germany. Course on Artiﬁcial Intelligence. he will be eaten. – if the agent enters a pit. Introduction 2. Semantics 4. – 4 × 4 grid.

x. . Information Systems and Machine Learning Lab (ISMLL). . Information Systems and Machine Learning Lab (ISMLL). B (x. y ) tile x. 4 – binary relations symbols P.4 ¬Wx. . 4 x. S Meaning of the predicates: P (x. . . how stench arises: (16 formulas) Sx. 4). Germany. y = 1. y contains a pit (x. y. y = 1. Sx. ∨ W4. . Wx.y tile x. . W.Artiﬁcial Intelligence / 4. . . . start is save: (2 formulas) ¬P1. y ) tile x. W (x. y = 1. Germany. Course on Artiﬁcial Intelligence. University of Hildesheim.1 ∨ W1. y = 1. y contains a breeze (x. 2.y ∨ Wx.y+1.1 x.2 ∨ . 4 Artiﬁcial Intelligence / 4. y contains a breeze.y+1. . University of Hildesheim.y tile x. . y contains stench. y ) tile x. . Course on Artiﬁcial Intelligence. y ) tile x.y tile x. Bx. Example Encoding in propositional logic 64 variables: Px. there is exactly one Wumpus: (121 formulas) W1. . .y ↔ Px−1. how breeze arises: (16 formulas) Bx. y contains the Wumpus (x. . . B. 4.y ∨ Px. .y ∨ Wx+1. y contains a pit. . .1. y contains the Wumpus. x = x or y = y Lars Schmidt-Thieme. Lars Schmidt-Thieme.y ↔ Wx−1. 4). x . summer term 2008 15/19 .y . y = 1. . . 3.y−1 ∨ Px. . . . .y−1 ∨ Wx. y = 1. .y ∨ ¬Wx .y tile x. 4). y = 1. . summer term 2008 14/19 ¬W1. S (x. 4). Example Encoding in ﬁrst logic (1/2) Vocabulary: – constants 1. . y contains stench (x. .y ∨ Px+1.

encode time steps. Course on Artiﬁcial Intelligence. Information Systems and Machine Learning Lab (ISMLL). Germany. Lars Schmidt-Thieme. Course on Artiﬁcial Intelligence. y ) ↔ P (x − 1. Germany. y − 1) ∨ P (x. Introduction 2. y ) → ∀x ∀y W (x . 1) ∧ ¬W (1. summer term 2008 16/19 Artiﬁcial Intelligence 1. y + 1) there is exactly one Wumpus: W (x.Artiﬁcial Intelligence / 4. y ) ∨ P (x. Information Systems and Machine Learning Lab (ISMLL). summer term 2008 17/19 . University of Hildesheim. Example 5. Syntax 3. Conclusion Lars Schmidt-Thieme. Example Encoding in ﬁrst logic (2/2) start is save: how breeze arises: ¬P (1. y ) → (x = x ∧ y = y ) Further possibilities: Encode actions as functions. 1) ∀x∀yB (x. Semantics 4. University of Hildesheim. y ) ∨ P (x + 1.

Lars Schmidt-Thieme. Germany. the relation named by the predicate holds between the objects named by the terms. – An atomic formula consists of a relation symbol applied to one or more terms. (not covered in this course) Lars Schmidt-Thieme. y ) ∧ P (y. Quantiﬁers allow the expression of general rules. the truth of a formula is determined. – Constant symbols name objects. a representation language far more powerful than propositional logic. Complex terms apply function symbols to terms to name an object. Information Systems and Machine Learning Lab (ISMLL). expressive. Course on Artiﬁcial Intelligence. x) → S (P ) – Typed/intuitionistic/default/relevance logics – . Complex formulas use connectives just like propositional logic. and function symbols name functions. – Given a V -structure. Germany.Artiﬁcial Intelligence / 5. summer term 2008 17/19 Artiﬁcial Intelligence / 5. Which other kind of logics exist? – Temporal logic: Gφ → Xφ – Description logic: C ⊆ D – Modal logic: p → p – Higher-order predicate logic: ∀P ∀x∀yP (x. Conclusion Summary We introduced ﬁrst-order logic.. – Knowledge representation should be declarative. University of Hildesheim. summer term 2008 18/19 . Information Systems and Machine Learning Lab (ISMLL). relation symbols (predicates) name properties and relations. and unambiguous. University of Hildesheim.. Course on Artiﬁcial Intelligence. it is true iff. context-independent. compositional. Conclusion Outlook Next lesson: Inference in ﬁrst-order predicate logic.

Information Systems and Machine Learning Lab (ISMLL).Artiﬁcial Intelligence / 5. Wolfgang Thomas: Einführung in die mathematische Logik – Uwe Schöning: Logik für Informatiker – Stuart Russell. Peter Norvig: Artiﬁcial Intelligence. University of Hildesheim. A Modern Approach Lars Schmidt-Thieme. Jörg Flum. Germany. Conclusion Literature – Shawn Hedman: A First Course in Logic – Heinz-Dieter Ebbinghaus. Course on Artiﬁcial Intelligence. summer term 2008 19/19 .