Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] termination when branching with fmaps

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] termination when branching with fmaps


Chronological Thread 
  • From: Li-yao Xia <lysxia AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] termination when branching with fmaps
  • Date: Thu, 18 Feb 2021 14:25:10 -0500
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=lysxia AT gmail.com; spf=Pass smtp.mailfrom=lysxia AT gmail.com; spf=None smtp.helo=postmaster AT mail-vs1-f49.google.com
  • Ironport-phdr: 9a23:wzX9cBG+B7BuYKsXjen/4p1GYnF86YWxBRYc798ds5kLTJ7zp8ywAkXT6L1XgUPTWs2DsrQY0ruQ7PyrBjdIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfLd/IA+0oAjeucUbg4VvIbstxxXUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vyiu47ttRRT1jioMKjw3/3zNisFokaxVvhyhqRx8zYDabo6aO/hxcb/Sc94BWWpMXdxcWzBdDo6ybYYCCfcKM+ZCr4n6olsDtR2wBQi1COLv0DBIgWL90qw70+s7DArL2wggHtIVsHXbrdX6LrwfUe+wzKbSzDXDa+la1iv66IjNax0sp+yHUr1sf8TL00YvCx/FgUuKqYzjJz6b2fgAvmiZ4ud8Se6hi24pph9xrDWrxMoiipTFipwbx13K+ih0wIk7KMOkRUN0btOoDJ9duSGYOoZ2TM0vXX1ktSAnwbMFoZ62ZDYGxIgjyhLFaPGKc5KE7gz+WOuTOzt1i3ZodKqiixu98EWs0PDwWtS63VpQsyZJjN3BumoQ2xDN9MSKTOZ28F271jaVzQ/T7/lJIUAqmqrfLJ4s2rswmYASsUTHByP2hl72gLKPekUq9eWl7/7rYrrhpp+bOI90jh/xPr4ylcy4BOQ0KgkOX26F9uSgzLDv41H1TbFQgvA1kqTVqo7WKdkZq6KjDAJY1p4v6xOlADen1NQYk2MHLFVAeB+fi4joO0rOIf/5DfilmFmsnzJryOrHPr3lGJnCMn/DkLL5cbZn90Fc0BYzzcxY559MFr4BJ+vzVlbtu9zcEx82KBe5w/3nCdV4zoMRQ3iDAq6fMKPIsF+H/PgjI+eWZNxdhDGoIP88ovXqkHURmFkHfKDv04FERmq/G6FCIgCIaH2kstYIWTMOrxEuTeXCh1iLUDoVbHG3CfFvrgonAZ6rWN+QDrumh6aMiX/iT89mI1teA1XJKk/GMoCNWvMCciWXe5YznTkNVLznQIgkh0j36V3KjoF/J++RwRU28JLu0N8vur/WnBA2sCJvVoGTjzDLQGZzkWcFATQx2fIn+BAv+hK4yaF9xsdgO5lL/foQC1U1MJfdy6pxDNWgAg8=

Hi Lorenzo,

For fixpoints on nested inductive types, you must make sure to apply your function to a subterm. In your case, that means `depth` must end up applied to `br x` for any `x`.


> Fixpoint depth (T : fmap_tree) : nat :=
> match T with
> | fmap_leaf n => 0
> | fmap_node n br => (maxn_f_codom id (fun x => depth (br x))).+1
> end.


Now it is clear that the only location where `depth` is called recursively is in fact good. The exact rules are a little looser than that, but then you have to be aware of those rules and of the precise definition of every function that separates `depth` from `br`; it's not sufficient to understand what those functions do extensionally.

Cheers,
Li-yao

On 2/18/2021 1:32 PM, Lorenzo Gheri wrote:
Hi All,

I have defined the following datatype:

  From mathcomp.ssreflect Require Import all_ssreflect.
  From mathcomp Require Import finmap.
  Open Scope fset.
  Open Scope fmap.

  Inductive fmap_tree :=
  | fmap_leaf (n : nat)
  | fmap_node (n : nat) (branching : {fmap nat -> fmap_tree}).

I would really like to keep this definition, namely to use finite maps (fmap from the math-comp libraries) instead of lists. I however run into problems when defining depth:

  Definition maxn_f_codom {A:Type} (f: A -> nat) (br: {fmap nat -> A}):=
    foldr maxn 0 (map (fun x=> match (br.[?x]) with
                                | None => 0
                                | Some T' => f T'
                                end)
           (enum_fset (domf br)) ).


  Fixpoint depth (T : fmap_tree) : nat :=
    match T with
    | fmap_leaf n => 0
    | fmap_node n br  => (maxn_f_codom depth br).+1
    end.

In particular the definition of maxn_f_codom above---which could as well be inlined in the depth definition---is accepted by Coq with no issues, but the Fixpoint for depth is ill-formed. I thought I could easily use enum_fset for turning the finite domain of the fmap into a list and then termination would have been guaranteed. I was being too naif! :)

Before I give up altogether and go back to branching with lists, is there any way for me to convince Coq that fmaps are OK as well?

Many thanks,
Lorenzo






Archive powered by MHonArc 2.6.19+.

Top of Page