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

发布于 2025-01-21 12:15:40 字数 1980 浏览 3 评论 0原文

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

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) and 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

I'm able to use rewrite under bindings with one parameter

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.

But I'm not able to go through a bit more involved case, namely when wrap : nat -> (nat -> nat -> nat) and 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.

A question mainly is: what should I use as a relation?
I'm not sure what namely i'm doing wrong here. Do I use wrong relation or do I try to pass wrong argument to setoid_rewrite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2025-01-28 12:15:40

您可以将“点角关系的重点关系”用作二进制函数的关系:

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.

You can use the "pointwise relation of a pointwise relation" as a relation on binary functions:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文