coq-club AT inria.fr
Subject: The Coq mailing list
List archive
Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?
Chronological Thread
- From: Arnaud Spiwack <aspiwack AT lix.polytechnique.fr>
- To: Coq Club <coq-club AT inria.fr>
- Cc: "Soegtrop, Michael" <michael.soegtrop AT intel.com>
- Subject: Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?
- Date: Thu, 2 Jun 2016 19:44:07 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=arnaud.spiwack AT gmail.com; spf=Pass smtp.mailfrom=arnaud.spiwack AT gmail.com; spf=None smtp.helo=postmaster AT mail-vk0-f47.google.com
- Ironport-phdr: 9a23:SPclXBUhasd5Vs9YBsD2PtZiRPfV8LGtZVwlr6E/grcLSJyIuqrYZhyFt8tkgFKBZ4jH8fUM07OQ6PCxHzFRqs/Z4TgrS99laVwssY0uhQsuAcqIWwXQDcXBSGgEJvlET0Jv5HqhMEJYS47UblzWpWCuv3ZJQk2sfTR8Kum9IIPOlcP/j7n0oM2CJVgZz2PlMPtbF1afk0b4joEum4xsK6I8mFPig0BjXKBo/15uPk+ZhB3m5829r9ZJ+iVUvO89pYYbCf2pN4xxd7FTDSwnPmYp/4Wr8ECbFUrcrkcbB04Ri1JjBxXPpEXxWY60uS/nvMJ83jObNIv4V+Zndy6l6vJCUhnhlStPDCY472jciYQkhblDoQ2orB9Xx4/EJpmSMOtic6jde9IDWGcHUNwHBH8JOZ+1c4ZaV7lJBu1ftYSo4gJW9RY=
When facing this sort of problems, unless you have a single instance and a quick-and-dirty method will suffice. It is often worth it using a combinator which encapsulates the logics (here applying = true
to the body of a boolean relation) and on which you can prove properties.
Below a more verbose proof than the above responses, with reusable components:
Require Import Coq.Classes.RelationClasses.
Require Import Coq.Classes.Morphisms.
Require Import Coq.Arith.Arith.
(* Generic lemma, probably has a place in the standard library *)
Instance equivalence_extensional A
: Proper (@relation_equivalence A ==> Basics.impl) Equivalence.
Proof.
intros r s eq__rs [r__r s__r t__r]. cbn in eq__rs.
split.
all: hnf in *; intros **.
all: rewrite <- eq__rs in *; eauto.
Qed.
Definition BRel {A} (r:A->A->bool) : A -> A -> Prop :=
fun x y => r x y = true.
Lemma brel_nat_eqb_eq : relation_equivalence (BRel Nat.eqb) eq.
Proof.
exact Nat.eqb_eq.
Qed.
Instance nat_eqb_equivalence : Equivalence (BRel Nat.eqb).
Proof.
rewrite brel_nat_eqb_eq.
typeclasses eauto.
Qed.
On 2 June 2016 at 19:16, Tej Chajed <tchajed AT mit.edu> wrote:
You can also prove it directly fairly easily, still relying on Nat.eqb_eq. I think this is quite similar in spirit to Emilio's ssreflect proof.Lemma eqb_equiv : Equivalence (fun m n => Nat.eqb m n = true).Proof.constructor; repeat intro;rewrite Nat.eqb_eq in *;congruence.Qed.On Thu, Jun 2, 2016 at 1:03 PM, Emilio Jesús Gallego Arias <e+coq-club AT x80.org> wrote:Dear Michael,
"Soegtrop, Michael" <michael.soegtrop AT intel.com> writes:
> Require Export Relations Morphisms Setoid Equalities.
> Require Import Arith.
> Lemma eqb_equiv : Equivalence (fun m n => Nat.eqb m n = true).
> Proof.
> setoid_rewrite Nat.eqb_eq.
I am not sure what you intend to prove, but here's a different proof
your result (using ssreflect's == equality instead of Nat.eqb).
From mathcomp
Require Import ssreflect ssrbool ssrnat eqtype ssrfun seq.
Require Export Relations Morphisms Setoid Equalities.
Lemma eqb_equiv : Equivalence (fun m n : nat => m == n).
Proof.
constructor.
- exact: eqxx.
- by move=> x y; rewrite eq_sym.
- by move=> x y z /eqP->.
Qed.
Best,
Emilio
- [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Emilio Jesús Gallego Arias, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Tej Chajed, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Arnaud Spiwack, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Arnaud Spiwack, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Abhishek Anand, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/03/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Abhishek Anand, 06/03/2016
- [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/03/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Abhishek Anand, 06/03/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Abhishek Anand, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Tej Chajed, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Jonathan Leivent, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Emilio Jesús Gallego Arias, 06/02/2016
- RE: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Soegtrop, Michael, 06/02/2016
- Re: [Coq-Club] Elegant way to show Equivalence (fun m n => Nat.eqb m n = true) from standard library lemmas?, Emilio Jesús Gallego Arias, 06/02/2016
Archive powered by MHonArc 2.6.18.