and Applications Lecture 3: Review of First-Order Logic (FOL) Juan - - PowerPoint PPT Presentation
and Applications Lecture 3: Review of First-Order Logic (FOL) Juan - - PowerPoint PPT Presentation
Artificial Intelligence: Methods and Applications Lecture 3: Review of First-Order Logic (FOL) Juan Carlos Nieves Snchez November 11, 2014 Outline Knowledge Engineering. Reducing first-order inference to propositional inferece.
Artificial Intelligence: Methods and Applications
Lecture 3: Review of First-Order Logic (FOL) Juan Carlos Nieves SΓ‘nchez November 11, 2014
Review of First-Order Logic 3
Outline
- Knowledge Engineering.
- Reducing first-order inference to propositional inferece.
- Unification.
- Generalized Modus Pones
- Forward and backward chaining
- Resolution
The knowledge-engineering process
1. Identify the task (identify the questions of interest). 2. Assemble the relevant knowledge (acquisition). 3. Decide on a vocabulaty of predicates, functions, and constants (the ontology). 4. Encode general knowledge about the domain (write down axioms). 5. Encode a description of the specific problem instance. 6. Pose queries to the inference procedure and get answers (use the system). 7. Debug/maintain the knowleg base.
Review of First-Order Logic 4
Relations
An n-ary relation R is a subset of the Catetian product π¬π Γ βββ Γ π¬π where each π¬π π β€ π β€ π is a set.
Review of First-Order Logic 6
For example: PR(x) β the set of numbers x which are prime: {2,3,5,7,11, . . . }. SQ(x,y) β the set of pairs (x,y) such that y is the square of x: 1,1 , 2,4 , 3,9 , . . . .
Can you define the relation of sum of two integer numbers?
Predicates
A relation can be formalized as a boolean-valued function on n-tuples:
Review of First-Order Logic 7
Let D be a set. R is an n-ary relation on the domain D if R is a relation on π¬π. Let R be an n-ary relation on a domain D. The predicate P associated with R is: For example: SQ(2,1) = F SQ(2,2) = F SQ(2,3) = F SQ(2,4) = T
The syntax of FOL
Review of First-Order Logic 8
ππππ’ππππ β π΅π’ππππππππ’ππππ | π·ππππππ¦ππππ’ππππ π΅π’ππππππππ’ππππ β ππ ππππππ’π ππ ππππππ’π πππ π1,β¦ πππ π = πππ π π·ππππππ¦ππππ’ππππ β ππππ’ππππ ππππ’ππππ Β¬ ππππ’ππππ | Sentence Sentence | Sentence Sentence | ππππ’ππππ β ππππ’ππππ | ππππ’ππππ ππππ’ππππ | π π£πππ’πππππ πππ πππππ , . . . ππππ’πππ πππ π β πΊπ£πππ’πππ πππ π, β¦ π·πππ‘π’πππ’ πππ πππππ π π£πππ’πππππ β β | β π·πππ‘π’πππ’ β A | X1 | Johm | β¦ πππ πππππ β A | x | s | β¦ ππ ππππππ’π β After | Loves | .. πΊπ£πππ’πππ β LeftLeg
An example of a FOL Theory
We build a knowledge base for natural numbers using the following vocabulary:
- The relation name Num
- The constant name 0
- The function names + and S
Assertions:
- ππ£π(0)
- β π¦ ππ£π π¦ β ππ£π π π¦
- β π¦ π π¦ != 0
- β π¦, π§ π¦ ! = π§ β π π¦ ! = π π§
- β π¦ ππ£π π¦ β π¦ + 0 = π¦
- β π¦ ππ£π π¦
β§ ππ£π π§ β π π¦ + π§ = π(π¦ + π§)
Review of First-Order Logic 9
Queries
Asking our knowledge base whether: ? π π π 0 = π π 0 + π(0) Should now in principle yield the answer true. By the first two assertions , all three objects involved are numbers. By the last assertion, the equality must hold. This means that π π π 0 = π π 0 + π(0) is a theorem of our system. It can be derived from our axioms.
Review of First-Order Logic 10
Another example of a knowledge base
The law says that is a crime for an American to sell weapons to a hostile
- nations. The country Nono, an enemy of America, has some missiles, and
all of its missiles were sold to by Colonel West, who is American.
Review of First-Order Logic 11
.. it is a crime for an American to sell weapons to hostile nations: β π¦, π§, π¨ π΅πππ ππππ π¦ β§ ππππππ π§ β§ πππππ‘ π¦, π§, π¨ β§ πΌππ‘π’πππ π¨ β π·π ππππππ(π¦) Nono β¦ has some missiles: β π¦ ππ₯ππ‘ ππππ, π¦ β§ πππ‘π‘πππ π¦ . .. all of its missiles were sold to it by Colonel West: βπ¦ πππ‘π‘πππ π¦ β§ ππ₯ππ‘ ππππ, π¦ β πππππ‘(πππ‘π’, π¦, ππππ) Missiles are weapons: β π¦ πππ‘π‘πππ π¦ β ππππππ( π¦) West, who is American: π΅πππ ππππ(πππ‘π’) The country Nono, an enemy of America: πΉππππ§(ππππ, π΅πππ πππ) An enemy of America counts as βhostileβ: β π¦ πΉππππππ§ π¦, π΅πππ πππ β πΌππ‘π’πππ(π¦)
How to solve queries automatically?
Universal Instantiation (UI)
Every instantiation of a universal quantified sentence is entailed by it: β π€ π½ πππΆππ({π€/π, π½}) for any variable π€ and ground term π. E.g., β π¦ πΏπππ π¦ β§ π»π ππππ§ π¦ β πΉπ€ππ(π¦) yields πΏπππ πΎπβπ β§ π»π ππππ§ πΎπβπ β πΉπ€ππ(πΎπβπ) πΏπππ πππβππ π β§ π»π ππππ§ πππβππ π β πΉπ€ππ(πππβππ π) πΏπππ πππ’βππ πΎπβπ β§ π»π ππππ§ πππ’βππ ππβπ β πΉπ€ππ(πππ’βππ (ππβπ)) β¦.
Review of First-Order Logic 12
Existential instantiation (EI)
For any sentence π½, variable π€, and constnat symbol π that does not appear alsewhere in the knowledge base: β π€ π½ πππΆππ({π€/π, πΏ) E.g. β π¦ π·π ππ₯π π¦ β§ OnHead x, John yields π·π ππ₯π π·1 β§ πππΌπππ (π·1, πΎπβπ) such that π·1 is a new constant symbol, called Skolen constant.
Review of First-Order Logic 13
OBSERVATIONS: UI can be applied several times to add new sentences; the new logical theory is logical equivalent to the old. EI can be applied once to replace the existence sentence; the new logical theory is not logical equivalent to the old, but is satisfiable iff the old logical theory was satisfiable.
Reduction to propositional inference
Suppose the KB contains just the following: βπ¦ πΏπππ π¦ β§ π»π ππππ§ π¦ β πΉπ€ππ π¦ πΏπππ πΎπβπ π»π ππππ§ πΎπβπ πΆπ ππ’βππ πππβππ π, πΎπβπ Instantiating the universal sentence in all possible ways, we have πΏπππ πΎπβπ β§ π»π ππππ§ πΎπβπ β πΉπ€ππ(πΎπβπ) πΏπππ πππβππ π β§ π»π ππππ§ πππβππ π β πΉπ€ππ(πππβππ π) πΏπππ πΎπβπ π»π ππππ§ πΎπβπ πΆπ ππ’βππ πππβππ π, πΎπβπ The new KB is propositionalized. Some of the proposition symbols are πΏπππ πΎπβπ , π»π ππππ§ πΎπβπ , πΉπ€ππ πΎπβπ , β¦ .
Review of First-Order Logic 14
Observations of the reduction
- Claim: A grounded sentence is entailed by the new knowledge base iff
entailed by the original knoledge base.
- Claim: Every FOL knowledge base can be propositionalized so as to
preserve entailment.
- Idea: propositonalize knowledge base and query, apply resolution,
return result.
- Problem: with functions symbols, there are infinitely many grounded
terms.
- Theorem: Helbrad (1930), If a sentence π½ is enteilated by an FOL
knowledge base, it is entailed by a finite subset of the propositonal knowled base.
- Idea: For π = 0 to β do
create a propositional knowleg base by instatiating with depth-π terms
see if π½ is entailed by this propositional knowledge base
- Problem: works if π½ is entailed, loops if π½ is not entailed
- Thoerem: Turing (1936), Church(1936), entailment if FOL is
semidecidable
Review of First-Order Logic 15
Problems with propositonalization
Propositionalization seems to generate lots of irrelevant sentences. E.g., from βπ¦ πΏπππ π¦ β§ π»π ππππ§ β πΉπ€ππ π¦ πΏπππ πΎπβπ β π§ π»π ππππ§(π§) πΆπ ππ’βππ (πππβππ π, πΎπβπ) it seems obvious that πΉπ€ππ πΎπβπ , but propositionalization produces lots of facts such as π»π ππππ§ πππβππ π that are inrrelevant. With π π-any predicates and π constants, there are π ππ instantiations. With function symbols, it gets much much worse!
Review of First-Order Logic 16
Unification
We can get the inference immediately if we can find a substitution π such that πΏπππ(π¦) and π»π πππ§(π¦) match πΏπππ(πΎπβπ) and π»π ππππ§(π§) π = {π¦/πΎπβπ, π§/πΎπβπ} works Uππππ§ π½, πΎ ππ π½π = πΎπ
Review of First-Order Logic 17
π· πΈ πΎ πΏπππ₯π‘(πΎπβπ, π¦) πΏπππ₯π‘(πΎπβπ, πΎπππ) {π¦/πΎπππ } πΏπππ₯π‘(πΎπβπ, π¦) πΏπππ₯π‘(π§, ππΎ) {π¦/ππΎ, π§/πΎπβπ} πΏπππ₯π‘(πΎπβπ, π¦) πΏπππ₯π‘(π§, πππ’βππ (π§)) {π¦/πππ’βππ (πΎπβπ), π§/πΎπβπ} πΏπππ₯π‘(πΎπβπ, π¦) πΏπππ₯π‘(π¦, ππΎ) ππππ
Generalized Modus Ponens (GMP)
πβ²1, πβ²2,..., πβ²π,
(π1β§π2 β§ ...β§ ππ βπ)
ππ
where πβ²π π = ππ π for all π πβ²1 is πΏπππ(πΎπβπ) π1 is πΏπππ(π¦) πβ²2 is π»π ππππ§(π§) π2 is π»π ππππ§(π¦) π is π = {π¦/πΎπβπ, π§/πΎπβπ} π is πΉπ€ππ(π¦) ππ is πΉπ€ππ πΎπβπ GMP used with knowledge bases of definte clauses (exactly one positive literal). All the variables assumed universally quantified
Review of First-Order Logic 18
Example knowledge base
The law says that is a crime for an American to sell weapons to a hostile
- nations. The country Nono, an enemy of America, has some missiles, and
all of its missiles were sold to iy by Colonel West, who is American.
Review of First-Order Logic 19
Prove that Colonel Est is a crimintal .. it is a crime for an American to sell weapons to hostile nations: π΅πππ ππππ π¦ β§ ππππππ π§ β§ πππππ‘ π¦, π§, π¨ β§ πΌππ‘π’πππ π¨ β π·π ππππππ(π¦) Nono β¦ has some missiles: β π¦ ππ₯ππ‘ ππππ, π¦ β§ πππ‘π‘πππ π¦ . If we apply Skolemization, we get ππ₯ππ‘ ππππ, π1 β§ πππ‘π‘πππ π1 . .. all of its missiles were sold to it by Colonel West: βπ¦ πππ‘π‘πππ π¦ β§ ππ₯ππ‘ ππππ, π¦ β πππππ‘(πππ‘π’, π¦, ππππ) Missiles are weapons: πππ‘π‘πππ π¦ β ππππππ( π¦) West, who is American: π΅πππ ππππ(πππ‘π’) The country Nono, an enemy of America: πΉππππ§(ππππ, π΅πππ πππ) An enemy of America counts as βhostileβ: πΉππππππ§ π¦, π΅πππ πππ β πΌππ‘π’πππ(π¦)
Extensional knowledge base (facts):
Forward chaining inference
Review of First-Order Logic 20
Intentional knowledge base (rules):
- π΅πππ ππππ π¦ β§ ππππππ π§ β§ πππππ‘ π¦, π§, π¨ β§ πΌππ‘π’πππ π¨ β π·π ππππππ(π¦)
- πππ‘π‘πππ π¦ β§ ππ₯ππ‘ ππππ, π¦ β πππππ‘(πππ‘π’, π¦, ππππ)
- πΉππππππ§ π¦, π΅πππ πππ β πΌππ‘π’πππ(π¦)
- πππ‘π‘πππ π¦ β ππππππ( π¦)
π΅πππ ππππ(πππ‘π’)
πππ‘π‘πππ π1 ππ₯ππ‘ ππππ, π1 πΉππππ§(ππππ, π΅πππ πππ) ππππππ(π1) πππππ‘(πππ‘π’, π1, ππππ) πΌππ‘π’πππ(ππππ) π·π ππππππ(πππ‘π’)
Properties of forward chaining
- Sound and complete for first-order definite clauses (proof similar to
propositional proof).
- Datalog = first-order definite clauses + no function. Forward chaining
terminates for Datalog in Poly interactions.
- May not terminate in general if π½ is not entailed.
- Forward chaining is widely used in deductive databases.
- Matching conjunctive premises against know facts is NP-hard.
Review of First-Order Logic 21
How can we avoid matching between conjunctive premises and know facts?
Backward chaining inference
Backward chaining inference
Review of First-Order Logic 22
π·π ππππππ(πππ‘π’)
π΅πππ ππππ πππ‘π’
ππππππ(π§) πππππ‘(πππ‘π’, π1, π¨) πΌππ‘π’πππ(ππππ) πππ‘π‘πππ π§ πππ‘π‘πππ π1 ππ₯ππ‘ ππππ, π1 πΉππππ§(ππππ, π΅πππ πππ)
Properties of backward chaining
- Depth-first recursive proof search: space is linear in size of proof.
- Incomplete due to innite loops
β fix by checking current goal against every goal on stack
- Inefficient due to repeated subgoals (both success and failure)
- fix using caching of previous results (extra space!)
- Widely used by classical logic programming interpreters!
Review of First-Order Logic 23
Resolution: a short review
Review of First-Order Logic 24
where For example: With Apply resolution steps to complete for FOL
Conversion to CNF
Review of First-Order Logic 25
Intentional knowledge base (rules):
- π΅πππ ππππ π¦ β§ ππππππ π§ β§ πππππ‘ π¦, π§, π¨ β§ πΌππ‘π’πππ π¨ β π·π ππππππ π¦
Β¬ π΅πππ ππππ π¦ β¨ Β¬ππππππ π§ β¨ Β¬πππππ‘ π¦, π§, π¨ β¨ Β¬πΌππ‘π’πππ π¨ β¨ π·π ππππππ π¦
- πππ‘π‘πππ π¦ β§ ππ₯ππ‘ ππππ, π¦ β πππππ‘(πππ‘π’, π¦, ππππ)
Β¬ πππ‘π‘πππ π¦ β¨ Β¬ ππ₯ππ‘ ππππ, π¦ β¨ πππππ‘(πππ‘π’, π¦, ππππ)
- πΉππππππ§ π¦, π΅πππ πππ β πΌππ‘π’πππ(π¦)
Β¬πΉππππππ§ π¦, π΅πππ πππ β¨ πΌππ‘π’πππ(π¦)
- πππ‘π‘πππ π¦ β ππππππ( π¦)
Β¬ πππ‘π‘πππ π¦ β¨ ππππππ( π¦)
Resolution example
Review of First-Order Logic 26
Observations
If a set of sentences is unsatisfiable, then resolution will always be able to derive a contradiction.
Review of First-Order Logic 27
Given a logical theory π and a formula π½, if π entails π½, then π β§ Β¬ π½ is unsatisfiable
- Resolution is one of the most powerful tools for implementing
automated reasoning.
- There are several extensions of the resolution rule in order to
implement inference in other non-classical logics, e.g. Possibilistic Logic.
Datum Sidfot 28
Sources of this Lecture
- S. Russell, P. Norvig, Artificial Intelligence: A Modern Approach. Third
Edition.
- M. Ben-Ari, Mathematical Logic for Computer Science, Prentice Hall,
1993.
- Some of these slides are based on the slides of the book: Artificial
Intelligence: A Modern Approach, by Stuart Russell and Peter Norvig