coq

The reference “X” was not found in the current environment

二次信任 提交于 2019-12-01 02:02:20
问题 I'm using CoqIDE to complete the exercises in the Software Foundations book about Coq. I can successfully compile Basics.v, resulting in Basics.vo and Basics.glob in my directory. When I try to run Induction.v, it works. When I try to compile it, it complains about tons of missing references, such as evenb and negb_involutive . If I copy Basics.v contents into Induction.v it compiles, but obviously this is not the way to go. This is not a duplicate of question Coq error: The reference evenb

Inductive subset of an inductive set in Coq

感情迁移 提交于 2019-12-01 00:40:24
I have an Inductive Set built with three constructors: Inductive MF : Set := | D : MF | cn : MF -> MF -> MF | dn : Z -> MF -> MF. I would like to somehow define a new inductive set B, such that B is a subset of MF containing just the elements obtained from D and dn. Furthermore, everything in B should be interpreted as type MF if needed. I tried defining first B and then MF as follows: Inductive B : Set := | D : B | dn : Z -> B -> B. Inductive MF : Set := | m : B -> MF | cn : MF -> MF -> MF | Dn : Z -> MF -> MF. Axiom m_inj : forall (a b : B), m a = m b -> a = b. Coercion m : B >-> MF. Axiom

How do I read the definition of ex_intro?

不打扰是莪最后的温柔 提交于 2019-11-30 20:42:20
I'm reading Mike Nahas's introductory Coq tutorial , which says: The arguments to "ex_intro" are: the predicate the witness a proof of the predicated called with the witness I looked at the definition : Inductive ex (A:Type) (P:A -> Prop) : Prop := ex_intro : forall x:A, P x -> ex (A:=A) P. and I'm having trouble parsing it. Which parts of the expression forall x:A, P x -> ex (A:=A) P correspond to those three arguments (predicate, witness, and proof)? To understand what Mike meant, it's better to launch the Coq interpreter and query for the type of ex_intro : Check ex_intro. You should then

Inductive subset of an inductive set in Coq

江枫思渺然 提交于 2019-11-30 19:04:04
问题 I have an Inductive Set built with three constructors: Inductive MF : Set := | D : MF | cn : MF -> MF -> MF | dn : Z -> MF -> MF. I would like to somehow define a new inductive set B, such that B is a subset of MF containing just the elements obtained from D and dn. Furthermore, everything in B should be interpreted as type MF if needed. I tried defining first B and then MF as follows: Inductive B : Set := | D : B | dn : Z -> B -> B. Inductive MF : Set := | m : B -> MF | cn : MF -> MF -> MF |

Proving f (f bool) = bool

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 18:08:31
How can I in coq, prove that a function f that accepts a bool true|false and returns a bool true|false (shown below), when applied twice to a single bool true|false would always return that same value true|false : (f:bool -> bool) For example the function f can only do 4 things, lets call the input of the function b : Always return true Always return false Return b (i.e. returns true if b is true vice versa) Return not b (i.e. returns false if b is true and vice vera) So if the function always returns true: f (f bool) = f true = true and if the function always return false we would get: f (f

Syntax Error with `<` in Coq Notations

我们两清 提交于 2019-11-30 17:27:11
问题 The following code: Reserved Notation "g || t |- x < y" (at level 10). Inductive SubtypeOf : GammaEnv -> ThetaEnv -> UnsafeType -> UnsafeType -> Set := | SubRefl : forall (gamma : GammaEnv) (theta : ThetaEnv) (u : UnsafeType) , gamma || theta |- u < u where "g || t |- x < y" := (SubtypeOf g t x y). gives the following error: Syntax error: '<' expected after [constr:operconstr level 200] (in [constr:operconstr]) I get a similar error if I use <: in place of < . But this code works fine:

Why Coq doesn't allow inversion, destruct, etc. when the goal is a Type?

若如初见. 提交于 2019-11-30 14:07:06
When refine ing a program, I tried to end proof by inversion on a False hypothesis when the goal was a Type . Here is a reduced version of the proof I tried to do. Lemma strange1: forall T:Type, 0>0 -> T. intros T H. inversion H. (* Coq refuses inversion on 'H : 0 > 0' *) Coq complained Error: Inversion would require case analysis on sort Type which is not allowed for inductive definition le However, since I do nothing with T , it shouldn't matter, ... or ? I got rid of the T like this, and the proof went through: Lemma ex_falso: forall T:Type, False -> T. inversion 1. Qed. Lemma strange2:

Nested recursion and `Program Fixpoint` or `Function`

送分小仙女□ 提交于 2019-11-30 14:02:21
I’d like to define the following function using Program Fixpoint or Function in Coq: Require Import Coq.Lists.List. Import ListNotations. Require Import Coq.Program.Wf. Require Import Recdef. Inductive Tree := Node : nat -> list Tree -> Tree. Fixpoint height (t : Tree) : nat := match t with | Node x ts => S (fold_right Nat.max 0 (map height ts)) end. Program Fixpoint mapTree (f : nat -> nat) (t : Tree) {measure (height t)} : Tree := match t with Node x ts => Node (f x) (map (fun t => mapTree f t) ts) end. Next Obligation. Unfortunately, at this point I have a proof obligation height t < height

How to call proof asistant Coq from external software

人走茶凉 提交于 2019-11-30 09:49:59
How to call proof assistant Coq from external software? Does Coq have some API? Is Coq command line interface rich enough to pass arguments in file and receive response in file? I am interested in Java or C++ bridges. This is legitimate question. Coq is not the usual business software from which one can expect the developer friendly API. I had similary question about Isabelle/HOL and it was legitimate question with non-trivial answer. As of today, there are three ways to interact with Coq, ordered from more effort to less power: The OCaml API: This is what Coq plugins do, however, some parts

Writing well-founded programs in Coq using Fix or Program Fixpoint

独自空忆成欢 提交于 2019-11-30 09:32:28
问题 Following the example given in the chapter GeneralRec of Chlipala book, I'm trying to write the mergesort algorithm. Here is my code Require Import Nat. Fixpoint insert (x:nat) (l: list nat) : list nat := match l with | nil => x::nil | y::l' => if leb x y then x::l else y::(insert x l') end. Fixpoint merge (l1 l2 : list nat) : list nat := match l1 with | nil => l2 | x::l1' => insert x (merge l1' l2) end. Fixpoint split (l : list nat) : list nat * list nat := match l with | nil => (nil,nil) |