Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Recursive Notation in Coq

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Recursive Notation in Coq


Chronological Thread 
  • 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:12:30 -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:yuJybh83s5tTWP9uRHKM819IXTAuvvDOBiVQ1KB31O4cTK2v8tzYMVDF4r011RmVBNudtagP1rWempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffgRFiCC8bL9sIxm7rQfcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh7W/ZlMJwgqJYrhyvqRNwzIzbb52aOvdlYqPQfskXSXZdUstfVSFMBJ63YYsVD+oGOOZVt5XwqEYUohu7GAKhGuPvyjtJhn/ux6I61/4uGhzB0QM6At0BqnHUo8nuOagOSuC61qjIzTHZY/NT2Df99JLEfQ48rvGRRL99d9faxkYzGQ3flFqQtZDlMC2P1uQLq2WW7OVuWOGyh2M6qAx9vzmiy8coh4XVmI8Y1l/J+Cd3zos1OdC1VVN3bMC6HJZfuC+XNoh7T8AtTW9mpSs216MKtJimdyYEz5QnwgTQa/2Bc4WQ/x3jVf2RLit/hHJ4YrK/nAi9/VKvyu3mUcm0zU5KoyxYmdfPrnAAzwHf5taER/dn8EqtxSyD2x7J5u1aPEw4ibLXJ4A9zrMwjJYfr1jPEjLslEnriKKabEsp9vau5u/6eLvpvIWcOJVxigzmMqQhhMi/AeMgPwgJQmib5eu81Lri/U3/T7VGl+Y2krXDv5DGP8sXvLK2AxRP3YYi7xazFTKm0NUEnXUdMl1KZQ+Hg5DoO1HIPv/4Ee+yj0mynDpo3fzLMKHtDo/TInTZjrvtYKpx51ZZyAUpzNBf45xUCqsGIPL2QkL+rsHXAQU8MwOo2OvoFM592ZkfWWKLGKOZNaLSsUOS6u0xPuaMeZcZuCzhJPg9+/7ukXg5lEcBcqmuxJsbcWy3HvB7I0qCenfsmdcAEWISvgUkVuDqiVuCUSRSZ3moRa486Cs7W8qaCtLIQZnoi7ic1g+6GIdXbyZIEAOiC3DtIqyIUvJEQyKWI9doljVMAbGtQooq/Rq1vQ7+jb9mMqzZ9jBO5sGr78R8++CGzUJ6zjdzFcnIizjQHVExpXsBQnoN5I46oUF5zQzbg69ln/NfFNpcouhVWxszc5XHxu1+TdXzRkTMcsrbEA/6EOXjOik4S5cK+/FLe1x0QojwhQvK3i7sBr4J0bGHGc5sq/OO7z3KP894jk3++uwkhlgiTNFIMDT71KVk/gnXQYvIjwOUm7v4LKk=

Thanks for that suggestion; I'm still learning to remember the possibilities of tactics in terms!

It is worth pointing out that this is inherently a parsing-only notation, as there is no magic inversion of Ltac code to detect when a Gallina term could have been produced by a notation rule as fancy as this one.  If you are willing to have your desugared goals contain literal calls to functions like [chainToProp], it is quite possible to get printing using your notation, too, if you skip the Ltac.

On 7/28/20 9:08 AM, Maximilian Wuttke wrote:
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





Archive powered by MHonArc 2.6.19+.

Top of Page