Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] FMap with abstract data type

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] FMap with abstract data type


Chronological Thread 
  • From: Vadim Zaliva <vzaliva AT cmu.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] FMap with abstract data type
  • Date: Fri, 24 May 2019 15:30:29 -0700
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=vzaliva AT cmu.edu; spf=Pass smtp.mailfrom=vadim.zaliva AT west.cmu.edu; spf=None smtp.helo=postmaster AT mail-io1-f41.google.com
  • Ironport-phdr: 9a23:uroDgRYQM7alOkExqiz0S2b/LSx+4OfEezUN459isYplN5qZoMWybnLW6fgltlLVR4KTs6sC17OP9fm5BidYvt6oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vMRm6txjdutQUjIdtNqo8yAbCr2dVdehR2W5mP0+YkQzm5se38p5j8iBQtOwk+sVdT6j0fLk2QKJBAjg+PG87+MPktR/YTQuS/XQcSXkZkgBJAwfe8h73WIr6vzbguep83CmaOtD2TawxVD+/4apnVAPkhSEaPDM/7WrZiNF/jLhDrR2uqRxwwY7abo+WOvRjYK3SYcgXSnBdUstLTSFNHp+wYokJAuEcPehYtY79p14WoBSxHwajGeLvyjpVjXD1x6I61+UhER/c0wc9GN8OrnXVo8/xNKcTT+C61rLFwinGb/NLwzvy9pXHcg04rPyKQLl+f83RyUw1GAPEiFWdsYrlMC2b1+sXqWib8+tgVfm1hG4hsAF9uCSgxsApioXRg4Ia0EjE9T5lwIYyP9G4SVJ7bcaiEJRKsiGVKZJ6Td8lQ25ypCk6yqcKtoK8fCgPzpks2h3Ra+SffoSW/h7uUPydLDR4iX5/Zb6yhhe//VKvx+HhUMS/zUxEoTBfktbWs3AAzxzT5daDSvt65kqh3CyA1wHX6u1dIEA0krfXJ4cvwrM/i5Yfq0vDHijxmEX5iK+ZaF8o9fSv6+Tiernmp5mcOJFoigzmLKgihsiyDf47PwUORWSX5OWx2bz58UD2XblGlvg2nbPYsJDeK8QbvKm5AwpN34Y98RmwEjam0NECkXgGNl1FfBOHj5bzNFzVLvH3E+y/g0i2nDh3wvDGI6ftDYvQIXjeiLvhZ6py61ZAyAovytBS/45bCrYYIP7qRkDxsMHYAQQiPgyvw+fnDc192ZkEVWKOBK+ZKqLSvkWS6uIhOenfLLMS7T36Mr0u4+PkpX4/g14UO6ezjrUNb3XtIP1qIkDRU3Pog8kIWTMUrAM6TfLjoFaHTHhea2vkDPF03S0yFI/zVdSLfYuqmrHUhH7nTK0TXXhPDxW3KVmtb5+NCqUHbT/UL8N8wGRdCOqRDrQ53BTrjzfUjrpqKu2Op38dvJPnkdlyvqjdyUh0+jtzAMCQlWqKSjMsxzJad3oNxKl65HdF5BKG2Kl8jeZfEIUPtexESRt8PpvBieF2FoKrVw==

The problem is that `Map.Equiv` is defined via `MapsTo` which uses strict equality.

