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
1
vote
2 answers

Coq: performing inversion on Prop for Set when there is only one case

Suppose I have some programming language, with a "has type" relation and a "small step" relation. Inductive type : Set := | Nat : type | Bool : type. Inductive tm : Set := | num : nat -> tm | plus : tm -> tm -> tm | lt : tm -> tm -> tm | ifthen :…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

How to make subst keep the prettiest name (minimum one in lexicographical order) in Coq?

The subst tactic is very useful in coq, it can remove useless variable names and make our context clear. But when we have a = a1 , a1 = a2 in our context, it often keeps a2 instead of a in the result, which makes our context ugly. Of course you can…
luochen1990
  • 3,689
  • 1
  • 22
  • 37
1
vote
0 answers

Automatically specializing hypotheses in Coq

In proofs, if I perform induction on an argument that is not final, I get universally-quanitified induction hypotheses. I find myself repeatedly writing tactics like this: match goal with | [H : forall (esub : expr) (x : exprvar) (tsub t :…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

Ltac: do something different in each goal

I've got a proof script where I'm exploring multiple cases, and it's currently quite slow, since I have a number of strategies for solving the goals, and I'm trying each one in each case. I know that I need to apply certain tactics in certain cases,…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

Ensuring two metavariables aren't unified to the same result

I'm trying to write a tactic which will automatically pick up inconsistencies in Setoid-based hypotheses. For instance, If I have the following hypotheses, H1 : x == y H2 : z == y H3 : x =/= z I would like to be able to solve this with some…
Langston
  • 1,083
  • 10
  • 26
1
vote
1 answer

Existential goals are filled in too soon

I have a Class containing both data and axioms. I want to build another instance in proof mode, based on (1) an existing instance and (2) some other input. I want to destruct this second input before creating the new instance of the record. The…
Langston
  • 1,083
  • 10
  • 26
1
vote
1 answer

Tactic to prove a boolean implication

Is there a tactic similar to intros to prove a boolean implication such as f : nat -> bool g : nat -> bool Lemma f_implies_g : forall n : nat, eq_true(implb (f n) (g n)). This tactic would pull eq_true(f n) into the context and require to prove…
V. Semeria
  • 3,128
  • 1
  • 10
  • 25
1
vote
1 answer

Coq: Defining Vernacular to avoid duplication

I'm currently working on proofs where I find myself writing code like this over and over again: Lemma eq_T: forall (x y : T), {x = y} + {x <> y} with eq_trait: forall (x y : trait), {x = y} + {x <> y} with eq_pi: forall (x y : pi), {x = y} + {x…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

Folding only applications

The fold tactic replaces all occurrence of a term with another, so fold (id f) tries to replace all occurrences of f with (id f). However, I want to only fold f if it occurs in the context (f [ ]), not if it occurs in the context ([ ] f). In…
Ifaz Kabir
  • 134
  • 8
1
vote
1 answer

How to use Cycle / Swap tactics?

Consider the proof code: Definition f (a: nat): nat. Proof. Admitted. Lemma rew: forall (a p : nat) (A: a + 1 = p), f a = f p. Proof. Admitted. Lemma userew: forall (a b: nat), f a = f b. Proof. intros. erewrite rew. cycle 1. (* Goal…
Siddharth Bhat
  • 823
  • 5
  • 15
1
vote
0 answers

Dealing with multiple integer libraries in Coq?

I often get proof terms of the form: Lemma of_nat_gt_0: forall (n: nat), (Z.of_nat n >=? Int32.unsigned (Int32.repr 0)) = true. The theorem is obviously true (Z of a natural will always be >= 0. Similarly, unsigned of a repr of a 0 will yield…
Siddharth Bhat
  • 823
  • 5
  • 15
1
vote
1 answer

Using destruct instead of inversion

I understand the principle of explosion proof using the inversion tactic: Theorem ex_falso_quodlibet : forall (P:Prop), False -> P. Proof. intros P contra. inversion contra. Qed. However, I don't understand the steps taken by Coq in order to…
Waiting for Dev...
  • 12,629
  • 5
  • 47
  • 57
1
vote
1 answer

Contradictory hypothesis using coq inversion tactic

From this example: Example foo : forall (X : Type) (x y z : X) (l j : list X), x :: y :: l = z :: j -> y :: l = x :: j -> x = y. It can be solved just doing inversion on the second hypothesis: Proof. intros X x y z l j eq1 eq2. inversion…
Waiting for Dev...
  • 12,629
  • 5
  • 47
  • 57
1
vote
1 answer

deriving facts on pattern matching in coq

Consider the following program Definition useGt0 (n: nat) (witness: n > 0) : nat := 10. Definition createGt0(n: nat) : nat := match n with | O => 42 | S(n') => useGt0 n (#???) end. Clearly, n > 0 is inhabited, because n = S n'.…
Siddharth Bhat
  • 823
  • 5
  • 15
1
vote
1 answer

The exact definition of an in built Tactic (case, destruct, inversion etc.) in Coq

How can one see the exact implementation of an in-built tactic in Coq ? More specifically is there an alternative to Print Ltac which works for locating the exact definition of in-built Tactics in Coq ?