将函数应用于 Coq 假设中的等式两边

csi*_*six 4 coq coq-tactic

我的问题与下面链接中提出的问题非常相似,但基于假设而不是目标。

在 Coq 中将函数应用于等式两边?

假设我有以下定义:

Definition make_couple (a:nat) (b:nat) := (a, b).
Run Code Online (Sandbox Code Playgroud)

并证明以下引理:

a, b : nat
H : (a, b) = make_couple a b
-------------------------------
(some goal to prove)
Run Code Online (Sandbox Code Playgroud)

我想提出以下假设:

new_H : fst (a, b) = fst (make_couple a b)
Run Code Online (Sandbox Code Playgroud)

一种方法是显式编写断言,然后使用 eapply f_equal :

assert (fst (a, b) = fst (make_couple a b)). eapply f_equal; eauto.
Run Code Online (Sandbox Code Playgroud)

但如果可能的话,我想避免显式地编写断言。我想要一些像这样工作的策略或等效策略:

apply_in_hypo fst H as new_H
Run Code Online (Sandbox Code Playgroud)

Coq 中有什么东西可以接近这个吗?

感谢您的回答。

Ant*_*nov 6

您可以使用f_equal引理来做到这一点。

About f_equal.
Run Code Online (Sandbox Code Playgroud)
f_equal : forall (A B : Type) (f : A -> B) (x y : A), x = y -> f x = f y

Arguments A, B, x, y are implicit
Argument scopes are [type_scope type_scope function_scope _ _ _]
f_equal is transparent
Expands to: Constant Coq.Init.Logic.f_equal
Run Code Online (Sandbox Code Playgroud)

以下是将其应用于假设的方法:

Goal forall a b : nat, (a, b) = (a, b) -> True.
  intros a b H.
  apply (f_equal fst) in H.
Run Code Online (Sandbox Code Playgroud)

可以使用intro-patterns以更简洁的方式重写上面的代码片段:

  Restart.
  intros a b H%(f_equal fst).
Abort.
Run Code Online (Sandbox Code Playgroud)