NM.Equiv =
fun (elt : Type) (eq_elt : elt -> elt -> Prop) (m m' : NM.t elt) =>
(forall k : NM.key, NM.In (elt:=elt) k m <-> NM.In (elt:=elt) k m') /\
(forall (k : NM.key) (e e' : elt), NM.MapsTo k e m -> NM.MapsTo k e' m' -> eq_elt e e')
     : forall elt : Type, (elt -> elt -> Prop) -> NM.t elt -> NM.t elt -> Prop

Vadim
--
Vadim Zaliva A button for name playback in email signature 
CMU ECE Ph.D. candidate
Mobile/Signal/WhatsApp: +1(510)220-1060




On Fri, May 24, 2019 at 3:15 PM Jasper Hugunin <jasperh AT cs.washington.edu> wrote:
I see. MapsTo is only up to strict equality of the values, while you need it to be up to Ae.

I'm don't think the standard library defines many lemmas about maps up to an equivalence relation on the values; in my experience they often aren't needed, as you can usually track the value equality conditions off to the side (but it is perhaps more proof burden). For example, instead of Map.MapsTo, you want the behavior of
MapsTo' k v m := exists v', Ae v v' * MapsTo k v' m
saying that m maps k to some v' which is the same up to Ae as v.
Map.Equiv Ae is then the right notion of equivalence, and you can then prove MapsTo'_A_proper making use of the Ae x y hypothesis.

- Jasper Hugunin

On Fri, May 24, 2019 at 2:24 PM Vadim Zaliva <vzaliva AT cmu.edu> wrote:
Jasper,

This is where I started, but using `Ae` as a equality for values it is impossible to prove the following:

Instance MapsTo_A_proper: Proper ((eq) ==> (Map.Equiv Ae) ==> (Ae) ==> iff) (NM.MapsTo).

It boils down to:

Ae x y →
Map.Equiv Ae m0 m1 →
Map.MapsTo k x m0 ↔ Map.MapsTo k y m1

(unless I am missing something)

Vadim

--
Vadim Zaliva A button for name playback in email signature 
CMU ECE Ph.D. candidate
Mobile/Signal/WhatsApp: +1(510)220-1060




On Fri, May 24, 2019 at 2:06 PM Jasper Hugunin <jasperh AT cs.washington.edu> wrote:
You can use

From Coq Require OrderedTypeEx FMapAVL FMapFacts.
Module Map := FMapAVL.Make OrderedTypeEx.Nat_as_OT.
Check Map.t : Type -> Type. (* The values can be anything you like *)
Check Map.Equiv : forall X, (X -> X -> Prop) -> (Map.t X -> Map.t X -> Prop).

(* You get a relation Map.Equiv for any relation between elements. Proving it is a congruence relation shouldn't be hard, but I'm not sure is in the standard library. *)
(* If the equality on values is Init.Logic.eq, i.e. a1 = a2, then you can instead use Map.Equal, which does have Proper instances proven in MapProperties. *)

Module MapProperties := FMapFacts.Properties Map.
(* Also MapProperties.F has useful stuff. *)

(* This can be used as *)
Axiom A : Type.
Check Map.t A. (* This is the type of maps with keys in nat and values in A. *)

- Jasper Hugunin

On Fri, May 24, 2019 at 11:51 AM Vadim Zaliva <vzaliva AT cmu.edu> wrote:

I am trying to figure out how to use FMap with abstract data type and
equality. I need a map where the keys are natural numbers, but values belong to an abstract type A. I can assume that this type has an equality Ae which is decidable, and a strict ordering.

I will need to have an Equiv relation between two maps (backed up by
Ae for elements). Finally, I would like to be able to prove Proper
instances for basic operations, like:

Instance MapsTo_A_proper:
  Proper ((eq) ==> (equiv) ==> (equiv) ==> iff) (NM.MapsTo).

Instance find_A_proper:
  Proper ((eq) ==> (equiv) ==> (equiv)) (NM.find (elt:=A)).

It looks like the map needs to be abstracted over A using a module.
This post http://www.newartisans.com/2016/10/using-fmap-in-coq/ gives
some good intro but stop shorts from abstracting values. It also looks
like I will need to use Sord functor from FMapInterface. I feel
like all pieces are there but having difficulty putting it all
together. I have not been able to find any relevant examples. Could
somebody please point me in the right direction? Thanks!



Vadim Zaliva A button for name playback in email signature
CMU ECE Ph.D. candidate
Mobile/Signal/WhatsApp: +1(510)220-1060




Archive powered by MHonArc 2.6.18.

Top of Page