1 / 36

CS421 – Logic Programming (Unification)

CS421 – Logic Programming (Unification). Based on slides by Mattox Beckman, updated by Vikram Adve, Gul Agha, Elsa Gunter. Contents. Logics Logic Programming Unification. Propositional Logic. Propositions P, Q, R Operations AND, OR, NOT, IMPLIES, EQUIV Models Propositions → { T, F }.

Download Presentation

CS421 – Logic Programming (Unification)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS421 – Logic Programming(Unification) Based on slides by Mattox Beckman, updated by Vikram Adve, Gul Agha, Elsa Gunter

  2. Contents • Logics • Logic Programming • Unification

  3. Propositional Logic • Propositions • P, Q, R • Operations • AND, OR, NOT, IMPLIES, EQUIV • Models • Propositions → { T, F }

  4. Predicate Logic • Terms • Objects – O = { o1, o2, … } • Functions – F : On→ O • Predicates – P : O → { T, F } • Operations • + Quantifiers • Models

  5. Horn Clauses • H ← T1 & T2 & T3 & … • Each element a predicate • Inference • Backwards Chaining • Forwards Chaining

  6. Example • Graduated(s) ← Quals(s) & Thesis(s) • Quals(s) ← LangR(s) & SystemR(s) & AreaR(s) & TheoryR(s) • LangR(s) ← CS421(s) • TheoryR(s) ← CS476(s) • CS421(P), CS476(P), CS423(P), …

  7. Logic Programming • Inference on Horn Clauses • Facts: H ← • Rules: H ← T1 & T2 & … • Unification • Back Tracking

  8. Example • (append empty x x) ← • (append (cons w x) y (cons w z)) ← (append x y z) • (append q r (cons 1 (cons 2 empty)))

  9. Example • (append empty x x) ← • (append (cons w x) y (cons w z)) ← (append x y z) • (append q r (cons 1 (cons 2 empty))) • q = empty • r = (cons 1 (cons 2 empty)) • x = (cons 1 (cons 2 empty))

  10. Example • (append empty x x) ← • (append (cons w x) y (cons w z)) ← (append x y z) • (append q r (cons 1 (cons 2 empty))) • q = (cons 1 x), w = 1, y = r • z = (cons 2 empty) • (append x r (cons 2 empty))

  11. Unification • Terms • Constructors/Constants • Variables • Substitution • Variable Assignment: Variables → Terms Term → Constant → Variable → Constructor(Term1, Term2, …)

  12. Unification Problem • { s1 = t1, s2 = t2, …, sn = tn } • Find unification solution σ • σ(si) = (ti), for all i = 1, …, n

  13. Unification Algorithm • S = { s1 = t1, s2 = t2, …, sn = tn } • S = { } → Unif(S) = Identity • S = { s = t  S’ } • Delete: if s = t • Orient: if s = x (x is a variable, s is not a variable) Unif(S) = Unif({ x = s S’ }) • Decompose: if c(q1, q2, …, qn) = c(r1, r2, …, rn) Unif(S) = Unif({ q1=r1  q2=r2  …  qn=rn  S’ }) • Eliminate: if x = t (x does not occur in t)

  14. Unification • Eliminate: if x = t (x does not occur in t) • f = x | t • g = Unif(f(S’)) • Unif(S) = { x | g(t) } o g • Bad example: x = (cons 1 x)

  15. Unification Example • x, y, z variables, f, g constructors • S = { g(y, f(y)) = x, f(x) = f(g(y, z)) }

  16. Unification Example • x, y, z variables, f, g constructors • Pick: g(y, f(y)) = x • S = { g(y, f(y)) = x, f(x) = f(g(y, z)) }

  17. Unification Example • x, y, z variables, f, g constructors • Pick: g(y, f(y)) = x • Orient: x = g(y, f(y) • S = { g(y, f(y)) = x, f(x) = f(g(y, z)) }

  18. Unification Example • x, y, z variables, f, g constructors • S = { x = g(y, f(y)), f(x) = f(g(y, z)) }

  19. Unification Example • x, y, z variables, f, g constructors • Pick: x = g(y, f(y)) • S = { x = g(y, f(y)), f(x) = f(g(y, z)) }

  20. Unification Example • x, y, z variables, f, g constructors • Pick: x = g(y, f(y)) • Eliminate • S = { x = g(y, f(y)), f(x) = f(g(y, z)) }

  21. Unification Example • x, y, z variables, f, g constructors • S = { f(g(y, f(y))) = f(g(y, z)) } • x |→ g(y, f(y))

  22. Unification Example • x, y, z variables, f, g constructors • Pick: f(g(y, f(y))) = f(g(y, z)) • S = { f(g(y, f(y))) = f(g(y, z)) } • x |→ g(y, f(y))

  23. Unification Example • x, y, z variables, f, g constructors • Pick: f(g(y, f(y))) = f(g(y, z)) • Decompose: g(y, f(y)) = g(y, z) • S = { f(g(y, f(y))) = f(g(y, z)) } • x |→ g(y, f(y))

  24. Unification Example • x, y, z variables, f, g constructors • S = { g(y, f(y)) = g(y, z) } • x |→ g(y, f(y))

  25. Unification Example • x, y, z variables, f, g constructors • Pick: g(y, f(y)) = g(y, z) • S = { g(y, f(y)) = g(y, z) } • x |→ g(y, f(y))

  26. Unification Example • x, y, z variables, f, g constructors • Pick: g(y, f(y)) = g(y, z) • Decompose: y = y, f(y) = z • S = { g(y, f(y)) = g(y, z) } • x |→ g(y, f(y))

  27. Unification Example • x, y, z variables, f, g constructors • S = { y = y, f(y) = z } • x |→ g(y, f(y))

  28. Unification Example • x, y, z variables, f, g constructors • Pick: y = y • S = { y = y, f(y) = z } • x |→ g(y, f(y))

  29. Unification Example • x, y, z variables, f, g constructors • Pick: y = y • Delete • S = { y = y, f(y) = z } • x |→ g(y, f(y))

  30. Unification Example • x, y, z variables, f, g constructors • S = { f(y) = z } • x |→ g(y, f(y))

  31. Unification Example • x, y, z variables, f, g constructors • Pick: f(y) = z • S = { f(y) = z } • x |→ g(y, f(y))

  32. Unification Example • x, y, z variables, f, g constructors • Pick: f(y) = z • Orient: z = f(y) • S = { f(y) = z } • x |→ g(y, f(y))

  33. Unification Example • x, y, z variables, f, g constructors • S = { z = f(y) } • x |→ g(y, f(y))

  34. Unification Example • x, y, z variables, f, g constructors • Pick: z = f(y) • S = { z = f(y) } • x |→ g(y, f(y))

  35. Unification Example • x, y, z variables, f, g constructors • Pick: z = f(y) • Elimination • S = { z = f(y) } • x |→ g(y, f(y))

  36. Unification Example • x, y, z variables, f, g constructors • S = { } • x |→ g(y, f(y)) • z |→ f(y)

More Related