coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Adam Chlipala <adamc AT csail.mit.edu>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Recursive Notation in Coq
- Date: Tue, 28 Jul 2020 09:32:57 -0400
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=adamc AT csail.mit.edu; spf=Pass smtp.mailfrom=adamc AT csail.mit.edu; spf=None smtp.helo=postmaster AT outgoing-stata.csail.mit.edu
- Ironport-phdr: 9a23:m5dR2xKvvr8gk97/rNmcpTZWNBhigK39O0sv0rFitYgeI/TxwZ3uMQTl6Ol3ixeRBMOHsqwC1bCd7v+ocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbAhEmTuwbalzIRmoognctssbipZ+J6gszRfEvmFGcPlMy2NyIlKTkRf85sOu85Nm7i9dpfEv+dNeXKvjZ6g3QqBWAzogM2Au+c3krgLDQheV5nsdSWoZjBxFCBXY4R7gX5fxtiz6tvdh2CSfIMb7Q6w4VSik4qx2ThLjlSUJOCMj8GzPl8J+kqxbrhKiqRJxzYHbb4OaO+Zlc6zHYd8XX3BMUtpfWiFDBI63cosBD/AGPeZdt4Twu0YBogG7BQKxGu7vyjtIhn7u3aIg1+QuCxzN0Qs6EN0TqnvUqcn6ObwOXuCu1qbIzDHDY+lT2Tf89IjEaA4uruyRXb9pd8fa1EYgGR/fgFqKtYzlIy2a1v4Ls2WD7+RuWuGihW45pg9+vDWhyNogh4jXio4IxV7J6Dh0zYYxKNGmVkJ2YN+pHIVfuS+UKYd6Xt0uT39otSs+y7ALtpi2dzUExpQgwh7Qcf2Hc46Q7x3/VOaRJTZ4hGp/d7K7nRm+606gxfPgVsWszVlKrzFFncXLtnAQzRzT8daIRuFy/ke73jaPyhjT5+dZKk43jarWM4MtzqAzm5YJv0nPAjX6lFvsgKOIa0ko5vCk5/r7brjmvJOQKZN4hhzkPqgznsGzG+o1PhYIUmOG4+qzzqfj8lf8QLhSjv05jK3ZsJfCKMQcu665HwBV0oEi6xa5ADeqyc8YnWUdI1JZYh2LlZTmO0rUL/D5CfezmVGskDZ3x/zcILLuH4jNImDCkLfnY7l991ZRxBctwd1c/Z5ZBK0NLOjtVkPrqtDUEwM1PxSxw+n9CdV90o0eWXiIAq+cKK7dq0KH6fgqI+aQf4IapC39JOIk5/7ql3M5nF4dfbWz0ZQJdX+4A+xqI1+Fbnr0ntcBDWAKsxIiQ+ztkV2OSCJcZ3KvX60n/Tw7E4KnDYLbRo+3mrCB3SG7HodXZm9cEFyMH23oJM24XKIHbzvXKct8mBQFU6KgQskvz0KArgj/npNrJ++c0S0ctIrq0NE9s+TfnBQ53TdvBsWZlWSMUyd5kn5eFGx+57x2vUEokgTL6qN/mfENTYUOtcMMaR8zMNvn98I/C932XVmZLNCUVFmhQ9OpRCotR844hdQVakd5XdCjklbO0zf4W+ZExYzOP4Q99+fn51a0Is98z3jc06x40gstWcJOMSujh7I5+gTOVdeQzxep0p2yfKFZ5xbjsX+ZxDPT7kpDWQ90F6DEQTYSalaE9dk=
That's harder to do with the solution
where you build a list and call a Gallina function, but it only
requires standard use of heterogeneous list types (e.g., see
Chapter 9 of CPDT). Type inference
is quite smart enough to reconstruct a list of types from a
(heterogeneous) list of values of those types. And, if working
with heterogeneous lists doesn't seem worth the trouble, you can
use a notation that constructs a tuple and passes it off to Ltac,
which can do recursive traversal of tuples as easily as of various
list types.
On 7/28/20 9:14 AM, Dominique
Larchey-Wendling wrote:
Thanks for the suggestion but can you do it when the type X is not uniform? I mean the type of red is actually red {X Y : Type} : phi X -> phi Y -> Prop where phi : Type -> Type D. ----- Mail original -----
De: "Maximilian Wuttke" <mwuttke97 AT posteo.de> À: "coq-club" <coq-club AT inria.fr> Envoyé: Mardi 28 Juillet 2020 15:08:43 Objet: Re: [Coq-Club] Recursive Notation in Coq
Hi Club, In addition to the solution I posted on Discourse [1], here's an implementation of Adam's idea: ``` Fixpoint chainToProp {X : Type} (R : X->X->Prop) (xs : list X) : Prop := match xs with | nil => True | x :: xs => match xs with | nil => True | y :: nil => R x y | y :: _ => R x y /\ chainToProp R xs end end. Notation "'chain' xs 'endchain'" := (ltac:(let x := eval cbv [chainToProp] in (chainToProp le xs) in exact x)) (only parsing). Check chain [1;2;3;4] endchain. (* 1 <= 2 /\ 2 <= 3 /\ 3 <= 4 *) (* : Prop *) ``` [1]: <https://coq.discourse.group/t/notation-for-inequality-chain/979/2> On 28/07/2020 14:44, Adam Chlipala wrote:My guess is that (1) you may need to add some kind of brackets around the notation, and (2) you may need to build a Gallina list of the different elements and then apply a Gallina function that checks relatedness of adjacent elements. There is indeed a built-in notation facility for variable-length forms, but I don't think it allows constructing subterms out of adjacent parts of the original argument list, and it doesn't allow referencing the same notation recursively in the expansion. On 7/28/20 8:39 AM, Dominique Larchey-Wendling wrote:Dear all, If a notations wizard could help me at defining the following recursive notation in Coq, I would be very grateful. x ⪯ y ⪯ .. ⪯ z := red x y /\ y ⪯ .. ⪯ z where red : _ -> _ -> Prop ie a ⪯ b ⪯ c ⪯ d would be (red a b) /\ (red b c /\ red c d). Sequences must have length >=2 (otherwise they would be meaningless) Thank you very much for some insights, Dominique
- [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Hugo Herbelin, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Hugo Herbelin, 07/29/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Dominique Larchey-Wendling, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Maximilian Wuttke, 07/28/2020
- Re: [Coq-Club] Recursive Notation in Coq, Adam Chlipala, 07/28/2020
Archive powered by MHonArc 2.6.19+.