Questions tagged [coq-tactic]

Tactics are programs written in Ltac, the untyped language used in the Coq proof assistant to transform goals and terms. This tag should be used on questions related to the issues in using Coq tactics to derive proofs using the Coq proof assistant.

Tactics are programs written in Ltac, the untyped language used in the Coq proof assistant to transform goals and terms. In general, the aim of using tactics is to construct a proof or proof object for the theorem in question. Initially, the proof object contains a hole corresponding to the goal of the theorem in question. As the proof proceeds, tactics transform the current goal/sub-goal and hypotheses in the local proof context using established theorems in the global context as well as hypotheses in the local context. Some tactics can introduce new sub-goals corresponding to new holes in the proof object. For example, if the goal is a conjunction P /\ Q, can be decomposed into two sub-goals P and Q using the split tactic. Certain tactics can also reduce the number of sub-goals (or holes in the proof object). The theorem is proved when there is no more sub-goals to prove (i.e. no more holes to fill in the proof object).

Strictly speaking, tactics are not necessary to prove theorems in Coq. It is possible to construct a proof object directly. However, tactics provide an interactive way of constructing a proof, which are closer to the manner proofs are developed manually.

For a comprehensive documentation of tactics, see the Coq reference manual: https://coq.inria.fr/refman/tactic-index.html

383 questions
4
votes
1 answer

Passing patterns to tactics

I'm writing a tactic that looks for the value associated to a key in a list of bindings. Something like: Require Import String List Program. Ltac assoc needle haystack := match haystack with | @nil (_ * ?T) => constr:(@None T) | cons (?k, ?v)…
Clément
  • 12,299
  • 15
  • 75
  • 115
4
votes
2 answers

Using `apply with` without giving names of parameters in Coq?

In using the Coq apply ... with tactic, the examples I have seen all involve explicitly giving the names of variables to instantiate. For example, given a theorem about the transitivity of equality. Theorem trans_eq : forall (X:Type) (n m o : X), …
thor
  • 21,418
  • 31
  • 87
  • 173
3
votes
1 answer

Creating Coq tactic: how to use a newly generated name?

I want to create a Coq tactic that looks something like the following. I assert a proposition named H, I prove that proposition, and then I use simpl within that proposition. The tactic would look something like this: Tactic Notation "foo" := …
Sambo
  • 189
  • 7
3
votes
1 answer

What is the tactic that does nothing?

Sometimes it is useful to have a tactic which does nothing. I've tried to search "empty tactic" or "null tactic" but these do not give me the answer.
sdpoll
  • 426
  • 2
  • 12
3
votes
1 answer

How to prove `plus_le_compat_l : forall n m p, n <= m -> p + n <= p + m.`

another problem from SFv1 which got me stuck. The theorem is as follows: Theorem plus_le_compat_l : forall n m p, n <= m -> p + n <= p + m. I have tried several avenues so far, the one that got me the furthest was to introduce n and start…
Felipe Balbi
  • 147
  • 7
3
votes
1 answer

Coq/SSReflect: standard way to case on (x < y) + (x == y) + (y < x)?

In vanilla Coq, I'd write Require Import Coq.Arith.Arith. Goal nat -> nat -> False. intros n m. destruct (lt_eq_lt_dec n m) as [[?|?]|?]. to get three goals, one for n < m, one for n = m, and one for m < n. In ssreflect, I'd start with From…
Jason Gross
  • 5,928
  • 1
  • 26
  • 53
3
votes
2 answers

Don't understand `destruct` tactic on hypothesis `~ (exists x : X, ~ P x)` in Coq

I'm new to Coq and try to learn it through Software foundations. In the chapter "Logic in Coq", there is an exercise not_exists_dist which I completed (by guessing) but not understand: Theorem not_exists_dist : excluded_middle → ∀ (X:Type) (P :…
jayven
  • 770
  • 8
  • 19
3
votes
1 answer

Coq - How can you apply an implication with a match clause?

I am writing a proof of the correctness of quicksort. My program defines a partition type, which handles the recursive partitioning step of quicksort. Inductive partition : Type := | empty | join (left: partition) (pivot: nat) (right:…
3
votes
2 answers

How do define a custom induction principle in coq?

This is kind of a follow up on a previous question I asked, but now I'm just trying to implement my own induction principle for the equality type, which I'm not sure how to do without some kind of pattern matching. I'm avoiding using the induction…
user5775230
3
votes
1 answer

How do I simplify a hypothesis of the form True -> P in Coq?

If I have a hypothesis in my proof context that looks like H: True -> P and I want to convert it to H: P, what's the easiest way to do this? I tried simpl in H but it does nothing, and the only way I've found is the extremely unsatisfactory pose…
psquid
  • 747
  • 1
  • 5
  • 17
3
votes
1 answer

How to do induction on the end of a list in Coq

In the standart way I have induction for list like this Approval is performed for lst Proving for x::lst But I want: Approval is performed for lst Proving for lst ++ x::nil For me, the place of x in the list is important. I tried to write…
he11boy
  • 71
  • 3
3
votes
2 answers

Coq/SSReflect: How to do case analysis when reflecting && and /\

I have the following reflect predicate: Require Import mathcomp.ssreflect.all_ssreflect. Inductive reflect (P : Prop) (b : bool) : Prop := | ReflectT (p : P) (e : b = true) | ReflectF (np : ~ P) (e : b = false). And I am trying to relate the…
Atharva Shukla
  • 2,098
  • 8
  • 21
3
votes
1 answer

How to setup Coq as theorem prover for First Order Logic

As far as I understand, then Coq have built-in First Order Logic https://coq.inria.fr/tutorial/1-basic-predicate-calculus. But Coq is not theorem prover, Coq is proof assistant and that means that user is required to provide some hints what…
TomR
  • 2,696
  • 6
  • 34
  • 87
3
votes
1 answer

Stuck proving lemma with unprovable subgoals

I'm trying to prove a lemma that's based on the following definitions. Section lemma. Variable A : Type. Variable P : A -> Prop. Variable P_dec : forall x, {P x}+{~P x}. Inductive vector : nat -> Type := | Vnil : vector O | Vcons : forall…
yarwest
  • 873
  • 8
  • 19
3
votes
2 answers

Coq tactic to sort a list?

For a proof, I want to use the fact that for any list of integers, there exists a sorted version of that list. This seems obvious to me, but I couldn't find a tactic that does something like that. I tried to create my own (below), but I got stuck,…
Harry Qu
  • 45
  • 6