setoid_rewrite: 在绑定下用 2 个参数重写

setoid_rewrite: rewrite under bindings with 2 parameters

我可以使用一个参数绑定下的重写

Require Import Setoid.
Require Import Relation_Definitions.
Require Import FunctionalExtensionality.

Parameters f f' : nat -> nat.
Parameter wrap : nat -> (nat -> nat) -> nat.
Axiom ff'_eq : forall x, f x = f' x.

Add Parametric Morphism :
  wrap
    with signature (Logic.eq ==> pointwise_relation nat Logic.eq ==> Logic.eq) 
  as wrap_mor.
Proof.
  cbv. intros x f f' H.
  apply functional_extensionality in H.
  rewrite H.
  reflexivity.
Qed.

Lemma test_lemma y :
  wrap y (fun x => f x) = wrap y (fun x => f' x).
  setoid_rewrite ff'_eq.
  reflexivity.
Qed.

但我无法完成更复杂的案例,即 wrap : nat -> (nat -> nat -> nat)f f' : nat -> nat -> nat -> nat

Require Import Setoid.
Require Import Relation_Definitions.
Require Import FunctionalExtensionality.

Parameter f f' : nat -> nat -> nat -> nat.
Parameter wrap : nat -> (nat -> nat -> nat) -> nat.
(* Axiom ff'_eq : forall x y z, f x y z = f' x y z. *)
Axiom ff''_eq : forall z, (forall x y, f x y z = f' x y z).

Definition pointwise_relation2 :
    forall (A1 A2 : Type) {B : Type}, relation B -> relation (A1 -> A2 -> B) := 
    let U := Type in
    fun (A1 A2 B : U) (R : relation B) (f g : A1 -> A2 -> B) =>
        forall (a1 : A1) (a2 : A2), R (f a1 a2) (g a1 a2).

Axiom test1 : forall (x : nat) (f g : nat -> nat -> nat),
    pointwise_relation2 nat nat Logic.eq f g -> wrap x f = wrap x g.

Add Parametric Morphism :
    wrap with signature 
    (Logic.eq ==> pointwise_relation2 nat nat Logic.eq ==> Logic.eq) 
    as wrap_mor.
Proof. exact test1. Qed.

Lemma test_lemma2 y z:
    wrap y (fun x1 x2 => f x1 x2 z) = wrap y (fun x1 x2 => f' x1 x2 z).
    specialize (ff''_eq z) as feq.
    Fail setoid_rewrite feq.

一个问题主要是:我应该用什么作为关系? 我不确定我在这里做错了什么。我是使用了错误的关系还是尝试将错误的参数传递给 setoid_rewrite?

您可以使用“逐点关系的逐点关系”作为二元函数的关系:

Require Import Setoid Morphisms.

Parameter f f' : nat -> nat -> nat -> nat.
Parameter wrap : nat -> (nat -> nat -> nat) -> nat.
(* Axiom ff'_eq : forall x y z, f x y z = f' x y z. *)
Axiom ff''_eq : forall z, (forall x y, f x y z = f' x y z).

(* The "Add Parametric Morphism" command expands to this instance, which is simpler to write... *)
Axiom test1 : Proper (eq ==> pointwise_relation nat (pointwise_relation nat eq) ==> eq) wrap.
Existing Instance test1.

Lemma test_lemma2 y z:
    wrap y (fun x1 x2 => f x1 x2 z) = wrap y (fun x1 x2 => f' x1 x2 z).
Proof.
    specialize (ff''_eq z) as feq.
    setoid_rewrite feq.