coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Ben Sherman <sherman AT csail.mit.edu>
- To: coq-club AT inria.fr
- Cc: Klaus Ostermann <klaus.ostermann AT uni-tuebingen.de>
- Subject: Re: [Coq-Club] How to represent tabular data in Coq
- Date: Wed, 17 May 2017 08:45:31 -0400
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=sherman AT csail.mit.edu; spf=Pass smtp.mailfrom=sherman AT csail.mit.edu; spf=None smtp.helo=postmaster AT outgoing-stata.csail.mit.edu
- Ironport-phdr: 9a23:9Qn8aRB11fdJR8vzJhYyUyQJP3N1i/DPJgcQr6AfoPdwSPv8p8bcNUDSrc9gkEXOFd2CrakV16yO6+jJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fdbghMizexe69+IAmrpgjNq8cahpdvJLwswRXTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Qiqp4bt1RxD0iScHLz85/3/Risxsl6JQvRatqwViz4LIfI2ZMfxzdb7fc9wHX2pMRtpeWCNcDI28bYQBAekPPehGoYf6vFYBtweyBQy2CePv1jNEmHn71rA63eQ7FgHG2RQtEs8Qv3TSsd77KacSXv6vzKnN1zrDae5d1DDm6IjIbB8hu/SMUqh2ccfK1UYvDBnKjlSUqYD/OjOV1/gNv3KF4OV9SOKikmgqoBxyrDi33sogl5fFi4EPxl3K6Sl12pg5KcemREJmfdKoCIZcuiKAO4drQc4vR3tktSI6x7EcupO2fi4Hw4k9yRHFcfyIaY2I7wrjVOmPJTd4g2poeLWihxau/kigzez8Vs+70FpTtSpFjsPDtmwX2BDJ9seHUeFy/kal2TqV0gDT6/1ELVoqmqXGNp4t2r8wlpwNvkTfBiL6hVv6gayMekgq5uSk8frrbq/4qpOBK4N4kgT+Pb4vmsy7D+Q4KA8OX22D9OSn1L3s41f5QLBQgf0wiaTWrIvaKt4apq69GQNV14cj6wqlAzi4zdsYgGELLEhZdxKfk4jpJ1bOLejkAve4mlSgiStkx/TbPrL6GZjNNXjCkLL5fbln8UJcyQwzzcpe551OEL0BLujzCQfNs4nTCQZ8OAipyc7mDs9838UQQzGhGKicZYnftxez5u81JuCKLNsOuDvnLvEjz/X1hH4931ocYe+k0YZBOyPwJehvP0jMOSmkudwGC2pf+1NmFOE=
From: Klaus Ostermann <klaus.ostermann AT uni-tuebingen.de>Subject: Re: [Coq-Club] How to represent tabular data in CoqDate: May 10, 2017 at 4:19:57 AM EDT
Dear Ben,
thanks these are very useful pointers.
A few question, though: Why don't you use the "In" predicate from
the standard library instead of "member"?
Note that [In] is a prop, whereas [member] is a type. Since [In] is a prop, it can't be used to retrieve any information, like looking up an element in a list. For example, imagine the list [1; 1]. If I have [p : In 1 [1; 1]], I don't know whether the proof was made with the first or second member of the list (in particular, it is admissible to assume that all elements of [In 1 [1; 1] are equal), but if I have [p : member 1 [1; 1]], that data may be used computationally.
Haven't you only given me the interface for tables but not their
representation?
How would I construct an actual table?
You would write a lambda that computes the value from the indices (i.e., [members] terms) that are input. So you'd be pattern matching on those [members] terms. Here's some example code that might give some idea:
Fixpoint get_members {A} {xs : list A} (m : members xs) : A
:= match m with
| here' x _ => x
| there' _ _ m' => get_members m'
end.
Fixpoint to_nat {A} {xs : list A} (m : members xs) : nat
:= match m with
| here' _ _ => 0
| there' _ _ m' => S (to_nat m')
end.
Fixpoint eq_members {A B} {xs : list A} {ys : list B}
(m : members xs) (m' : members ys) :=
Nat.eqb (to_nat m) (to_nat m').
Definition ComputeTable {R C A} (r : list R) (c : list C)
(f : R -> C -> A) : Table' R C r c A :=
{| lookup' := fun mr mc => f (get_members mr) (get_members mc) |}.
Definition UpdateTable {R C A r c}
(t : Table' R C r c A) (mr : members r) (mc : members c)
(a : A)
: Table' R C r c A
:= {| lookup' := fun mr' mc' =>
if andb (eq_members mr mr') (eq_members mc mc')
then a
else lookup' _ _ _ _ _ t mr' mc' |}.
The difference between "member" and "members" is also interesting.
How do I "see" that "member" requires UIP?
Sorry, I wasn't clear about this. Neither one requires UIP. But I believe the types [members xs] and [sigT (fun x => member x xs)] are isomorphic only if [A] satisfies UIP. The reason is that [member] could be equivalently defined
Inductive member {A} (x : A) : list A -> Type :=
| here : forall y xs, x = y -> member x (y :: xs)
| there : forall y xs, member x xs -> member x (y :: xs).
So if there is more than one proof of [x = y], there will be more elements in [sigT (fun x => member x xs)] than [members xs]. Usually I've found that I prefer [members] to [member] for this reason.
- [Coq-Club] How to represent tabular data in Coq, Klaus Ostermann, 05/08/2017
- Re: [Coq-Club] How to represent tabular data in Coq, Wilayat Khan, 05/09/2017
- <Possible follow-up(s)>
- Re: [Coq-Club] How to represent tabular data in Coq, Ben Sherman, 05/10/2017
- Re: [Coq-Club] How to represent tabular data in Coq, Klaus Ostermann, 05/10/2017
- Re: [Coq-Club] How to represent tabular data in Coq, Ben Sherman, 05/17/2017
- Re: [Coq-Club] How to represent tabular data in Coq, Jason Gross, 05/17/2017
Archive powered by MHonArc 2.6.18.