coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Gaëtan Gilbert <gaetan.gilbert AT skyskimmer.net>
- To: coq-club AT inria.fr
- Subject: Re: [Coq-Club] order in fixpoint
- Date: Fri, 29 Mar 2019 00:42:58 +0100
- Authentication-results: mail2-smtp-roc.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 relay5-d.mail.gandi.net
- Ironport-phdr: 9a23:2K/l6Bzpd5FReCTXCy+O+j09IxM/srCxBDY+r6Qd2+gRIJqq85mqBkHD//Il1AaPAdyDraIZwLKJ+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhUiDanYr5/LBq6oRnTu8ILnYZsN6E9xwfTrHBVYepW32RoJVySnxb4+Mi9+YNo/jpTtfw86cNOSL32cKskQ7NWCjQmKH0169bwtRbfVwuP52ATXXsQnxFVHgXK9hD6XpP2sivnqupw3TSRMMPqQbwoXzmp8qFmQwLqhigaLT406HzZhNJ+jKxboxyvqRJwzIHWb46JO/RzZb/dcNAASGZdQspcWS5MD4WhZIUPFeoBOuNYopH8qVQUsRy+GROjBOX3xTFJh3/22bY13Po7EQHawQctGN0Ov27Ko9XpLqgSV/q5zKbJzTXHdPxZxy396JTTfxA6ovGNXalwccnQyUkqEgPKkE+QpZbjPzyLyuQAqm6W5PduW+Kojm4osQBxoj63y8g2lInGnJkVykze+Splx4Y1INu1Q1N4b968CJZcqTyWOolsTs4gX21kojs2x74ItJKhYSQHzJYqywbCZ/GEc4WE+AzvWPqQLDtimn5pZrKyiwyy/ES9zOD3S9O630xQriVfl9nBrnAN2ALX6siAUvZ95Fmu2TKV2AHT6uxIOF07mbDeK5E7w74wkoAfsUvZES/whUr2jbWadkM69ei08+jnY7PmqYGAN4JslA3yL6Yjlta9DOgkKAQCQmuW9Oqm2LH++UD0Qq1GjvgsnanYtJDaK94bpqm8AwJN3YYs8QiwDyu839Qeh3UHI1NFeBacgIf3IVHOPOv1Dey8g1WsizdrxPHGPrjkAprTNHjPirHhcqhh60JE0go80chf545ICrEGOP/8RkjxtMXBAhAlNwy03v3oBc5m1oIeXGKPGrWWPLnTsV+O/OIvIvODaJUbuDbneLAZ4KvlimZ8klsAd4Go24EWYTa2BKdIOUKcNFXlAcsIF1Alvw40Qfb2wAmNWDNPbnD0UKM47DwhFKq9DpbYRYGohbGbmiG2AssFNSh9FlmQHCKwJM2/UPAWZXfKe54zonk/TbGkDrQZ+1SrvQ7+xaBgK7OKqDYbpIng1d1w6veVkxwup2UtU5atllqVRmQxpVsmAics1fkh81d+20yA0K19juYeE9FPtasQD1UKcKXExuk/MOjcHwLMetDTFQS8T9GvEGx0QpQ0yt4KJUl0HdmjyBbOw3jyDg==
> I don't understand how is defined the order
> relation in Fixpoint definitions. The
> recursive call is in a smaller argument.
It has to be smaller in a syntactic sense, and destructing-then-reconstructing doesn't work.
Consider:
Fixpoint bla n :=
match n with
| 0 | 1 => 0
| S (S n0) => bla (S n0)
end.
this doesn't work because (S n0) is directly from the match on n
(note the error is different: since there's only 1 argument there's no guessing to do)
A fixpoint with the same meaning which is accepted is
Fixpoint bla n :=
match n with
| 0 | 1 => 0
| S (S n0 as n1) => bla n1
end.
In your case it's a bit trickier because you need the proof of nonemptiness to recurse
I guess you can use something like
Fixpoint last (A:Set)(s:queue A):
(s <> nilq _) -> A:=
match s with
| nilq _ => (fun p => (False_elim A (p (eq_refl _))))
| consq _ x y =>
fun _ =>
match y return (y <> nilq _ -> A) -> A with
| nilq _ => fun _ => x
| consq _ _ _ => fun last => last (not_eq_consq_nilq _ _ _)
end (last _ y)
end.
TBH I didn't write this in one go, I went through tactics first to figure out the layout of the thing (specifically to figure out the use of a cut around the match)
Gaëtan Gilbert
On 28/03/2019 23:51,
psperatto AT gmail.com
wrote:
I have defined a set of queues of type A
and other functions as follows:
Inductive queue (A:Set):Set :=
| nilq : queue A
| consq : A-> queue A-> queue A.
Fixpoint ins_back (A:Set)(a:A)(s:queue A):
(queue A):=
match s with
| nilq _ => consq _ a (nilq _)
| consq _ x y => consq _ x (ins_back _ a y)
end.
Theorem False_elim (A:Set)(f:False):A.
elim f.
Qed.
Fixpoint set_queue (A:Set)(s:queue A): Prop:=
match s with
| nilq _ => False
| consq _ x y => True
end.
Theorem eq_subst (A:Set)(x y :A)(P:A->Prop)
(e:(eq x y))(i:(P y)) : P x.
rewrite -> e.
exact i.
Qed.
Theorem not_eq_consq_nilq (A:Set)(x:A)
(y:queue A): not (eq (consq A x y)(nilq A)).
intro.
exact (eq_subst (queue A) (nilq A)
(consq A x y)(set_queue A)
(eq_sym H) I).
Qed.
I want to define a recursive function that
computes the last element on a non-empty
queue.
To this end I've defined:
Fixpoint last (A:Set)(s:queue A):
(not (eq s (nilq A))) -> A:=
match s with
| nilq _ => (fun p =>
(False_elim A (p (eq_refl _))))
| consq _ x (nilq _) => (fun p => x)
| consq _ x (consq _ x2 y) =>
(fun p => last _ (consq _ x2 y)
(not_eq_consq_nilq _ x2 y))
end.
I get the message:
Cannot guess decreasing argument of fix.
I don't understand how is defined the order
relation in Fixpoint definitions. The
recursive call is in a smaller argument.
Someone can help me ???
Regards,
Patricia
------------------------------------------------------------------------
Avast logo <https://www.avast.com/antivirus>
El software de antivirus Avast ha analizado este correo electrónico en busca de virus.
www.avast.com <https://www.avast.com/antivirus>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
- [Coq-Club] order in fixpoint, psperatto, 03/28/2019
- Re: [Coq-Club] order in fixpoint, Jason -Zhong Sheng- Hu, 03/29/2019
- Re: [Coq-Club] order in fixpoint, Gaëtan Gilbert, 03/29/2019
Archive powered by MHonArc 2.6.18.