Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] How do I define this function for non-empty lists?

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] How do I define this function for non-empty lists?


Chronological Thread 
  • From: Jason Gross <jasongross9 AT gmail.com>
  • To: coq-club <coq-club AT inria.fr>, Talia Ringer <tringer AT cs.washington.edu>
  • Subject: Re: [Coq-Club] How do I define this function for non-empty lists?
  • Date: Thu, 29 Oct 2020 12:25:25 -0400
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-ed1-f45.google.com
  • Ironport-phdr: 9a23:FS014h9Y+TMh3f9uRHKM819IXTAuvvDOBiVQ1KB22uIcTK2v8tzYMVDF4r011RmVBNqduqgP27OempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffgdFiCC5bL9sIxm7rhjdvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/9KpgVgPmhzkbOD446GHXi9J/jKRHoBK6uhdzx5fYbJyJOPZie6/Qe84RS2hcUcZLTyFODY28YIkPAeQPPuhWspfzqEcVoBSkGQWhHvnixiNUinL026AxzuQvERvB3AwlB98AtG7brM7yNKcUTOu7zbPIzTLYb/NNxDzw74rIfQo6ofGLW7JwftDRyU40FwPeilidsoPlPzaP2eQMt2iX9fZvVeWqi2M+rQx6vzegyNs2hIbTmoIV1k7L9T9/wIstJNC1SlJ3bMOkHpZRtyyXOY97T80sTWxspis0yqMLtJq/cSUXx5kqxQPTZvyHfYaH7B/tW/idLzlliH57Zb+ygxC/+lWuxO37U8m7yldKrixdn9nNsHANzR3T5dKdRvtz5EetwS2P1xzJ5e5YIkA0krTbJIA7wr4+kpoTtkrCEjXql0Xxia+abl8r+vKn6uTmfLXqvJicN5V7ig3mPaQum9C/AeQlMgcVRWSU5eO81Ljl8EbkQ7tKluU7nrfFvJ3eP8gWpa60DxVL3oo/6BuzFTir3dQekHIaNlxKYgiHgJLsO1zWIPD3E/O/g1O0nTdu3f/GP7nhDozTIXfejbvtZLh95kFcxQYpwtBf4JVUCr4FIP3tQEP+qNvYDhohPwy1xeboFsl925sAVW6TBqKVKqDfvF+S6u4xP+WBZ5UZtTn9JvQ94v7hl345mVsTfamz2psXbWi1HvZ8LEWCZnrshNgBEX0NvgolV+znjEaPUTFWZ3moXqI84is3B56hDYfGXoytmqCO3D+nHp1KYWBLEkyDEXDxd4mdR/gMbD+SLdR6nzwfVbmhTpch2gu0uA/7zbpnNOvU9TcCuZLtztgmr9HUwBo17Hl/C9mXmzWGSHgxlWcVTRc32rp+qApz0AHHmZRxh/1RXeZS4fxESE9uKYTdyeN3Efj5QUTed8yJSVCpXtKgRzw9U4Ri7cUJZhNfEs6liFjsxS2xGPdBlbWQA5o76KXHxCnZKMN0ynKA364k2Qp1CvBTPHGr0/YsvzPYAJTExgDAz/7zKPYsmRXV/WLG9lKg+UFVVAkqDPfAVHEbI0ba9JH3uh6EQLipBrAqdABGzJzac/oYWpjSlVxDAczbFpHbamO1lX23AE/RlLyJZYvuPW4a2XeEURRWo0Uo5X+DcDMGKGK5uWuHVW5hEFvuZwXn9uws8H4=

The difference between Defined and Qed is exactly the question of whether tactics like cbv, reflexivity, unfold, etc can see their definition.  See also https://coq.inria.fr/refman/proof-engine/proof-handling.html#coq:cmd.defined and https://stackoverflow.com/questions/25478682/what-is-the-difference-between-qed-and-defined .

I believe there exist automated ways of doing lemma transport, such as https://arxiv.org/abs/1909.05027 (The Marriage of Univalence and Parametricity) and Talia Ringer's PUMPKIN PATCH and DEVOID (https://github.com/uwplse/pumpkin-pi).  I've cc'd Talia so she can say more.

The way I'd suggest doing it is:
1. First prove that the various functions you want to lift preserve non-emptyness.  Look at (2) for the comment on how to phrase non-emptyness.
2. Write wrapper functions that combine the functions with the proofs so that you have functions on the sigma type { ls : list _ | match ls with nil => False | _ => True end }.  (Note that you could use `ls <> nil` as the proof property, but then you will need function extensionality or proof irrelevance to prove that two proofs of non-nil are equal.)
3. Prove that your sigma type is isomorphic to your inductive type.
4. Use DEVOID or univalent/parametric transport (or just make the isomorphism functions be coercions and do the rewriting manually) to automatically lift all the functions and proofs from the sigma types to your inductive type.

-Jason

On Thu, Oct 29, 2020, 11:38 Agnishom Chattopadhyay <agnishom AT cmi.ac.in> wrote:
Thanks! That worked.

What is the difference between Defined and Qed?

Also, is this method (i.e, transporting lemmas and functions from the standard library lists to my type) advisable for what I am trying to do?

On Thu, Oct 29, 2020 at 10:20 AM Gaëtan Gilbert <gaetan.gilbert AT skyskimmer.net> wrote:
If you do "cbv" in your proof, you will get the goal

   match list_nil_dec nat nil with
   | left _ => < 1 >
   | right pr => match pr eq_refl return (nonEmpty nat) with
                 end :| 1
   end = < 1 >

this means reduction is blocked by your lemma list_nil_dec.
If you change the Qed to Defined for list_nil_dec, reflexivity works.

Gaëtan Gilbert

On 29/10/2020 16:09, Agnishom Chattopadhyay wrote:
> Hi;
>
> For an application, non-empty lists occur naturally. One way to deal with this would be to define a type of non-empty lists and then all the necessary functions and lemmas for them.
>
> However, I am trying to recycle the theorems available in the standard library. To do this, I am defining a function which lifts functions on list to functions on my non-empty type provided they preserve non-emptiness.
>
> But I am facing some trouble with this. For example, I cannot prove the lemma simple <https://gist.github.com/Agnishom/573a697dab82ddb72360136014065f7f>, over here.
>
> What am I doing wrong?
>
> --Agnishom



Archive powered by MHonArc 2.6.19+.

Top of Page