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: Lorenzo Gheri <lor.gheri AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] termination when branching with fmaps
  • Date: Fri, 19 Feb 2021 13:58:19 +0000
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=lor.gheri AT gmail.com; spf=Pass smtp.mailfrom=lor.gheri AT gmail.com; spf=None smtp.helo=postmaster AT mail-il1-f171.google.com
  • Ironport-phdr: 9a23:BkpfPBSLy/cHaxqyIJwQ5P9109psv+yvbD5Q0YIujvd0So/mwa69bRCN2/xhgRfzUJnB7Loc0qyK6vGmBjJLvMnJmUtBWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYdFRrlKAV6OPn+FJLMgMSrzeCy/IDYbxlViDanbr5+MRG7oR/Tu8QXjodvKqQ8wQbVr3VVfOhb2XlmLk+JkRbm4cew8p9j8yBOtP8k6sVNT6b0cbkmQLJBFDgpPHw768PttRnYUAuA/WAcXXkMkhpJGAfK8hf3VYrsvyTgt+p93C6aPdDqTb0xRD+v4btnRAPuhSwaMTMy7WPZhdFqjK9Drx2hqR5wzY7abo+WKfRwYL/ScMgASmZdRMtcTTBNDp++YoYJEuEPPfxYr474p1YWqxW+AhOsC/3pyj5JgX/9wKw00+Q/HgHc3QwrAtUDsHDTrNXvLqsSXuC1w7fSzTXCdP5W1jL955LJchAlu/2DQbVwcc/IxEQpCgjKgUmep5b/MDOJyuQCrXKb7+x4WO6yl2MqpAV8rDazysoxiITEhIwYx1/E+ylk3Io7K9K2RVB5bNO6DpZdqj2WOot0T84gXW1luTo2x7kItJC0YCQHzoksyR3Ha/GfbYSE/hbuWPySLDp4nn5pZbOyiheo/US9yODwS8+520tQoCVfiNnDrHUN2gTT6seZTvt9+V+s2TOV2ADS7uFIOEE0la7GJ5I4zL48i5gevVnZEi/5n0X2i6CWdkE69eSy9+vnZbDmqoedN49ylA7+LrwjltKjDek8KAQDXGiW9f6h2LDi/ED1WqhGg/8rnqXBtZDVP8Ubpqq3Aw9P1YYj7g6yDzOh0NQCh3UHI1JFdwydj4joIFzOL/X4Au2+g1Soijtk2/fGPrj5DpXXMnfDiKvhfap660NE1AUzyslf64tIBbEFPfL8QVT8tMfYDx88Kwy72fzrCNR71oMEWGKAGLWVMK3IsQzA2uV6KO6VIYQRpTzVKv4/5veog2Vqt0UaePyN2oEabmK/VttmLl+YKS7ohc1HHmcHpAsWQ+njiVnEWjlWMSXhF5kg7y02Xdr1RbzIQZqg1eTYjXWLW6ZOb2UDMWiiVHLhdoGKQfAJMXvALcpokzhCXr+kGdZ4iUOe8TTiwr8iFdL6vzUCvMu6htdw7uzX0xo18G4sVpnP4yS2V2hx21gwaXo20aR4+xIvz16C1e15h6UdG4UMvrVGVQA1MZOaxOt/WYj/

Hi Li-yao and All,

thank you very much for your answer. That was helpful indeed. However, the main issue there stays:

Since `br` is not a partial function, but a fmap, I cannot really do `fun x => depth (br x)`, but I must do `fun x => depth (br.[? x])`, namely what happens is not a simple function application.

Around fmaps nice results have been developed and that's why I was eager to use this type for finite branching. Has anyone tried something similar, and would be happy to share their experience?

Best,
Lorenzo




On Thu, 18 Feb 2021 at 19:25, Li-yao Xia <lysxia AT gmail.com> wrote:
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