algebraic datatypes are horn clause theories
play

Algebraic Datatypes are Horn-Clause Theories Frantiek Farka - PowerPoint PPT Presentation

Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes are Horn-Clause Theories Frantiek Farka University of Dundee, and University of St Andrews ff32@st-andrews.ac.uk 8 December


  1. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes are Horn-Clause Theories František Farka University of Dundee, and University of St Andrews ff32@st-andrews.ac.uk 8 December 2015 8 December 2015 1/20

  2. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Introduction Logic programming Programming in Horn-clause logic Goals resolved by a search - SLD resolution Automated theorem proving (ATP) Functional programming Program specified by a term Type of a term is a proposition Interactive theorem proving (ITP) 8 December 2015 2/20

  3. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Introduction Logic programming Programming in Horn-clause logic Goals resolved by a search - SLD resolution Automated theorem proving (ATP) Functional programming Program specified by a term Type of a term is a proposition Interactive theorem proving (ITP) How are the two related? 8 December 2015 2/20

  4. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Introduction (cont) Propositions as Types Due to Barendregt, 1991 Relating lambda calculi and different logics λω λ C Prop ω Pred ω λ 2 λΠ 2 Prop 2 Pred 2 λω λΠω Prop ω Pred ω λ → λΠ Prop Pred 8 December 2015 3/20

  5. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming Propositional Logic Programming Infinite set of elementary propositions P , propositions denoted nat , bool , . . . A program is a set of Horn-clauses, i. e. clauses in the form H ← B 1 , . . . B n Resolution step: P ⊢ B 1 , . . . , P ⊢ B n A ← B 0 . . . B n ∈ P P ⊢ A 8 December 2015 4/20

  6. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming Propositional Logic Programming Infinite set of elementary propositions P , propositions denoted nat , bool , . . . A set of clause names α, β 1 , . . . equipped with arity ( ar ( α ) = 1, . . . ) A program is a set of Horn-clauses, i. e. clauses in the form α : H ← B 1 , . . . B n where ar ( α ) = n Resolution step: P ⊢ β 1 : B 1 , . . . , P ⊢ β n : B n α : A ← B 0 . . . B n ∈ P P ⊢ α ( β 1 , . . . , β n ) : A 8 December 2015 4/20

  7. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming (cont.) A proof in PLP Success tree - all leafs are empty goals Applicative term as a proof Example Resolution in P nat = { ζ : nat , σ : nat ← nat } ζ : nat P ⊢ ζ : nat σ : nat ← nat P ⊢ σ ( ζ ) : nat 8 December 2015 5/20

  8. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming (cont.) A proof in PLP Success tree - all leafs are empty goals Note that success tree can have infinite branches (coinductive int.) Applicative term as a proof Example Resolution in P nat = { ζ : nat , σ : nat ← nat } ζ : nat P ⊢ ζ : nat σ : nat ← nat P ⊢ σ ( ζ ) : nat . . . σ : nat ← nat P ⊢ σ ( . . . ) : nat σ : nat ← nat P ⊢ σ ( σ ( . . . )) : nat 8 December 2015 5/20

  9. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming (cont.) Theorem: Inductive soundness and completeness A proposition A is in the least model M P of a program P iff there is a finite term π s. t. P ⊢ π : A Theorem: Coinductive soundness A proposition A is in the greatest model M ω P of a program P if there is an infinite term π s. t. P ⊢ π : A 8 December 2015 6/20

  10. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Propositional Logic Programming (cont.) Theorem: Inductive soundness and completeness A proposition A is in the least model M P of a program P iff there is a finite term π s. t. P ⊢ π : A Theorem: Coinductive soundness A proposition A is in the greatest model M ω P of a program P if there is an infinite term π s. t. P ⊢ π : A Models are as usual in LP: T P ( X ) = { A | α : A ← B 0 , . . . , B n − 1 ∈ P && ∀ i ∈ 0 , . . . , n − 1 B i ∈ X } And M P = µ ( T P ) and M ω P = ν ( T P ) 8 December 2015 6/20

  11. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes Simply Typed Lambda Calculus ( Λ → ) Infinite set V of variables ( x , y , . . . ), and infinite set B of type variables/identifiers: α, β, . . . Function types: σ → τ Lambda abstraction, for y : σ the expression ( λ x : τ. y ) is of type τ → σ Application, for x : σ → τ and y : σ is xy : τ 8 December 2015 7/20

  12. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes Simply Typed Lambda Calculus ( Λ → ) Infinite set V of variables ( x , y , . . . ), and infinite set B of type variables/identifiers: α, β, . . . , n at, b ool Function types: σ → τ Lambda abstraction, for y : σ the expression ( λ x : τ. y ) is of type τ → σ Application, for x : σ → τ and y : σ is xy : τ Algebraic Datatypes Constructors and eliminators/destructors for algebraic data types 8 December 2015 7/20

  13. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes (cont.) Algebraic Datatypes Algebraic type is a type variable α and a set C of i constructors c j Each constructor is equipped with arity n and with a n-tuple of ADTs Inference rules: Γ ⊢ t 1 : β j , 1 , . . . , Γ ⊢ t ar ( c j ) : β j , ar ( c j ) CON c j Γ ⊢ c j t 1 . . . t ar ( c j ) : α for j = 0 , . . . , i − 1, and Γ ⊢ t : α Γ, x 0 : β 0 , 1 , . . . , x ar ( c 0 ) : β 0 , ar ( c 0 ) ⊢ s 0 : γ , . . . , Γ, x i − 1 : β i − 1 , 1 , . . . , x ar ( c i − 1 ) : β i − 1 , ar ( c i − 1 ) ⊢ s i − 1 : γ CASE α Γ ⊢ case t of ( s 0 , . . . , s i − 1 ) : γ 8 December 2015 8/20

  14. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Algebraic Datatypes (cont.) Example (Algebraic Datatypes) data Bool where true : () → Bool false : () → Bool data Nat where zero : Nat succ : Nat → Nat two : Nat two = succ ( succ zero ) prec : Nat → Nat prec x = case x of → zero zero succ x 0 → x 0 8 December 2015 9/20

  15. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion ADTs are Horn-Clause Theories Translating ADTs to PLP, map | · | Let there be an isomorphism of type variables B and propositions P and of constructors and clause names Then for each constructor c j s. t. c j : ( β 1 , . . . , β n ) → α | c j | = γ j : A ← B 1 , . . . , B n Example ( N at and B ool) | Nat | = { ζ : nat ; σ : nat ← nat } , | Bool | = { τ : bool ; φ : bool } 8 December 2015 10/20

  16. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion ADTs are Horn-Clause Theories Translating ADTs to PLP, map | · | Let there be an isomorphism of type variables B and propositions P and of constructors and clause names Then for each constructor c j s. t. c j : ( β 1 , . . . , β n ) → α | c j | = γ j : A ← B 1 , . . . , B n Example ( N at and B ool) | Nat | = { ζ : nat ; σ : nat ← nat } , | Bool | = { τ : bool ; φ : bool } Lemma: PLP resolution for ADTs For an ADT α there exist a term t such that Γ ⊢ λ → t : α iff | Γ | ⊢ PLP τ : A for some proof τ 8 December 2015 10/20

  17. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Resolution with And-Or Trees And-Or Trees Due to Komendantskaya and Johann, 2015 even ζ : even ǫ : even ← odd ⊥ ǫ Example For a program P: odd ζ : even ⊥ ζ ⊥ o ǫ : odd ← even ǫ : even ← odd o : odd ← even even resolve goal even ζ : even ǫ : even ← odd ⊥ ǫ . . . 8 December 2015 11/20

  18. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Resolution with And-Or Trees (cont.) Inductive success A finite subtree; all children in and-nodes any one child in or-nodes. ǫ ( o ( ζ )) : even Example ζ : even ǫ : even ← odd ⊥ ǫ For a program P: o ( ζ ) : odd ζ : even ǫ : even ← odd ⊥ ζ ⊥ o ǫ : odd ← even o : odd ← even ζ : even resolve goal even with ǫ ( o ( ζ )) ζ : even ǫ : even ← odd ⊥ ǫ . . . 8 December 2015 12/20

  19. Introduction Calculi Resolution for ADTs Induction and Coinduction Future Work Discussion Resolution with And-Or Trees (cont.) Inductive success A finite subtree; all children in and-nodes any one child in or-nodes. ǫ ( o ( ζ )) : even Example ζ : even ǫ : even ← odd ⊥ ǫ For a program P: o ( ζ ) : odd ζ : even ǫ : even ← odd ⊥ ζ ⊥ o ǫ : odd ← even o : odd ← even ζ : even resolve goal even with ǫ ( o ( ζ )) ζ : even ǫ : even ← odd ⊥ ǫ . . . 8 December 2015 13/20

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