Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Rewriting inside map expressions to manipulate finite/indexed sum expessions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Rewriting inside map expressions to manipulate finite/indexed sum expessions


Chronological Thread 
  • From: Kyle Stemen <bluelightning32 AT gmail.com>
  • To: "coq-club-at-inria.fr |coq-club/Example Allow|" <tbnhbei0kt AT sneakemail.com>
  • Cc: coq-club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Rewriting inside map expressions to manipulate finite/indexed sum expessions
  • Date: Wed, 8 Jul 2020 17:33:54 -0700
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=bluelightning32 AT gmail.com; spf=Pass smtp.mailfrom=bluelightning32 AT gmail.com; spf=None smtp.helo=postmaster AT mail-qk1-f182.google.com
  • Ironport-phdr: 9a23:2VZGqhbTA4GnlAQmwB6Ux8j/LSx+4OfEezUN459isYplN5qZrsW6bnLW6fgltlLVR4KTs6sC17OI9fmwEjdeqdbZ6TZeKcEKD0dEwewt3CUYSPafDkP6KPO4JwcbJ+9lEGFfwnegLEJOE9z/bVCB6le77DoVBwmtfVEtfre9FYHdldm42P6v8JPPfQpImCC9YbRvJxmqsAndrMYbjZZjJ6or1xfEoXREdupXyGh1IV6fgwvw6t2/8ZJ+8ylcoe4t+9JFXa7nY6k2ULtUASg8PWso/sPrrx7DTQWO5nsYTGoblwdDDhbG4h/nQJr/qzP2ueVh1iaUO832Vq00Vi+576h3Uh/oiTwIOCA//WrKl8F/lqNboBampxxi347ZZZyeOfRicq/Be94RWGxMVdtTWSNcGIOxd4QAD+QDMuhYoYfzpEYAowWiCgS3Huzj1iVFi2Xq0aEm0eksFxzN0gw6H9IJtXTZtND7NacWUe+r0aLG0CnDYO1T2Tjj7ojDbxcsruqIXbJtb8XRzUgvFwzFjlWMr4zlPjWV1usDvmSF9OdgWuevhHQmqwF1uDSg2sAsiozQi48T11vL+jl3zpwvKt2kVE50f8SkEJ1IuiyENYZ7QswsTnx0tCskyrMLupy2cSgXxJonxBPRa/2Kf5aK7x/9UOufISt1iW5rdr6imxu/7Ueux+n8WMS6zVtHqDdOnNfLtnAIzRPT686HR+Nn8Ueu3zaP1hvT6uFDIUAxjKbUMYIhzqcsmZoWsETPBDX5l1nsgK+XcEUo4umo6+L9YrXnvJCQLYF0ihv4P68zmcK/Gfw1PhYSU2Wf4+ix173u8VfnTLlUkPE6iLTVvZPEKckdu6W3GRVa0pw55Ba6Fzqm0MoXnX0ALF9dfRKIlYnpO1XXLPDhDveznk2gkDl2y/3FILHtGJrNLn/EkLfuebZy9VRQxxY0zdBa/55UC7cBL+zvWkLpqtDUEhs0Pxa3zuvnEtlxyJ0SVXyVDqOEM67er0eE5uc1LOmNYI8Vtiz9K/8g5/P2lnA5nUIdcret3ZsWZ3C4HuhmI0OYYXrqjdcMH3kGsxExTOzvklKCUDpTa2yuUKI74zE3EJimApvbRoCxnLyB2z+2EYFRZmBfE1yDDXPod5ifVPoXcyKTIsphkiQeWrS7So8h0wuutA7gxLZ9IOrU4H5QiZW2ntNy/qjYkQw4sDVoSsWbyWCECW9u1ncDQCZz16RiqwtQ2l6Gyax1y9VcEdtM87kBBhswM57Wwu0iCMzaQQTMd9SETV+nRpOtBjRnHfwrxNpbQFd5Fp2Zkh3G0iziV7URirGPBZM07qTd2Xeqfe5yzn/H0O8qiFxwEZgHDnGvmqMqr1ubPIXOiUjMz//7J5RZ5zbE8SK49UTLuUhZVABqVqCcBCIQY0LXqZLy4UaQFubzW4RiCRNIzIu5EoUPatDtig8YFvLqOdCbemHo3mnpVUzOybSLY47nPW4a2XeFURRWo0Uo5X+DcDMGKGK5uWuHVW5hEFvuZwXn9uws8H4=

I use the setoid_rewrite tactic to do rewrites under the map function. To enable it, you have to show that map is a pointwise_relation,

Require Import Coq.Classes.Morphisms.
Require Import Coq.Setoids.Setoid.
Require Import List.
Import ListNotations.

Instance map_ext_inst {T U: Type} :
  Proper (pointwise_relation T eq ==> eq ==> eq) (@map T U).
Proof.
  intros f g Hf_g l1 l2 Hl1_l2.
  rewrite Hl1_l2.
  apply map_ext.
  assumption.
Qed.

Note that you may have to explicitly specify all of the parameters to get the setoid_rewrite to work. That's why the example below has (fun n => f n) instead of (f).

Example map_ext_rewrite_test : forall (f g: nat -> nat) l,
  (forall a, f a = g a) ->
  map (fun n => f n) l = map (fun n => g n) l.
Proof.
  intros f g l Heq.
  setoid_rewrite Heq.
  reflexivity.
Qed.



On Wed, Jul 8, 2020 at 4:57 PM Agnishom Chattopadhyay agnishom-at-cmi.ac.in |coq-club/Example Allow| <x0mk80tcezojwqt AT sneakemail.com> wrote:
Thanks for pointing out this feature of => i. I will look into the documentation and try to understand how it works.

On Wed, Jul 8, 2020 at 6:49 PM Laurent Thery <Laurent.Thery AT inria.fr> wrote:

Hi,

I am not sure I follow everything but it seems that in your particular
example you could use Nat.min_0_r.

More generally if you look at the documentation of under you can
handle binders :

https://coq.inria.fr/distrib/current/refman/proof-engine/ssreflect-proof-language.html

For example, interactively this gives:

From mathcomp Require Import ssreflect.
Require Import List PeanoNat.

Goal forall l, (map (fun i => i + 1) l) = l.
Proof.
move=> l.
under map_ext => i.
  replace (i + 1) with (1 + i); last first.
    by rewrite Nat.add_comm.
  over.

Hope this helps

--
Laurent



Archive powered by MHonArc 2.6.19+.

Top of Page