hands on diet puzzle
play

Hands-On: Diet Puzzle What is the secret of your long life? a man - PowerPoint PPT Presentation

Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Hands-On: Diet


  1. Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Hands-On: “Diet Puzzle” “What is the secret of your long life?” a man was asked. How to Build an Automated Theorem Prover He replied: “I strictly follow my diet: If I don’t drink beer for dinner, then I always have fish. Any time I have both beer Part 2a: Implementing a Propositional Prover and fish for dinner, then I do without ice cream. If I have ice cream or don’t have beer, then I never eat fish.” Jens Otten Question 1: “Does the man have beer for dinner?” Question 2: “Does he have both ice cream and fish for dinner?” University of Oslo ◮ formalize this puzzle in the language of (propositional) logic! ◮ ( ( ¬ beer → fish) ∧ (beer ∧ fish → ¬ ice cream) ∧ (ice cream ∨ ¬ beer → ¬ fish) ) → beer (for Question 1) → (ice cream ∧ fish) (for Question 2) Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 1 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 2 / 33 Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Representing First-Order Logic in Prolog Hands-On: Representing Logic in Prolog ◮ download SWI-Prolog at https://www.swi-prolog.org ◮ terms ( f ( a , x )) are represented by Prolog terms ( f(a,X) ) , i.e., ◮ open your favourite editor and express the “diet puzzle” in variables ( x , y , z ) are represented by Prolog variables ( X , Y , Z ) Prolog syntax and save it in files named ex diet1.pl and starting with a capital letter; ex diet2.pl constants ( a , b , c ) are represented by Prolog constants ( a , b , c ) ◮ ex diet1.pl : starting with a small letter fof(diet1,conjecture, ◮ atomic formulae ( p , q ( a , x )) are represented by Prolog terms, ( ∼ b => f) & ((b & f) => ∼ i) & ((i | ∼ b) => ∼ f) => b ). i.e., propositional variables and predicate symbols are represented ◮ ex diet2.pl : by Prolog constants ( p , q(a,X) ) starting with a small letter fof(diet2,conjecture, ◮ logical operators ¬ , ∧ , ∨ , → , ∀ x , ∃ x are represented by ( ∼ b => f) & ((b & f) => ∼ i) & ((i | ∼ b) => ∼ f) => (i&f) ). ∼ , & , | , => , ![X]: , ?[X]: ◮ you can find the code for this example and all of the following Prolog source code on the tutorial’s website at ◮ in a Prolog file, a formula F is represented (in TPTP syntax) by http://jens-otten.de/tutorial tableaux19 fof( formula name ,conjecture, F ). Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 3 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 4 / 33

  2. Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization How to Implement a Calculus in Prolog? Representing Sequents in Prolog Remember: A (proof) calculus consists of Remember: A sequent has the form ◮ axioms of the form Γ = ⇒ ∆ with Γ = { A 1 , . . . , A n } , ∆ = { B 1 , . . . , B m } w · · · w 1 w 2 w n ◮ rules of the form and is represented in Prolog by two lists: w ( w 1 , . . . , w n are the premises, w is the conclusion) Γ > ∆ with Γ= [A1,...,An] , ∆= [B1,...,Bm] ◮ the predicate select1(A,G,G’) succeeds if A is element of list G and It can be implemented in Prolog in the following way: returns G’ as G without A , e.g. select1(b,[a,b,c],L) � L=[a,c] ◮ axioms: prove(w). A ′ , Γ ′ = ⇒ ∆ ◮ rules: with Γ= { A }∪ Γ ′ is implemented by prove(w) :- prove(w1), prove(w2), ..., prove(wn). ◮ a rule of the form A , Γ ′ = ⇒ ∆ ◮ query “ is there a proof for w ′ ?” : ?- prove(w’). prove(G > D) :- select1(A,G,G’), prove([A’|G’] > D). Proof search (with backtracking) is done (implicitly) by Prolog. ◮ the proof search of formula A is invoked by ?- prove([] > [A]). ◮ for a complete proof search, iterative deepening has to be added ◮ implementation of the select1 predicate: ◮ first optimization: bottom-up proof search select1(X,L,L1) :- append(L2,[X|L3],L), append(L2,L3,L1). Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 5 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 6 / 33 Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Hands-On: Getting Started Sequent Calculus – Axiom ◮ definition of the logical operators and the select1 predicate ◮ new operators are defined with: op(Precedence,Type,Name) ◮ the only axiom ◮ leanseq v0.pl : :- op( 500, fy, ∼ ). % negation axiom :- op(1000, xfy, &). % conjunction Γ 1 , A = ⇒ A , ∆ 1 :- op(1100, xfy, ’|’). % disjunction :- op(1110, xfy, =>). % implication :- op( 500, fy, !). % universal quantifier: ![X]: ◮ leanseq v1.pl : :- op( 500, fy, ?). % existential quantifier: ?[X]: :- op( 500,xfy, :). % axiom % ------------------------------------------------------- prove(G > D) :- member(A,G), member(A,D). prove0(F) :- prove([] > [F]). % ------------------------------------------------------- % some space for the actual prover % ------------------------------------------------------- select1(X,L,L1) :- append(L2,[X|L3],L), append(L2,L3,L1). % ------------------------------------------------------- Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 7 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 8 / 33

  3. Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Sequent Calculus – Rules for ∧ Sequent Calculus – Rules for ∨ ◮ rules for ∧ (conjunction) ◮ rules for ∨ (disjunction) Γ 1 , A , B = ⇒ ∆ Γ = ⇒ A , ∆ 1 Γ = ⇒ B , ∆ 1 Γ 1 , A = ⇒ ∆ Γ 1 , B = ⇒ ∆ Γ = ⇒ A , B , ∆ 1 ∧ -left ∧ -right ∨ -left ∨ -right Γ 1 , A ∧ B = ⇒ ∆ Γ = ⇒ A ∧ B , ∆ 1 Γ 1 , A ∨ B = ⇒ ∆ Γ = ⇒ A ∨ B , ∆ 1 ◮ leanseq v1.pl : ◮ leanseq v1.pl : % conjunction % disjunction prove(G > D) :- select1(A&B,G,G1), prove(G > D) :- select1(A|B,G,G1), prove([A,B|G1] > D). prove([A|G1] > D), prove([B|G1] > D). prove(G > D) :- select1(A&B,D,D1), prove(G > D) :- select1(A|B,D,D1), prove(G > [A|D1]), prove(G > [B|D1]). prove(G > [A,B|D1]). Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 9 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 10 / 33 Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Logic in Prolog Sequent Calculus in Prolog First-Order Logic Free Variables Iterative Deepening Skolemization Sequent Calculus – Rules for → Sequent Calculus – Rules for ¬ ◮ rules for ¬ (negation) ◮ rules for → (implication) Γ 1 = ⇒ A , ∆ Γ , A = ⇒ ∆ 1 Γ 1 = ⇒ A , ∆ Γ 1 , B = ⇒ ∆ Γ , A = ⇒ B , ∆ 1 ¬ -right → -right ¬ -left → -left Γ 1 , ¬ A = ⇒ ∆ Γ = ⇒ ¬ A , ∆ 1 Γ 1 , A → B = ⇒ ∆ Γ = ⇒ A → B , ∆ 1 ◮ leanseq v1.pl : ◮ leanseq v1.pl : % implication % negation prove(G > D) :- select1(A=>B,G,G1), prove(G > D) :- select1( ∼ A,G,G1), prove(G1 > [A|D]), prove([B|G1] > D). prove(G1 > [A|D]). prove(G > D) :- select1(A=>B,D,D1), prove(G > D) :- select1( ∼ A,D,D1), prove([A|G] > [B|D1]). prove([A|G] > D1). Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 11 / 33 Jens Otten (UiO) How to Build a Theorem Prover — Part 2 TABLEAUX Tutorial 2019 12 / 33

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend