coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Talia Ringer <tringer AT cs.washington.edu>
- To: Coq-Club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] conversion from vector to list and back
- Date: Thu, 21 May 2020 20:12:25 -0700
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=tringer AT cs.washington.edu; spf=Pass smtp.mailfrom=tringer AT cs.washington.edu; spf=None smtp.helo=postmaster AT mail-wm1-f50.google.com
- Ironport-phdr: 9a23:xtcb3R/A6fVjdf9uRHKM819IXTAuvvDOBiVQ1KB21+wcTK2v8tzYMVDF4r011RmVBNidsqsewLSK+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhIiTanfL9+MQu6oQrQu8QZnIBvNrs/xhzVr3VSZu9Y33loJVWdnxb94se/4ptu+DlOtvwi6sBNT7z0c7w3QrJEAjsmNXs15NDwuhnYUQSP/HocXX4InRdOHgPI8Qv1Xpb1siv9q+p9xCyXNtD4QLwoRTiv6bpgRxj1hicaLD456H/YhdBsjKxVpxKhogZww4/SYIqIMPZzcafQcdYcSGFcXMheSjZBD5uzYIsBDeUPPehWoYrgqVUQsRSzHhOjCP/1xzJSmnP6wa833uI8Gg/GxgwgGNcOvWzKotrvMKcSUPq6x7TUwzXCafNW1iny6JLVeR0mvfGMR7NwcczeyUYxDQPIlUmfqZf/MzKbzOsNqGib7+tmVeKgl24nrAdxriKxycgxl4nEn4QYwU3L+itl2og6P8G4SFJlbt6+FptdryWXO5d4T84gQ29lpDs3xqAatZO7YSUHyIkqyhzDZ/GIfIaG7AzuWPuSLDl2mH9oebayiwiy/0W+xOPwS8u53VVMoyFYnNfMsXUN2AbS6siBUvZ98Uah2SqP1wDO8e5IO0E0la3DJ54uw74wipoTsVnYESPshEr2i6qWel0+9eiy5OXnY6vmqoWbN49uhQHzNLkllM+nAekgLAQCQ2yW9f6/2bDj50H1XatGg/4snqTZrJzXI9kQqLSjDA9PyIkj7g6yDze439QcmnkKNFdFdwiGj4jtIl3PLvX4Aeqmj1SikDpn2+rKPrLmApXKIXjDlKnucaxh5E5bzQo/1dFf55RKBbEdOP//RFP9udjCAhI6MwG42fvrBMt+248EWW+DHreVMKbIvl+J4uIvLfOMZIgQuDvlN/gl/f/ujXk2mVADZ6mkxocYaGuiEvVoOUqZenrsgtYHEWcFogo+S+rqhEecXjFOena+R7g86S0jCIK6EYfDQZigj6CG3CeiB5FZemRGCk2XHnrzbIWFW/IMaDqILcN7kzwEU6KhS4472h20ug/60ekvEu2B0SoB8LnnydI9s+bUjFQ58SF+J8WbyWCECW9uyDAmXTgziZx2pU10gm2C16d1mbQMCcZS4fxESC8xLtjDxvd6Ctb9RgXHONqFVQD1EZ2dHTgtQ4dpkJc1aEFnFoD+30mfjRrvOKcckvmwPLJx6rjVhimjLN071H/d1KgngEUhRI1COXD03vcipTiWPJbAlgCir4jvdakY23SQpmKKzG7Lo0QBFQAtCePKWncQYkaQptP8tBubHu2eTI8/Ow4E8vasb65Da9nnl1JDHaaxM8+YfGuqm2a2CgqPwPWBYJe4Img=
In general, this happens with dependent types when you are dealing with some kind of equivalence. If two types are equivalent, you can find functions that get you back and forth that are mutual inverses, so:
f : A -> Bg : B -> A
where two properties called section and retraction hold:
section: forall a, g (f a) = aretraction: forall b, f (g b) = b
But note that these properties don't hold definitionally. You must prove section and retraction hold, and then you rewrite by it in order to get the type you actually want. So the Coq specification is correct.
This problem of dealing with equivalent types is called "transport," and it's hard. It is easier in homotopy type theory, or in my tool DEVOID for some types like lists and vectors (paper: http://tlringer.github.io/pdf/ornpaper.pdf, tool: https://github.com/uwplse/ornamental-search), or in the univalent parametricity framework (https://arxiv.org/pdf/1909.05027.pdf).
If you want to do these conversions yourself, without using any external tools at all, your best bet is to prove section and retraction, and then rewrite by those. But it will suck. I really recommend using a tool for this kind of thing.
Talia
On Thu, May 21, 2020 at 6:05 AM Fritjof Bornebusch <fritjof AT uni-bremen.de> wrote:
On Thu, May 21, 2020 at 02:34:31PM +0200, Maximilian Wuttke wrote:
> On 21/05/2020 14:18, Fritjof Bornebusch wrote:
> >
> > => In environment
> > bv : BitVector_10
> > The term "Vector.of_list (Vector.to_list bv)" has type
> > "Vector.t bool (length (Vector.to_list bv))"
> > while it is expected to have type "BitVector_10".
>
> You might have to 'cast' `length (Vector.to_list bv)` to `10`. (The are
> equal, but not simply by conversion). You can try to use the function
> `cast: forall {A m} (v: t A m) {n}, m = n -> t A n`.
>
> Heads up: Some functions (including `cast` and `to_list`) in the vector
> library don't have the expected `cbn` simplification behaviour. Also,
> many obvious lemmas are missing. There are some libraries that extend
> (among others) this part of the standard library.
>
>
Thanks for the hint. Do you have a link to these libraries?
- [Coq-Club] conversion from vector to list and back, Fritjof Bornebusch, 05/21/2020
- Re: [Coq-Club] conversion from vector to list and back, Siegfried, 05/21/2020
- Re: [Coq-Club] conversion from vector to list and back, Maximilian Wuttke, 05/21/2020
- Re: [Coq-Club] conversion from vector to list and back, Fritjof Bornebusch, 05/21/2020
- Re: [Coq-Club] conversion from vector to list and back, Talia Ringer, 05/22/2020
- Re: [Coq-Club] conversion from vector to list and back, Talia Ringer, 05/22/2020
- Re: [Coq-Club] conversion from vector to list and back, Fritjof Bornebusch, 05/22/2020
- Re: [Coq-Club] conversion from vector to list and back, Talia Ringer, 05/22/2020
- Re: [Coq-Club] conversion from vector to list and back, Talia Ringer, 05/22/2020
- Re: [Coq-Club] conversion from vector to list and back, Fritjof Bornebusch, 05/21/2020
Archive powered by MHonArc 2.6.19+.