coq

Substitute argument of `fix` in proof

拜拜、爱过 提交于 2019-12-11 15:15:48
问题 This question is probably trivial, but I'm stuck on it since yesterday and I couldn't find the relevant keyword to search for. Consider the following: Fixpoint mfp (t: nat*nat) := fst t. Lemma ml: forall (t: nat*nat), mfp t = fst t. Proof. intros. unfold mfp. (* substitute t0 with t in lhs *) reflexivity. Qed. After unfolding mfp , I have to prove (fix mfp (t0 : nat * nat) : nat := fst t0) t = fst t which trivially holds, yet I don't know how to tell Coq "Do the substitution of t0 by t ". Do

IndProp test_nostutter_4

别来无恙 提交于 2019-12-11 14:29:30
问题 The authors of the book have provided proofs for some unit tests for nostutter exercise. Unfortunately, they didn't provide explanations how they work. I was able to understand all the proofs but one: Inductive nostutter {X:Type} : list X -> Prop := | ns_nil : nostutter [] | ns_one : forall (x : X), nostutter [x] | ns_cons: forall (x : X) (h : X) (t : list X), nostutter (h::t) -> x <> h -> nostutter (x::h::t). Example test_nostutter_4: not (nostutter [3;1;1;4]). Proof. intro. repeat match

Applying hypotesis to a variable

孤者浪人 提交于 2019-12-11 11:48:11
问题 Let's say I'm in the middle of a proof and I have hypotheses like these: a : nat b : nat c : nat H : somePred a b and the definition of somePred says: Definition somePred (p:nat) (q:nat) : Prop := forall (x : nat), P(x, p, q). How do I apply H to c and to get P(c, a, b) ? 回答1: The answer is: specialize H with c. 来源: https://stackoverflow.com/questions/29316168/applying-hypotesis-to-a-variable

Rewrite under exists

微笑、不失礼 提交于 2019-12-11 10:28:23
问题 Say I have the following relation: Inductive my_relation: nat -> Prop := constr n: my_relation n. and I want to prove the following: Lemma example: (forall n, my_relation n -> my_relation (S n)) -> (exists n, my_relation n) -> exists n, my_relation (S n). Proof. intros. After introducing, I have the following environment: 1 subgoal H : forall n : nat, my_relation n -> my_relation (S n) H0 : exists n : nat, my_relation n ______________________________________(1/1) exists n : nat, my_relation

Conversion of nat to Q in Coq

*爱你&永不变心* 提交于 2019-12-11 09:59:47
问题 How can I convert nat to Q (Rational) in Coq? I want to be able to write things like this: Require Import Coq.QArith.QArith. Open Scope Q_scope. Definition a := 2/3. When I try to do this, Coq tells me: Error: The term "2" has type "nat" while it is expected to have type "Q". 回答1: You can write something like: Definition a := Z.of_nat 2 # Pos.of_nat 3. The # operator is just notation for the Qmake constructor of the Q type. That constructor takes elements of Z and positive as arguments, so

Proven correct receipt module

匆匆过客 提交于 2019-12-11 08:21:40
问题 I'm working on a register which produces receipts when customers buy articles. As an exercise, I'm thinking about making a receipt module in Coq which cannot produce erroneous receipts. In short, the articles and the payments on the receipt should always sum to 0 (where articles have price > 0 and payments have amount < 0). Is this doable, or sensible? To do a quick sketch, a receipt would consist of receipt items and payments, like type receipt = { items : item list; payments : payment list

Proving equality between instances of dependent types

♀尐吖头ヾ 提交于 2019-12-11 07:22:07
问题 When attempting to formalize the class which corresponds to an algebraic structure (for example the class of all monoids), a natural design is to create a type monoid (a:Type) as a product type which models all the required fields (an element e:a , an operator app : a -> a -> a , proofs that the monoid laws are satisfied etc.). In doing so, we are creating a map monoid: Type -> Type . A possible drawback of this approach is that given a monoid m:monoid a (a monoid with support type a ) and m'

Are Coq tacticals right associative or left associative?

你离开我真会死。 提交于 2019-12-11 07:21:14
问题 I was going through software foundations and got the example: repeat (try (left; reflexivity); right). and was confused what this meant. For example do we get: try [ (left; reflexivity); right ] or [try (left; reflexivity);] right second or first? in particular I was trying to understand: Theorem In10 : In 10 [1;2;3;4;5;6;7;8;9;10]. Proof. repeat (try (left; reflexivity); right). Qed. 回答1: A good way of solving those problems on your own is to use tactics like idtac (always succeeds) and fail

Just a universally quantified hypotesis in coq proof

本小妞迷上赌 提交于 2019-12-11 06:47:12
问题 Another hard goal (for me, of course) is the following: Goal ~(forall P Q: nat -> Prop, (exists x, P x) /\ (exists x, Q x) -> (exists x, P x /\ Q x)). Proof. I absolutely have no idea of what could I do. If I introduce something, I get a universal quantifier in the hypotesis, and then I can't do anything with it. I suppose that it exists a standard way for managing such kind of situations, but I was not able to find it out. 回答1: To progress in that proof, you will have to exhibit an instance