考虑以下发展, Adam Chlipala 的simplHyp
一个孤立部分:
(** Fail if H is in context *)
Ltac notInCtx H := assert H; [ assumption | fail 1 ] || idtac.
Ltac injectionInCtx :=
match goal with
(* Is matching on G strictly necessary? *)
| [ H : ?F ?X = ?F ?Y |- ?G ] =>
(* fail early if it wouldn't progress *)
notInCtx (X = Y);
injection H;
match goal with
(* G is used here *)
| [ |- X = Y -> G ] =>
try clear H; intros; try subst
end
end.
Goal forall (x y : nat), S x = S y -> x = y.
intros x y H.
injectionInCtx.
exact eq_refl.
Qed.
查看内联注释 -G
一开始就匹配,最终用于验证最终目标是否保持不变。这是为了排除injection H
可能修改目标或添加无关假设的可能性吗?