coq manual section 4 4 5
play

Coq Manual (Section 4.4.5) G.C. Alexandru Jochem Raat May 26, 2020 - PowerPoint PPT Presentation

Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Coq Manual (Section 4.4.5) G.C. Alexandru Jochem Raat May 26, 2020 G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5) Inductive


  1. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Coq Manual (Section 4.4.5) G.C. Alexandru Jochem Raat May 26, 2020 G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  2. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Introduction This section gives an overview of inductive definitions and their rules in Coq: Inductive definitions and their typing/correctness rules Template polymorphism on inductive definitions Destructors of inductive definitions G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  3. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Structure 1 Inductive Definitions 2 Template Polymorphism 3 Destructors 4 Pattern Matching 5 Guarded Fixpoints 6 Questions G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  4. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Notation Ind [ p ] (Γ I := Γ C ), where: p : number of parameters Γ I : types of the inductive types, ”type constructors” Γ C : types of the constructors of the inductive types, ”value constructors” Example of parameterized lists: Inductive list (A:Set) : Set := | nil : list A | cons : A -> list A -> list A. G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  5. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Example 2 Inductive even : nat -> Prop := | even_O : even 0 | even_S : forall n, odd n -> even (S n) with odd : nat -> Prop := | odd_S :forall n, even n -> odd (S n). G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  6. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Arity of sort ”A type T is an arity of sort s if it converts to the sort s or to a product ∀ x : T . U with U an arity of sort s.” (p. 211) ∀ A : Prop . A → Prop, is an arity of sort Prop. Set, is an arity of sort Set A → B → Set, is an arity of sort Set. G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  7. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Arity Any type is an arity if there is a sort s , for which it is an arity of sort s . So, A → B → Set is an arity, but A → B is not. G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  8. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Positivity Condition used to prevent logical contradiction caused by inductive definitions By preventing the type constructors from being used in a wrong way in the value constructors G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  9. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Three definitions for a type T (all in regards to a term X ): 1 Positivity condition T = X t 1 ... t n and X does not occur freely in t i T = ∀ x : U , V , where U is strictly positive and V satisfies the positivity condition 2 Strict positivity X does not occur in T T converts to X t 1 ... t n and X does not occur in t i T converts to ∀ x : U , V and X does not occur in U and strictly positively in V T converts to I a 1 . . . a m t 1 . . . t p , where I is inductive with m parameters and X does not occur in t i and the (instantiated) types of constructors of I satisfy nested positivity. 3 Nested positivity T = ( I b 1 . . . b m u 1 . . . u p , I is an inductive type with m parameters and X does not occur in u i T = ∀ x : U , V and U strictly positive and V nested positive G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  10. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Correctness Rule G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  11. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Examples! Switch to the editor, with the example Coq file! :) G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  12. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Structure 1 Inductive Definitions 2 Template Polymorphism 3 Destructors 4 Pattern Matching 5 Guarded Fixpoints 6 Questions G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  13. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Template Polymorphism Inductive types, polymorphic over Sort Used when arity is in Type hierarchy G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  14. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Example Inductive option (A:Type) : Type := | None : option A | Some : A -> option A. Should be able to package terms of any sort. E.g. Type(1) , Set , Prop , etc. Should return the lowest applicable sort, not just Type G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  15. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Example For example, if a : Set then option a should be in Set as well. This way a function of type Set -> Set that can take a value like 2 , can also take a value like Some 2 . G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  16. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Typing rule If A is an arity of some sort, A / s is A with its sort replaced by the sort s . We have r recursively uniform parameters. These are the same in all occurrences of I j in all constructors, even in the hypotheses. The sorts s i are are introduced by the inductive declaration and allow all eliminations. G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  17. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Examples Check (fun A:Type => option A). fun A : Type => option A : Type -> Type Check (fun A:Set => option A). fun A : Set => option A : Set -> Set Check (fun A:Prop => option A). fun A : Prop => option A : Prop -> Set G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  18. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Structure 1 Inductive Definitions 2 Template Polymorphism 3 Destructors 4 Pattern Matching 5 Guarded Fixpoints 6 Questions G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  19. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Introduction Basic Question: How to use inductive types Want to retain strong normalization ⇒ primitive recursion Several possible ways to go about this, in Coq the problem is factorized into: pattern matching recursion with guarded fixpoints G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  20. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Structure 1 Inductive Definitions 2 Template Polymorphism 3 Destructors 4 Pattern Matching 5 Guarded Fixpoints 6 Questions G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  21. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: match m as x in I a return P with | ( c 1 x 11 . . . x 1 p 1 ) ⇒ f 1 | . . . | ( c n x n 1 . . . x np n ) ⇒ f n end G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  22. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  23. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  24. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  25. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  26. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

  27. Inductive Definitions Template Polymorphism Destructors Pattern Matching Guarded Fixpoints Questions Pattern matching construct Concrete syntax: match m as x in I a return P with | ( c 1 x 11 . . . x 1 p 1 ) ⇒ f 1 | . . . | ( c n x n 1 . . . x np n ) ⇒ f n end Abstract syntax: case ( m , ( λ ax . P ) , λ x 11 . . . x 1 p 1 . f 1 | . . . | λ x n 1 . . . x np n . f n ) G.C. Alexandru, Jochem Raat Coq Manual (Section 4.4.5)

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