modular dependent induction in coq mendler style paolo
play

Modular dependent induction in Coq, Mendler-style Paolo Torrini - PowerPoint PPT Presentation

Modular dependent induction in Coq, Mendler-style Paolo Torrini Dept. of Computer Science, KU Leuven ITP16, Nancy, 22.08.2016 * The Author left the Institution in April 2016 motivation: cost-effective theorem proving modularity in


  1. Modular dependent induction in Coq, Mendler-style Paolo Torrini Dept. of Computer Science, KU Leuven ∗ ITP’16, Nancy, 22.08.2016 * The Author left the Institution in April 2016

  2. motivation: cost-effective theorem proving modularity in specifications and proofs component-based definitions: enabling partiality extensibility: reuse when code is extended, no need for reimplementation low-cost: closeness with conventional ones goal: better scalability in programming language semantics 2/34

  3. expression problem in functional programming conventional inductive datatypes associated with a fixed set of constructors inherently not modular extending a conventional datatype requires defining a new datatype reimplementing functions, remaking proofs 3/34

  4. solving the expression problem: modular datatypes (MDTs) non-total functional languages (e.g. Haskell): datatypes ´ a la carte [Swierstra JFP’08] based on initial algebra semantics of inductive types Coq (totality required): meta-theory ´ a la carte (MTC/3MT) [Delaware, Oliveira, Schrijvers POPL ’13] based on higher-order encodings of initial semantics inductive reasoning by algebraic properties significant boilerplate 4/34

  5. Mendler-style modular induction applying Mendler-style induction to modular datatypes [Torrini, Schrijvers FICS’15] Mendler-style higher-order encodings type-directed approach restriction to non-dependent induction (corresponding to iteration) extending to the general case (dependent induction) current work [Torrini ITP’16] integration of Mendler-style induction (type-directed) with minimal use of MTC-style induction (algebraic) structural induction without restrictions 5/34

  6. modular datatypes MDT definition signature functor F non-recursive datatype fmap satisfying functor laws recursive datatype Fix F using a type-level fixpoint operator extensibility: functors can be composed by coproduct (+) structurally recursive functions: defined by fold of algebras on fixpoints 6/34

  7. example: definition of an arithmetic language – conventional datatypes – terms (natural literals, sums): Trm = dt Lit ( Nat ) | Add ( Trm , Trm ) values (integers): Val = dt Val ( vv : Nat ) 7/34

  8. example: language definition with MDT modular datatype, monolithic functor: Trm F C = dt Lit ( Nat ) | Add ( C , C ) recursive datatype as fixpoint of the functor: Trm := Fix Trm F ∼ Trm Trm = 8/34

  9. example: language definition with MDT modular datatype, composite functor (using coproduct): Trm F1 C = dt Lit ( Nat ) Trm F2 C = dt Add ( C , C ) Trm F := Trm F1 + Trm F2 recursive datatype as fixpoint of the functor: Trm := Fix Trm F ∼ Trm Trm = 8/34

  10. example: evaluation function – conventional definition – Trm = dt Lit ( Nat ) | Add ( Trm , Trm ) Val = dt Val ( vv : Nat ) eval : Trm → Val eval ( Lit n ) := Val n eval ( Add ( e 1 , e 2 )) := Val ( vv ( eval e 1 ) + vv ( eval e 2 )) 9/34

  11. example: evaluation function for MDT (1) Trm F -algebra with carrier Val Trm F C = dt Lit ( Nat ) | Add ( C , C ) eval C : Trm F Val → Val eval C ( Lit n ) := Val n eval C ( Add ( u 1 , u 2 )) := Val ( vv u 1 + vv u 2 ) 10/34

  12. example: evaluation function for MDT (2) recursion by folding Trm := Fix Trm F eval : Trm → Val eval := fold Trm F Val eval C fmap eval Trm F Trm Trm F Val in eval C eval Trm Val 11/34

  13. example: evaluation function for MDT (3) Mendler Trm F -algebra with carrier Val Trm F C = dt Lit ( Nat ) | Add ( C , C ) eval M : ∀ A . ( A → Val ) → ( Trm F A → Val ) eval M A rc ( Lit n ) := Val n eval M A rc ( Add ( u 1 , u 2 )) := Val ( vv ( rc u 1 ) + vv ( rc u 2 )) 12/34

  14. example: evaluation function for MDT (4) recursion by folding (Mendler-style) Trm := Fix Trm F eval : Trm → Val eval := fold Trm F Val eval M fmap eval Trm F Trm Trm F Val φ in eval M Val id eval Trm Val where φ := eval M Trm eval 13/34

  15. critical notions: Fix and fold in Haskell: no guarantee of totality / termination Fix F = dt In ( out : F ( Fix F )) fold f x := f ( fmap ( fold f ) ( out x )) 14/34

  16. critical notions: Fix and fold in a theorem prover: termination needed for consistency strictly positive datatypes, structurally recursive definitions (!) Fix F = dt In ( out : F ( Fix F )) non-positive occurrence of Fix (!) fold f x := f ( fmap ( fold f ) ( out x )) not structurally recursive 14/34

  17. modular reasoning in Coq encoding MDTs direct encoding of signature functors higher-order, eliminative encoding of fixed points: Church-style (conventional) or equiv. Mendler-style impredicative sets needed close-up problem: eliminative definitions complicate induction background problem: semantic soundness ( fold uniqueness) dealing with inductive reasoning: using Mendler algebras, Mendler-style induction can be used for non-dependent induction MTC/3MT: general solution by algebraic reasoning, using fold uniqueness integrating the two techniques 15/34

  18. algebra types endofunctor F on sets, C set F -algebras with carrier C type of conventional Church algebras Alg C F C := F C → C semantically: a morphism on sets type of Mendler algebras Alg M F C := ∀ A . ( A → C ) → F A → C semantically: a function between morphisms A : approximates recursive call argument type (restriction: not used elsewhere, not further analysed) A → C : iterative call type 16/34

  19. fixpoint and fold – eliminative encoding Church encoding type-level fixpoint operator – not a constructor Fix C F := ∀ A . Alg C F A → A fold as application of a fixpoint fold C F C : Alg C F C → Fix C F → C fold C F C alg x := x alg defined functions – not constructors in C F : F ( Fix C F ) → Fix C F out C F : Fix C F → F ( Fix C F ) 17/34

  20. fixpoint and fold – eliminative encoding Mendler encoding type-level fixpoint operator – not a datatype Fix M F := ∀ A . Alg M F A → A fold as application of a fixpoint fold M F C : Alg M F C → Fix M F → C fold M F C alg x := x alg defined functions – not constructors in M F : F ( Fix M F ) → Fix M F out M F : Fix M F → F ( Fix M F ) 17/34

  21. initial algebra semantics (conventional) fmap (fold F C alg) F ( Fix F ) F C alg in F fold F C alg Fix F C need uniqueness of fold : ( h ◦ in C = alg ◦ ( fmap h )) → ( h = fold C C alg ) 18/34

  22. initial algebra semantics (Mendler-style) fmap (fold F C alg) F ( Fix F ) F C φ alg C id C in F fold F C alg Fix F C where φ := alg ( Fix F ) ( fold F C alg ) need commutativity of upper triangle need uniqueness of fold : ( h ◦ in M = alg ( Fix M F ) h ) → ( h = fold M C alg ) 19/34

  23. inductively defined relations as MDT consider unary relations (predicates) on type T R : ( T → Prop ) → T → Prop endofunctor in diagram category T → Prop P : T → Prop predicate on T T -indexed R -algebras on T -indexed carrier P Church algebras and fixpoint: Alg CI T R P := ∀ w : T . R P w → P w Fix CI T R w := ∀ P . Alg CI T R P → P w Mendler algebras and fixpoint: Alg MI T R P := ∀ A . ( ∀ w : T . A w → P w ) → ∀ w : T . R A w → P w Fix MI T R w := ∀ P . Alg MI T R P → P w 20/34

  24. example: inductive relations conventional inductive predicate: IsTrm : Trm → Prop = dt IsLit ( n : Nat ) : IsTrm ( Lit n ) IsAdd ( e 1 e 2 : Trm ) : IsTrm e 1 → IsTrm e 1 → IsTrm ( Add e 1 e 2 ) Trm -indexed functor: IsTrm R ( P : Trm ) : Trm → Prop = dt IsLit ( n : Nat ) : IsTrm R P ( Lit n ) IsAdd ( e 1 e 2 : Trm ) : P e 1 → P e 1 → IsTrm R P ( Add e 1 e 2 ) modular inductive predicate (Church-style): Fix CI Trm IsTrm R IsTrm : Trm → Prop := modular inductive predicate (Mendler-style): Fix MI Trm IsTrm R IsTrm : Trm → Prop := 21/34

  25. inductive proofs consider non-dependent induction (corresponding to iteration) for T : Set and P : T → Prop, find a proof Γ , w : T ⊢ ? : X w → P w ( G ) by induction on modular inductive type X : T → Prop problem: X is not syntactically a datatype, no induction principle supplied by Coq generic clue: fold a T -indexed algebra with carrier P however, choosing X := Fix CI T R , the algebra to fold is ∀ w : T . R T P w → P w – hardly an induction step 22/34

  26. Mendler-style induction (1) Mendler-style induction: induction hypothesis given explicitly, inductive call argument typed with a fresh variable Γ , A : Type , i hyp : ∀ v : T . A v → P v , ( 1 ) w : T , i arg : R A w ⊢ t : P w Coq inversion tactic applied to i arg (to deconstruct R ) can introduce inductive call arguments of type A w in new subgoals Γ , A : Type , i hyp : ∀ v : T . A v → P v , w : T , . . . , i call arg n : A w , . . . ⊢ s t : P w . . . freshness of A makes proof an iteration: i call arg n only used in i hyp , not further analysed 23/34

  27. Mendler-style induction (2) by abstracting (1) we get a Mendler algebra Γ ⊢ λ A i hyp w i arg . t : ( 2 ) ∀ A . ( ∀ v : T . A v → P v ) → ∀ w : T . R A w → P w i.e. (2) can be rewritten Alg MI T R P Γ ⊢ λ A i hyp w i arg . t : ( 3 ) chosen X := Fix MI T R , the original goal is obtained by folding (3) Γ ⊢ fold MI T R P ( λ A i hyp w i arg . t ) : ( G ) ∀ w : T . Fix MI T R w → P w 24/34

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