Semester 3 Artificial 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")
Component Meaning Examples Constants Specific objects S o c r a t e s Socrates S ocr a t es , A l i c e Alice A l i ce , 2 2 2 Variables Placeholders for objects x , y , z x, y, z x , y , z Functions Map objects to objects F a t h e r O f ( x ) FatherOf(x) F a t h er O f ( x ) , P l u s ( x , y ) Plus(x,y) P l u s ( x , y ) Predicates Properties/relations (true or false) M a n ( x ) Man(x) M an ( x ) , L o v e s ( x , y ) Loves(x,y) L o v es ( x , y ) Connectives Combine sentences ¬ , ∧ , ∨ , → , ↔ \neg, \land, \lor, \rightarrow, \leftrightarrow ¬ , ∧ , ∨ , → , ↔ Quantifiers Scope over variables ∀ , ∃ \forall, \exists ∀ , ∃ Equality Same object x = y x = y x = y
∀ x ( M a n ( x ) → M o r t a l ( x ) ) \forall x\; (Man(x) \rightarrow Mortal(x)) ∀ x ( M an ( x ) → M or t a l ( x ))
"Every man is mortal."
A ∀ y \forall y ∀ y over a finite domain is just "AND " over every y y y . So placing why in or outside the
∀ y ( d y → M ) = ( d 1 → M ) ∧ ( d 2 → M ) \forall y\,(d_y \rightarrow M) \;=\; (d_1 \rightarrow M) \; \boxed{ \;\land\; } \; (d_2 \rightarrow M) ∀ y ( d y → M ) = ( d 1 → M ) ∧ ( d 2 → M )
( ∀ y d y ) → M = ( d 1 ∧ d 2 ) → M \big(\forall y\,d_y\big) \rightarrow M \;=\; (d_1 \; \boxed{ \;\land\; } \; d_2) \rightarrow M ( ∀ y d y ) → M = ( d 1 ∧ d 2 ) → M
∃ x ( S t u d e n t ( x ) ∧ S m a r t ( x ) ) \exists x\; (Student(x) \land Smart(x)) ∃ x ( S t u d e n t ( x ) ∧ S ma r t ( x ))
"Some student is smart."
The ∃ \exists ∃ case mirrors the ∀ \forall ∀ case. ∃ \exists ∃ over a finite domain is a big OR .
∃ y ( d y → M ) = ( d 1 → M ) ∨ ( d 2 → M ) \exists y\,(d_y \rightarrow M) \;=\; (d_1 \rightarrow M) \; \boxed{ \;\lor\; } \; (d_2 \rightarrow M) ∃ y ( d y → M ) = ( d 1 → M ) ∨ ( d 2 → M )
( ∃ y d y ) → M = ( d 1 ∨ d 2 ) → M \big(\exists y\,d_y\big) \rightarrow M \;=\; (d_1 \; \boxed{ \;\lor\; } \; d_2) \rightarrow M ( ∃ y d y ) → M = ( d 1 ∨ d 2 ) → M
∀ \forall ∀ goes with → \rightarrow → , and ∃ \exists ∃ goes with ∧ \land ∧ .
∀ x ∃ y L o v e s ( x , y ) \forall x\, \exists y\; Loves(x,y) ∀ x ∃ y L o v es ( x , y ) : everybody loves someone (possibly different people).
∃ y ∀ x L o v e s ( x , y ) \exists y\, \forall x\; Loves(x,y) ∃ y ∀ x L o v es ( x , y ) : there's one person everybody loves.
The second statement is much stronger than the first.
¬ ∀ 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) ¬∀ x P ( x ) ≡ ∃ x ¬ P ( x ) ¬∃ x P ( x ) ≡ ∀ x ¬ P ( x )
In ∀ x ( P ( x ) → Q ( x , y ) ) \forall x\, (P(x) \rightarrow Q(x,y)) ∀ x ( P ( x ) → Q ( x , y )) :
x x x is bound , because a quantifier captures it.
y y y is free , because nothing binds it.
A formula with no free variables is a sentence . Only sentences have definite truth values.
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 ¬ A ∨ ¬ B ∨ C
$$ 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)
I m p l i c a t i o n c a n b e u s e d f o r i f t h e n . − ∗ ∗ A s t u d e n t p a s s e s a c o u r s e o n l y i f t h e y s t u d y . ∗ ∗ T h i s n e e d s t o b e t r u e f o r s t u d e n t s w h o d i d n o t s t u d y , a n d s t u d e n t s w h o d i d n o t p a s s a n y c o u r s e s . S o r e f r a m e i t a s , " I f t h e r e i s a s t u d e n t , w h o p a s s e d a c o u r s e , t h e n h e m u s t h a v e s t u d i e d "
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" I m pl i c a t i o n c anb e u se df or i f t h e n . − ∗ ∗ A s t u d e n tp a sses a co u r seo n l y i f t h ey s t u d y . ∗ ∗ T hi s n ee d s t o b e t r u e f or s t u d e n t s w h o d i d n o t s t u d y , an d s t u d e n t s w h o d i d n o tp a ss an y co u r ses . S or e f r am e i t a s , " I f t h er e i s a s t u d e n t , w h o p a sse d a co u r se , t h e nh e m u s t ha v es t u d i e d "
\forall s,\forall c,\Big(\big(Student(s) \land Course(c) \land Passes(s,c)\big) \rightarrow Studies(s)\Big)
− T h e r e i s a c o u r s e t h a t e v e r y s t u d e n t t a k e s . T h e s e i s a c o u r s e , i f s o m e o n e i n t h e d o m a i n i s a n s t u d e n t , h e t a k e s t h a t c o u r s e - There is a course that every student takes.
These is a course, if someone in the domain is an student, he takes that course − T h er e i s a co u r se t ha t e v er y s t u d e n tt ak es . T h ese i s a co u r se , i f so m eo n e in t h e d o maini s an s t u d e n t , h e t ak es t ha t co u r se
\exists c ; \forall s , \big(Student(s)\land Course(c) \to Takes(s,c) \big)
− ∗ ∗ O n l y p r o f e s s o r s t e a c h c o u r s e s . ∗ ∗ i f s o m e o n e f r o m t h e a l l d o m a i n t e a c h e s a c o u r s e , t h e n i t m u s t b e a p r o f e s s o r - **Only professors teach courses.**
if someone from the all domain teaches a course, then it must be a professor − ∗ ∗ O n l y p r o f essor s t e a c h co u r ses . ∗ ∗ i f so m eo n e f r o m t h e a l l d o main t e a c h es a co u r se , t h e ni t m u s t b e a p r o f essor
\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)
− ∗ ∗ E v e r y p e r s o n i s l o v e d b y s o m e b o d y u n l e s s h e / s h e i s c r u e l . ∗ ∗ A u n l e s s B m e a n s , i f n o t B , t h e n A s o , i f h e i s n o t c r u e l , t h e n h e i s l o v e d b y s o m e b o d y - **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 − ∗ ∗ E v er y p er so ni s l o v e d b y so m e b o d y u n l ess h e / s h e i scr u e l . ∗ ∗ A u n l ess B m e an s , i f n o tB , t h e n A so , i f h e i s n o t cr u e l , t h e nh e i s l o v e d b y so m e b o d y
\forall x,\Big(\big(Person(x) \land \neg Cruel(x)\big) \rightarrow \exists y,\big(Person(y) \land Loves(y,x)\big)\Big)