From the prep exercises you did for today:
Write down
something(s) you learned / some new idea
question(s) you still have / thing(s) that are confusing
what’s the FOL expression for “f is not O(g)”?
homework 4 due next Sunday
3 of 15 actually emailed me about the whatever-they-are exercises
Nima, Jakayline, Dylan each received +1 internets
whatever-they-are = before-class tasks, inspired by one of those
What’s the FOL expression for “f is not O(g)”?
√x is not O(sin(x))
(s speaker notes)
can “stay at first-order level” or use “lifted” versions to do inference in FOL
uses substitutions to use generalized modus ponens
how to find those substs?
function UNIFY(x, y, θ=empty)
"""returns a substitution to make x and y identical,
or failure"""
if θ = failure then return failure
else if x = y then return θ
else if VARIABLE?(x) then return UNIFY-VAR(x, y, θ)
else if VARIABLE?(y) then return UNIFY-VAR(y, x, θ)
else if COMPOUND?(x) and COMPOUND?(y) then
return UNIFY(ARGS(x), ARGS(y), UNIFY(OP(x), OP(y), θ))
else if LIST?(x) and LIST?(y) then
return UNIFY(REST(x), REST(y),
UNIFY(FIRST(x), FIRST(y), θ))
else return failure
function UNIFY-VAR(var, x, θ)
"returns a substitution"
if {var/val} ∈ θ for some val then return UNIFY(val, x, θ)
else if {x/val} ∈ θ for some val then
return UNIFY(var, val, θ)
else if OCCUR-CHECK?(var, x) then return failure
else return add {var/x} to θ
OCCUR-CHECK?(var, x): does var occur inside
expression x? E.g. S(t) occurs in
S(S(t)) (why is this a problem?)
make things look the same: overlay the ASTs, or solve system of equations
| n | left | right |
|---|---|---|
| 1 | Knows(John, x) | Knows(y, Mother(y)) |
| 2 | P(x, G(x), z) | P(F(y), z, G(F(A))) |
(and compare against the algorithm)
now your turn
| n | left | right |
|---|---|---|
| 3 | T(x, F(x)) | T(G(y), F(H(A))) |
| 4 | R(x, F(x)) | R(F(y), y) |
| 5 | Likes(x, y) | Likes(y, z) |
| 6 | S(x, x, F(A)) | S(y, F(z), y) |
Text example:
The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.
Make that a KB:
| n | expression |
|---|---|
| 1 | American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal(x) |
| 2 | Owns(Nono, M1) |
| 3 | Missle(M1) |
| 4 | Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono) |
| 5 | Missile(x) ⇒ Weapon(x) |
| 6 | Enemy(x, America) ⇒ Hostile(x) |
| 7 | American(West) |
| 8 | Enemy(Nono, America) |
go through KB, try to unify premises with things in KB, add conclusions to KB
Iteration 1:
then:
at end of iteration 1: KB includes…
| n | expression |
|---|---|
| 1 | American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(x) ⇒ Criminal(x) |
| 2 | Owns(Nono, M1) |
| 3 | Missle(M1) |
| 7 | American(West) |
| 8 | Enemy(Nono, America) |
| 9 | Weapon(M1)) |
| 10 | Sells(West, M1, Nono) |
| 11 | Hostile(Nono) |
iteration 2: premises of (1) satisfied, add Criminal(West) to KB
forward chaining is pretty expensive. Lots of tricks to make it more efficient.
→ Horn clauses and definite clauses
(“positive” and “negative” literals: presence or absence of “¬” in front of the literal – purely syntactical, unrelated to underlying true/false value)
A ⇒ B ≡ ¬ A ∨ B
any clause (disjunction) becomes an implication
¬ A ∨ ¬ B ∨ C ¬ D
≡ ( ¬ A ∨ ¬ B ∨ ¬ D ) ∨ C
≡ (¬ ( A ∧ B ∧ D ) ) ∨ C
≡ A ∧ B ∧ D ⇒ C
Exactly one positive (no ‘¬’) term makes this nice.
What if 2+?
¬ A ∨ ¬ B ∨ C ∨ D
≡ ¬ (A ∧ B) ∨ (C ∨ D)
≡ A ∧ B ⇒ C ∨ D
Now your chaining/search needs to branch: one for C, one for D.
Every clause with k > 1 positive terms increases the downstream work by factor of k, yikes
all Horn clauses → forward chaining runs time linear of size of KB ≈ search over an “asterisk” graph
clauses with k > 1 positive literals → search over tree with branching factor k
Horn, definite clauses are about algorithmic efficiency
What kind of search does forward chaining resemble?
breadth-first search!
it’s not quite BFS, but it rhymes, doesn’t it?
Previous example:
Algorithm is given: Criminal(West)?
Iterate through premises of American(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(x) ⇒ Criminal(x)
→ Algorithm given: American(x)? Unifies with American(West), returns
→ Algorithm given: Weapon(y)? Unifies with RHS of KB 5
» Algorithm given: Missile(x)? Unfies with KB 3, returns, returns
» Algorithm given Sells(x, y, z), unifies with RHS of KB 4
etc
What kind of search does backward chaining resemble?
depth-first search!
it’s not quite DFS, but it rhymes, doesn’t it?