coq

Coq: Defining a subtype

怎甘沉沦 提交于 2019-12-06 14:19:21
I have a type, say Inductive Tt := a | b | c. What's the easiest and/or best way to define a subtype of it? Suppose I want the subtype to contain only constructors a and b . A way would be to parametrize on a two-element type, e.g. bool: Definition filt (x:bool): Tt := match x with | true => a | false => b end. Check filt true: Tt. This works but is very awkward if your expression has several (possibly interdependent) subtypes defined this way. Besides, it works only half way, as no subtype is defined. For this I must additionally define e.g. Notation _Tt := ltac: (let T := type of (forall {x

Stuck in the construction of a very simple function

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 11:49:12
I am learning Coq. I am stuck on a quite silly problem (which has no motivation, it is really silly). I want to build a function from ]2,+oo] to the set of integers mapping x to x-3. That should be simple... In any language I know, it is simple. But not in Coq. First, I write (I explain with a lot of details so that someone can explain what I don't understand in the behaviour of Coq) Definition f : forall n : nat, n > 2 -> nat. I get a subgoal ============================ forall n : nat, n > 2 -> nat which means that Coq wants a map from a proof of n>2 to the set of integers. Fine. So I want

How do you selectively simplify arguments to each time a function is called, without evaluating the function itself?

这一生的挚爱 提交于 2019-12-06 08:44:46
问题 I'm using Coq 8.5pl1. To make a contrived but illustrative example, (* fix so simpl will automatically unfold. *) Definition double := fix f n := 2*n. Theorem contrived n : double (2 + n) = 2 + double (1 + n). Now, I only want to simplify the arguments to double, and not any part outside of it. (For example, because the rest has already carefully been put into the correct form.) simpl. S (S (n + S (S (n + 0)))) = S (S (S (n + S (n + 0)))) This converted the outside (2 + ...) to (S (S ...)) as

Proving equality on coinductive lazy lists in Coq

南笙酒味 提交于 2019-12-06 08:40:12
I am experimenting with Coq Coinductive types. I use the lazy list type form the Coq'Art book (sect. 13.1.4): Set Implicit Arguments. CoInductive LList (A:Set) : Set := | LNil : LList A | LCons : A -> LList A -> LList A. Implicit Arguments LNil [A]. CoFixpoint LAppend (A:Set) (u v:LList A) : LList A := match u with | LNil => v | LCons a u' => LCons a (LAppend u' v) end. In order to match the guard condition I also use the following decomposition functions form this book: Definition LList_decomp (A:Set) (l:LList A) : LList A := match l with | LNil => LNil | LCons a l' => LCons a l' end. Lemma

Are constructors in the plain calculus of constructions disjoint and injective?

风格不统一 提交于 2019-12-06 07:58:43
问题 Based on this answer, it looks like the calculus of inductive constructions, as used in Coq, has disjoint, injective constructors for inductive types. In the plain calculus of constructions (i.e., without primitive inductive types), which uses impredicative encodings for types (e.g., ∏(Nat: *).∏(Succ: Nat → Nat).∏(Zero: Nat).Nat ), is this still true? Can I always find out which "constructor" was used? Also, is injectivity (as in ∀a b.I a = I b → a = b ) provable in Coq with Prop or

Defining different equality types as inductive types in Coq

与世无争的帅哥 提交于 2019-12-06 05:50:24
问题 I am trying to define in Coq different types of equalities. During an university course my professor gave us the rules of four different types, as follows (I provide just the links to the rules): Gentzen : https://ibb.co/imQOCF Leibniz : https://ibb.co/n0uBzv Martin-Lof : https://ibb.co/fALZKv Path Induction : https://ibb.co/esZuKv The difference among these four types relies on the type C. I am trying to prove the isomorphism among them. Unfortunately I have some troubles in declaring as

Set theory notation with whitespaces and curly braces in Coq

女生的网名这么多〃 提交于 2019-12-06 05:12:30
I'd like to have standard notation like "x ∈ { x }" in Coq. But there are problems: 1) Curly braces has special meaning in Coq, so the following happens: Notation " x ∈ y " :=(tin x y) (at level 50). Notation " { x } ":=(Sing x). Check fun x => (x ∈ { x }). (*error: Unknown interpretation for notation "_ ∈ { _ }". *) How to define this notation correctly? 2) If the first problem cannot be solved, there is another. (Here I decided to use the additional symbol '`' in the notation.) Notation " { x }` ":=(Sing x). Check fun x => (x ∈ { x }`). (* fun x : Ens => x ∈ {x }` *) Now I should a) either

Coq: a single notation for multiple constructors

。_饼干妹妹 提交于 2019-12-06 02:16:36
Is it possible to define a single notation for multiple constructors in Coq? If the constructors differ by their argument types, they might be inferrable from them. A minimal (non-)working example: Inductive A : Set := a | b | c: C -> A | d: D -> A with C: Set := c1 | c2 with D: Set := d1 | d2. Notation "' x" := (_ x) (at level 19). Check 'c1. (*?6 c1 : ?8*) In this case, constructor inference doesn't work. Maybe there's another way to specify a constructor as a variable? You can create a typeclass with the constructors as instances and let the instance resolution mechanism infer the

In Coq, which tactic to change the goal from `S x = S y` to `x = y`

可紊 提交于 2019-12-06 01:52:26
I want to change the goal from S x = S y to x = y . It's like inversion , but for the goal instead of a hypothesis. Such a tactic seems legit, because when we have x = y , we can simply use rewrite and reflexivity to prove the goal. Currently I always find myself using assert (x = y) to introduce a new subgoal, but it's tedious to write when x and y are complex expression. The tactic apply f_equal. will do what you want, for any constructor or function. The lema f_equal shows that for any function f , you always have x = y -> f x = f y . This allows you to reduce the goal from f x = f y to x =

How do inductive proposition work in Coq?

北城余情 提交于 2019-12-06 00:35:37
I was going through IndProp in software foundations and Adam Chlipala's chapter 4 book and I was having difficulties understanding inductive propositions. For the sake of a running example, lets use: Inductive ev : nat -> Prop := | ev_0 : ev 0 | ev_SS : forall n : nat, ev n -> ev (S (S n)). I think I do understand "normal" types using Set like: Inductive nat : Set := | O : nat | S : nat -> nat. and things like O just return the single object of type nat and S O is taking an object of type nat and returning another different one of the same type nat . By different object I guess I mean they