Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Program Fixpoint and Nested fix expressions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Program Fixpoint and Nested fix expressions


Chronological Thread 
  • From: Gert Smolka <smolka AT cs.uni-saarland.de>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Program Fixpoint and Nested fix expressions
  • Date: Mon, 14 Sep 2020 19:44:28 +0200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=smolka AT cs.uni-saarland.de; spf=Pass smtp.mailfrom=smolka AT cs.uni-saarland.de; spf=None smtp.helo=postmaster AT triton.rz.uni-saarland.de
  • Ironport-phdr: 9a23:gpeLmhwSNIWuuBLXCy+O+j09IxM/srCxBDY+r6Qd2+0TIJqq85mqBkHD//Il1AaPAdyFrase16GG6ujJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVhTexe65+IAu5oAnetcQanJZpJ7osxBfOvnZGYfldy3lyJVKUkRb858Ow84Bm/i9Npf8v9NNOXLvjcaggQrNWEDopM2Yu5M32rhbDVheA5mEdUmoNjBVFBRXO4QzgUZfwtiv6sfd92DWfMMbrQ704RSiu4qF2QxLulSwJNSM28HvPh8JwkK1Vrx2uqQFxzY7afo+aNvlwcKTGcNMGXGpBW9pdVyxdDo6+aYYEEuoPPfxfr4n4v1YArAWxBROwBOjy1zFIg3j23ak50+s7DArL2xcgH9cJsHTQr9X6LrwfXvyuzKXS0DXDafJW1S7m6IfSaB8hu/WMUqh2ccXM00UgCh3Kg0yWpIf4MDybyv4DvHKH7+p8S+2vkWgnphl+rDWr2sohio3Ei58ax13a9Sh0xJg5KN68RUN5Y9OpE4Vduj2bOoZ3Qs4vXm5ltiY7x7AIvZO3YicExZo5yhPdbfGMboaG4hXmVOmLIDd4gmpoeLO5hxao8Eiv0PfwVseu0FtMsyFLkcHMu2gQ2xHd5cWLUP9w80a71TuNzQzf9OFJLVgqmabGKZMt2L09moQJvUnHHyL6glv6ga6Qe0454Oan8f7nba/jppKEN497lAX+MqM2l8yjG+Q4MxQOX2+d+eimzr3i/Ff1QKhMjv03i6XZq4rVKt4Bpq69GQBV1Jss5wyiADi4yNgYnH8HI0xZeB+fkoTkNV7DLOr8APq+mVihki1ny+7GM7H5B5XCNHnDkLPvfbZn7E5czRI+zcta55JTDrEBI+j8V1Ttu9zDFBM5Lgq0w+f+BNVmzIwRQ3iPAquDP6PUrFCE/P8gLPeUaI8PpDn9M+Ql5+LpjXIhhVAderCp0YILZ3C8A/RpOF6UYWHsg9cECWcFpBAyTO3siF2YUD5cfWy+X6wm5mJzNIXzBoDaA4upnbap3SGhH5QQaHoVJEqLFCLHep+YE8wJbyaRK4c1iTkDUbuoY4Q6kwyotUrhwrN9KuPS9msUuMSwh5BO++TPmERqpnRPBMOH3jTVFjAmriYzXzYzmZtHjwl4w1aH37J/hqYAR9dIoe5PU0IhPJfGy+V8B5b+V1CYJ4rbeBOdWtyjRAoJYJcxztsJORkvB8+jkhfFmTC4RaITlvmQDZUu9qva0z79KpQlkiqU5Owal1AjB/B3Gyi+nKclr1rYHMjUlUTcjK+jb6AV2iKL+GrRlWc=


> On 14. Sep 2020, at 18:42, Christian Doczkal <christian.doczkal AT inria.fr>
> wrote:
>
> Unfortunately, I don't remember the precise rules that make this definition
> okay. It's something along the lines of "l" being structurally smaller than
> "a" and "flatten_list" applying flatten only to arguments that are
> "structurally no greater than y". However, this seems to not be covered by
> relevant section of the current manual:
> https://coq.inria.fr/refman/language/core/inductive.html#id10
>
> Maybe someone can chime in and provide the precise rules making this legal.

Smiley! What you are referring to is the guard condition, which was extended
over the years but never documented.
Anyway, nested inductive types (e.g., rose trees) are impossible without the
extended guard condition.

BTW, someone should delete the reference to Giménez in the reference Manual:
"Before accepting a fixpoint definition as being correctly typed, we check
that the definition is “guarded”. A precise analysis of this notion can be
found in [Gimenez94].”
At this point there was only a minimal guard condition.

I’m intrigued by Dominique’s idea to define the eliminator for rose trees
with ACC. Below is a minimal version.
It shows that the extended guard condition can be quite nice.

Cheers, Gert


Inductive tree := T (A: list tree).
Implicit Type s t: tree.

Definition dst s t := let (A) := t in In s A.

Fixpoint tree_Acc t: Acc dst t.
Proof.
destruct t as [A].
constructor.
induction A as [| t A IH]; cbn.
- intros t [].
- intros s [[]|H].
+ apply tree_Acc.
+ apply IH, H.
Defined.

Eval cbv -[dst] in tree_Acc.



>
> By the way, one can also make this slightly more readable by factoring out
> flatten_list.
>
> -------------------------------------------------
>
> Definition flatten_list (f : arb -> list nat) : list (nat * arb) -> list
> nat :=
> (fix flatten_list (arbs : list (nat * arb)) : list nat :=
> match arbs with
> | [] => []
> | (n',a')::arbs' => n' :: (f a' ++ flatten_list arbs')
> end).
>
> Fixpoint flatten (a : arb) : list nat :=
> match a with
> | A n => [n]
> | B n l => n :: flatten_list flatten l
> end.
>
> -------------------------------------------------
>
> This pattern is used extensively throughout the mathematical components
> library. Note that replacing the definition with the more standard
>
> Fixpoint flatten_list (f : arb -> list nat) (arbs : list (nat * arb)) :=
> ...
>
> does *not* work, because this would lead to "flatten" not being applied to
> any arguments in the clause for "B", even after the reduction that is
> happening before checking the guard condition.
>
> Best,
> Christian
>
> On 9/14/20 9:28 AM, Tj Barclay wrote:
>> Enclosed is an arbritrary example (Coq 8.11.2) of an attempt to show
>> termination of a recursive function on the size of a nested-recursive
>> datatype.
>
>> (* Function in question *)
>> Program Fixpoint flatten (a : arb) {measure (size_arb a)}: list nat :=
>> match a with
>> | A n => [n]
>> | B n l => n :: (fix flatten_list (arbs : list (nat * arb)) : list nat :=
>> match arbs with
>> | [] => []
>> | (n',a')::arbs' => n' :: (flatten a' ++ flatten_list
>> arbs')
>> end) l
>> end.
>> Obligation 1.
>> (* Example End *)




Archive powered by MHonArc 2.6.19+.

Top of Page