问题是,如果我知道forall x, f x ≡ g x
(其中≡
是一些等价关系,而f
,g
是函数),什么是正确的{ {1}}实例,它可以让我用一个由等价关系链接的较大术语用Proper
重写f
吗?
假设需要,可以使用功能扩展性-我猜这是必需的吗?
一些示例代码可以更好地演示该问题:
g
如果我们可以将Require Import Setoid.
(** Feel free to assume FunExt *)
Require Import FunctionalExtensionality.
Section FOOBAR.
Variable T: Type.
Variable f: T -> T.
Variable g: T -> T.
Variable t0: T.
Variable combiner: (T -> T) -> T -> T.
Variable equiv: T -> T -> Prop.
Infix "≡" := equiv (at level 50).
Axiom equivalence_equiv: Equivalence equiv.
Axiom F_EQUIV_G_EXT: forall (t: T), f t ≡ g t.
(** Check that coq can resolve the Equivalence instance **)
Theorem equivalence_works: t0 ≡ t0.
Proof.
reflexivity.
Qed.
Theorem rewrite_in_lambda:
combiner (fun t => f t) t0 ≡
combiner (fun t => g t) t0.
Proof.
intros.
(* I wish to replace x with y.
What are the Proper rules I need for this to happen? *)
rewrite F_EQUIV_G_EXT.
Abort.
End FOOBAR.
替换为f
,就证明了这一点,但是我不确定该怎么做。我的等效关系需要什么附加能量才能成功?
答案 0 :(得分:3)
解决方案是使用来自coq stdlib的pointwise_relation
:Link here
我还复制粘贴了定义,以防链接bitrots:
Definition pointwise_relation (R : relation B) : relation (A -> B) :=
fun f g => forall a, R (f a) (g a).
因此,我们希望表单具有适当的实例:
Axiom proper: Proper (pointwise_relation T equiv ==> equiv ==> equiv) combiner.
也就是说,如果第一个函数是逐点相等的,而第二个参数是相等的,那么结果是相等的。
以下是编译的完整代码清单:
Require Import Setoid.
Require Import Relation_Definitions.
Require Import Morphisms.
(** Feel free to assume FunExt *)
Require Import FunctionalExtensionality.
Section FOOBAR.
Variable T: Type.
Variable x: T -> T.
Variable y: T -> T.
Variable t0: T.
Variable combiner: (T -> T) -> T -> T.
Variable equiv: T -> T -> Prop.
Infix "≡" := equiv (at level 50).
Axiom equivalence_equiv: Equivalence equiv.
Axiom proper: Proper (pointwise_relation T equiv ==> equiv ==> equiv) combiner.
Axiom X_EQUIV_Y_EXT: forall (t: T), x t ≡ y t.
(** Check that coq can resolve the Equivalence instance **)
Theorem equivalence_works: t0 ≡ t0.
Proof.
reflexivity.
Qed.
Theorem rewrite_in_lambda:
combiner (fun t => x t) t0 ≡
combiner (fun t => y t) t0.
Proof.
intros.
(* I wish to replace x with y.
What are the Proper rules I need for this to happen? *)
setoid_rewrite X_EQUIV_Y_EXT.
reflexivity.
Qed.
End FOOBAR.