lecture 7
Dr: Dina Awny First Order Logic
Dr. Sarah Ahmed
Logics
A logic is a triple ⟨L,S,R⟩ where
❑L, the logic’s language, is a class of sentences described by a formal grammar
❑ S, the logic’s semantics is a formal specification of how to assign meaning in
the“real world”to the elements of L
❑R, the logic’s inference system, is a set of formal derivation rules over L
There are several logics: propositional, first-order, higher-order, modal, temporal,
intuitionistic, linear, equational, non-monotonic, fuzzy, . . .
We will concentrate on propositional logic and first-order logic
Propositional Logic
Each sentence is made of
❑ propositional variables (A, B, . . . , P, Q, . . .)
❑ logical constants (True, False)
❑ logical connectives (∧, ∨, ⇒, . . .)
Every propositional variable stands for a basic fact
Examples: I’m hungry, Apples are red, Aly and Emad are Friends
Propositional Logic
Propositional Logic is about facts in the world that are either true or false, nothing else
Semantics of Propositional Logic:
Since each propositional variable stands for a fact about the world, its meaning ranges
over the Boolean values {true,false}
Note:
- true, false, which are values (i.e., semantical entities)
- True, False, which are logical constants (i.e., symbols of the language)
Propositional Logic
The Language
➢ Each propositional variable (A, B, . . . , P, Q, . . .) is a sentence
➢ Each logical constant (True, False) is a sentence
If φ and ψ are sentences, all of the following are also sentences :
(φ)
¬φ,
φ∧ψ
φ∨ψ
φ⇒ψ
φ⇔ψ
➢ Nothing else is a sentence
Properties of Logical Connectives
❖ ∧ and ∨ are commutative ❖∧ and ∨ are mutually distributive
φ1∧φ2 ≡ φ2∧φ1 φ1 ∧(φ2 ∨φ3) ≡ (φ1 ∧φ2)∨(φ1 ∧φ3)
φ1∨φ2 ≡ φ2∨φ1 φ1 ∨(φ2 ∧φ3) ≡ (φ1 ∨φ2)∧(φ1 ∨φ3)
❖∧ and ∨ are associative ❖∧ and ∨ are related by ¬ (DeMorgan’s
φ1 ∧(φ2 ∧φ3) ≡ (φ1 ∧φ2)∧φ3 Laws)
φ1 ∨(φ2 ∨φ3) ≡ (φ1 ∨φ2)∨φ3 ¬(φ1 ∧φ2) ≡ ¬φ1 ∨¬φ2
¬(φ1 ∨φ2) ≡ ¬φ1 ∧¬φ2
The Language Propositional Logic
More formally, it is the language generated by the following grammar Symbols:
➢ Propositional variables: A, B, . . . , P, Q, . . .
➢ Logical constants:
True (true) ∧ (and) ⇒ ( implies)
False (false) ∨ (or) ) ⇔ (equivalent) ¬ (not)
Grammar Rules:
Sentence::= AtomicS | ComplexS
AtomicS:= True|False|A|B| ... |P |Q| ...
ComplexS::= (Sentence) | Sentence Connective Sentence | ¬Sentence
Connective ::= ∧|∨|⇒|⇔
Semantics of Propositional Logic
• The meaning of True is always true The meaning of False is always false
• The meaning of the other sentences depends on the meaning of the propositional
variables
Base cases: truth tables
Semantics of Propositional Logic
An assignment of Boolean values to the propositional variables of a sentence is called
an interpretation of the sentence
Interpretations: {P → false, H → false}, {P → false, H → true}, . . .
An interpretation is a model of a sentence φ if it makes the sentence true
Semantics of Propositional Logic
The meaning of a sentence in general depends on its interpretation Some sentences,
however, have always the same meaning
A Sentence is:
✓ satisfiable if it is true in some interpretation
✓ unsatisfiable if it is true in no interpretation
✓ valid if it is true in every possible interpretation
✓ invalid if it is false in some possible interpretation
Limitations of Propositon Logic
Propositional logic has very limited expressive power (unlike natural language)
E.g., cannot say: “pits cause breezes in adjacent squares
"except by writing one sentence for each square
Every student will take a bonus
First Order Logic
Syntax of Fist-Order-Logic
• Constant symbols KingAly, 2, President, [], . . .
• Relation symbols Brothers( , ), > , Red( ), ...
• Function symbols Sqrt ( ), LeftLegOf ( ), …
• Variables x, y, a, b,...
• Connectives ∧ ∨ ¬ ⇒ ⇔
• Equality =
• Quantifiers ∀ ,∃
Atomic Sentence
Atomic sentence = relation(term1, . . . , termn)
or term1 = term2
Term = function(term1, . . . , termn)
or constant or variable
E.g., Brother (KingJohn , RichardTheLionheart )
At(Wumpus,2,1)
Complex Sentence
Complex sentences are made from atomic sentences using connectives
¬S, S1 ∧ S2, S1 ∨ S2, S1 ⇒S2, S1 ⇔ S2
E.g. Siblings(KingJohn,Richard) ⇒ Siblings(Richard,KingJohn)
x>2 ∨ 1<x
1>2 ∧ ¬y>2
Language of First-Order-Logic:
Grammar
FOL
A key element of FOL are predicates, which are used to describe objects, properties,
and relationships between objects
E.g. On(x,y)
• A quantified statement is a statement that applies to a class of objects
E.g. ∀x On(x,Table) → Fruit(x)
• This means that there is only fruit on the table
• The first element is called a quantifier, x is a variable and Table is constant
• On is a predicate
• The use of quantifiers allows FOL to handle infinite domains, while propositional
logic can only handle finite domains.
Truth in First-Order-Logic
Truth in First-Order-Logic
likes(Maha, Food).
likes(Maha, Juice).
likes(Aly, Juice).
likes(Aly, Maha).
The following queries yield the specified answers.
?- likes(Maha,Food). yes.
?- likes(Aly, Juice). yes
?- likes(Aly,Food). no.
?- likes(Aly, x). ===> ?
How do you add the following facts?
1. Aly likes anything that Maha likes
2. Aly likes anyone who likes Juice
Universal Quantification
Existantial Quantification
Diagnostic rule — In Wumpus
∀y Breezy(y)⇒∃x Pit(x) ∧ Adjacent(x,y)
Properties of Quantifier
∀x∀y is the same as ∀y∀x
∃x∃y is the same as ∃y∃x
∃x∀y is not the same as ∀y∃x
∃x∀yLoves(x, y)
“There is a person who loves everyone in the world”
∀y∃xLoves(x, y)
“Everyone in the world is loved by at least one person”
Quantifier Duality
Each quantifier can be expressed using the other quantifier and negation:
• ∀x Likes(x,IceCream) is equivalent to ¬∃x ¬Likes(x,IceCream)
• ∃x Likes(x,Broccoli) is equivalent to ¬∀x ¬Likes(x,Broccoli)
Proof in FOL
Example of Proof
Unification
Generlized Modus Ponens (GMP)
Example
GMP is complete for KBs of universally quantified definite clauses,
but incomplete for general first-order logic
Example:
PhD(x) → HighlyQualified (x )
¬ PhD(x) → EarlyEarnings(x)
HighlyQualified (x ) → Rich(x)
EarlyEarnings(x) → Rich(x)
should be able to infer
Rich(Dina). But the second sentence has two positive literals, so Modus ponens will not work.
Example
GMP is complete for KBs of universally quantified definite clauses,
but incomplete for general first-order logic
Example:
PhD(x) → HighlyQualified (x )
¬ PhD(x) → EarlyEarnings(x)
HighlyQualified (x ) → Rich(x)
EarlyEarnings(x) → Rich(x)
should be able to infer
Rich(Dina). But the second sentence has two positive literals, so Modus ponens will not work.
➢ Generalized modus ponens is a sound inference method, but it is complete only for a
subset of FOL (clauses with exactly one positive literal)
Proof by Resolution
❖ Resolution is a sound and complete inference method for first-order logic.
❖ Resolution is a refutation procedure: to prove that KB |= α, we show that KB ∧¬α is
unsatisfiable
❖ The knowledge base and ¬α are expressed in universally quantified, conjunctive normal
form
❖ Like in propositional logic, the resolution inference rule combines two clauses to make a
new one:
❖ Inference continues until an empty clause is derived (contradiction)
Resolution Inference Rule
Conjunctive Normal Form (CNF)
Resolution Proof
To prove α:
1. Negate it
2. Convert to CNF
3. Add the result to the knowledge base
4. Infer a contradiction (empty clause)
Example: to prove Rich(Dina), add ¬ Rich(Dina) to the CNF KB
¬ PhD(x) ∨ HighlyQualified (x )
PhD(x) ∨ EarlyEarnings(x)
¬ HighlyQualified (x ) ∨ Rich(x)
¬ EarlyEarnings(x) ∨ Rich(x)
Construct proof Tree