type based methods for termination and productivity in coq
play

Type-Based Methods for Termination and Productivity in Coq Bruno - PowerPoint PPT Presentation

Type-Based Methods for Termination and Productivity in Coq Bruno Barras 1 Jorge Luis Sacchini 2 1 INRIA Saclay & LIX 2 Carnegie Mellon University Qatar July 22, 2013 Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination


  1. Type-Based Methods for Termination and Productivity in Coq Bruno Barras 1 Jorge Luis Sacchini 2 1 INRIA Saclay & LIX 2 Carnegie Mellon University – Qatar July 22, 2013 Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 1 / 26

  2. Coq Coq is a total dependently-typed programming language Totality means: ◮ Functions must be defined in their entire domain (no partial functions) ◮ Recursive functions must be terminating ◮ Co-recursive functions must be productive Non-terminations leads to inconsistencies Ex: (let f x = f x in f 0) : 0 = 1 Totality ensures logical consistency and decidability of type checking Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 2 / 26

  3. Coq Termination and productivity are undecidable problems Approximate the answer Coq imposes syntactic restrictions on (co-)recursive definitions For termination: guarded-by-destructors Recursive calls performed only on structurally smaller terms Γ( f : I → T ) ⊢ M : I → T Γ ⊢ (fix f : I → T := M ) : I → T Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 3 / 26

  4. Coq Termination and productivity are undecidable problems Approximate the answer Coq imposes syntactic restrictions on (co-)recursive definitions For termination: guarded-by-destructors Recursive calls performed only on structurally smaller terms Γ( f : I → T ) ⊢ M : I → T G ( f , M ) Γ ⊢ (fix f : I → T := M ) : I → T The predicate G ( f , M ) checks that all recursive calls of f in M are guarded by destructors Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 3 / 26

  5. Coq Termination and productivity are undecidable problems Approximate the answer Coq imposes syntactic restrictions on (co-)recursive definitions For termination: guarded-by-destructors Recursive calls performed only on structurally smaller terms Γ( f : I → T ) ⊢ M : I → T G ( f , M ) Γ ⊢ (fix f : I → T := M ) : I → T The predicate G ( f , M ) checks that all recursive calls of f in M are guarded by destructors Actually, the guard condition is checked on a normal form of the body M → ∗ N Γ( f : I → T ) ⊢ M : I → T G ( f , N ) Γ ⊢ (fix f : I → T := M ) : I → T Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 3 / 26

  6. Termination in Coq Typical example: fix half : nat → nat := λ x . case x of | O ⇒ O | S O ⇒ O | S ( S p ) ⇒ S (half p ) Recursive call is guarded. The recursive argument is smaller. The initial implementation of G (due to Eduardo Gim´ enez around 1994) has been extended over the years to allow more functions. Most recent extension: commutative cuts (due to Pierre Boutillier). Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 4 / 26

  7. Termination in Coq Typical example: fix half : nat → nat := λ x . case x of | O ⇒ O p ≺ S ( S p ) | S O ⇒ O | S ( S p ) ⇒ S (half p ) Recursive call is guarded. The recursive argument is smaller. The initial implementation of G (due to Eduardo Gim´ enez around 1994) has been extended over the years to allow more functions. Most recent extension: commutative cuts (due to Pierre Boutillier). Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 4 / 26

  8. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ x | S x 1 , O ⇒ S x 1 | S x 1 , S y 1 ⇒ minus x 1 y 1 Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  9. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ x | S x 1 , O ⇒ S x 1 " | S x 1 , S y 1 ⇒ minus x 1 y 1 x 1 ≺ x ( x 1 is a strict subterm of S x 1 ≡ x ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  10. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ x | S x 1 , O ⇒ S x 1 " | S x 1 , S y 1 ⇒ minus x 1 y 1 x 1 ≺ x ( x 1 is a strict subterm of S x 1 ≡ x ) � � Division: div x y = x y +1 fix div : nat → nat → nat := λ xy . case x of | O ⇒ O | S x 1 ⇒ S (div (minus x 1 y ) y ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  11. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ x | S x 1 , O ⇒ S x 1 " | S x 1 , S y 1 ⇒ minus x 1 y 1 x 1 ≺ x ( x 1 is a strict subterm of S x 1 ≡ x ) � � Division: div x y = x y +1 fix div : nat → nat → nat := λ xy . case x of | O ⇒ O " | S x 1 ⇒ S (div (minus x 1 y ) y ) minus x 1 y � x 1 ≺ S x 1 ≡ x Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  12. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ x | S x 1 , O ⇒ S x 1 | S x 1 , S y 1 ⇒ minus x 1 y 1 � � Division: div x y = x y +1 fix div : nat → nat → nat := λ xy . case x of | O ⇒ O | S x 1 ⇒ S (div (minus x 1 y ) y ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  13. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ O | S x 1 , O ⇒ S x 1 " | S x 1 , S y 1 ⇒ minus x 1 y 1 x 1 ≺ x ( x 1 is a strict subterm of S x 1 ≡ x ) � � Division: div x y = x y +1 fix div : nat → nat → nat := λ xy . case x of | O ⇒ O | S x 1 ⇒ S (div (minus x 1 y ) y ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  14. Termination in Coq Subterm relation Subtraction: fix minus : nat → nat → nat := λ xy . case x , y of | O , ⇒ O | S x 1 , O ⇒ S x 1 " | S x 1 , S y 1 ⇒ minus x 1 y 1 x 1 ≺ x ( x 1 is a strict subterm of S x 1 ≡ x ) � � Division: div x y = x y +1 fix div : nat → nat → nat := λ xy . case x of | O ⇒ O $ | S x 1 ⇒ S (div (minus x 1 y ) y ) minus x 1 y �� x 1 ≺ S x 1 ≡ x Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 5 / 26

  15. Termination in Coq Nested fixpoints Inductive rose( A ) : Type := node : A → list (rose A ) → rose A rmap := λ f : A → B . fix rmap : rose A → rose B := λ t . case t of node x ts ⇒ node ( f x ) (map rmap ts ) map := λ f : A → B . fix map : list A → list B := λ l . case l of nil ⇒ nil cons x xs ⇒ cons ( f x ) (map xs ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 6 / 26

  16. Termination in Coq Nested fixpoints Inductive rose( A ) : Type := node : A → list (rose A ) → rose A rmap := λ f : A → B . fix rmap : rose A → rose B := λ t . case t of " node x ts ⇒ node ( f x ) (map rmap ts ) map := λ f : A → B . fix map : list A → list B := λ l . case l of nil ⇒ nil " cons x xs ⇒ cons ( f x ) (map xs ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 6 / 26

  17. Termination in Coq Nested fixpoints Inductive rose( A ) : Type := node : A → list (rose A ) → rose A rmap := λ f : A → B . fix rmap : rose A → rose B := λ t . case t of node x ts ⇒ node ( f x ) (map rmap ts ) map := fix map : ( A → B ) → list A → list B := λ f l . case l of nil ⇒ nil " cons x xs ⇒ cons ( f x ) (map f xs ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 6 / 26

  18. Termination in Coq Nested fixpoints Inductive rose( A ) : Type := node : A → list (rose A ) → rose A rmap := λ f : A → B . fix rmap : rose A → rose B := λ t . case t of $ node x ts ⇒ node ( f x ) (map rmap ts ) map := fix map : ( A → B ) → list A → list B := λ f l . case l of nil ⇒ nil " cons x xs ⇒ cons ( f x ) (map f xs ) Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 6 / 26

  19. Syntactic criteria Limitations Works on syntax: small changes in code can make functions ill-typed Not compositional Difficult to understand for users ◮ Many questions about termination in the Coq list ◮ Error messages not informative Difficult to implement: termination checking is the most delicate part of Coq’s kernel Inefficient: guard condition is checked on the normal form of fixpoints bodies Difficult to study ◮ Little documentation ◮ Complicated to even define Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 7 / 26

  20. Termination in Coq Many ways to get around the guard condition: ◮ Adding extra argument to act as measure of termination ◮ Wellfounded recursion ◮ Ad-hoc predicate (Bove) ◮ Tool support (Function, Program) But this complicates function definition May affect efficiency Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 8 / 26

  21. Termination using sized types Long history: Haskell [Pareto et al.], λ � [Joao Frade et al.], F ω � [Abel], CIC � [Barthe et al.], CC+rewriting [Blanqui et al.] . . . Bruno Barras, Jorge Luis Sacchini Type-Based Methods for Termination and Productivity in Coq 9 / 26

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