linear logic programming
play

Linear Logic Programming Carsten Sch urmann ITU, currently CMU - PowerPoint PPT Presentation

Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Linear Logic Programming Carsten Sch urmann ITU, currently CMU May 4, 2011 Carsten Sch urmann ITU, currently CMU Linear Logic Programming Intuitionistic Logic Linear


  1. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Running a Logic Program #query * 1 * 1 plus (s (s z)) (s z) X. ◮ What do the numbers mean? ◮ Help! #query d e l a ty. d : bound on number of let-bindings before aborting forward-chaining, * means no bound e : expected number of solutions, * means don’t know l : number of solutions to look for, * means infinite a : number of times to execute the query ty : type to search for proof of Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  2. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Exercise 1: Declare lists in Celf as follows list : type. nil : list. cons : nat -> list -> list. 1. Write a program that appends two lists. append: list -> list -> list -> type. 2. Write a program that reverses a list. rev: list -> list -> type. 3. Write a program that sums up all elements of a list. sum : list -> nat -> type. 4. Compute the n -th Fibonacci numbers fib : nat -> nat -> type. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  3. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Formalities: plus : nat -> nat -> nat -> type. p z : plus z Y Y. p s : plus X Y Z -> plus (s X) Y (s Z). Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  4. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Formalities: plus : nat -> nat -> nat -> type. p z : plus z Y Y. p s : plus X Y Z -> plus (s X) Y (s Z). Definite Clauses D ::= P | G → D | ∀ x : A . D Goals G ::= P Atoms ::= a M 1 . . . M n P Programs Σ ::= · | Σ , a : K | Σ , c : D Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  5. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Objects, Proofs, and Substitution Objects Think about them as natural numbers, trees. ◮ nat , list are datatypes ◮ z , s , nil , cons are constructors. Proofs They look like objects, because they are. Lookup We write Σ( c ) = D to lookup the type, axiom, formula associated with the name of a constructor. Substitutions We write [ T / x ] T ′ for the in place substitution of object T for variable x in term T ′ . ◮ Substitutions are capture avoiding. ◮ Tacit renaming of variables. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  6. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Backward-Chaining (Focused) Proof Search Goal formulas Σ ⊢ G bwd G is derivable form Σ by backward chaining search. Definite clauses Σ; [ D ] ⊢ P bwd P is derivable from Σ by focusing/decomposing D . Disclaimer: We describe rules that guess instantiation of universal variables. A real implementation would use unification to compute them. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  7. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Backward-Chaining (Focused) Proof Search Σ( c ) = D Σ; [ D ] ⊢ P bwd g/atm Σ ⊢ G bwd Σ ⊢ P bwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Σ; [[ T / x ] D ] ⊢ P bwd d/all Σ[ D ] ⊢ P bwd Σ; [ ∀ x : A . D ] ⊢ P bwd Σ; [ D ] ⊢ P bwd Σ ⊢ G bwd d / arr Σ; [ G → D ] ⊢ P bwd d/atm Σ; [ P ] ⊢ P bwd Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  8. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Higher-Order Logic Programming Ideas similar to what you can find in λ -Prolog. So far, the Σ is given ahead of time. Now, we extend our language to extend Σ dynamically ◮ Extension 1: Goals can introduce clauses D → G ◮ Extension 2: Goals can declare new parameters ∀ x : A . G We will write Γ for the dynamically introduced signature (called contexts), and Σ for the static signatures (continued to be called programs). Refine judgment and rules to Σ; Γ ⊢ D bwd Σ; Γ; [ D ] ⊢ P bwd Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  9. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Higher-order Logic Programming plus : nat -> nat -> nat -> type. #query * 1 * 1 plus z Y Y -> (plus X Y Z -> plus (s X) Y (s Z)) -> plus (s (s z)) (s z) V Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  10. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Higher-order Logic Programming plus : nat -> nat -> nat -> type. #query * 1 * 1 plus z Y Y -> (plus X Y Z -> plus (s X) Y (s Z)) -> plus (s (s z)) (s z) V Definite Clauses D ::= P | G → D | ∀ x : A . D Goals ::= P | D → G | ∀ x : A . G G Atoms P ::= a M 1 . . . M n Programs Σ ::= · | Σ , a : K | Σ , c : D Contexts Γ ::= Γ , x : A | Γ , c : D Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  11. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Higher-order Backward-Chaining (Focused) Proof Search Σ; Γ ⊢ G bwd Σ; Γ; [ D ] ⊢ P bwd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . (Σ; Γ)( c ) = D Σ; Γ; [ D ] ⊢ P bwd Σ; Γ ⊢ P bwd Σ; Γ; [ P ] ⊢ P bwd Σ; Γ , x : A ⊢ G bwd Σ; Γ; [[ T / x ] D ] ⊢ P bwd Σ; Γ ⊢ ∀ x : A . G bwd Σ; Γ; [ ∀ x : A . D ] ⊢ P bwd Σ; Γ , D ⊢ G bwd Σ; Γ; [ D ] ⊢ P bwd Σ; Γ ⊢ G bwd Σ; Γ ⊢ D → G bwd Σ; Γ; [ G → D ] ⊢ P bwd Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  12. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Inversion and Focusing [Andreoli ’91] Motivation A rule can be invertible: J 1 J 2 rule J iff 1. if J implies J 1 2. and J implies J 2 . Focusing No backtrack over sequences of invertible rules Thus Focusing removes derivations from the search space! Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  13. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Foreshadowing Right inversion Σ; Γ ⊢ G bwd Left focusing Σ; Γ; [ D ] ⊢ P bwd Asynchronous connective A connective is asynchronous, if it has a right inversion and a left-focusing rule. Synchronous connective A connective is synchronous, if it does not have a right inversion rule, one needs to work on the hypotheses first. Choice is non-deterministic. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  14. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Exercises 2 In these exercises you are asked to explore the higher-order features of Celf. The means that you are allowed to declare new predicates, but you are not allowed to define constructors for them. 1. Write a program that returns if a given numbers occurs at least twice in a given list. twice: list -> nat -> type. 2. Generalize the previous program and write one that checks for n duplicates. duplicates: list -> nat -> nat -> type. The last argument stands for the multiplicity. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  15. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Philosphical Considerations ◮ Judgments-as-relations-as-types ◮ Derivations-as-objects ◮ Dynamic generation of clauses ◮ Weakening: We don’t have to use them ◮ Contraction: We may use them more than once ◮ Exchange: We may use them irrespective of order ◮ But life is not that simple ◮ Consider money ◮ Consider locations in a Petri net ◮ Consider authorization certificates ◮ Consider ballots in an election ◮ We want resources! Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  16. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Meet the Connectives Example: You want to spend one dollar, three quarters, two dimes and one nickel on a sandwich that costs two dollars. Can you do it? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  17. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Meet the Connectives Example: You want to spend one dollar, three quarters, two dimes and one nickel on a sandwich that costs two dollars. Can you do it? Rules: q q q q m 3 n n m 1 n d d m 2 d q $ $ $ $ r 1 r 2 coke sandwich To show: v 1 v 2 v 3 w 1 w 2 u z $ q q q d d n . . . sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  18. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Meet the Connectives Rules: q q q q m 3 n n m 1 n d d m 2 d q $ $ $ $ r 1 r 2 coke sandwich To show: w 1 w 2 z d d n v 1 v 2 v 3 m 2 u $ q q q q . . . sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  19. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Meet the Connectives Rules: q q q q m 3 n n m 1 n d d m 2 d q $ $ $ $ r 1 r 2 coke sandwich To show: w 1 w 2 z d d n m 2 v 1 v 2 v 3 q q q q m 3 u $ $ . . . sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  20. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Meet the Connectives Rules: q q q q m 3 n n m 1 n d d m 2 d q $ $ $ $ r 1 r 2 coke sandwich To show: w 1 w 2 z d d n m 2 v 1 v 2 v 3 q q q q m 3 u $ $ r 2 sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  21. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Linear Logic and Resources ◮ A ⊸ B is true if we can prove B while consuming the resource A exactly once. ◮ A ⊗ B is true if we split our supply of linear resources into two piles, prove A with one and B with the other. ◮ 1 is the unit for ⊗ ◮ A & B is true, if either A and B are true (independently) using all resources Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  22. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Γ; ∆ ⊢ A Propositional Dual Intuitionistic Linear Logic Γ; ∆ , A ⊢ B Γ; ∆ 1 ⊢ A ⊸ B Γ; ∆ 2 ⊢ A ⊸ I ⊸ E Γ; ∆ ⊢ A ⊸ B Γ; ∆ 1 , ∆ 2 ⊢ B Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  23. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Γ; ∆ ⊢ A Propositional Dual Intuitionistic Linear Logic Γ; ∆ , A ⊢ B Γ; ∆ 1 ⊢ A ⊸ B Γ; ∆ 2 ⊢ A ⊸ I ⊸ E Γ; ∆ ⊢ A ⊸ B Γ; ∆ 1 , ∆ 2 ⊢ B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ 1 ⊢ A Γ; ∆ 2 ⊢ B Γ; ∆ 1 ⊢ A ⊗ B Γ; ∆ 2 , A , B ⊢ C ⊗ I ⊗ E Γ; ∆ 1 , ∆ 2 ⊢ A ⊗ B Γ; ∆ 1 , ∆ 2 ⊢ C Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  24. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Γ; ∆ ⊢ A Propositional Dual Intuitionistic Linear Logic Γ; ∆ , A ⊢ B Γ; ∆ 1 ⊢ A ⊸ B Γ; ∆ 2 ⊢ A ⊸ I ⊸ E Γ; ∆ ⊢ A ⊸ B Γ; ∆ 1 , ∆ 2 ⊢ B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ 1 ⊢ A Γ; ∆ 2 ⊢ B Γ; ∆ 1 ⊢ A ⊗ B Γ; ∆ 2 , A , B ⊢ C ⊗ I ⊗ E Γ; ∆ 1 , ∆ 2 ⊢ A ⊗ B Γ; ∆ 1 , ∆ 2 ⊢ C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ 1 ⊢ 1 Γ; ∆ 2 ⊢ C 1I 1E Γ; · ⊢ 1 Γ; ∆ 1 , ∆ 2 ⊢ C Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  25. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Γ; ∆ ⊢ A Propositional Dual Intuitionistic Linear Logic Γ; ∆ , A ⊢ B Γ; ∆ 1 ⊢ A ⊸ B Γ; ∆ 2 ⊢ A ⊸ I ⊸ E Γ; ∆ ⊢ A ⊸ B Γ; ∆ 1 , ∆ 2 ⊢ B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ 1 ⊢ A Γ; ∆ 2 ⊢ B Γ; ∆ 1 ⊢ A ⊗ B Γ; ∆ 2 , A , B ⊢ C ⊗ I ⊗ E Γ; ∆ 1 , ∆ 2 ⊢ A ⊗ B Γ; ∆ 1 , ∆ 2 ⊢ C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ 1 ⊢ 1 Γ; ∆ 2 ⊢ C 1I 1E Γ; · ⊢ 1 Γ; ∆ 1 , ∆ 2 ⊢ C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆ ⊢ A Γ; ∆ ⊢ B Γ; ∆ ⊢ A & B &E 1 Γ; ∆ ⊢ A & B &E 2 &I Γ; ∆ ⊢ A & B Γ; ∆ ⊢ A Γ; ∆ ⊢ B Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  26. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Linear Higher-order Logic Programming ◮ Asynchronous connectives (negative) A − + ◮ Synchronous connectives (positive) A ◮ Collapse definite clauses and goals into one category A − G → D = Π x : ! G . D G ⊸ D = Π x : ↓ G . D − | A + . A − ::= P | Π p : A 1 & A − − A 2 − | ↓ A − | 1 + A ::= ! A ::= a M 1 . . . M n P Σ ::= · | Σ , a : K | Σ , c : A − − Γ , ∆ ::= · | Γ , x : A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  27. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Proof Search Focusing Style Γ; ∆ ⊢ A − Γ; ∆; [ A − ] ⊢ P (Σ; Γ)( c ) = A − Γ; ∆; [ A − ] ⊢ P Γ; ∆ ⊢ P Γ; ∆; [ P ] ⊢ P − ] ⊢ P Γ; ∆; [ A − ⊢ P Γ; ∆ , A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  28. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Proof Search Focusing Style Γ; ∆ ⊢ A − Γ; ∆; [ A − ] ⊢ P (Σ; Γ)( c ) = A − Γ; ∆; [ A − ] ⊢ P Γ; ∆ ⊢ P Γ; ∆; [ P ] ⊢ P − ] ⊢ P Γ; ∆; [ A − ⊢ P Γ; ∆ , A − − − Γ; ∆ ⊢ A Γ; ∆ ⊢ A Γ; ∆; [ A i ] ⊢ P 1 2 i = 1 , 2 Γ; ∆ ⊢ A 1 & A − − Γ; ∆; [ A − 1 & A − 2 ] ⊢ P 2 Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  29. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Proof Search Focusing Style Γ; ∆ ⊢ A − Γ; ∆; [ A − ] ⊢ P (Σ; Γ)( c ) = A − Γ; ∆; [ A − ] ⊢ P Γ; ∆ ⊢ P Γ; ∆; [ P ] ⊢ P − ] ⊢ P Γ; ∆; [ A − ⊢ P Γ; ∆ , A − − − Γ; ∆ ⊢ A Γ; ∆ ⊢ A Γ; ∆; [ A i ] ⊢ P 1 2 i = 1 , 2 Γ; ∆ ⊢ A 1 & A − − Γ; ∆; [ A − 1 & A − 2 ] ⊢ P 2 + �→ Γ; ∆; [ A + �→ Γ; ∆ ⊢ A − p : A − ] ⊢ P p : A + . A + . A − − ] ⊢ P Γ; ∆ ⊢ Π p : A Γ; ∆; [Π p : A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  30. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic + �→ Γ; ∆ ⊢ B + �→ Γ; ∆; [ D ] ⊢ P p : A − p : A − ; ∆ ⊢ B − − Γ , x : A Γ; ∆; [[ T / x ] A 2 ] ⊢ P x occurs in A − − �→ Γ; ∆ ⊢ B 2 − − − x : ! A x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P − − Γ; ∆; [ A 2 ] ⊢ P Γ; · ⊢ A x does not 1 occur in A − − − x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P 2 Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  31. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic + �→ Γ; ∆ ⊢ B + �→ Γ; ∆; [ D ] ⊢ P p : A − p : A − ; ∆ ⊢ B − − Γ , x : A Γ; ∆; [[ T / x ] A 2 ] ⊢ P x occurs in A − − �→ Γ; ∆ ⊢ B 2 − − − x : ! A x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P − − Γ; ∆; [ A 2 ] ⊢ P Γ; · ⊢ A x does not 1 occur in A − − − x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P 2 − ⊢ B − − Γ; ∆ , x : A − Γ; ∆ 1 ; [ A 2 ] ⊢ P Γ; ∆ 2 ⊢ A 1 − �→ Γ; ∆ ⊢ B − − − x : ↓ A x : ↓ A 1 �→ Γ; ∆ 1 , ∆ 2 ; [ A 2 ] ⊢ P Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  32. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic + �→ Γ; ∆ ⊢ B + �→ Γ; ∆; [ D ] ⊢ P p : A − p : A − ; ∆ ⊢ B − − Γ , x : A Γ; ∆; [[ T / x ] A 2 ] ⊢ P x occurs in A − − �→ Γ; ∆ ⊢ B 2 − − − x : ! A x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P − − Γ; ∆; [ A 2 ] ⊢ P Γ; · ⊢ A x does not 1 occur in A − − − x : ! A 1 �→ Γ; ∆; [ A 2 ] ⊢ P 2 − ⊢ B − − Γ; ∆ , x : A − Γ; ∆ 1 ; [ A 2 ] ⊢ P Γ; ∆ 2 ⊢ A 1 − �→ Γ; ∆ ⊢ B − − − x : ↓ A x : ↓ A 1 �→ Γ; ∆ 1 , ∆ 2 ; [ A 2 ] ⊢ P − ] ⊢ P Γ; ∆; [ A Γ; ∆ ⊢ B − − − ] ⊢ P x : 1 �→ Γ; ∆ ⊢ B x : 1 �→ Γ; ∆; [ A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  33. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Buy a Sandwich with Change Signature Σ = m 1 : n ⊸ n ⊸ d m 2 : n ⊸ d ⊸ d ⊸ q m 3 : q ⊸ q ⊸ q ⊸ q ⊸ $ r 1 : $ ⊸ coke r 2 : $ ⊗ $ ⊸ sandwich . . . · ⊢ $ ⊗ q ⊗ q ⊗ q ⊗ d ⊗ d ⊗ n ⊸ sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  34. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Now in Celf dollar : type. quarter : type. dime : type. nickel : type. cent : type. coke : type. sandwich : type. nn->d : nickel -o nickel -o dime. ndd->q : nickel -o dime -o dime -o quarter. qqqq->$ : quarter -o quarter -o quarter -o quarter -o dollar. $->coke : dollar -o coke. $$->sandw: dollar -o dollar -o sandwich. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  35. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Now in Celf Running a query: #query * ? * 1 dollar -o quarter -o quarter -o quarter -o nickel -o dime -o dime -o dollar -o sandwich. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  36. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Now in Celf Running a query: #query * ? * 1 dollar -o quarter -o quarter -o quarter -o nickel -o dime -o dime -o dollar -o sandwich. Problem 1: ? = 96 $$->sandw X7 (qqqq->$ X3 X1 X2 (ndd->q X4 X5 X6)) $$->sandw X7 (qqqq->$ X1 X3 X2 (ndd->q X4 X5 X6)) $$->sandw X7 (qqqq->$ X2 X3 X1 (ndd->q X4 X5 X6)) $$->Sandw X7 (qqqq->$ X3 X2 X1 (ndd->q X4 X5 X6)) etc. Problem 2: Adequacy? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  37. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic A Mystery Program el : nat -> type. mystery : list -> type. mystery/nil : mystery nil. mystery/cons : mystery (cons N L) o- el N o- mystery L. What could this program do? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  38. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic A Mystery Program el : nat -> type. mystery : list -> type. mystery/nil : mystery nil. mystery/cons : mystery (cons N L) o- el N o- mystery L. What could this program do? Compute permutations! #query * ? * 1 el z -o el (s z) -o mystery L. #query * ? * 1 el z -o el (s z) -o el (s (s z)) -o mystery L. #query * ? * 1 el z -o el N -o mystery (cons z (cons (s z) nil)). #query * ? * 1 el N -o el z -o mystery (cons z (cons (s z) nil)). Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  39. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Affine Logic So far, exact change was necessary to buy a sandwich. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  40. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Affine Logic So far, exact change was necessary to buy a sandwich. How can we express that we can buy a sandwhich, but still have some money leftover? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  41. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Affine Logic So far, exact change was necessary to buy a sandwich. How can we express that we can buy a sandwhich, but still have some money leftover? Linear Logic must use resources exactly once Affine Logic may use resources at most once Relevance Logic must use all resources at least once Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  42. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Now in Celf nn->d : nickel -@ nickel -@ dime. ndd->q : nickel -@ dime -@ dime -@ quarter. qqqq->$ : quarter -@ quarter -@ quarter -@ quarter -@ dollar. $->coke : dollar -@ coke. $$->sandw: dollar -@ dollar -@ sandwich. #query * 96 * 1 quarter -@ quarter -@ quarter -@ nickel -@ dime -@ dime -@ dollar -@ sandwich. #query * 96 * 1 cent -@ quarter -@ quarter -@ quarter -@ nickel -@ dime -@ dime -@ dollar -@ sandwich. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  43. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Affine Logic Linear Logic must use resources exactly once Affine Logic may use resources at most once Judgment Γ; ∆; Φ ⊢ A Γ unrestricted, ∆ linear, Φ affine ax u ax l ax a Γ , A ; · ; Φ ⊢ A Γ; A ; Φ ⊢ A Γ; · ; Φ , A ⊢ A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Γ; ∆; Φ , A ⊢ B Γ; ∆ 1 ; Φ 1 ⊢ A − @ B Γ; ∆ 2 ; Φ 2 ⊢ A − @ I − @ E Γ; ∆; Φ ⊢ A − @ B Γ; ∆ 1 , ∆ 2 ; Φ 1 ; Φ 2 ⊢ B Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  44. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Affine Linear Higher-order Logic Programming ◮ Asynchronous connectives (negative) A − + ◮ Synchronous connectives (positive) A ◮ Extending what we had. − | A + . A A − ::= P | Π p : A − 1 & A − 2 − | ↓ A − | @ A + − A ::= ! A P ::= a M 1 . . . M n − Σ ::= · | Σ , a : K | Σ , c : A Γ , ∆ ::= · | Γ , x : A − Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  45. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Proof Search Focusing Style Γ; ∆; Φ ⊢ A − Γ; ∆; Φ; [ A − ] ⊢ P (Σ; Γ)( c ) = A − Γ; ∆; Φ; [ A − ] ⊢ P Γ; ∆; Φ ⊢ P Γ; ∆; Φ; [ P ] ⊢ P − ] ⊢ P − ] ⊢ P Γ; ∆; Φ; [ A Γ; ∆; Φ; [ A − ⊢ P − ⊢ P Γ; ∆; Φ , A Γ; ∆; Φ , A − − − Γ; ∆; Φ ⊢ A Γ; ∆; Φ ⊢ A Γ; ∆; Φ; [ A i ] ⊢ P 1 2 i = 1 , 2 Γ; ∆; Φ ⊢ A 1 & A − − Γ; ∆; Φ; [ A − 1 & A − 2 ] ⊢ P 2 + �→ Γ; ∆; Φ; [ A + �→ Γ; ∆; Φ ⊢ A − p : A − ] ⊢ P p : A + . A + . A − − ] ⊢ P Γ; ∆; Φ ⊢ Π p : A Γ; ∆; Φ; [Π p : A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  46. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic + �→ Γ; ∆; Φ ⊢ B + �→ Γ; ∆; [ D ] ⊢ P p : A − p : A − ; ∆; Φ ⊢ B − − Γ , x : A Γ; ∆; Φ; [[ T / x ] A 2 ] ⊢ P x occurs in A − − �→ Γ; ∆; Φ ⊢ B 2 − − − x : ! A x : ! A 1 �→ Γ; ∆; Φ; [ A 2 ] ⊢ P − − Γ; ∆; Φ; [ A 2 ] ⊢ P Γ; · ; · ⊢ A x does not 1 occur in A − − − x : ! A 1 �→ Γ; ∆; Φ; [ A 2 ] ⊢ P 2 − ⊢ B − − Γ; ∆; Φ , x : A − Γ; ∆ 1 ; Φ 1 ; [ A 2 ] ⊢ P Γ; ∆ 2 ; Φ 2 ⊢ A 1 − �→ Γ; ∆; Φ ⊢ B − − − x : ↓ A x : ↓ A 1 �→ Γ; ∆ 1 , ∆ 2 ; Φ 1 ; Φ 2 ; [ A 2 ] ⊢ P Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  47. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic + �→ Γ; ∆; Φ ⊢ B + �→ Γ; ∆; [ D ] ⊢ P p : A − p : A − ; ∆; Φ ⊢ B − − Γ , x : A Γ; ∆; Φ; [[ T / x ] A 2 ] ⊢ P x occurs in A − − �→ Γ; ∆; Φ ⊢ B 2 − − − x : ! A x : ! A 1 �→ Γ; ∆; Φ; [ A 2 ] ⊢ P − − Γ; ∆; Φ; [ A 2 ] ⊢ P Γ; · ; · ⊢ A x does not 1 occur in A − − − x : ! A 1 �→ Γ; ∆; Φ; [ A 2 ] ⊢ P 2 − ⊢ B − − Γ; ∆; Φ , x : A − Γ; ∆ 1 ; Φ 1 ; [ A 2 ] ⊢ P Γ; ∆ 2 ; Φ 2 ⊢ A 1 − �→ Γ; ∆; Φ ⊢ B − − − x : ↓ A x : ↓ A 1 �→ Γ; ∆ 1 , ∆ 2 ; Φ 1 ; Φ 2 ; [ A 2 ] ⊢ P − ⊢ B − − − Γ; ∆ 1 ; Φ 1 ; [ A 2 ] ⊢ P Γ; ∆ 2 ; Φ 2 ⊢ A Γ; ∆; Φ , x : A 1 − �→ Γ; ∆; Φ ⊢ B − − − x : @ A x : @ A 1 �→ Γ; ∆ 1 , ∆ 2 ; Φ 1 , Φ 2 ; [ A 2 ] ⊢ P Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  48. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Example: Subsets element : nat -> type. sublist : list -> type. sublist/nil : sublist nil. sublist/cons : sublist (cons N L) @- element N @- sublist L. Question: How many solutions will Celf compute? #query * * * 1 element z -@ element (s z) -@ element (s (s z)) -@ sublist L. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  49. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Example: Subsets element : nat -> type. sublist : list -> type. sublist/nil : sublist nil. sublist/cons : sublist (cons N L) @- element N @- sublist L. Question: How many solutions will Celf compute? #query * * * 1 element z -@ element (s z) -@ element (s (s z)) -@ sublist L. Answer: 16. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  50. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Structural Operational Semantics Definition Register R ::= r 0 | r 1 | r 2 Instruction I ::= return R | add R 1 R 2 I | const N R I Example Compute the circumference of a rectangle. const a r 1 const b r 2 const z r 3 add r 2 r 3 b add r 2 r 3 add r 1 r 3 add r 1 r 3 a return r 3 Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  51. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Exercises 3 1. Extend the calculator by predecessor function prec : register -> cmd -> cmd. 2. Extend the calculator by a construct for swapping the content of two registers: swap : register -> register -> cmd -> cmd. 3. Extend the calculator by a comparison operator that either executes the first block of instructions if the content of the register is 0 or the second otherwise. eqz : register -> cmd -> cmd -> cmd. 4. Implement a label to jump to operation. label : (cmd -> cmd) -> cmd. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  52. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Concurrent Monadic Linear Logic Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  53. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Tuning the Operational Semantics So far backward-chaining operational semantics only. Excels for single conclusion inference rules. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  54. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Tuning the Operational Semantics So far backward-chaining operational semantics only. Excels for single conclusion inference rules. But how do you express that you would like to buy a coke and a sandwich? (exact change only) Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  55. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Tuning the Operational Semantics So far backward-chaining operational semantics only. Excels for single conclusion inference rules. But how do you express that you would like to buy a coke and a sandwich? (exact change only) u 1 u 2 v 1 v 2 v 3 w 1 w 2 z $ $ q q q d d n . . . . . . sandwich coke Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  56. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Tuning the Operational Semantics So far backward-chaining operational semantics only. Excels for single conclusion inference rules. But how do you express that you would like to buy a coke and a sandwich? (exact change only) u 1 u 2 v 1 v 2 v 3 w 1 w 2 z $ $ q q q d d n . . . . . . sandwich coke Idea: Maybe tensor is invertible? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  57. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Non-Invertibility of Tensor Recall Γ; ∆ 1 ; Φ 1 ⊢ A Γ; ∆ 2 ; Φ 2 ⊢ B ⊗ I Γ; ∆ 1 , ∆ 2 ; Φ 1 , Φ 2 ⊢ A ⊗ B Assume Γ; ∆ 1 , ∆ 2 ; Φ 1 , Φ 2 ⊢ A ⊗ B To Show Γ; ∆ 1 ; Φ 1 ⊢ A Using Γ; ∆ 1 ; Φ 1 ⊢ A ⊗ B Γ; ∆ 2 , A , B ; Φ 2 ⊢ C ⊗ E Γ; ∆ 1 , ∆ 2 ; Φ 1 , Φ 2 ⊢ C But How? Tensor is not right-invertible. We have to think of something else. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  58. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Tensor as a synchronous (positive connective) Solution: We introduce a new type of connective. + + ∃ ! x :! A − 1 . A = ∃ x : A − 1 . A 2 2 + + + + ∃ p : A 1 . A = A 1 ⊗ A 2 2 Categories: − | A + . A A − ::= P | Π p : A − 1 & A − 2 − | ↓ A − | 1 | @ A + + + − | ∃ p : A A ::= ! A 1 A 2 ::= a M 1 . . . M n P Σ ::= · | Σ , a : K | Σ , c : A − Γ , ∆ ::= · | Γ , x : A − Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  59. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Handling Tensor Generalization of the rules + + − p 1 : A 1 �→ p 2 : A 2 �→ Γ; ∆; Φ ⊢ B + �→ Γ; ∆; Φ ⊢ B + + − − p : A [ p 1 , p 2 ] : ∃ p 1 : A 1 . A 2 �→ Γ; ∆; Φ ⊢ B + + p 1 : A 1 �→ p 2 : A 2 �→ Γ; ∆; Φ; [ B − ] ⊢ P + �→ Γ; ∆; [ B + + − ] ⊢ P − ] ⊢ P p : A [ p 1 , p 2 ] : ∃ p : A 1 . A 2 �→ Γ; ∆; Φ; [ B Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  60. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic The question remains: Example: You have three dollars. A can of coke costs one dollar, and a sandwich two. Can you buy both? Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  61. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic The question remains: Example: You have three dollars. A can of coke costs one dollar, and a sandwich two. Can you buy both? Rules: $ $ $ r 1 r 2 coke sandwich To show: u v w $ $ $ . . . . . . coke sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  62. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic The question remains: Example: You have three dollars. A can of coke costs one dollar, and a sandwich two. Can you buy both? Rules: $ $ $ r 1 r 2 coke sandwich To show: u v w $ $ $ . . . . . . coke sandwich Idea: Think left! (as we already did :-) Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  63. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Think Left Example: You have three dollars. A can of coke costs one dollar, and a sandwich two. Can you buy both? Rules: $ $ $ r 1 r 2 coke sandwich To show: v w $ $ r 2 u $ sandwich . . . . . . coke sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  64. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Think Left Example: You have three dollars. A can of coke costs one dollar, and a sandwich two. Can you buy both? Rules: $ $ $ r 1 r 2 coke sandwich To show: u v w $ $ $ r 1 r 2 coke sandwich . . . . . . coke sandwich Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  65. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Now we are done! u v w $ $ $ r 1 r 2 coke sandwich . . . . . . coke sandwich Quiesence We cannot do another step on the left. Truth We have derived what we needed to derive. Concurrency The rules could fire in an arbitrary order. Finally Switch back to right, find coke and sandwich. Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  66. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Summary Solution: We introduce a new type of connective. − | A + . A + } − ::= P | Π p : A − 1 & A − 2 | { A A − | ↓ A − | 1 | @ A − | ∃ p : A + + + A ::= ! A 1 . A 2 P ::= a M 1 . . . M n Σ ::= · | Σ , a : K | Σ , c : A − − Γ , ∆ ::= · | Γ , x : A + } switches to forward chaining mode. Comment 1: { A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  67. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Summary Solution: We introduce a new type of connective. − | A + . A + } − ::= P | Π p : A − 1 & A − 2 | { A A − | ↓ A − | 1 | @ A − | ∃ p : A + + + A ::= ! A 1 . A 2 P ::= a M 1 . . . M n Σ ::= · | Σ , a : K | Σ , c : A − − Γ , ∆ ::= · | Γ , x : A + } switches to forward chaining mode. Comment 1: { A + } is a monad that encapsulates true concurrency. Comment 2: { A Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  68. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Summary Solution: We introduce a new type of connective. − | A + . A + } − ::= P | Π p : A 1 & A − 2 | { A − A − | ↓ A − | 1 | @ A − | ∃ p : A + + + A ::= ! A 1 . A 2 P ::= a M 1 . . . M n Σ ::= · | Σ , a : K | Σ , c : A − − Γ , ∆ ::= · | Γ , x : A + } switches to forward chaining mode. Comment 1: { A + } is a monad that encapsulates true concurrency. Comment 2: { A + } corresponds to the focusing rule switching from Comment 3: { A negative to positive. It is dual to ↓ A − . Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  69. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Summary Solution: We introduce a new type of connective. − | A + . A + } − ::= P | Π p : A 1 & A − 2 | { A − A − | ↓ A − | 1 | @ A − | ∃ p : A + + + A ::= ! A 1 . A 2 P ::= a M 1 . . . M n Σ ::= · | Σ , a : K | Σ , c : A − − Γ , ∆ ::= · | Γ , x : A + } switches to forward chaining mode. Comment 1: { A + } is a monad that encapsulates true concurrency. Comment 2: { A + } corresponds to the focusing rule switching from Comment 3: { A negative to positive. It is dual to ↓ A − . Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  70. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Buy a Coke and a Sandwich with 3 Dollars Signature Σ = r 1 : $ ⊸ { coke } r 2 : $ ⊗ $ ⊸ { sandwich } . . . · ⊢ $ ⊗ $ ⊗ $ ⊸ { coke ⊗ sandwich } Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  71. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Buy a Coke and a Sandwich with 3 Dollars Signature Σ = r 1 : $ ⊸ { coke } r 2 : $ ⊗ $ ⊸ { sandwich } . . . u 1 : $ , u 2 : $ , u 3 : $ ⊢ { coke ⊗ sandwich } ⊸ I · ⊢ $ ⊗ $ ⊗ $ ⊸ { coke ⊗ sandwich } Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  72. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Buy a Coke and a Sandwich with 3 Dollars Signature Σ = r 1 : $ ⊸ { coke } r 2 : $ ⊗ $ ⊸ { sandwich } v 1 : coke ⊢ coke v 2 : sandwich ⊢ sandwich v 1 : coke , v 2 : sandwich ⊢ coke ⊗ sandwich u 2 : $ , u 3 : $ ⊢ $ ⊗ $ v 1 : coke , v 2 : sandwich ⊢ coke ⊗ sandwich u 1 : $ ⊢ $ u 2 : $ , u 3 : $ , v 1 : coke ⊢ coke ⊗ sandwich u 1 : $ , u 2 : $ , u 3 : $ ⊢ { coke ⊗ sandwich } · ⊢ $ ⊗ $ ⊗ $ ⊸ { coke ⊗ sandwich } Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

  73. Intuitionistic Logic Linear Logic Concurrent Monadic Linear Logic Forward-Chaining + Γ; ∆; Φ ⊢ A + } Γ; ∆; Φ ⊢ { A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + + − ; ∆; Φ; [ A − ] ⊢ B − ] ⊢ B − ] ⊢ B Γ , A Γ; ∆; Φ; [ A Γ; ∆; Φ; [ A + + + − ; ∆; Φ ⊢ B − ; ∆ , A ; Φ ⊢ B − ; ∆; Φ , A ⊢ B Γ , A Γ Γ + Γ; ∆; Φ > > B + Γ; ∆; Φ ⊢ B Carsten Sch¨ urmann ITU, currently CMU Linear Logic Programming

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