Dulranga's Notes
Semester 3Artificial Intelligence

First Order Logic

Propositional Logic cannot express statements like "all men are mortal" or relationships between real world objects since propositions are binary.

First-order logic (also called predicate logic) adds:

  • Objects (things in the world)
  • Relations/predicates (properties of and links between objects)
  • Functions
  • Quantifiers ("for all", "there exists")

Syntax

ComponentMeaningExamples
ConstantsSpecific objectsSocratesSocrates, AliceAlice, 22
VariablesPlaceholders for objectsx,y,zx, y, z
FunctionsMap objects to objectsFatherOf(x)FatherOf(x), Plus(x,y)Plus(x,y)
PredicatesProperties/relations (true or false)Man(x)Man(x), Loves(x,y)Loves(x,y)
ConnectivesCombine sentences¬,∧,∨,→,↔\neg, \land, \lor, \rightarrow, \leftrightarrow
QuantifiersScope over variables∀,∃\forall, \exists
EqualitySame objectx=yx = y

Quantifiers

Universal: ∀\forall("for all")

∀x  (Man(x)→Mortal(x))\forall x\; (Man(x) \rightarrow Mortal(x))

"Every man is mortal." A ∀y\forall y over a finite domain is just "AND" over every yy. So placing why in or outside the

∀y (dy→M)  =  (d1→M)    ∧    (d2→M)\forall y\,(d_y \rightarrow M) \;=\; (d_1 \rightarrow M) \; \boxed{ \;\land\; } \; (d_2 \rightarrow M) (∀y dy)→M  =  (d1    ∧    d2)→M\big(\forall y\,d_y\big) \rightarrow M \;=\; (d_1 \; \boxed{ \;\land\; } \; d_2) \rightarrow M

Existential: ∃\exists ("there exists")

∃x  (Student(x)∧Smart(x))\exists x\; (Student(x) \land Smart(x))

"Some student is smart." The ∃\exists case mirrors the ∀\forall case. ∃\exists over a finite domain is a big OR.

∃y (dy→M)  =  (d1→M)    ∨    (d2→M)\exists y\,(d_y \rightarrow M) \;=\; (d_1 \rightarrow M) \; \boxed{ \;\lor\; } \; (d_2 \rightarrow M) (∃y dy)→M  =  (d1    ∨    d2)→M\big(\exists y\,d_y\big) \rightarrow M \;=\; (d_1 \; \boxed{ \;\lor\; } \; d_2) \rightarrow M
Rule of thumb:

∀\forall goes with →\rightarrow, and ∃\exists goes with ∧\land.

Order matters with mixed quantifiers

  • ∀x ∃y  Loves(x,y)\forall x\, \exists y\; Loves(x,y): everybody loves someone (possibly different people).
  • ∃y ∀x  Loves(x,y)\exists y\, \forall x\; Loves(x,y): there's one person everybody loves.

The second statement is much stronger than the first.

Quantifiers Negation

¬∀x P(x)≡∃x ¬P(x)¬∃x P(x)≡∀x ¬P(x)\neg\forall x\,P(x) \equiv \exists x\,\neg P(x) \\ \\ \neg\exists x\,P(x) \equiv \forall x\,\neg P(x)

Free vs. Bound Variables

In ∀x (P(x)→Q(x,y))\forall x\, (P(x) \rightarrow Q(x,y)):

  • xx is bound, because a quantifier captures it.
  • yy is free, because nothing binds it.

A formula with no free variables is a sentence. Only sentences have definite truth values.

Horn Clauses

A Horn Clause is a clause with ==🟢at most== one positive literal in the clause.

¬A∨¬B∨C\neg A \lor \neg B \lor C

Definition

$$ Ex:

\neg A \lor \neg B \lor C ;;\equiv;; (A \land B) \implies C

## Examples - **Every professor teaches some course.** We need to talk about every professors from the everything domain. So need to reframe it like this: *For everything in domain, **if** it is a professor, **then** there is a course that he teaches.*

\forall p,\Big(Prof(p) \rightarrow \exists c,\big(Course(c) \land Teaches(p,c)\big)\Big)

Implicationcanbeusedforifthen.−∗∗Astudentpassesacourseonlyiftheystudy.∗∗Thisneedstobetrueforstudentswhodidnotstudy,andstudentswhodidnotpassanycourses.Soreframeitas,"Ifthereisastudent,whopassedacourse,thenhemusthavestudied" Implication can be used for if then. - **A student passes a course only if they study.** This needs to be true for students who did not study, and students who did not pass any courses. So reframe it as, "If there is a student, who passed a course, then he must have studied"

\forall s,\forall c,\Big(\big(Student(s) \land Course(c) \land Passes(s,c)\big) \rightarrow Studies(s)\Big)

−Thereisacoursethateverystudenttakes.Theseisacourse,ifsomeoneinthedomainisanstudent,hetakesthatcourse- There is a course that every student takes. These is a course, if someone in the domain is an student, he takes that course

\exists c ; \forall s , \big(Student(s)\land Course(c) \to Takes(s,c) \big)

−∗∗Onlyprofessorsteachcourses.∗∗ifsomeonefromthealldomainteachesacourse,thenitmustbeaprofessor- **Only professors teach courses.** if someone from the all domain teaches a course, then it must be a professor

\forall x,\exists c,\Big(\big(Course(c) \land Teaches(x,c)\big) \rightarrow Prof(x)\Big) \qquad (Wrong)

Here $\exists c$ is only belongs to the whole. So if we pick $c=\text{Book}$, $Course(c)$ is wrong, so whole implication is true. So parentheses are very important.

\forall x,\Big(\exists c,\big(Course(c) \land Teaches(x,c)\big) \rightarrow Prof(x)\Big) \qquad (Correct)

If we need the $c$ to be scoped for the whole expression, we need to account for all $c$

\forall x,\forall c,\Big(\big(Course(c) \land Teaches(x,c)\big) \rightarrow Prof(x)\Big) \qquad (Correct)

−∗∗Everypersonislovedbysomebodyunlesshe/sheiscruel.∗∗AunlessBmeans,ifnotB,thenAso,ifheisnotcruel,thenheislovedbysomebody- **Every person is loved by somebody unless he/she is cruel.** A unless B means, if not B, then A so, if he is not cruel, then he is loved by somebody

\forall x,\Big(\big(Person(x) \land \neg Cruel(x)\big) \rightarrow \exists y,\big(Person(y) \land Loves(y,x)\big)\Big)

On this page