coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Jan-Oliver Kaiser <janno AT mpi-sws.org>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] Need help for manual induction scheme definition
- Date: Tue, 24 Sep 2019 18:15:10 +0200
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=janno AT mpi-sws.org; spf=Pass smtp.mailfrom=janno AT mpi-sws.org; spf=None smtp.helo=postmaster AT jupiter.mpi-klsb.mpg.de
- Autocrypt: addr=janno AT mpi-sws.org; prefer-encrypt=mutual; keydata= mQENBFNx+loBCAC52t5xTWGjj9DMTCyTP3vL0cLh63ZNGTD7Ut5F3zVEyA1wlCRziuDVg+4b 7U7UBd2GpE4tY0YzRMlQElFP7XpkkEXC+JY+Vnor+4GyHvvbvRLKaB6mbQTsZ5R7I0O1gOy4 yCvljA9NrnFUI4f2HIZyOnjjgXlGjs4JgYCes/hgfvCLmtWq7Gve9xtEGq4IEKw9qz07Homh ExBDCwx8nfVphUnnt+PosxJuO/7rFN2v6wdL8PeQFMUsm9MADpNssuvSI+XC0QO0cK45g1zb ZTpaAzc3dXTjYjZm5tLo6ChWI8QpZRCfJUztaLIWiPd2NZLyr5OoM6HnUaj5vJZrEa4ZABEB AAG0JUphbi1PbGl2ZXIgS2Fpc2VyIDxqYW5ub0BtcGktc3dzLm9yZz6JAVQEEwEIAD4CGyMF CwkIBwIGFQgJCgsCBBYCAwECHgECF4AWIQT/HCVoRd2YP5nVLNFZLRd4BiFNXAUCXMwQ/QUJ CztKIwAKCRBZLRd4BiFNXGO4B/0Z6bkJ1KDroeCely6usOSCWI6cHwJBdvlh2mn2aCvUWBIQ nDqvJZRMVd/SsSSTWruCKG61DVN36Jge15BK25SESKYB2/vOs4DWcNOtyQYY3ndPkn18/Jzj 4saQiN47C7AfDLUSLChHFaXzwyUD/rjIl2kyoYSAduFO3XhBwBwiCOpspv3Pl8jRiwxrGA3w eYZvz7P+vLtUMYA/iXEB22Mx6/KQ6k5HGi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hpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vIhi6twvcutUZjYZmK6s61wfErGZPd+lK321jOEidnwz75se+/Z5j9zpftvc8/MNeUqv0Yro1Q6VAADspL2466svrtQLeTQSU/XsTTn8WkhtTDAfb6hzxQ4r8vTH7tup53ymaINH2QLUpUjms86tnVBnlgzoBOjUk8m/Yl9ZwgbpGrhy/qRxxw43abo+bO/VxfKzSYdwUSHFdXstSTSFNHp+wYoUNAucHIO1Wr5P9p1wLrRamAQejHuXvxiZRiH/y3K06zfouERvb1wIlBd0OsW/Uo8vvNKwPVu21zrPHzTPFb/NRwjr97ZDIchE4rfGXU7NwatDdyU41FwPKl1idr5HuMTCN1ukVrmSW4e5tWfiyh2MjsQ18oTmiyt0xhoTJno4Z10zI+CFjzIs3JdC0Ukp2bcC+HJdNtyyWK417Sd44TW5yoiY10LgGtIa7fCcUzJQnwAbSa/6ac4iQ4xLjSPieIS1iiHJgYLK/hg++8Uukyu3nTca4ylNKrjJKktXWq38CyQTf6smBSvRj4keswSuD2g7X5+1ePEw5kbDXJp0gz7Iqi5YesVzPHirsl0X3iK+WeF8k+u+t6+n/YLXpvJmcN4lzigzlN6Qugs2/Df0jMgkARGiX4+O81Kfs/UHhWrVFkuU2krXFsJDdPckUuqm5AxZM3ok/7xa/Eiyp3c8DnXgHKVJFYAiIg5LoO1HIOvD4DO2wj06ikDdxlLj6OejqBYyIJXzemp/ge6x84ghS0lkd19dasrBdDPQmJPPtV1W5l9XZFRIje1i2yuDhD/14zoJbQn2URKiDP/WB4hez+uszLrzUN8cuszHnJq19vqK8vToCgVYYOJKR894PcnnhRaZjO0TcemX3xNAbHjVS51dsfKnRkFSHFAVrSTOyUqY7vGxpCp++DJvOXMaomL3E3yOgFNtTfm8ABl3eSS65JbXBYO8FbWepGuEklzUFUba7TIp4jkOrrA6/0KV8aO3O9X9BuA==
- Openpgp: preference=signencrypt
I can't say what exactly is wrong with your approach. While trying to fix it, I got confused by the way it was written. Below is a working implementation written in a way that I vaguely understand. The first match return type annotation is optional. Coq is smart enough to figure that one out. The other annotations are not optional, AFAICT.
Require Import List.
Inductive t : Set :=
| Base : t
| Rec : list (option t) -> t -> t
.
Section All.
Variables (T: Set) (P: T -> Prop).
Fixpoint All (l : list T) : Prop :=
match l with
| nil => True
| hd :: tl => P hd /\ All tl
end.
End All.
Section Induc.
Parameter P: t -> Prop.
Parameter HBase : P Base.
Definition Ret x := match x with Some e => P e | None => True end.
Parameter HRec: forall l x,
All
(option t)
Ret
l ->
P x ->
P (Rec l x).
Fixpoint induc (e : t) { struct e } : P e :=
match e as e return P e with
| Base => HBase
| Rec l x =>
let induc_rec :=
fix induc_rec l : All (option t) Ret l :=
match l with
| nil => I
| hd :: tl =>
conj
(match hd as hd return Ret hd with
| Some e => induc e
| None => I
end)
(induc_rec tl)
end
in
HRec l x (induc_rec l) (induc x)
end.
End Induc.
On 9/24/19 6:10 PM, Vincent Siles wrote:
I tried to prove it using tactics and check the proof term and that's what is happening, but I can't managed to replicate it, now I get:
In environment
induc : forall u : t, P u
u : t
l : list (option t)
x : t
induc_rec :
forall l : list (option t),
All (option t)
(fun x : option t => match x with
| Some x0 => P x0
| None => True
end) l
l0 : list (option t)
hd : option t
tl : list (option t)
The term
"match hd as o return match o with
| Some x0 => P x0
| None => True
end with
| Some e => induc e
| None => I
end" has type "match hd with
| Some x0 => P x0
| None => True
end" while it is expected to have type
"?A@{l0:=l; l:=l0}" (unable to find a well-typed instantiation for
"?A": cannot ensure that "Type" is a subtype of "Prop").
I guess I'll go with the tactic solution, it's a bit more readable anyway :D
PS: sorry for the dup, first answer got sent with the wrong address...
Le mar. 24 sept. 2019 à 17:50, Matthieu Sozeau <matthieu.sozeau AT inria.fr <mailto:matthieu.sozeau AT inria.fr>> a écrit :
Hi Vincent,
You should write a return clause `match e as e’ return match e’
with None => True | Some t => P t end with ...` for the match on the
option value, I guess. Coq cannot infer its type automatically. The
error message is sadly misleading.
Best,
-- Matthieu
> Le 24 sept. 2019 à 17:41, Vincent Siles
<vincent.siles AT ens-lyon.org
<mailto:vincent.siles AT ens-lyon.org>>
a
écrit :
>
> Hi !
> I'm facing an somehow complex inductive type, for which I have to
write the induction scheme by hand. Here is a stripped down example
of what I'm doing:
>
> Require Import List.
>
> Inductive t : Set :=
> | Base : t
> | Rec : list (option t) -> t -> t
> .
>
> Section All.
> Variables (T: Set) (P: T -> Prop).
>
> Fixpoint All (l : list T) : Prop :=
> match l with
> | nil => True
> | hd :: tl => P hd /\ All tl
> end.
> End All.
>
> Section Induc.
> Parameter P: t -> Prop.
> Parameter HBase : P Base.
> Parameter HRec: forall l x,
> All
> (option t)
> (fun x => match x with Some e => P e | None => True end)
> l ->
> P x ->
> P (Rec l x).
>
> Fixpoint induc (e : t) { struct e } : P e :=
> match e with
> | Base => HBase
> | Rec l x => HRec l x
> ((fix induc_rec l := match l with
> | nil => I
> | hd :: tl =>
> conj (match hd with
> | Some e => induc e (* error here *)
> | None => I
> end) (induc_rec tl)
> end) l) (induc x)
> end.
> End Induc.
>
> Coq complains that:
> In environment
> induc : forall e : t, P e
> e : t
> l : list (option t)
> x : t
> induc_rec : list (option t) -> True
> l0 : list (option t)
> hd : option t
> tl : list (option t)
> e0 : t
> The term "induc e0" has type "P e0" while it is expected to have type
> "?P@{l0:=l; l:=l0; h0:=Some e0}" (cannot instantiate
> "?P" because "e" is not in its scope: available arguments are
> "induc" "e" "l" "x" "induc_rec" "l" "hd" "tl" "Some e").
>
> I'm still investigating, but I think I need some external help on
that one :D
>
> Best regards,
> V.
- [Coq-Club] Need help for manual induction scheme definition, Vincent Siles, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Vincent Siles, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Matthieu Sozeau, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Vincent, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Matthieu Sozeau, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Vincent Siles, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Jan-Oliver Kaiser, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Dominique Larchey-Wendling, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Vincent Siles, 09/24/2019
- Re: [Coq-Club] Need help for manual induction scheme definition, Vincent, 09/24/2019
Archive powered by MHonArc 2.6.18.