[英]Can the injection tactic modify the end goal, or add extraneous assumptions?
考慮以下開發,這是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
可能改變目標或添加無關緊要的假設的可能性?
我認為您不能修改G
,但是您可以提出一個假設,根據該假設, injection
將產生多個等式。
我們定義injectionInCtx2
,它與injectionInCtx
相同,只是它不使用G
Ltac injectionInCtx2 :=
match goal with
| [ H : ?F ?X = ?F ?Y |- _ ] =>
(* fail early if it wouldn't progress *)
notInCtx (X = Y);
injection H;
match goal with
| [ |- X = Y -> _ ] =>
try clear H; intros; try subst
end
end.
Definition make_pair {A} (n:A) := (n, n).
Goal forall (x y : nat), make_pair x = make_pair y -> x = y.
Proof.
intros x y H.
(* [injection H] gives [x = y -> x = y -> x = y] *)
Fail injectionInCtx.
injectionInCtx2.
reflexivity.
Qed.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.