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
7
votes
3 answers

Dependent types: Vector of vectors

I'm new to dependent types (I'm trying both Idris and Coq, despite their big differences). I'm trying to express the following type: given a type T and a sequence of k nats n1, n2, ... nk, a type consisting of k sequences of T with length n1, n2,…
lodo
  • 2,314
  • 19
  • 31
7
votes
1 answer

Example uses of MSets in Coq

MSets appear to be the way to go for OCaml-style finite sets. Sadly, I can't find example uses. How can I define an empty MSet or a singleton MSet? How can I union two MSets together?
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
7
votes
2 answers

Coq: why do I need to manually unfold a value even though it has a `Hint Unfold` on it?

I've come up with the following toy proof script: Inductive myType : Type := | c : unit -> myType. Inductive myProp : myType -> Type := | d : forall t, myProp (c t). Hint Constructors myProp. Definition myValue : myType := c tt. Hint Unfold…
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
7
votes
1 answer

Idiomatically expressing "The Following Are Equivalent" in Coq

Exercise 6.7 in Coq'Art, or the final exercise of the Logic chapter in Software Foundations: show that the following are equivalent. Definition peirce := forall P Q:Prop, ((P->Q)->P)->P. Definition classic := forall P:Prop, ~~P -> P. Definition…
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
7
votes
1 answer

Coq rewriting using lambda arguments

We have a function that inserts an element into a specific index of a list. Fixpoint inject_into {A} (x : A) (l : list A) (n : nat) : option (list A) := match n, l with | 0, _ => Some (x :: l) | S k, [] => None | S k, h :: t…
ScarletAmaranth
  • 5,065
  • 2
  • 23
  • 34
7
votes
2 answers

How does the discriminate tactic work?

I was curious about how the discriminate tactic works behind the curtain. Therefore I did some experiments. First a simple Inductive definition: Inductive AB:=A|B. Then a simple lemma which can be proved by the discriminate tactic: Lemma l1: A=B ->…
Cryptostasis
  • 1,166
  • 6
  • 15
7
votes
1 answer

How can I read Coq's definition of proj1_sig?

In Coq, sig is defined as Inductive sig (A:Type) (P:A -> Prop) : Type := exist : forall x:A, P x -> sig P. Which I read as "A sig P is a type, where P is a function taking an A and returning a Prop. The type is defined such that an element x…
Dr. John A Zoidberg
  • 1,168
  • 2
  • 14
  • 25
7
votes
1 answer

The reference "X" was not found in the current environment

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…
RaptorDotCpp
  • 1,425
  • 14
  • 26
7
votes
1 answer

What is the downside of using functional extensionality in COQ

Adding Axioms to COQ often makes proofs easier but also introduces some side effects. For instance, by using the classical axiom one leaves the intuitionistic realm and proofs are no longer computable. My question is, what is the downside of using…
Cryptostasis
  • 1,166
  • 6
  • 15
7
votes
3 answers

Counting number of different elements in a list in Coq

I'm trying to write a function that takes a list of natural numbers and returns as output the amount of different elements in it. For example, if I have the list [1,2,2,4,1], my function DifElem should output "3". I've tried many things, the closest…
Sara
  • 339
  • 1
  • 8
7
votes
2 answers

How to import the Library: Coq.Arith.PeanoNat in Coq?

I need to use the part of the standard library called Coq.Arith.PeanoNat (https://coq.inria.fr/library/Coq.Arith.PeanoNat.html). I've tried either importing the entire Arith library or just this module, but I can't use it either way. Every other…
Sara
  • 339
  • 1
  • 8
7
votes
2 answers

How is "less than" defined for real numbers in Coq?

I am just wondering how is the "less than" relationship defined for real numbers. I understand that for natural numbers (nat), < can be defined recursively in terms of one number being the (1+) successor S of another number. I heard that many things…
thor
  • 21,418
  • 31
  • 87
  • 173
7
votes
2 answers

How to use a custom induction principle in Coq?

I read that the induction principle for a type is just a theorem about a proposition P. So I constructed an induction principle for List based on the right (or reverse) list constructor . Definition rcons {X:Type} (l:list X) (x:X) : list X := l…
thor
  • 21,418
  • 31
  • 87
  • 173
7
votes
1 answer

Coq can't see that two types are the same

I am trying to define the rev function on a vector, the size of it is embedded in it and I can't figure out how to define the rev function on it. Here is my type definition: Inductive vect {X : Type} : nat -> Type -> Type := Nil : vect 0 X |…
永劫回帰
  • 652
  • 10
  • 21
7
votes
1 answer

How to instantiate a variable of forall in a hypothesis in Coq?

I have two hypotheses IHl: forall (lr : list nat) (d x : nat), d = x \/ In x l' -> (something else) Head : d = x I want to apply IHl on Head as it satisfies d = x \/ In x l of IHl. I tried apply with tactic which fails with a simple hint Error:…
xywang
  • 941
  • 8
  • 24