Logical Agents
Philipp Koehn 5 March 2020
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
Logical Agents Philipp Koehn 5 March 2020 Philipp Koehn - - PowerPoint PPT Presentation
Logical Agents Philipp Koehn 5 March 2020 Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020 1 The world is everything that is the case. Wittgenstein, Tractatus Philipp Koehn Artificial Intelligence: Logical Agents 5 March
Philipp Koehn 5 March 2020
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
1
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
2
– forward chaining – backward chaining – resolution
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
3
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
4
TELL it what it needs to know
i.e., what they know, regardless of how implemented
i.e., data structures in KB and algorithms that manipulate them
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
5
function KB-AGENT( percept) returns an action static: KB, a knowledge base t, a counter, initially 0, indicating time TELL(KB, MAKE-PERCEPT-SENTENCE( percept,t)) action← ASK(KB, MAKE-ACTION-QUERY(t)) TELL(KB, MAKE-ACTION-SENTENCE(action, t)) t←t + 1 return action
– represent states, actions, etc. – incorporate new percepts – update internal representations of the world – deduce hidden properties of the world – deduce appropriate actions
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
6
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
7
Computer game from 1972
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
8
– gold +1000, death -1000 – -1 per step, -10 for using the arrow
– squares adjacent to wumpus are smelly – squares adjacent to pit are breezy – glitter iff gold is in the same square – shooting kills wumpus if you are facing it – shooting uses up the only arrow – grabbing picks up gold if in same square – releasing drops the gold in same square
Forward, Grab, Release, Shoot
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
9
Yes—Wumpus and Pits do not move
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
10
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
11
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
12
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
13
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
14
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
15
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
16
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
17
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
18
(2,2) has pit w/ prob 0.86, vs. 0.31
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
19
– wumpus was there ⇒ dead ⇒ safe – wumpus wasn’t there ⇒ safe
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
20
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
21
such that conclusions can be drawn
i.e., define truth of a sentence in a world
– x + 2 ≥ y is a sentence; x2 + y > is not a sentence – x + 2 ≥ y is true iff the number x + 2 is no less than the number y – x + 2 ≥ y is true in a world where x=7, y =1 x + 2 ≥ y is false in a world where x=0, y =6
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
22
KB ⊧ α
if and only if α is true in all worlds where KB is true
entails “the Ravens won or the Jays won”
that is based on semantics
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
23
structured worlds with respect to which truth can be evaluated
if α is true in m
⇒ KB ⊧ α if and only if M(KB) ⊆ M(α)
α = Ravens won
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
24
⇒ 8 possible models
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
25
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
26
KB = wumpus-world rules + observations
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
27
KB = wumpus-world rules + observations α1 = “[1,2] is safe”, KB ⊧ α1, proved by model checking
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
28
KB = wumpus-world rules + observations
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
29
KB = wumpus-world rules + observations α2 = “[2,2] is safe”, KB / ⊧ α2
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
30
Entailment = needle in haystack; inference = finding it
whenever KB ⊢i α, it is also true that KB ⊧ α
whenever KB ⊧ α, it is also true that KB ⊢i α
say almost anything of interest, and for which there exists a sound and complete inference procedure.
is known by the KB.
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
31
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
32
⇒ P2 is a sentence (implication)
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
33
E.g. P1,2 P2,2 P3,1 false true false (with these symbols, 8 possible models, can be enumerated automatically)
¬P is true iff P is false P1 ∧ P2 is true iff P1 is true and P2 is true P1 ∨ P2 is true iff P1 is true or P2 is true P1 ⇒ P2 is true iff P1 is false or P2 is true i.e., is false iff P1 is true and P2 is false P1 ⇔ P2 is true iff P1 ⇒ P2 is true and P2 ⇒ P1 is true
¬P1,2 ∧ (P2,2 ∨ P3,1) = true ∧ (false ∨ true)=true ∧ true=true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
34
P Q ¬P P ∧ Q P ∨ Q P⇒Q P⇔Q false false true false false true true false true true false true true false true false false false true false false true true false true true true true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
35
– observation R1 ∶ ¬P1,1
– rule R2 ∶ B1,1 ⇔ (P1,2 ∨ P2,1) – rule R3 ∶ B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) – observation R4 ∶ ¬B1,1 – observation R5 ∶ B2,1
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
36
B1,1 B2,1 P1,1 P1,2 P2,1 P2,2 P3,1 R1 R2 R3 R4 R5 KB false false false false false false false true true true true false false false false false false false false true true true false true false false ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ false true false false false false false true true false true true false false true false false false false true true true true true true true false true false false false true false true true true true true true false true false false false true true true true true true true true false true false false true false false true false false true true false ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ true true true true true true true false true true false true false
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
37
function TT-ENTAILS?(KB,α) returns true or false inputs: KB, the knowledge base, a sentence in propositional logic α, the query, a sentence in propositional logic symbols←a list of the proposition symbols in KB and α return TT-CHECK-ALL(KB, α, symbols,[]) function TT-CHECK-ALL(KB, α, symbols, model) returns true or false if EMPTY?(symbols) then if PL-TRUE?(KB, model) then return PL-TRUE?(α,model) else return true else do P ← FIRST(symbols); rest← REST(symbols) return TT-CHECK-ALL(KB, α, rest, EXTEND(P, true, model)) and TT-CHECK-ALL(KB, α, rest, EXTEND(P, false, model))
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
38
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
39
α ≡ β if and only if α ⊧ β and β ⊧ α (α ∧ β) ≡ (β ∧ α) commutativity of ∧ (α ∨ β) ≡ (β ∨ α) commutativity of ∨ ((α ∧ β) ∧ γ) ≡ (α ∧ (β ∧ γ)) associativity of ∧ ((α ∨ β) ∨ γ) ≡ (α ∨ (β ∨ γ)) associativity of ∨ ¬(¬α) ≡ α double-negation elimination (α ⇒ β) ≡ (¬β ⇒ ¬α) contraposition (α ⇒ β) ≡ (¬α ∨ β) implication elimination (α ⇔ β) ≡ ((α ⇒ β) ∧ (β ⇒ α)) biconditional elimination ¬(α ∧ β) ≡ (¬α ∨ ¬β) De Morgan ¬(α ∨ β) ≡ (¬α ∧ ¬β) De Morgan (α ∧ (β ∨ γ)) ≡ ((α ∧ β) ∨ (α ∧ γ)) distributivity of ∧ over ∨ (α ∨ (β ∧ γ)) ≡ ((α ∨ β) ∧ (α ∨ γ)) distributivity of ∨ over ∧
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
40
e.g., True, A ∨ ¬A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B
KB ⊧ α if and only if (KB ⇒ α) is valid
e.g., A ∨ B, C
e.g., A ∧ ¬A
KB ⊧ α if and only if (KB ∧ ¬α) is unsatisfiable i.e., prove α by reductio ad absurdum
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
41
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
42
– Legitimate (sound) generation of new sentences from old – Proof = a sequence of inference rule applications Can use inference rules as operators in a standard search alg. – Typically require translation of sentences into a normal form
– truth table enumeration (always exponential in n) – improved backtracking – heuristic search in model space (sound but incomplete) e.g., min-conflicts-like hill-climbing algorithms
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
43
KB = conjunction of Horn clauses
– proposition symbol; or – (conjunction of symbols) ⇒ symbol e.g., C ∧ (B ⇒ A) ∧ (C ∧ D ⇒ B)
α1,...,αn, α1 ∧ ⋯ ∧ αn ⇒ β β
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
44
add its conclusion to the KB, until query is found P ⇒ Q L ∧ M ⇒ P B ∧ L ⇒ M A ∧ P ⇒ L A ∧ B ⇒ L A B
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
45
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
46
e.g., A and B
e.g., A ∧ B ⇒ C, therefor we establish C is true
– no more inference can be carried out, or – goal is reached
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
47
P ⇒ Q L ∧ M ⇒ P B ∧ L ⇒ M A ∧ P ⇒ L A ∧ B ⇒ L A B
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
48
in which A is premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
49
in which B is premise
⇒ L has now fulfilled premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
50
in which L is premise
⇒ M has now fulfilled premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
51
in which M is premise
⇒ P has now fulfilled premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
52
in which P is premise
⇒ Q has now fulfilled premise
⇒ L has now fulfilled premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
53
in which P is premise
⇒ Q has now fulfilled premise
⇒ L has now fulfilled premise
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
54
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
55
function PL-FC-ENTAILS?(KB,q) returns true or false inputs: KB, the knowledge base, a set of propositional Horn clauses q, the query, a proposition symbol local variables: count, a table, indexed by clause, init. number of premises inferred, a table, indexed by symbol, each entry initially false agenda, a list of symbols, initially the symbols known in KB while agenda is not empty do p← POP(agenda) unless inferred[p] do inferred[p]←true for each Horn clause c in whose premise p appears do decrement count[c] if count[c] = 0 then do if HEAD[c] = q then return true PUSH(HEAD[c],agenda) return false
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
56
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
57
to prove Q by BC, check if Q is known already, or prove by BC all premises of some rule concluding q
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
58
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
59
⇒ Q
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
60
⇒ P
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
61
⇒ L
⇒ repeated subgoal
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
62
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
63
⇒ L
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
64
⇒ L
⇒ L is true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
65
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
66
⇒ M
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
67
⇒ M
⇒ M is true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
68
⇒ P
⇒ P is true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
69
⇒ Q
⇒ Q is true
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
70
e.g., object recognition, routine decisions
e.g., Where are my keys? How do I get into a PhD program?
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
71
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
72
conjunction of disjunctions of literals ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ clauses E.g., (A ∨ ¬B) ∧ (B ∨ ¬C ∨ ¬D)
ℓ1 ∨ ⋯ ∨ ℓk, m1 ∨ ⋯ ∨ mn ℓ1 ∨ ⋯ ∨ ℓi−1 ∨ ℓi+1 ∨ ⋯ ∨ ℓk ∨ m1 ∨ ⋯ ∨ mj−1 ∨ mj+1 ∨ ⋯ ∨ mn where ℓi and mj are complementary literals. E.g., P1,3 ∨ P2,2, ¬P2,2 P1,3
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
73
B1,1 ⇔ (P1,2 ∨ P2,1)
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
74
B1,1 ⇔ (P1,2 ∨ P2,1)
⇒ β) ∧ (β ⇒ α). (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1)
(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬(P1,2 ∨ P2,1) ∨ B1,1)
(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ ((¬P1,2 ∧ ¬P2,1) ∨ B1,1)
(¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬P1,2 ∨ B1,1) ∧ (¬P2,1 ∨ B1,1)
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
75
reformulated as: (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬P1,2 ∨ B1,1) ∧ (¬P2,1 ∨ B1,1)
¬P1,2 ∨ B1,1 ¬B1,1 ¬P1,2
¬P1,2 P1,2 false
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
76
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
77
function PL-RESOLUTION(KB, α) returns true or false inputs: KB, the knowledge base, a sentence in propositional logic α, the query, a sentence in propositional logic clauses←the set of clauses in the CNF representation of KB ∧ ¬α new←{} loop do for each Ci, Cj in clauses do resolvents← PL-RESOLVE(Ci,Cj) if resolvents contains the empty clause then return true new←new ∪ resolvents if new ⊆ clauses then return false clauses←clauses ∪ new
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
78
– observe glitter → done – unexplored safe spot → plan route to it – if Wampus in possible spot → shoot arrow – take a risk to go possibly risky spot
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020
79
to derive new information and make decisions
– syntax: formal structure of sentences – semantics: truth of sentences wrt models – entailment: necessary truth of one sentence given another – inference: deriving sentences from other sentences – soundess: derivations produce only entailed sentences – completeness: derivations can produce all entailed sentences
inference to determine state of the world, etc.
Philipp Koehn Artificial Intelligence: Logical Agents 5 March 2020