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
6
votes
1 answer

Extracting Coq to Haskell while keeping comments

Is there anyway to keep comments while extracting Coq to Haskell? Ideally, I would like to have machine generated Haskell files untouched by humans, and so the motivation of extracting comments is clear. However, I couldn't find how to do it, and I…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
6
votes
2 answers

Extracting Coq to Haskell

I'm experimenting with Coq's extraction mechanism to Haskell. I wrote a naive predicate for prime numbers in Coq, here it is: (***********) (* IMPORTS *) (***********) Require Import Coq.Arith.PeanoNat. (************) (* helper''…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
6
votes
1 answer

"if" is not just sugar for "match"

What is the difference between these two definitions: Definition f : forall x:bool, if x then bool else nat := fun x => match x with | true => true | false => 42 end. (* ^ Accepted by Coq *) Definition g : forall…
Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56
6
votes
1 answer

What do ellipses mean in a Coq proof?

Here is a proof that appears in this online course https://softwarefoundations.cis.upenn.edu/plf-current/StlcProp.html#lab222. Proof with eauto. remember (@empty ty) as Gamma. intros t t' T HT. generalize dependent t'. induction HT; …
Mark
  • 5,286
  • 5
  • 42
  • 73
6
votes
1 answer

Injectivity of successor of natural numbers in Coq

I am a little confused whether the injectivity of the successor function defined on natural numbers in Coq is an axiom? According to Wikipedia/Peano axioms, it is an axiom (7). When I look at Coq.Init.Peano manual page I see the…
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
6
votes
1 answer

Why we cannot pattern match on Set/Type in Coq/Agda/Idris?

Think about a function which accepts a Set, and returns its byte length, named byteLength: byteLength : Set -> Maybe Nat and if I want to implement this function directly, I need to pattern match on the type argument: byteLength Char = Just…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
6
votes
1 answer

Is it possible to force induction tactic to produce more equations?

I'm playing with inductive propositions. I have the following inductive definition: Inductive subseq {X : Type} : list X -> list X -> Prop := | empty_subseq : subseq [ ] [ ] | subseq_left_elim : forall (l1 l2 : list X) (x : X), subseq…
Ilya Vlasov
  • 243
  • 1
  • 2
  • 8
6
votes
1 answer

Can you find function by type signature in Coq?

I'm looking for utility similar to one of Hoogle for Haskell. For the sake of example, let's say I need a function of signature forall n m:nat, n <> m -> m <> n. When my Google searches don't yield any results, I write Definition foo: forall n…
SzymonPajzert
  • 692
  • 8
  • 18
6
votes
1 answer

Implicit arguments in a computed type in Coq

I have a library to write indexed types without having to explicitly thread the index. This leads to cleaner top-level types by hiding away the irrelevant plumbing. It goes something like this: Section Indexed. Local Open Scope type. Context {I :…
gallais
  • 11,823
  • 2
  • 30
  • 63
6
votes
1 answer

Obtain decidable total order on a type from an injection into `nat`

Since the natural numbers support a decidable total order, the injection nat_of_ascii (a : ascii) : nat induces a decidable total order on the type ascii. What would be a concise, idiomatic way of expressing this in Coq? (With or without type…
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
6
votes
2 answers

Software Foundations - automatic grading

In order to learn Coq, I downloaded Benjamin Pierce's ebook Software Foundations from here, and extracted the contents. I am now starting to work through the exercises in Basics.v, by editing the file directly in Vim. I would like to automatically…
user82216
6
votes
2 answers

Coq: destruct (co)inductive hypothesis without losing information

Consider the following development: Require Import Relation RelationClasses. Set Implicit Arguments. CoInductive stream (A : Type) : Type := | scons : A -> stream A -> stream A. CoInductive stream_le (A : Type) {eqA R : relation A} …
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
6
votes
2 answers

Raising the failure level of a coq tactic

When implementing a complex tactic in Ltac, there are some Ltac commands or tactic invocation that I expect to fail and where that is expected (e.g. to terminate a repeat, or to cause backtracking). These failures are usually raised at failure level…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
6
votes
1 answer

Ltac : optional arguments tactic

I want to make a Ltac tactic in coq which would take either 1 or 3 arguments. I have read about ltac_No_arg in the LibTactics module but if I understood it correctly I would have to invoke my tactic with : Coq < mytactic arg_1 ltac_no_arg…
L. Soret
  • 169
  • 10
6
votes
3 answers

Idiomatic ways of selecting subterm to rewrite

Suppose we have a conclusion of form: a + b + c + d + e. We also have a lemma: plus_assoc : forall n m p : nat, n + (m + p) = n + m + p. What are idiomatic ways to arbitrarily "insert a pair of parentheses" into the term? That is, how can we easily…
AntlerM
  • 181
  • 6