# 1 Declarative Programming Motivation Warm Fuzzies What is Logic?... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses,

## Presentation on theme: "1 Declarative Programming Motivation Warm Fuzzies What is Logic?... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses,"— Presentation transcript:

1 Declarative Programming Motivation Warm Fuzzies What is Logic?... Logic Programming? Mechanics of Prolog Terms, Substitution, Unification, Horn Clauses, Proof process Example: List Processing Theoretical Foundations Semantics Logic / Theorem Proving … Resolution Other Issues Search Strategies Declarative/Procedural,... “Impure'' Operators” --- NOT, ! Utilities ? Constraint Programming ? Bayesian Belief Nets

2 Entailment Spse we assert  1,  2, … on(a,b), on(a,b) ⇒ above(a,b), … Then... you should believe  1,  2, … What else should we believe? (Should we believe some β – eg, “ above(a,b) ”?) Entailment addresses this: You should believe all (and only) entailments. Later: Present ALGORITHM for computing these entailments a b c

3 Interpretation Vocabulary: (literals) on ab : if a is immediately on b on bc : if b is immediately on c above ab : a is (somewhere) above b above ac : a is (somewhere) above c An “interpretation” (aka “world”) assigns True xor False to each literal n literals ⇒ 2 n possible worlds, I b a c on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …  

4 Models Write  Ii  if  is True (+) in world I i So  I1 on b c ⊭ I6 on ac on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   Let I (  ) = { I ∣⊨ I  }

5 Models Write  Ii  if  is True (+) in world I i So  I1 on b c ⊭ I6 on bc on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   Let I (  ) = { I ∣⊨ I  } I (on ab )

6 Models Before seeing anything, REAL-WORLD  I = {I 1,…,I 16 } on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …  

7 Models Before seeing anything, REAL-WORLD  I = {I 1,…,I 16 } Asserting  means REAL-WORLD  I (  ) Eg: Asserting on ab means REAL-WORLD ∈ I (on ab ) = {I 1,…,I 8 } Each assertion ELIMINATES some possible worlds on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …  

8 I (on ab ) on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …  

9 on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   I (¬on ab )

10 on ab on ac above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   I (on ac ) I (on ab )

11 on ab on bc above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   I (on ac & on ab )

12 on ab on bc above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   I (¬on ac v above ab )

13 Boolean Combinations I (χ) = {I ∣⊨ I χ} I ( on ab ) = {I1,…,I8} I (¬ on ab ) = {I9,…,I16} I ( on ab ⋀ on ac ) = {I1,…,I8} ∩ {I1,…,I4,I9,…,I12} = {I1,…,I4} I (¬ on ab ⋁ above ab ) = {I9,…,I16} ∪ {I1,I2,I5,I6,I9,I10,I13,I14} = {I1,I2,I5,I6,I9,…,I16} Note: I ( ¬  ) = I – I (  ) I (  ⋁ ξ) = I (  ) ∪ I (ξ) I (  ⋀ ξ) = I (  ) ∩ I (ξ) on ab on bc above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …  

14 What else to believe? Assert ¬ on ab ⋁ above ab ⇒ REAL-WORLD  I (¬ on ab ⋁ above ab ) = {I 1, I 2, I 5, I 6, I 9, …, I 16 } on ab on bc above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   Assert on ab REAL-WORLD  I (¬ on ab ⋁ above ab ) ⋂ I ( on ab ) = {I 1, I 2, I 5,I 6 }

15 What else to believe? on ab on bc above a b above a c I1I1 ++++ … I2I2 +++0 … I3I3 ++0+ … I4I4 ++00 … I5I5 +0++ … I6I6 +0+0 … I7I7 +00+ … I8I8 +000 … I9I9 0+++ … I 10 0++0 … I 11 0+0+ … I 12 0+00 … I 13 00++ … I 14 00+0 … I 15 000+ … I 16 0000 …   REAL-WORLD  I (¬ on ab ⋁ above ab ) ⋂ I ( on ab ) = {I 1, I 2, I 5,I 6 } In each such world, above ab also holds! I ( [¬ on ab ⋁ above ab ] & on ab )  I ( above ab ) ⇒ We should believe above ab !

16 Entailment Given set of assertions  = {  1, … } set of (remaining) possible worlds = I (  ) Spse  holds in each world I  I (  ) I (  )  I (  ) Then you should believe  … as  is true, in every “still possible” world ! Write this    “  entails  ” “  is entailed by  ”

17 Answering Queries 1. Semantical Approach Entailment specifies what we should believe. Given n literals, write n  2 n table. Let W = all 2 n rows For each assertion  i let W := W ⋂ I (  i ) (ie, eliminate every row that does not satisfy  i ) Check  column. If ``+'' in each row (of W) then Answer “YES: {  i }   '' else Answer “IDK: {  i } ⊭  '' Problem: HUGE table! (  in predicate calculus) To decide {  i }  

