Questions tagged [coq]

Coq is a formal proof management system, semi-interactive theorem prover and functional programming language. Coq is used for software verification, the formalization of programming languages, the formalization of mathematical theorems, teaching, and more. Due to the interactive nature of Coq, we recommend questions to link to executable examples at https://x80.org/collacoq/ if deemed appropriate.

Coq is an interactive theorem prover based on the calculus of inductive constructions.

Resources

2862 questions
12
votes
1 answer

Forall introduction in coq?

I'm trying to (classically) prove ~ (forall t : U, phi) -> exists t: U, ~phi in Coq. What I'm trying to do is prove it contrapositively: 1. Assume there is no such t (so ~(exists t: U, ~phi)) 2. Choose arbitrary t0:U 3. If ~phi[t/t0], then…
Maty
  • 223
  • 1
  • 7
12
votes
2 answers

Step by step simplification in coq?

Is there a way to simplify one step at a time? Say you have f1 (f2 x) both of which can be simplified in turn via a single simpl, is it possible to simplify f2 x as a first step, examine the intermediate result and then simplify f1? Take for example…
savx2
  • 1,011
  • 2
  • 10
  • 28
12
votes
1 answer

Fail to use let-destruct for tuple in Coq

I'm a new user for Coq. I have defined some functions: Definition p (a : nat) := (a + 1, a + 2, a + 3). Definition q := let (s, r, t) := p 1 in s + r + t. Definition q' := match p 1 with | (s, r, t) => s + r + t end. I'm trying to destruct the…
xywang
  • 941
  • 8
  • 24
12
votes
2 answers

Coq: Prop versus Set in Type(n)

I want to consider the following three (related?) Coq definitions. Inductive nat1: Prop := | z1 : nat1 | s1 : nat1 -> nat1. Inductive nat2 : Set := | z2 : nat2 | s2 : nat2 -> nat2. Inductive nat3 : Type := | z3 : nat3 | s3 : nat3 ->…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
12
votes
1 answer

Coq QArith division by zero is zero, why?

I noticed that in Coq's definition of rationals the inverse of zero is defined to zero. (Usually, division by zero is not well-defined/legal/allowed.) Require Import QArith. Lemma inv_zero_is_zero: (/ 0) == 0. Proof. unfold Qeq. reflexivity.…
larsr
  • 5,447
  • 19
  • 38
12
votes
1 answer

How can a coq Set or Type be a proposition

I'm reading a tutorial on Coq. It constructs a bool type as follows: Coq < Inductive bool : Set := true | false. bool is defined bool_rect is defined bool_ind is defined bool_rec is defined Then it shows what each of these things are using…
dspyz
  • 5,280
  • 2
  • 25
  • 63
12
votes
1 answer

Impredicative polymorphism in F#

OCaml's Hindley-Milner type system does not allow for impredicative polymorphism (à la System-F), except through a somewhat recent extension for record types. The same applies to F#. It however is sometimes desirable to translate programs written…
David Monniaux
  • 1,948
  • 12
  • 23
11
votes
1 answer

Unable to find an instance for the variable

Context: I'm working on exercises in Software Foundations. Theorem neg_move : forall x y : bool, x = negb y -> negb x = y. Proof. Admitted. Theorem evenb_n__oddb_Sn : forall n : nat, evenb n = negb (evenb (S n)). Proof. intros n. induction n…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
11
votes
3 answers

Non-empty list append theorem in Coq

I am trying to prove the following lemma in Coq: Require Import Lists.List. Import ListNotations. Lemma not_empty : forall (A : Type) (a b : list A), (a <> [] \/ b <> []) -> a ++ b <> []. Right now my current strategy was to destruct on a, and…
11
votes
2 answers

How to install SSReflect and MathComp in Linux?

I have successfully installed Coq 8.6 and CoqIDE in Linux (Ubuntu 17.04). However, I don't know to proceed in order to add SSReflect and MathComp to this installation. All the references that I have checked seemed to be very confusing to me. Does…
Marcus
  • 437
  • 2
  • 11
11
votes
1 answer

How to prove excluded middle is irrefutable in Coq?

I was trying to prove the following simple theorem from an online course that excluded middle is irrefutable, but got stuck pretty much at step 1: Theorem excluded_middle_irrefutable: forall (P:Prop), ~~(P \/ ~ P). Proof. intros P. unfold not.…
thor
  • 21,418
  • 31
  • 87
  • 173
11
votes
2 answers

Compute with a recursive function defined by well-defined induction

When I use Function to define a non-structurally recursive function in Coq, the resulting object behaves strangely when a specific computation is asked. Indeed, instead of giving directly the result, the Eval compute in ... directive return a rather…
eponier
  • 3,062
  • 9
  • 20
11
votes
1 answer

Coq: typeclasses vs dependent records

I can't understand the difference between typeclasses and dependent records in Coq. The reference manual gives the syntax of typeclasses, but says nothing about what they really are and how should you use them. A bit of thinking and searching…
Anton Fetisov
  • 273
  • 2
  • 8
11
votes
1 answer

Simple graph theory proofs using Coq

Is there a well established Coq graph library for proving simple theorems ? I would like to learn how to prove simple stuff like: "G1, G2 are isomorphic if and only if their complements are isomorphic". Are there related/similar examples or…
Vor
  • 365
  • 3
  • 17
11
votes
2 answers

Proving that a reversible list is a palindrome in Coq

Here is my inductive definition of palindromes: Inductive pal { X : Type } : list X -> Prop := | pal0 : pal [] | pal1 : forall ( x : X ), pal [x] | pal2 : forall ( x : X ) ( l : list X ), pal l -> pal ( x :: l ++ [x] ). And the theorem I want…
user287393
  • 1,221
  • 8
  • 13