Module - 3 1 Knowledge Representation
Description: Module - 3 1 Knowledge Representation Propositional and First-Order Logic Logic roadmap overview Propositional logic (review) Problems with propositional logic First-order logic (review) Properties, relations, functions, quantifiers,
Related Topics
Download Presentation
"Module - 3 1 Knowledge Representation" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Presentation Transcript
slide1. Module - 3 1 Knowledge Representation<br>
slide2. Propositional and First-Order Logic<br>
slide3. Logic roadmap overview Propositional logic (review)
Problems with propositional logic
First-order logic (review)
Properties, relations, functions, quantifiers, …
Terms, sentences, wffs, axioms, theories, proofs, …
Extensions to first-order logic
Logical agents
Reflex agents
Representing change: situation calculus, frame problem
Preferences on actions
Goal-based agents<br>
slide4. Disclaimer “Logic, like whiskey, loses its beneficial effect when taken in too large quantities.”
- Lord Dunsany<br>
slide5. Propositional Logic<br>
slide6. Big Ideas Logic is a great knowledge representation language for many AI problems.
Propositional logic is the simple foundation and fine for some AI problems.
First order logic (FOL) is much more expressive as a KR language and more commonly used in AI.
There are many variations: horn logic, higher order logic, three-valued logic, probabilistic logics, etc.<br>
slide7. Propositional logic Logical constants: true, false
Propositional symbols: P, Q,... (atomic sentences)
Wrapping parentheses: ( … )
Sentences are combined by connectives:
and [conjunction]
or [disjunction]
implies [implication / conditional]
is equivalent [biconditional]
not [negation]
Literal: atomic sentence or negated atomic sentence
P, P<br>
slide8. Examples of PL sentences (P Q) R
“If it is hot and humid, then it is raining”
Q P
“If it is humid, then it is hot”
Q
“It is humid.”
We’re free to choose better symbols, btw:
Ho = “It is hot”
Hu = “It is humid”
R = “It is raining”<br>
slide9. Propositional logic (PL) Simple language for showing key ideas and definitions
User defines set of propositional symbols, like P and Q
User defines semantics of each propositional symbol:
P means “It is hot”, Q means “It is humid”, etc.
A sentence (well formed formula) is defined as follows:
A symbol is a sentence
If S is a sentence, then S is a sentence
If S is a sentence, then (S) is a sentence
If S and T are sentences, then (S T), (S T), (S T), and (S ↔ T) are sentences
A sentence results from a finite number of applications of the rules<br>
slide10. Some terms The meaning or semantics of a sentence determines its interpretation
Given the truth values of all symbols in a sentence, it can be “evaluated” to determine its truth value (True or False)
A model for a KB is a possible world – an assignment of truth values to propositional symbols that makes each sentence in the KB True<br>
slide11. Model for a KB Let the KB be [PQR, Q P]
What are the possible models? Consider all possible assignments of T|F to P, Q and R and check truth tables
FFF: OK
FFT: OK
FTF: NO
FTT: NO
TFF: OK
TFT: OK
TTF: NO
TTT: OK
If KB is [PQR, Q P, Q], then the only model is TTT P: it’s hot
Q: it’s humid
R: it’s raining<br>
slide12. More terms A valid sentence or tautology is a sentence that is True under all interpretations, no matter what the world is actually like or what the semantics is. Example: “It’s raining or it’s not raining”
An inconsistent sentence or contradiction is a sentence that is False under all interpretations. The world is never like what it describes, as in “It’s raining and it’s not raining.”
P entails Q, written P |= Q, means that whenever P is True, so is Q. In other words, all models of P are also models of Q.<br>
slide13. Truth tables Truth tables for the five logical connectives Truth tables are used to define logical connectives
and to determine when a complex sentence is true given the values of the symbols in it<br>
slide14. On the implies connective: P Q Note that is a logical connective
So PQ is a logical sentence and has a truth value, i.e., is either true or false
If we add this sentence to the KB, it can be used by an inference rule, Modus Ponens, to derive/infer/prove Q if P is also in the KB
Given a KB where P=True and Q=True, we can also derive/infer/prove that PQ is True<br>
slide15. P Q When is PQ true? Check all that apply
P=Q=true
P=Q=false
P=true, Q=false
P=false, Q=true<br>
slide16. P Q When is PQ true? Check all that apply
P=Q=true
P=Q=false
P=true, Q=false
P=false, Q=true
We can get this from the truth table for
Note: in FOL it’s much harder to prove that a conditional true.
Consider proving prime(x) odd(x) ✔ ✔ ✔<br>
slide17. 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. 17<br>
slide18. 18<br>
slide19. Rule of Inference Rules of inference are a set of logical principles and deductive rules that draw conclusions from existing information or assertions 19<br>
slide20. Modus Ponens 20 Modus ponens works only for knowledge bases that contain only implications of positive literals.
Implications of positive literals are often called Horn clauses, after a logician who studied them deeply.
But disjunction (or) and negation (not) break the rule. And many legal sentences cannot be expressed in Horn clauses.<br>
slide21. CMPT 310 - Blind Search 21<br>
slide22. 22<br>
slide23. Modus tollens If P implies Q and Q is false, then P is false.
Notation
Example
If it is raining, then the streets are wet (P -> Q), and streets are not wet (~Q).
Therefore, it is not raining (~P). 23<br>
slide24. Hypothetical syllogism If P implies Q and Q implies R, then P implies R.
Notation
Example
If it is raining, then the streets are wet (P -> Q),
and if the streets are wet, then roads are slippery (Q -> R);
therefore, if it is raining, then roads are slippery (P -> R) 24<br>
slide25. Addition If P is true, then P or Q is true..
Notation
Example
It is raining (P), therefore it is raining or streets are wet (P∨Q). 25<br>
slide26. Simplification If P and Q is true, then P is true.
Notation
Example
It is raining and streets are wet (P∧Q); therefore it is raining (P). 26<br>
slide27. Resolution If both P or Q and not P or R is true, then Q or R is true.
Notation
Example
It is raining or streets are wet (P∨Q) and it is not raining or roads are slippery (~P∨R);
therefore streets are wet or roads are slippery (Q∨R). 27<br>
slide28. Propositional Theorem Proving 28 Logical Equivalence
Ex: - (P ∧ Q) ≡ (Q ∧P)
Other Logical Sequences
Commutativity of Conjunction and Disjunction
Associativity
(P ∧ Q) ∧ R= P ∧ (Q ∧ R),
(P ∨ Q) ∨ R= P ∨ (Q ∨ R)
De Morgan's law
¬ (P ∧ Q) = (¬P) ∨ (¬Q)
¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
Implication Elimination
Double – Negation Elimination (~~P ≡ P) etc… (Refer Textbook 7.11)
Validity are also called as Tautologies
A sentence is valid if it is true in all models. example, the sentence P ∨ ¬P is valid.
Satisfiability
A sentence is satisfiable if it is true in, or satisfied by, some model. For example, the knowledge base given earlier, (R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5), is satisfiable because there are three models in which it is true,<br>
slide29. Conjunctive Normal Form The resolution rule applies only to clauses (that is, disjunctions of literals),
Every sentence of propositional logic is logically equivalent to a conjunction of clauses.
A sentence expressed as a conjunction of clauses is said to be in conjunctive normal form or CONJUNCTIVE NORMAL FORM (CNF) 29<br>
slide30. CNF Rules Step 1: Eliminate ⇔
replacing α ⇔ β with (α ⇒ β) ∧ (β ⇒ α).
Eliminate ⇒,
replacing α ⇒ β with ¬α ∨ β:
CNF requires ¬ to appear only in literals,
so we “move ¬ inwards”
Now we have a sentence containing nested ∧ and ∨ operators applied to literals. We apply the distributivity law from distributing ∨ over ∧ wherever possible. 30<br>
slide31. CNF Conversion - Example ¬((¬A→¬B)∧¬C) - Convert and Resolve to CNF
Step 1: Remove the conditional symbol
≡¬((¬¬A∨¬B)∧¬C)
Step 2:Remove the double negation
≡¬((A∨¬B)∧¬C)
Step 3: Apply the De Morgan's law that that opens a negation as a whole
≡¬(A∨¬B)∨¬¬C
Step 4: Remove the double negation
≡¬(A∨¬B)∨C
Step 5: Apply the De Morgan's law again
≡(¬A∧¬¬B)∨C
Step 6: Remove the double negation again
≡(¬A∧B)∨C
Step 7: Apply the distributive property over disjunction ≡(¬A∨C)∧(B∨C) 31<br>
slide32. CNF Conversion - Example 32 Final CNF conversion
It is much harder to read, but it can be used as input to a resolution procedure.<br>
slide33. Inference rules Logical inference creates new sentences that logically follow from a set of sentences (KB).
An inference rule is sound if every sentence X it produces when operating on a KB logically follows from the KB
i.e., inference rule creates no contradictions
An inference rule is complete if it can produce every expression that logically follows from (is entailed by) the KB.
Note analogy to complete search algorithms<br>
slide34. Rule of Soundness A derivation rule is sound if it derives true conclusions from true premises. 34<br>
slide35. Entailment in Propositional Logic Given
• a set Γ of sentences & a sentence φ,
we write Γ |= φ
iff every interpretation that makes all sentences in Γ true makes φ also true
Γ |=φ is read as “Γ entails φ ”or “φ logically follows from Γ ” 35<br>
slide36. Fancy Symbols A ∧ B ⇒ C is a sentence, a bunch of symbols manipulated by an inference system I.
A ∧B |= C is a mathematical abbreviation standing for the statement:
“every interpretation that makes A∧B true, makes C also true”
A∧B ⊢I C is a mathematical abbreviation standing for the statement: “ I derives C from A ∧ B”
In other words,
⇒ is a formal symbol of the logic, which is used by the inference system
|= is a shorthand we use to talk about the meaning of formal sentences
⊢I is a shorthand we use to talk about the output of the inference system I 36<br>
slide37. Propositional Wumpus hunter problems Lack of variables prevents stating more general rules
We need a set of similar rules for each cell.
Change of the KB over time is difficult to represent
Standard technique is to index facts with the time when they’re true.
This means we have a separate KB for every time point.<br>
slide38. Propositional logic summary Inference is the process of deriving new sentences from old
Sound inference derives true conclusions given true premises
Complete inference derives all true conclusions from a set of premises
A valid sentence is true in all worlds under all interpretations
If an implication sentence can be shown to be valid, then—given its premise—its consequent can be derived
Different logics make different commitments about what the world is made of and what kind of beliefs we can have
Propositional logic commits only to the existence of facts that may or may not be the case in the world being represented
Simple syntax and semantics suffices to illustrate the process of inference
Propositional logic can become impractical, even for very small worlds<br>
slide2. Propositional and First-Order Logic<br>
slide3. Logic roadmap overview Propositional logic (review)
Problems with propositional logic
First-order logic (review)
Properties, relations, functions, quantifiers, …
Terms, sentences, wffs, axioms, theories, proofs, …
Extensions to first-order logic
Logical agents
Reflex agents
Representing change: situation calculus, frame problem
Preferences on actions
Goal-based agents<br>
slide4. Disclaimer “Logic, like whiskey, loses its beneficial effect when taken in too large quantities.”
- Lord Dunsany<br>
slide5. Propositional Logic<br>
slide6. Big Ideas Logic is a great knowledge representation language for many AI problems.
Propositional logic is the simple foundation and fine for some AI problems.
First order logic (FOL) is much more expressive as a KR language and more commonly used in AI.
There are many variations: horn logic, higher order logic, three-valued logic, probabilistic logics, etc.<br>
slide7. Propositional logic Logical constants: true, false
Propositional symbols: P, Q,... (atomic sentences)
Wrapping parentheses: ( … )
Sentences are combined by connectives:
and [conjunction]
or [disjunction]
implies [implication / conditional]
is equivalent [biconditional]
not [negation]
Literal: atomic sentence or negated atomic sentence
P, P<br>
slide8. Examples of PL sentences (P Q) R
“If it is hot and humid, then it is raining”
Q P
“If it is humid, then it is hot”
Q
“It is humid.”
We’re free to choose better symbols, btw:
Ho = “It is hot”
Hu = “It is humid”
R = “It is raining”<br>
slide9. Propositional logic (PL) Simple language for showing key ideas and definitions
User defines set of propositional symbols, like P and Q
User defines semantics of each propositional symbol:
P means “It is hot”, Q means “It is humid”, etc.
A sentence (well formed formula) is defined as follows:
A symbol is a sentence
If S is a sentence, then S is a sentence
If S is a sentence, then (S) is a sentence
If S and T are sentences, then (S T), (S T), (S T), and (S ↔ T) are sentences
A sentence results from a finite number of applications of the rules<br>
slide10. Some terms The meaning or semantics of a sentence determines its interpretation
Given the truth values of all symbols in a sentence, it can be “evaluated” to determine its truth value (True or False)
A model for a KB is a possible world – an assignment of truth values to propositional symbols that makes each sentence in the KB True<br>
slide11. Model for a KB Let the KB be [PQR, Q P]
What are the possible models? Consider all possible assignments of T|F to P, Q and R and check truth tables
FFF: OK
FFT: OK
FTF: NO
FTT: NO
TFF: OK
TFT: OK
TTF: NO
TTT: OK
If KB is [PQR, Q P, Q], then the only model is TTT P: it’s hot
Q: it’s humid
R: it’s raining<br>
slide12. More terms A valid sentence or tautology is a sentence that is True under all interpretations, no matter what the world is actually like or what the semantics is. Example: “It’s raining or it’s not raining”
An inconsistent sentence or contradiction is a sentence that is False under all interpretations. The world is never like what it describes, as in “It’s raining and it’s not raining.”
P entails Q, written P |= Q, means that whenever P is True, so is Q. In other words, all models of P are also models of Q.<br>
slide13. Truth tables Truth tables for the five logical connectives Truth tables are used to define logical connectives
and to determine when a complex sentence is true given the values of the symbols in it<br>
slide14. On the implies connective: P Q Note that is a logical connective
So PQ is a logical sentence and has a truth value, i.e., is either true or false
If we add this sentence to the KB, it can be used by an inference rule, Modus Ponens, to derive/infer/prove Q if P is also in the KB
Given a KB where P=True and Q=True, we can also derive/infer/prove that PQ is True<br>
slide15. P Q When is PQ true? Check all that apply
P=Q=true
P=Q=false
P=true, Q=false
P=false, Q=true<br>
slide16. P Q When is PQ true? Check all that apply
P=Q=true
P=Q=false
P=true, Q=false
P=false, Q=true
We can get this from the truth table for
Note: in FOL it’s much harder to prove that a conditional true.
Consider proving prime(x) odd(x) ✔ ✔ ✔<br>
slide17. 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. 17<br>
slide18. 18<br>
slide19. Rule of Inference Rules of inference are a set of logical principles and deductive rules that draw conclusions from existing information or assertions 19<br>
slide20. Modus Ponens 20 Modus ponens works only for knowledge bases that contain only implications of positive literals.
Implications of positive literals are often called Horn clauses, after a logician who studied them deeply.
But disjunction (or) and negation (not) break the rule. And many legal sentences cannot be expressed in Horn clauses.<br>
slide21. CMPT 310 - Blind Search 21<br>
slide22. 22<br>
slide23. Modus tollens If P implies Q and Q is false, then P is false.
Notation
Example
If it is raining, then the streets are wet (P -> Q), and streets are not wet (~Q).
Therefore, it is not raining (~P). 23<br>
slide24. Hypothetical syllogism If P implies Q and Q implies R, then P implies R.
Notation
Example
If it is raining, then the streets are wet (P -> Q),
and if the streets are wet, then roads are slippery (Q -> R);
therefore, if it is raining, then roads are slippery (P -> R) 24<br>
slide25. Addition If P is true, then P or Q is true..
Notation
Example
It is raining (P), therefore it is raining or streets are wet (P∨Q). 25<br>
slide26. Simplification If P and Q is true, then P is true.
Notation
Example
It is raining and streets are wet (P∧Q); therefore it is raining (P). 26<br>
slide27. Resolution If both P or Q and not P or R is true, then Q or R is true.
Notation
Example
It is raining or streets are wet (P∨Q) and it is not raining or roads are slippery (~P∨R);
therefore streets are wet or roads are slippery (Q∨R). 27<br>
slide28. Propositional Theorem Proving 28 Logical Equivalence
Ex: - (P ∧ Q) ≡ (Q ∧P)
Other Logical Sequences
Commutativity of Conjunction and Disjunction
Associativity
(P ∧ Q) ∧ R= P ∧ (Q ∧ R),
(P ∨ Q) ∨ R= P ∨ (Q ∨ R)
De Morgan's law
¬ (P ∧ Q) = (¬P) ∨ (¬Q)
¬ (P ∨ Q) = (¬ P) ∧ (¬Q).
Implication Elimination
Double – Negation Elimination (~~P ≡ P) etc… (Refer Textbook 7.11)
Validity are also called as Tautologies
A sentence is valid if it is true in all models. example, the sentence P ∨ ¬P is valid.
Satisfiability
A sentence is satisfiable if it is true in, or satisfied by, some model. For example, the knowledge base given earlier, (R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5), is satisfiable because there are three models in which it is true,<br>
slide29. Conjunctive Normal Form The resolution rule applies only to clauses (that is, disjunctions of literals),
Every sentence of propositional logic is logically equivalent to a conjunction of clauses.
A sentence expressed as a conjunction of clauses is said to be in conjunctive normal form or CONJUNCTIVE NORMAL FORM (CNF) 29<br>
slide30. CNF Rules Step 1: Eliminate ⇔
replacing α ⇔ β with (α ⇒ β) ∧ (β ⇒ α).
Eliminate ⇒,
replacing α ⇒ β with ¬α ∨ β:
CNF requires ¬ to appear only in literals,
so we “move ¬ inwards”
Now we have a sentence containing nested ∧ and ∨ operators applied to literals. We apply the distributivity law from distributing ∨ over ∧ wherever possible. 30<br>
slide31. CNF Conversion - Example ¬((¬A→¬B)∧¬C) - Convert and Resolve to CNF
Step 1: Remove the conditional symbol
≡¬((¬¬A∨¬B)∧¬C)
Step 2:Remove the double negation
≡¬((A∨¬B)∧¬C)
Step 3: Apply the De Morgan's law that that opens a negation as a whole
≡¬(A∨¬B)∨¬¬C
Step 4: Remove the double negation
≡¬(A∨¬B)∨C
Step 5: Apply the De Morgan's law again
≡(¬A∧¬¬B)∨C
Step 6: Remove the double negation again
≡(¬A∧B)∨C
Step 7: Apply the distributive property over disjunction ≡(¬A∨C)∧(B∨C) 31<br>
slide32. CNF Conversion - Example 32 Final CNF conversion
It is much harder to read, but it can be used as input to a resolution procedure.<br>
slide33. Inference rules Logical inference creates new sentences that logically follow from a set of sentences (KB).
An inference rule is sound if every sentence X it produces when operating on a KB logically follows from the KB
i.e., inference rule creates no contradictions
An inference rule is complete if it can produce every expression that logically follows from (is entailed by) the KB.
Note analogy to complete search algorithms<br>
slide34. Rule of Soundness A derivation rule is sound if it derives true conclusions from true premises. 34<br>
slide35. Entailment in Propositional Logic Given
• a set Γ of sentences & a sentence φ,
we write Γ |= φ
iff every interpretation that makes all sentences in Γ true makes φ also true
Γ |=φ is read as “Γ entails φ ”or “φ logically follows from Γ ” 35<br>
slide36. Fancy Symbols A ∧ B ⇒ C is a sentence, a bunch of symbols manipulated by an inference system I.
A ∧B |= C is a mathematical abbreviation standing for the statement:
“every interpretation that makes A∧B true, makes C also true”
A∧B ⊢I C is a mathematical abbreviation standing for the statement: “ I derives C from A ∧ B”
In other words,
⇒ is a formal symbol of the logic, which is used by the inference system
|= is a shorthand we use to talk about the meaning of formal sentences
⊢I is a shorthand we use to talk about the output of the inference system I 36<br>
slide37. Propositional Wumpus hunter problems Lack of variables prevents stating more general rules
We need a set of similar rules for each cell.
Change of the KB over time is difficult to represent
Standard technique is to index facts with the time when they’re true.
This means we have a separate KB for every time point.<br>
slide38. Propositional logic summary Inference is the process of deriving new sentences from old
Sound inference derives true conclusions given true premises
Complete inference derives all true conclusions from a set of premises
A valid sentence is true in all worlds under all interpretations
If an implication sentence can be shown to be valid, then—given its premise—its consequent can be derived
Different logics make different commitments about what the world is made of and what kind of beliefs we can have
Propositional logic commits only to the existence of facts that may or may not be the case in the world being represented
Simple syntax and semantics suffices to illustrate the process of inference
Propositional logic can become impractical, even for very small worlds<br>