310 likes | 454 Views
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
E N D
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
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
Interpretation • Vocabulary: (literals) onab: if a is immediately on b onbc: if b is immediately on c aboveab: a is (somewhere) above b aboveac: a is (somewhere) above c • An “interpretation” (aka “world”) assigns True xor False to each literal n literals ⇒ 2 n possible worlds, I a b c
Models • Write Ii if is True (+) in world Ii • So I1onbc ⊭I6onac • Let I () = { I ∣⊨I }
I(onab) Models • Write Ii if is True (+) in world Ii • So I1onbc ⊭I6onbc • Let I () = { I ∣⊨I }
Models • Before seeing anything, REAL-WORLDI= {I1,…,I16}
Models • Before seeing anything, REAL-WORLDI= {I1,…,I16} • Asserting means REAL-WORLDI() Eg: Asserting onabmeans REAL-WORLD ∈ I(onab) = {I1,…,I8} Each assertion ELIMINATES some possible worlds
I(onab) I(onac)
Boolean Combinations I(χ) = {I ∣⊨ I χ} • I (onab) = {I1,…,I8} • I (¬onab) = {I9,…,I16} • I (onab ⋀ onac) = {I1,…,I8}∩ {I1,…,I4,I9,…,I12} = {I1,…,I4} • I (¬onab ⋁ aboveab) = {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(ξ)
What else to believe? • Assert ¬onab ⋁ aboveab ⇒ REAL-WORLD I (¬onab ⋁ aboveab)= {I1, I2, I5, I6, I9, …, I16 } • Assert onab • REAL-WORLD I (¬onab ⋁ aboveab) ⋂ I(onab) = {I1, I2, I5,I6}
What else to believe? • REAL-WORLD I (¬onab ⋁ aboveab) ⋂ I(onab) = {I1, I2, I5,I6} • In each such world,aboveabalso holds! I ( [¬onab ⋁ aboveab]&onab) I(aboveab ) ⇒ We should believeaboveab !
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 ”
Answering Queries1. Semantical Approach • Entailment specifies what we should believe. • To decide {i} Given n literals, write n 2n table. Let W = all 2n 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)
Answering Queries2. 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 Rulesto initial set of premises, to find new ones • Sound preserves truth If believe ``antecedent'', must believe conclusion • Inference Rules HornClause
-- - man(s) --- --- -- man(X) mortal(X) - - -- - mortal(s) - - -- - KB1 r1 • -- - man(s) --- --- -- man(X) mortal(X) - - -- - mortal(s) • - -- - cat(p) • -- - man(s) --- --- -- man(X) mortal(X) - - -- - mortal(s) • - -- - cat(p) KB2 KBk r2 r9 r3 … Derivation Process • -- - man(s) --- --- -- man(X) mortal(X) - - -- - - - -- - KB0
New Facts from Old:A sound Inference rule Called “Modus Ponens” Written:
Sound Rules of Inference irj KB0 KB1 Inference rule irjmaps KB0 into KB1 If irj is sound [aka Truth-Preserving], then KB0 ⊨KB1 … I(KB0) I(KB1) So… RW ∊ KB0 RW ∊ KB1 … if believeKB0 , must believe KB1 !
RW I(KB1) Sound Rules of Inference If irj is sound [aka Truth-Preserving], then KB0 ⊨KB1 … I(KB0) I(KB1) So… RW ∊ KB0 RW ∊ KB1 Hence: If believeKB0 , must believe KB1. Possible worlds I(KB0)
Sound Rules of Inference – con’t • In general, KB1 = KB0 + . So KB1⊨KB0 • … KB1, KB0 hold in EXACTLY same worlds: Possible worlds I(KB0) I(KB1) • If each rij is sound, then sequence ri1 … rin is sound.
KB0 KB1 KBN KB0 KB1 KBN ri1 ri1 … riN … riN Answering Queries • Adding Truths (Forward Chaining) • Given KB0 produce KBNs.t. If {rij}j sound, thenKB0⊧KBN • Answering Questions (Backward Chaining) • Given KB0 , ; determine if KB⊧ • Requires sound <ri j >j s.t. and KBN
How to Reason? Q:How to reason? Given KB, q, determine if KB ⊨ q ? A: Select Inference Rule IR Select Facts(s) {Fi} from KB Apply rule IR to Facts {Fi} 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?
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 ?
Just say “No” f’sure Degenerate ⊦ • For any , ⊂ WFFs: ⊬N ⊢P • Notice • ⊢Nis SOUND (returns everything logically entailed) • ⊢Pis COMPLETE (returns everything logically entailed) • ⊢N , ⊢Pis DECIDABLE(answer every question)
Fundamental Limitation • For any sufficiently complicated domain • as complex as arithmetic • No ⊢ can be • SOUND, COMPLETE, DECIDABLE!! • Reduction to halting Problem. Not Predicate Calculus’s fault: Reasoning is inherently undecidable, no manner what formalism used
Responses • Deals only with WORST-case! • “Typical” case can be better. • TradeOffs (to increase efficiency): • ? Sacrifice SOUNDness? • No – too severe. • ? Sacrifice COMPLETEness? • Reasonable ... Specific proposals: • - Use only (incomplete set of) Inference Rules • - Use complete set of Inference Rules, • but limit depth (…stop expanding nodes…) • ? Sacrifice EXPRESSIVEness? • [EXPRESSIVEness what can be distinguished.] • Common approach! • (After all, Logic’s distinctions caused problems!) • Disallow “Ⅴ” “¬” “” …
Implemented Systems • DataBase Systems • ≈Sound, Complete, Limited Expressiveness • Prolog • ≈Sound, complete, Limited Expressiveness • General Theorem Provers • ≈Sound, Complete, Complete Expressiveness • Production System (Emycin, OPS) • ≈Sound, ≈ Complete, Limited Expressiveness • Frame systems • ?Sound?, ?Complete?, Limited Expressiveness • Description Languages • Sound, Complete, Limited Expressiveness • Truth Maintenance