Course: Engineering Artificial Intelligence
description
Transcript of Course: Engineering Artificial Intelligence
University College Cork (Ireland) Department of Civil and Environmental Engineering
Course:Engineering Artificial Intelligence
Dr. Radu Marinescu
Lecture 7
University College Cork (Ireland) Department of Civil and Environmental Engineering
Today’s class
o Logic• Propositional logic• First order logic
R. Marinescu October-2009 page 2
University College Cork (Ireland) Department of Civil and Environmental Engineering
What is logic?
o A formal language• Syntax – what expressions are legal• Semantics – what legal expressions mean• Proof system – a way of manipulating syntactic expressions to get
other syntactic expressions (which will tell us something new)
R. Marinescu October-2009 page 3
University College Cork (Ireland) Department of Civil and Environmental Engineering
What is logic?
o A formal language• Syntax – what expressions are legal• Semantics – what legal expressions mean• Proof system – a way of manipulating syntactic expressions to get
other syntactic expressions (which will tell us something new)o Why proofs? Two kinds of inferences an agent
might want to make• Multiple percepts => conclusions about the world• Current state & operators => properties of next state
R. Marinescu October-2009 page 4
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional logic syntax
o Syntax: what you’re allowed to write•for (int t = 0; t == 100; t++) {…}• “Colorless green ideas sleep furiously” (Noam Chomsky)
R. Marinescu October-2009 page 5
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional logic syntax
o Syntax: what you’re allowed to write•for (int t = 0; t == 100; t++) {…}• “Colorless green ideas sleep furiously” (Noam Chomsky)
o Sentences (WFF: well formed formulas)•true and false are sentences
R. Marinescu October-2009 page 6
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional logic syntax
o Syntax: what you’re allowed to write•for (int t = 0; t == 100; t++) {…}• “Colorless green ideas sleep furiously” (Noam Chomsky)
o Sentences (WFF: well formed formulas)•true and false are sentences• Propositional variables are sentences: P, Q, R, Z
R. Marinescu October-2009 page 7
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional logic syntax
o Syntax: what you’re allowed to write•for (int t = 0; t == 100; t++) {…}• “Colorless green ideas sleep furiously” (Noam Chomsky)
o Sentences (WFF: well formed formulas)•true and false are sentences• Propositional variables are sentences: P, Q, R, Z• If Φ and Ψ are sentences, then so are
(Φ), ¬ Φ, Φ /\ Ψ, Φ \/ Ψ, Φ → Ψ, Φ ↔ Ψ
R. Marinescu October-2009 page 8
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional logic syntax
o Syntax: what you’re allowed to write•for (int t = 0; t == 100; t++) {…}• “Colorless green ideas sleep furiously” (Noam Chomsky)
o Sentences (WFF: well formed formulas)•true and false are sentences• Propositional variables are sentences: P, Q, R, Z• If Φ and Ψ are sentences, then so are
(Φ), ¬ Φ, Φ ˄ Ψ, Φ ˅ Ψ, Φ → Ψ, Φ ↔ Ψ• Nothing else is a sentence
R. Marinescu October-2009 page 9
University College Cork (Ireland) Department of Civil and Environmental Engineering
Precedence
o Precedence rules enable “shorthand” form of sentences, but formally only the fully parenthesized form is legal
o Syntactically ambiguous forms allowed in shorthand only when semantically equivalent: A ˄ B ˄ C is equivalent to (A ˄ B) ˄ C and A ˄ (B ˄ C)
R. Marinescu October-2009 page 10
¬
˄
˅
→
↔
highest
lowest
A ˅ B ˄ C A ˅ (B ˄ C)
A ˄ B → C ˅ D (A ˄ B) → (C ˅ D)
A → B ˅ C ↔ D (A → (B ˅ C)) ↔ D
University College Cork (Ireland) Department of Civil and Environmental Engineering
Semantics
o Meaning of a sentence is truth value {t, f}o Interpretation is an assignment of truth values to
propositional variables• holds(Φ, i) [Sentence Φ is t in interpretation i]• fails(Φ, i) [Sentence Φ is f in interpretation i]
R. Marinescu October-2009 page 11
University College Cork (Ireland) Department of Civil and Environmental Engineering
Semantic rules
o holds(true, i) for all io fails(false, i) for all Io holds(¬Φ, i) if and only if fails(Φ, i)
o holds(Φ ˄ Ψ, i) iff holds(Φ, i) and holds(Ψ, i)
o holds(Φ ˅ Ψ, i) iff holds(Φ, i) or holds(Ψ, i)
R. Marinescu October-2009 page 12
(negation)
(conjunction)
(disjunction)
University College Cork (Ireland) Department of Civil and Environmental Engineering
Semantic rules
o holds(true, i) for all io fails(false, i) for all Io holds(¬Φ, i) if and only if fails(Φ, i)
o holds(Φ ˄ Ψ, i) iff holds(Φ, i) and holds(Ψ, i)
o holds(Φ ˅ Ψ, i) iff holds(Φ, i) or holds(Ψ, i)
o holds(P, i) iff i(P) = to fails(P, i) iff i(P) = f
R. Marinescu October-2009 page 13
(negation)
(conjunction)
(disjunction)
University College Cork (Ireland) Department of Civil and Environmental Engineering
Some important shorthand
o Φ → Ψ ≡ ¬Φ ˅ Ψ (conditional, implication)
o Φ ↔ Ψ ≡ (Φ → Ψ) ˄ (Ψ → Φ) (biconditional, equivalence)
R. Marinescu October-2009 page 14
antecedent → consequent
University College Cork (Ireland) Department of Civil and Environmental Engineering
Some important shorthand
o Φ → Ψ ≡ ¬Φ ˅ Ψ (conditional, implication)
o Φ ↔ Ψ ≡ (Φ → Ψ) ˄ (Ψ → Φ) (biconditional, equivalence)
R. Marinescu October-2009 page 15
antecedent → consequent
P Q ¬P P˄Q P˅Q P→Q Q→P P↔Q
f f t f f t t t
f t t f t t f f
t f f f t f t f
t t f t t t t t
Truth tables
University College Cork (Ireland) Department of Civil and Environmental Engineering
Some important shorthand
o Φ → Ψ ≡ ¬Φ ˅ Ψ (conditional, implication)
o Φ ↔ Ψ ≡ (Φ → Ψ) ˄ (Ψ → Φ) (biconditional, equivalence)
R. Marinescu October-2009 page 16
antecedent → consequent
P Q ¬P P˄Q P˅Q P→Q Q→P P↔Q
f f t f f t t t
f t t f t t f f
t f f f t f t f
t t f t t t t t
Truth tables
Note that implication is not “causality”, if P is f then P→Q is t
University College Cork (Ireland) Department of Civil and Environmental Engineering
Terminology
o A sentence is valid iff its truth table value is t in all interpretations
• Valid sentences: true, ¬false, P ˅ ¬P
o A sentence is satisfiable iff its truth value is t in at least one interpretation
• Valid sentences: P, true, ¬P
o A sentence is unsatisfiable iff its truth value is f in all interpretations
• Unsatisfiable sentences: P ˄¬P, false, ¬true
R. Marinescu October-2009 page 17
University College Cork (Ireland) Department of Civil and Environmental Engineering
Terminology
o A sentence is valid iff its truth table value is t in all interpretations
• Valid sentences: true, ¬false, P ˅ ¬P
o A sentence is satisfiable iff its truth value is t in at least one interpretation
• Valid sentences: P, true, ¬P
o A sentence is unsatisfiable iff its truth value is f in all interpretations
• Unsatisfiable sentences: P ˄¬P, false, ¬true
R. Marinescu October-2009 page 18
All are finitely decidable!
University College Cork (Ireland) Department of Civil and Environmental Engineering
Examples
R. Marinescu October-2009 page 19
Sentence Valid?Interpretation that makesentence’s truth value = f
smoke → firesmoke ˅ ¬fire
valid
University College Cork (Ireland) Department of Civil and Environmental Engineering
Examples
R. Marinescu October-2009 page 20
Sentence Valid?Interpretation that makesentence’s truth value = f
smoke → smoke¬ smoke ˅ smoke
valid
smoke → fire¬ smoke ˅ fire
satisfiable,not valid
smoke = t, fire = f
University College Cork (Ireland) Department of Civil and Environmental Engineering
Examples
R. Marinescu October-2009 page 21
Sentence Valid?Interpretation that makesentence’s truth value = f
smoke → smoke¬smoke ˅ smoke
valid
smoke → fire¬smoke ˅ fire
satisfiable,not valid
smoke = t, fire = f
(s → f) → (¬s → ¬f) satisfiable,not valid
s = f, f = ts → f = t, ¬s → ¬f = f
University College Cork (Ireland) Department of Civil and Environmental Engineering
Examples
R. Marinescu October-2009 page 22
Sentence Valid?Interpretation that makesentence’s truth value = f
smoke → smoke¬smoke ˅ smoke
valid
smoke → fire¬smoke ˅ fire
satisfiable,not valid
smoke = t, fire = f
(s → f) → (¬s → ¬f) satisfiable,not valid
s = f, f = ts → f = t, ¬s → ¬f = f
(s → f) → (¬f → ¬s) valid
University College Cork (Ireland) Department of Civil and Environmental Engineering
Satisfiability
o Related to constraint satisfactiono Given a sentence S, try to find an interpretation i
such that holds(S, i)o Analogous to finding an assignment of values to
variables such that the constraints hold
R. Marinescu October-2009 page 23
University College Cork (Ireland) Department of Civil and Environmental Engineering
Satisfiability
o Related to constraint satisfactiono Given a sentence S, try to find an interpretation i
such that holds(S, i)o Analogous to finding an assignment of values to
variables such that the constraints hold
o Brute force method: enumerate all interpretations and check
o Better methods• Heuristic search• Constraint propagation• Stochastic search
R. Marinescu October-2009 page 24
University College Cork (Ireland) Department of Civil and Environmental Engineering
Satisfiability problems
o Scheduling nurses to work in a hospital• Propositional variables represent, for example, that Pat is working
on Tuesday at 2• Constraints on the schedule are represented using logical
expressions over the variables
o Finding bugs in software• Propositional variables represent states of the program• Use logic to describe how the program works and to assert there
is a bug• If the sentence is satisfiable, you’ve found a bug
R. Marinescu October-2009 page 25
University College Cork (Ireland) Department of Civil and Environmental Engineering
A good lecture?
o Imagine we knew that:• If today is sunny, then Thomas will be happy (S → H)• If Thomas is happy, the lecture will be good (H → G)• Today is sunny (S)
Should we conclude that the lecture will be good?
R. Marinescu October-2009 page 26
University College Cork (Ireland) Department of Civil and Environmental Engineering
Checking interpretations
R. Marinescu October-2009 page 27
S H G
t t t
t t f
t f t
t f f
f t t
f t f
f f t
f f f
University College Cork (Ireland) Department of Civil and Environmental Engineering
Checking interpretations
R. Marinescu October-2009 page 28
S H G S→H H→G S
t t t t t t
t t f t f t
t f t f t t
t f f f t t
f t t t t f
f t f t f f
f f t t t f
f f f t t f
University College Cork (Ireland) Department of Civil and Environmental Engineering
Checking interpretations
R. Marinescu October-2009 page 29
S H G S→H H→G S G
t t t t t t t
t t f t f t f
t f t f t t t
t f f f t t f
f t t t t f t
f t f t f f f
f f t t t f t
f f f t t f f
Good lecture!
University College Cork (Ireland) Department of Civil and Environmental Engineering
Entailment
o A knowledge base (KB) entails a sentence S iff every interpretation that makes KB true also makes S true
R. Marinescu October-2009 page 30
KB Sholds
interpretations interpretationssubset
holds holds
University College Cork (Ireland) Department of Civil and Environmental Engineering
Computing entailment
o Enumerate all interpretationso Select those in which all elements of KB are trueo Check to see if S is true in all those
interpretations
R. Marinescu October-2009 page 31
KB Sholds
interpretations interpretationssubset
holds holds
University College Cork (Ireland) Department of Civil and Environmental Engineering
Computing entailment
o Enumerate all interpretationso Select those in which all elements of KB are trueo Check to see if S is true in all those
interpretations
R. Marinescu October-2009 page 32
KB Sholds
interpretations interpretationssubset
holds holds
Way too many interpretations in general !!
University College Cork (Ireland) Department of Civil and Environmental Engineering
Entailment and Proof
o A proof is a way to test whether a KB entails a sentence, without enumerating all possible interpretations
R. Marinescu October-2009 page 33
KB Sholds
interpretations interpretationssubset
holds holds
proof
University College Cork (Ireland) Department of Civil and Environmental Engineering
Proof
o Proof is a sequence of sentenceso First ones are premises (in KB)o Then, you can write down on the next line the result
of applying an inference rule to previous lineso When S is on a line, you have proved S from KB
o If inference rules are sound, then any S you can prove from KB is entailed by KB
o If inference rules are complete, then any S that is entailed by KB can be proved from KB
R. Marinescu October-2009 page 34
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction
o Some inference rules
R. Marinescu October-2009 page 35
α → β
α
β
Modusponens
α → β
¬β
¬α
Modustolens
α
β
α ˄ β
AND-introduction
α ˄ β
α
AND-elimination
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 36
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 37
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
4 P 1 And-Elim
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 38
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
4 P 1 And-Elim
5 R 4,2 Modus Ponens
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 39
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
4 P 1 And-Elim
5 R 4,2 Modus Ponens
6 Q 1 And-Elim
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 40
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
4 P 1 And-Elim
5 R 4,2 Modus Ponens
6 Q 1 And-Elim
7 Q ˄ R 5,6 And-Intro
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Natural deduction example
R. Marinescu October-2009 page 41
Step Formula Derivation
1 P ˄ Q given
2 P → R given
3 (Q ˄ R) → S given
4 P 1 And-Elim
5 R 4,2 Modus Ponens
6 Q 1 And-Elim
7 Q ˄ R 5,6 And-Intro
8 S 7,3 Modus Ponens
Prove S
University College Cork (Ireland) Department of Civil and Environmental Engineering
Proof systems
o There are many natural deduction systems; they are typically “proof checkers”, sound but not complete
o Natural deduction uses lots of inference rules which introduces a large branching factor in the search for a proof
o In general, you need to do “proof by cases” which introduces even more branching
R. Marinescu October-2009 page 42
1 P ˅ R
2 Q ˅ R
3 P → R
Prove R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution
o Resolution rule:
o Single inference rule is a sound and complete proof system
o Requires all sentences to be converted to conjunctive normal form (CNF)
R. Marinescu October-2009 page 43
α ˅ β
¬β ˅ γ
α ˅ γ
University College Cork (Ireland) Department of Civil and Environmental Engineering
Conjunctive normal form (CNF)
o Conjunctive normal form (CNF) formulas:
R. Marinescu October-2009 page 44
CBADBCBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
Conjunctive normal form (CNF)
o Conjunctive normal form (CNF) formulas:
• (A ˅ B ˅ ¬C) is a clause, which is a disjunction of literals
• A, B, and ¬C are literals, each of which is a variable or the negation of a variable
• Each clause is a requirement that must be satisfied and can be satisfied in multiple ways
• Every sentence in propositional logic can be written in CNF
R. Marinescu October-2009 page 45
CBADBCBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
Converting to CNF
1. Eliminate arrows using definitions
2. Drive in negations using De Morgan’s Laws
3. Distribute OR over AND
4. Every sentence can be converted to CNF, but it may grow exponentially in size
R. Marinescu October-2009 page 46
CABACBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
CNF conversion example
R. Marinescu October-2009 page 47
DCBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
CNF conversion example
1. Eliminate arrows
R. Marinescu October-2009 page 48
DCBA
DCBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
CNF conversion example
1. Eliminate arrows
2. Drive in negations
R. Marinescu October-2009 page 49
DCBA
DCBA
DCBA
University College Cork (Ireland) Department of Civil and Environmental Engineering
CNF conversion example
1. Eliminate arrows
2. Drive in negations
3. Distribute
R. Marinescu October-2009 page 50
DCBA
DCBA
DCBA
DCBDCA
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution
o Resolution rule:
R. Marinescu October-2009 page 51
α ˅ β
¬β ˅ γ
α ˅ γ
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution
o Resolution rule:
o Resolution refutation:• Convert all sentences to CNF• Negate the desired conclusion (converted to CNF)• Apply resolution until either
Derive false (a contradiction) Can’t apply any more
R. Marinescu October-2009 page 52
α ˅ β
¬β ˅ γ
α ˅ γ
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution
o Resolution refutation:• Convert all sentences to CNF• Negate the desired conclusion (converted to CNF)• Apply resolution until either
Derive false (a contradiction) Can’t apply any more
o Resolution refutation is sound and complete• If we derive a contradiction, then the conclusion follows from
axioms• If we can’t apply any more, then the conclusion cannot be proved
from the axioms
R. Marinescu October-2009 page 53
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 54
1 P ˅ Q
2 P → R
3 Q → R
Prove R Step Formula Derivation
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 55
1 P ˅ Q
2 P → R
3 Q → R
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 56
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 57
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 58
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 59
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 60
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
6 ¬P 2,4
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 61
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
6 ¬P 2,4
7 ¬Q 3,4
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 62
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
6 ¬P 2,4
7 ¬Q 3,4
8 R 5,7
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 63
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
6 ¬P 2,4
7 ¬Q 3,4
8 R 5,7
9 [] 4,8
1 P ˅ Q
2 P → R
3 Q → R
University College Cork (Ireland) Department of Civil and Environmental Engineering
Propositional resolution example
R. Marinescu October-2009 page 64
Prove R Step Formula Derivation
1 P ˅ Q given
2 ¬P ˅ R given
3 ¬Q ˅ R given
4 ¬R negated conclusion
5 Q ˅ R 1,2
6 ¬P 2,4
7 ¬Q 3,4
8 R 5,7
9 [] 4,8
1 P ˅ Q
2 P → R
3 Q → R
false ˅ R
¬R ˅ false
false ˅ false
University College Cork (Ireland) Department of Civil and Environmental Engineering
Example problem
R. Marinescu October-2009 page 65
Prove R
1 (P → Q) → Q
2 (P → R) → R
3 (R →S) → ¬(S → Q)
Do it yourselves!
University College Cork (Ireland) Department of Civil and Environmental Engineering
Proof strategies
o Unit preference: prefer a resolution step involving a unit clause (clause with one literal)
• Produces a shorter clause – which is good since we are trying to produce a zero-length clause, that is a contradiction
R. Marinescu October-2009 page 66
University College Cork (Ireland) Department of Civil and Environmental Engineering
Proof strategies
o Unit preference: prefer a resolution step involving a unit clause (clause with one literal)
• Produces a shorter clause – which is good since we are trying to produce a zero-length clause, that is a contradiction
o Set of support: choose a resolution involving the negated goal or any clause derived from the negated goal
• We’re trying to produce a contradiction that follows from the negated goal, so these are “relevant” clauses
• If a contradiction exists, one can find one using the set-of-support strategy
R. Marinescu October-2009 page 67