Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] finite data types

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] finite data types


Chronological Thread 
  • From: Gaëtan Gilbert <gaetan.gilbert AT skyskimmer.net>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] finite data types
  • Date: Tue, 19 Mar 2019 17:35:23 +0100
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gaetan.gilbert AT skyskimmer.net; spf=Pass smtp.mailfrom=gaetan.gilbert AT skyskimmer.net; spf=None smtp.helo=postmaster AT relay7-d.mail.gandi.net
  • Ironport-phdr: 9a23:L5qinh/5M+SXuv9uRHKM819IXTAuvvDOBiVQ1KB30e0cTK2v8tzYMVDF4r011RmVBN2dta4P27uempujcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47xaFLIv3K98yMZFAnhOgppPOT1HZPZg9iq2+yo9JDffhlEiCC8bL59Ixm7rgHcvdQKjIV/Lao81gHHqWZSdeRMwmNoK1OTnxLi6cq14ZVu7Sdete8/+sBZSan1cLg2QrJeDDQ9LmA6/9brugXZTQuO/XQTTGMbmQdVDgff7RH6WpDxsjbmtud4xSKXM9H6QawyVD+/6apgVR3mhzodNzMh7W/ZlMJwgqJYrhyvqRNwzIzbb52aOvdlYqPQfskXSXZdUstfVSFMBJ63YYsVD+oGOOZVt4jzqEESqhuiHwasAvvgxD5Jhn/yxqI1zf4hER3b1wEnENIBqmrbrMnvO6cUS+y1w6jIzTHYYPxIwzf99JPFcgsiofCMRrJwcsvRyUwqFwzblFWcs4rlMC2J1ukUtWWQ8uRuVeWqi2E9qgFxpCCixsgtionVhoIV10vL+T9lz4YyIN21TlNwb928EJZIqS2WKol7TtkgTm10oio2174LtJChcCQU1Jgr2wbTZ+Gbf4WM+B7vSvqdLSliiH54ZL6yhQy+/Eimx+bhTMe7ykxKoTBAktTUtnACyRjT6s+fR/tn4Eih3SyA1gDR5+1dPE84j6/bJIQgwr40jJYTvl7MHinrl0X3lqOWcFsr+vSw5+TmZLXpuIOcOpdqhg3jMKkigM6yDfgiPgQTXGWW9/6w2KP/8UHlWLlKi+c5kqjdsJDUP8Qboau5Dhda0ok59Rm/Ey2p0NICkXkILVJFfAmIgJbzO1HSO/34FvS/glS3kDdoxvDGO7jhDYvXLnTZlrfuY6p951ZGyAUv1dBf+45UCrYZLf3vXU/xrcXUAQM9Mwyp2OnqE85914MbWWKXGKCVKqLSsVmS5uIuOeaAfoEVuCyuY8QisvXplDoynUIXVaivx5oeLn6iTdp8JEDMTnNvnt4HJkgLugAzVvCi3FKLXCJaYTC9XqY26ysnIJmlHJzAR4WojabH2iqnSM4FLltaA0yBRC+7P76PXO0BPXrLc51R1wccXL3kcLcPkBSntQv00b1id7SG4S4JrpHi0d14/avVmA1grGUoXfTY6HmESiRPpk1NXyU/hf4tuk9s0VSC1K11mbpeGMABv6oUADd/DobVyqlBM/63Wg/FeY3UGkyrRty3XnQ9CNc4wttIbE97F9TkiB3fjXKn


> To have a good notion of equality over type "unsigned" above, it's
> better to define it this way:
>
> Definition unsigned (max:Z) : Set :=
> { x : Z | -1 < x /\ x < max}.
>
> so that proofs of the proposition "-1 < x /\ x < max" are unique.

Isn't that also true with "x >= 0 /\ x < max"?

Gaëtan Gilbert

On 19/03/2019 16:54, Xavier Leroy wrote:
On Tue, Mar 19, 2019 at 10:36 AM Alix Trieu <alix.trieu AT cs.au.dk <mailto:alix.trieu AT cs.au.dk>> wrote:

CompCert provides a formalization of machine integers you might be
interested to look at:
https://github.com/AbsInt/CompCert/blob/master/lib/Integers.v


Actually, this formalization follows the same approach proposed by the original poster, using a subset of Z:

Definition unsigned (max:Z) : Set :=
  { x : Z | x >= 0 /\ x < max}.
Definition unsigned_8 := unsigned (2^8).

A nice property of this approach is that it computes relatively efficiently (like type Z) while the Fin.t type does not (like type nat).

To have a good notion of equality over type "unsigned" above, it's better to define it this way:

Definition unsigned (max:Z) : Set :=
  { x : Z | -1 < x /\ x < max}.

so that proofs of the proposition "-1 < x /\ x < max" are unique.

Have fun,

- Xavier Leroy







> On 18 Mar 2019, at 15:10,
fritjof AT uni-bremen.de

<mailto:fritjof AT uni-bremen.de>
wrote:
>
> Hi,
>
> I want to create a finite data type, like *Unsinged 8*,
> which containes values from 0 to 2^8 -1.
> I came up with an idea like:
>
> Definition unsigned (max:Z) : Set :=
>  { x : Z | x >= 0 /\ x < max}.
>
> Definition unsigned_8 := unsigned (2^8).
>
> But I'm not sure, if this is the right way.
>
> Does someone know if there is a better way to define
> finite types?
>
> --f.
>




Archive powered by MHonArc 2.6.18.

Top of Page