coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Anton Trunov <anton.a.trunov AT gmail.com>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] recursive call
- Date: Mon, 11 Jan 2021 11:08:29 +0300
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=anton.a.trunov AT gmail.com; spf=Pass smtp.mailfrom=anton.a.trunov AT gmail.com; spf=None smtp.helo=postmaster AT mail-lf1-f46.google.com
- Ironport-phdr: 9a23:SSZ5fxGLHLSvKvkx7nVYg51GYnF86YWxBRYc798ds5kLTJ7zo8mwAkXT6L1XgUPTWs2DsrQY0rWQ6f24Ej1fqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjWwba5wIRmsswncttUajYRmJ6sz1xDEvmZGd+NKyG1yOFmdhQz85sC+/J5i9yRfpfcs/NNeXKv5Yqo1U6VWACwpPG4p6sLrswLDTRaU6XsHTmoWiBtIDBPb4xz8Q5z8rzH1tut52CmdIM32UbU5Uims4qt3VBPljjoMOjgk+2/Vl8NwlrpWrhK9qBJwzIHafY+bNPRgcKzfft0UQnFMXtpIVyxEHo+8b5cDAugHMO1Fr4f9vVwOrR6mCASwAuPv1jhIhnnr1qMkyeQhDAfG3As+H9kTt3nbttP1NLsVUeCz1qXH1y/Pb+9M2Tfg7ojIdQ4hrOqDXbJ1a8XRyE0vGxnZgVWXrIzoJjWY3fkCvGaH9eRvT/6vi3I5pAFrpDii3sgihIfNi48axF7J9SV3zZo7KNGmR0B2ZdCqHZRTuiyZOYV6XN4uTm51tSg6xLALup61cScWxJonxRPSZeGKfpWO7xn+V+iROS91iGx5dL+7nRq/8kitxvfhWsS10ltGtCVIn9jUun0O1BHf8NaLRudg8ku7xDqC1QPe5vtHLE00k6fQNoQvzaQqlpUJtETOBi/2l1vyjK+Rbkgk//Kn6+XjYrn/op+cOZJ4hhjwMqkhm8GzG+s4Mg8JX2iU/eSzyqfv8lH+QLVPlvE2k6/Zv47GJckDuKK1HwtY3pwg5hu/FTuqzdUVkHsdIF9KeR+Ll43pNEvPIPD8A/e/mVOskDJzyv/cOL3hHpLNLn7ZnLj7Z7p991RcyBc1zdBY+ZJZEb4BIPfpVU/wsNzUFAM2Mwuxw+r/EtVyypseWX6TAq+eKK7drViI5vs2L+aQYI8VpS3yJuM+5//uiH85gUUScbOo3ZsRcnC4H+5pL1+XYXr20Z89FjIBuRN7R+j3gnWDVyRSbjC8RfES/DY+XaugEYDFDry3nbqGwm/vF5tKYWYAAxaQC2rucJusVPIFaSbUKchkxG9XHYO9QpMsgEn9/DTxzKBqe7KNpn8o8Kn73d0w3NX90Ako/GUtXcuY2mCJCWpzmzFQHm5k7OVEuUV4j2y7/+19iv1cG8ZU4qoQAAg/PJ/Yied9DoKrA1+TTpKyUF+jB+6eL3QxQ9Y2mYJcZk98H5CmgEmG0Xb0RbASkLOPCdo/9aeOh3U=
By the way, Christian probably meant
Fixpoint foo (T : Type) (s : list T) :=
match s with
| x :: (y :: s') as ys' => foo T ys'
| _ => s
end.
in his example and not
Fixpoint foo (T : Type) (s : list T) :=
match s with
| x :: (y :: s' as ys') => foo T ys'
| _ => s
end.
because “as” binds stronger than “::”.
This syntax is a common source of confusion — I myself this the same thing
once too and due to
a rather weak spec all my proofs went through :)
Hope this helps,
Anton
> On 11 Jan 2021, at 00:07, Christian Doczkal <christian.doczkal AT inria.fr>
> wrote:
>
> If I understand your problem correctly, then there is a confusion about
> what is "structurally smaller". Consider the following two definitions:
>
> Require Import List.
>
> Fail Fixpoint foo (T : Type) (s : list T) :=
> match s with
> | x :: y :: s' => foo T (y :: s')
> | _ => s
> end.
>
> Fixpoint foo (T : Type) (s : list T) :=
> match s with
> | x :: (y :: s' as ys') => foo T ys'
> | _ => s
> end.
>
>
> The first one fails because "y::s'" (i.e. a combination of two terms
> "y" and "s'") is *not* considered structurally smaller than s.
>
> However, the above matches are just shorthands for two nested matches
> and one can give names to the intermediate results using "as", as shown
> above.
>
> I hope this helps!
>
> Best,
> Christian
>
> PS. It might help do minimize ones examples before posting to the
> list.
>
> On Sun, 2021-01-10 at 16:40 -0300, Patricia Peratto wrote:
>> I want to select the smallest value from a list of A elements over
>> which is defined
>> an order relation.
>>
>> I have defined:
>>
>> Theorem False_el (A:Type)(x:False):A.
>> exact (False_rect A x).
>> Qed.
>>
>> Theorem not_empty_list (A:Type)(l:list A)(q:l=nil)
>> (p:not(l=nil)): A.
>> exact (False_el A (p q)).
>> Qed.
>>
>> Inductive trich (A:Type):Type:=
>> |Lt (x y:A):trich A
>> |Le (x y:A):trich A.
>>
>> Parameter decide_trich: forall(A:Type)(x y:A),trich A.
>>
>> Definition min (A:Type)(x y:A)(z:trich A): A :=
>> match (z) with
>> | Lt _ x y => x
>> | Le _ x y => y
>> end.
>>
>> Fixpoint selsmaller (A:Type)(l:list A)
>> (p:not (l=nil)):A :=
>> match l with
>> | nil => not_empty_list A nil
>> (eq_refl nil) p
>> | cons x nil => x
>> | cons x y =>
>> let z:=(selsmaller y) in
>> min A x z (decide_trich A x z)
>> end.
>>
>> Since does not substitute l by nil in p I change the definition of
>> selsmaller in
>> the following way: I add the following definitions:
>>
>> Definition nil_cons_Prop (A:Type)(l:list A) : Prop :=
>> match l with
>> | nil => False
>> | cons x y => True
>> end.
>>
>> Parameter eq_subst : forall (A:Type)
>> (x y:A)(P:A->Prop)(q:x=y),P x-> P y.
>>
>> Theorem neq_nil_cons (A:Type)(x:A)(y:list A):
>> not(cons x y=nil).
>> intro.
>> apply (eq_subst (list A) (cons x y) nil (nil_cons_Prop A) H I).
>> Qed.
>>
>> Fixpoint selsmaller (A:Type)(l:list A):
>> (not (l=nil))->A :=
>> match l with
>> | nil => (fun (p:not(nil=nil))=>
>> not_empty_list A nil
>> (eq_refl nil) p)
>>
>> | cons x nil => (fun p =>x)
>>
>> | cons x (cons y w) =>
>> (fun p => let z:=(selsmaller A(cons y w)
>> (neq_nil_cons A y w)) in
>> min A x z (decide_trich A x z))
>> end.
>>
>> I have got the message: Cannot guess decreasing argument of fix
>> but the recursive argument (cons y w) is structurally smaller.
>>
>> I don´t know how to continue.
>>
>> Regards,
>> Patricia
>
- [Coq-Club] recursive call, Patricia Peratto, 01/10/2021
- Re: [Coq-Club] recursive call, Christian Doczkal, 01/10/2021
- Re: [Coq-Club] recursive call, Castéran Pierre, 01/10/2021
- Re: [Coq-Club] recursive call, Anton Trunov, 01/11/2021
- Re: [Coq-Club] recursive call, Christian Doczkal, 01/10/2021
Archive powered by MHonArc 2.6.19+.