18 Answering Queries 2. Syntactic Approach Proof Process (aka ``derivation'', ``deduction'') is mechanic process... for deciding whether conclusion follows from premises First consider “forward chaining”: KB ↝ KB' Implemented by... Apply sequence of individual (sound) Inference Rules to initial set of premises, to find new ones Sound  preserves truth If believe ``antecedent'', must believe conclusion Inference Rules  HornClause

19 Derivation Process - -- - man(s) --- --- -- man(X)  mortal(X) - - -- - KB 0 r1r1 - -- - man(s) --- --- -- man(X)  mortal(X) - - -- - mortal(s) - - -- - KB 1 r2r2 - -- - man(s) --- --- -- man(X)  mortal(X) - - -- - mortal(s) - - -- - cat(p) KB 2 r3r3 … r9r9 - -- - man(s) --- --- -- man(X)  mortal(X) - - -- - mortal(s) - - -- - cat(p) KB k

20 New Facts from Old: A sound Inference rule If “P  Q” “P”  KB Thencan add“Q”to KB Called “Modus Ponens” Written: [MP] P  Q P Q

21 Sound Inference Rules [MP] P  Q P Q [  D]P  Q ¬P Q [  E]  x.  (x)  (A) for any A [MT] P  Q ¬Q ¬P [&I]P Q P  Q [&E] P  Q P [RC] P  Q Q  R P  R [  I] P P  Q [MG] P  Q ¬P  Q Q [ ]P ¬ P Contradiction

22 Sound Rules of Inference KB 0 ir j KB 1 If ir j is sound [aka Truth-Preserving], then KB 0 ⊨ KB 1 … I (KB 0 )  I (KB 1 ) So… RW ∊ KB 0  RW ∊ KB 1 … if believe KB 0, must believe KB 1 ! Inference rule ir j maps KB 0 into KB 1

23 I (KB 1 ) Sound Rules of Inference Possible worlds I (KB 0 ) If ir j is sound [aka Truth-Preserving], then KB 0 ⊨ KB 1 … I (KB 0 )  I (KB 1 ) So… RW ∊ KB 0  RW ∊ KB 1 Hence: If believe KB 0, must believe KB 1. RW

24 Sound Rules of Inference – con’t Possible worlds I (KB 0 ) I (KB 1 ) In general, KB 1 = KB 0 + . So KB 1 ⊨ KB 0 … KB 1, KB 0 hold in EXACTLY same worlds: If each ri j is sound, then sequence  ri 1 … ri n  is sound.

25 Answering Queries If { ri j } j sound, then KB 0 ⊧ KB N Adding Truths (Forward Chaining) Given KB 0 produce KB N s.t. ri 1 KB 0 KB 1 KB N… ri N Answering Questions (Backward Chaining) Given KB 0,  ; determine if KB ⊧  Requires sound j s.t. ri 1 KB 0 KB 1 KB N… ri N and  KB N

26 Q: How to reason? Given KB, q, determine if KB ⊨ q ? A: Select Inference Rule IR Select Facts(s) {F i } from KB Apply rule IR to Facts {F i } to get new Fact  Add  to KB Repeat until find  = q Issues: 1. Lots of Inference Rules… Which one to use, when? 2. Is overall system “complete”? If  answer, guaranteed to find it? How to Reason?

27 ? Properties of Derivation Process ⊢  is SOUND  ⊢     ⊨  Produces only “true” results ⊢  is COMPLETE  ⊢     ⊨  Produces all “true” results ⊢  is DECIDABLE  ⊢  ?  returns Y or N in finite time

28 Degenerate ⊦  For any ,  ⊂ WFFs:  ⊬ N   ⊢ P  Notice ⊢ N is SOUND (returns everything logically entailed) ⊢ P is COMPLETE (returns everything logically entailed) ⊢ N, ⊢ P is DECIDABLE (answer every question) f’sure Just say “No”

29 For any sufficiently complicated domain as complex as arithmetic No ⊢  can be SOUND, COMPLETE, DECIDABLE!! Reduction to halting Problem. Fundamental Limitation Not Predicate Calculus’s fault: Reasoning is inherently undecidable, no manner what formalism used

30 Deals only with WORST -case! “Typical” case can be better. TradeOffs (to increase efficiency): ? Sacrifice SOUND ness? No – too severe. ? Sacrifice COMPLETE ness? Reasonable... Specific proposals: - Use only (incomplete set of) Inference Rules - Use complete set of Inference Rules, but limit depth (…stop expanding nodes…) ? Sacrifice EXPRESSIVE ness? [ EXPRESSIVE ness  what can be distinguished.] Common approach! (After all, Logic’s distinctions caused problems!) Disallow “ Ⅴ ” “¬” “  ” … Responses

31 o DataBase Systems ≈Sound, Complete, Limited Expressiveness Prolog ≈Sound, complete, Limited Expressiveness o General Theorem Provers ≈Sound, Complete, Complete Expressiveness o Production System (Emycin, OPS) ≈Sound, ≈ Complete, Limited Expressiveness o Frame systems ?Sound?, ?Complete?, Limited Expressiveness o Description Languages Sound, Complete, Limited Expressiveness o Truth Maintenance Implemented Systems

Similar presentations