coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: karsar <karen.sarkisyan AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Type for finite set of naturals [1..N]?
- Date: Wed, 10 Jan 2018 15:45:13 +0800
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=karen.sarkisyan AT gmail.com; spf=Pass smtp.mailfrom=karen.sarkisyan AT gmail.com; spf=None smtp.helo=postmaster AT mail-oi0-f45.google.com
- Ironport-phdr: 9a23:UmI6hByqksOehczXCy+O+j09IxM/srCxBDY+r6Qd1O4WIJqq85mqBkHD//Il1AaPAd2Craocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HObwlSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRDqhicJNzA3/mLKhMJukK1WuwiuqwBlzoPOfI2ZKPhzc6XAdt0aX2pBWcNRWjRCAoymdYsPFPAOPfxFpIT6pFsBtwG+CheqBO/10T9HnGX23a470+Q6EQDJxgogEskBsHTRttr1NaMSXfqpw6nPyDXOdvVb0irz5ojPdxAuu/CMXbRofMXNyUkvEwLFjk2KpozhJTyZzOINvHaH7+dmSOmhiHYnphlvrjSzwsogkIrEi4IPxlza6Cl0w5w5KNK4RUN9fNWqCoFftzuAOItzWs4iQ39nuCI9yrAevJ60ZikKyJA+yx7YavyLb5GE4hzsWeuROzt4i3VleLWwhxa270es0PHzVs6x0FpSrypFlMfDtmwV2hDN9sSKTuFx80Sh1DqVyQzf9+JJLVo7mKfbM5Ihx6Q/lpsXsUTNBC/2n0D2gbeVdko+4Oin9eLnbq/9ppCGLY90iQD+Mr8um8OlB+Q1KQcOX22B9uS90L3v51H2QLJPjvEuiKnWrIjaJdgHpq6+GwJazoEj6w+mAzi61NQYgGIIIUleeBOHiojpI0vBLOr5Dfe5mVSskS1ky+rIPr37Ud3xKS3Il66kdrJg4WZdzhAyxJZR/cF6ELYEdfH6QFT4rpSMDRYjPgry2O/9C9Rmx4oYcW2KC66ddqjVtAnbtaoUP+CQadpN637GIP8/6qu2gA==
you may want to read CPDT chapter
for {_:_|_} subset types.
For Fin (definition is from CPDT here, Coq.Vectors.Fin gives the same up to constructor names)
Inductive fin : nat -> Set :=
| First : forall n, fin (S n)
| Next : forall n, fin n -> fin (S n).
So, we can construct terms of (fin 2) as (First 1) and (Next (First 0))
values of (fin 3) are (First 2), (Next (First 1)) and (Next (Next (First 0))
This way we get for fin 3 terms that may be associated with 1, 2 and 3.
Pay attention that terms of (fin 3) are different from terms of (fin 2). This is because
(fin 2) and (fin 3) are different types! So you don't pass (fin 2) terms to a function
which expects (fin 3) elements, although you may expect that according
to 'common sense' 2 belongs to both sets of {1,2} and {1,2,3}.
Fin might be used if you define lists of given length and want to extract an element
by a given index. Knowing the length of the list you may use Fin n to ensure that
your index is never out of range.
Best,
Karen
On Wed, Jan 10, 2018 at 2:55 PM, Siddharth Bhat <siddu.druid AT gmail.com> wrote:
Thank you, that does help.
How does the set notation work? I haven't seen that before, that is cool.
Is there some place that uses Fin in some trivial way? Eg. Establishes a bijection with [1..n]? If not, I suppose I can stumble through :)
Thanks
SiddharthOn Wed 10 Jan, 2018, 11:36 ikdc, <ikdc AT mit.edu> wrote:On 01/10/2018 12:58 AM, Siddharth Bhat wrote:
> Hello all, I'm looking for a type that encodes the fact that its
> inhabitants are naturals from 1 to N.
>
> I believe Fin is the type I am looking for? I'm not sure what Fin
> represents, exactly. Does Fin act as a witness for the *entire interval*
> [1..n]? Or can it witness some k \in [1..n]?
>
> Ideally. There would be a type (forall n : nat), "T n" whose inhabitants
> can be put in bijection with [1..n]
>
> Thanks
> Siddharth
>
Fin N is indeed such a type. The two constructors represent the following:
- Fin (N + 1) has one element for each element of Fin N
- as well as one extra element
Hopefully that explains its definition.
I believe it is isomorphic to the type { n : nat | n < N } (or
alternatively { n : nat | 0 < n /\ n <= N }) which may be easier to work
with depending on what you're trying to do.
ikdc
--Sending this from my phone, please excuse any typos!
- [Coq-Club] Type for finite set of naturals [1..N]?, Siddharth Bhat, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, ikdc, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, Siddharth Bhat, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, karsar, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, Dominique Larchey-Wendling, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, Siddharth Bhat, 01/10/2018
- Re: [Coq-Club] Type for finite set of naturals [1..N]?, ikdc, 01/10/2018
Archive powered by MHonArc 2.6.18.