Coq 注入策略能否修改最终目标,或添加无关的假设?

Coq 注入策略能否修改最终目标,或添加无关的假设?,coq,ltac,Coq,Ltac,考虑以下发展,这是一个独立的部分: 请参阅内联注释-G在开始时匹配,并最终用于验证最终目标是否保持不变。这是否排除了injection H可能修改目标或添加额外假设的可能性?我认为您不能修改G,但您可以创建一个假设,从中injection将生成多个等式 我们定义了injectionCtx2,它与injectionCtx相同,只是它不使用G Ltac injectionInCtx2 := match goal with | [ H : ?F ?X = ?F ?Y |- _ ] =>

考虑以下发展,这是一个独立的部分:


请参阅内联注释-
G
在开始时匹配,并最终用于验证最终目标是否保持不变。这是否排除了
injection H
可能修改目标或添加额外假设的可能性?

我认为您不能修改
G
,但您可以创建一个假设,从中
injection
将生成多个等式

我们定义了
injectionCtx2
,它与
injectionCtx
相同,只是它不使用
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.

injection
does:“该策略推导出所有子项在不同位置的相等性,并将它们作为当前目标结论的先行条件添加。”没错,我的措辞不正确,但我不知道如何做得更好。我的观点是,模式是否会失败?当然,所有Ln,consNl=cons0 nil->n=0的目标。简介l n H.注射H.撤销。失败注入CTX。中止。对于我测试过的Coq版本,最后一个示例在第一次匹配时失败,而不是在第二次匹配时失败。
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.