Say I have the following definitions in Coq:
Inductive Compare := Lt | Eq | Gt.
Fixpoint compare (x y : nat) : Compare :=
match x, y with
| 0, 0 => Eq
| 0, S _ => Lt
| S _, 0 => Gt
| S x', S y' => compare x' y'
end.
Now consider this lemma:
Lemma foo : forall (x: nat),
(forall z, match compare x z with
| Lt => False
| Eq => False
| Gt => False
end) -> nat -> False.
Proof.
intros x H y.
At this point proof state looks like this:
x : nat
H : forall z : nat,
match compare x z with
| Lt => False
| Eq => False
| Gt => False
end
y : nat
============================
False
I'd like to write Ltac match goal
that will detect that:
a) there is a hypothesis x : nat
that is used as an argument to compare
somewhere inside a quantified hypothesis H
b) and there is some other hypothesis of type nat
- namely y
- that can be used to specialize the quantified hypothesis.
c) and once we have those two things specialize H
to y
I tried doing it like this:
match goal with
| [ X : nat, Y : nat
, H : forall (z : nat), context [ compare X z ] |- _ ] => specialize (H Y)
end.
But there are at least two things that are wrong with this code:
Using
context
under aforall
seems disallowed.I can't figure out a correct way to pass
X
as argument tocompare
in a way that it is recognized as something that exists as a hypothesis.doing it like this: