Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Need help for manual induction scheme definition

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Need help for manual induction scheme definition


Chronological Thread 
  • From: Vincent Siles <vincent.siles AT ens-lyon.org>
  • To: Coq-Club Club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Need help for manual induction scheme definition
  • Date: Tue, 24 Sep 2019 18:10:46 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=vincent.siles AT ens-lyon.org; spf=None smtp.mailfrom=SRS0=tghc=XT=ens-lyon.org=vincent.siles AT bounce.ens-lyon.org; spf=Pass smtp.helo=postmaster AT sonata.ens-lyon.org
  • Ironport-phdr: 9a23:+s6V/BUbpQBw1ilJuhnfnqn0Of/V8LGtZVwlr6E/grcLSJyIuqrYbByFt8tkgFKBZ4jH8fUM07OQ7/m7HzdYqsfa+Fk5M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aFRrwLxd6KfroEYDOkcu3y/qy+5rOaAlUmTaxe7x/IAi4oAnLuMQanYRuJ6I/xxDUvnZGZuNayH9yK1mOhRj8/MCw/JBi8yRUpf0s8tNLXLv5caolU7FWFSwqPG8p6sLlsxnDVhaP6WAHUmoKiBpIAhPK4w/8U5zsryb1rOt92C2dPc3rUbA5XCmp4ql3RBP0jioMKiU0+3/LhMNukK1boQqhpx1hzI7SfIGVL+d1cqfEcd8HWWZNQsNdWipcCY2+coQPFfIMMulWr4b/p1UAoxiwCxSyCuzz0TJHnGP60Lcg3ug9DQ3L3gotFM8OvnTOq9X1Mb8fXu+0zKnO0TrMcfVW2Svg44bVcxAhpe+DXaltesfW10kvFgXFgUmOpozjIzOZzP8Ns2mf7+V+TuKikHAoqwdqojS2wsctio7JhoQPxlDD7yV5z584KNulQ0B4ed6pCIZcui6GO4dsQM4vQXtktDs7x7AHo5K3YSYHxZc/yxLBd/CKd5KE7xHjWeqLPDt1hXNodKiwihuw90Wr1/fyWdOu0FlQqypIitnMuW4J1xzU8sWHUfx9/kG71jaTzQ/f8P9LIUYvlabCL54gwrkwlpwJvUTEBC/2l136jK6Qdko65uil8/nrb7r6qpOGNYJ5iBvyPrkvl8G+G+g0LwYDUmuD9eS5zrLj/En5QLtQjv0xl6nUqI3UK9gGqKKlGwJVzokj6xajADq+0dsWg2EKI0xDeBKcloTpP1HPIPf+DfulhFSsijhryujYPr3gBJXCMmbMkLH9fbpn8E5cyQ4zws5E559PEb4BJ+/zWkntu9PGFBM2LQq0w/3+BNV51oIeXmSPDrWeMKPIvl+E/vgvLPWUZI8JpDb9LOAo6OLpjX8ggFMSYa2p3YYMZ32jBfRnI0CZYWL2jdsbEGcKuBA+TO3wh1GYXz5TfSX6Y6VpzTYiTamiEI2LbYSwivTV1yCiW5ZSe2puC1aWEH6ueZ/SCNkWbyfHHM5nmTECSfCaSosszln6qg78wLdhMqzP+ykVrrru0sMw4/zUk1c17zMiXJfV6H2EU2whxjBAfDQxxq0q5BUlkg7eg5g9uORREJlo390MUgo+MsSFnfd9DdnuU0TMeMzMTEehRJOhGz5jF4ttke9LWF50HpCZtj6GxzCjWuNHmrqQQZgl9aSa2GL+dZ4kmiT2kZI5hlxjefNhcGivh6px7Q/WXdebmUKEka2nM6kax2vJ5WCFi22UsxMAXQ==

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> 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> 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.




Archive powered by MHonArc 2.6.18.

Top of Page