分解构造函数的相等性 coq
Decomposing equality of constructors coq
我经常在 Coq 中发现自己在做以下事情:我有证明目标,例如:
some_constructor a c d = some_constructor b c d
而且我真的只需要证明 a = b
因为其他一切都是相同的,所以我这样做:
assert (a = b).
然后证明子目标,然后
rewrite H.
reflexivity.
完成证明。
但在我的证明底部闲逛似乎只是不必要的混乱。
Coq 中是否有一个通用策略,用于获取构造函数的相等性并将其拆分为构造函数参数的相等性,有点像 split
但用于相等性而不是连词。
您可以使用 Coq 的搜索功能:
Search (?X _ = ?X _).
Search (_ _ = _ _).
在一些噪音中它揭示了一个引理
f_equal: forall (A B : Type) (f : A -> B) (x y : A), x = y -> f x = f y
及其用于多参数等式的兄弟姐妹:f_equal2
... f_equal5
(截至 Coq 8.4 版)。
这是一个例子:
Inductive silly : Set :=
| some_constructor : nat -> nat -> nat -> silly
| another_constructor : nat -> nat -> silly.
Goal forall x y,
x = 42 ->
y = 6 * 7 ->
some_constructor x 0 1 = some_constructor y 0 1.
intros x y Hx Hy.
apply f_equal3; try reflexivity.
此时你只需要证明x = y
.
特别是,标准 Coq 提供了 f_equal
策略。
Inductive u : Type := U : nat -> nat -> nat -> u.
Lemma U1 x y z1 z2 : U x y z1 = U x y z2.
f_equal
另外,ssreflect 提供了通用的同余策略congr
。
我经常在 Coq 中发现自己在做以下事情:我有证明目标,例如:
some_constructor a c d = some_constructor b c d
而且我真的只需要证明 a = b
因为其他一切都是相同的,所以我这样做:
assert (a = b).
然后证明子目标,然后
rewrite H.
reflexivity.
完成证明。
但在我的证明底部闲逛似乎只是不必要的混乱。
Coq 中是否有一个通用策略,用于获取构造函数的相等性并将其拆分为构造函数参数的相等性,有点像 split
但用于相等性而不是连词。
您可以使用 Coq 的搜索功能:
Search (?X _ = ?X _).
Search (_ _ = _ _).
在一些噪音中它揭示了一个引理
f_equal: forall (A B : Type) (f : A -> B) (x y : A), x = y -> f x = f y
及其用于多参数等式的兄弟姐妹:f_equal2
... f_equal5
(截至 Coq 8.4 版)。
这是一个例子:
Inductive silly : Set :=
| some_constructor : nat -> nat -> nat -> silly
| another_constructor : nat -> nat -> silly.
Goal forall x y,
x = 42 ->
y = 6 * 7 ->
some_constructor x 0 1 = some_constructor y 0 1.
intros x y Hx Hy.
apply f_equal3; try reflexivity.
此时你只需要证明x = y
.
特别是,标准 Coq 提供了 f_equal
策略。
Inductive u : Type := U : nat -> nat -> nat -> u.
Lemma U1 x y z1 z2 : U x y z1 = U x y z2.
f_equal
另外,ssreflect 提供了通用的同余策略congr
。