warmup

From the prep exercises you did for today:

Write down


today


from the prep exercises

  1. What’s the FOL expression for “f is not O(g)”?

  2. √x is not O(sin(x))

(s speaker notes)


unification


unification: make things look the same

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)

forward chaining

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:

  1. the law; (2) and (3) existential instantiation
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


FwdChainAIM94 M 3: Missile(M1) WEAPON Weapon(M1) M->WEAPON KB 5 and_M_OWNS M->and_M_OWNS and_CRIMINAL WEAPON->and_CRIMINAL AMW 7: American(West) AMW->and_CRIMINAL NME 8: Enemy(Nono, America) HOSTILE Hostile(Nono) NME->HOSTILE KB 6 OWNS 2: Owns(Nono, M1) OWNS->and_M_OWNS SELLS Sells(West, M1, Nono) SELLS->and_CRIMINAL HOSTILE->and_CRIMINAL CRIMINAL Criminal(West) and_M_OWNS->SELLS KB 4 and_CRIMINAL->CRIMINAL KB 1

or/implies, Horn & definite clauses

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)


first trick: ∨ into ⇒

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


this seems familiar…


backward chaining

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


this seems familiar…


el fin


  1. a numeronym for “propositionalization”↩︎