Skip to Content.
Sympa Menu

coq-club - [Coq-Club] Defining three mutually recursive functions on inductive type in Coq

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

[Coq-Club] Defining three mutually recursive functions on inductive type in Coq


Chronological Thread 
  • From: Wilayat Khan <wilayatk AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: [Coq-Club] Defining three mutually recursive functions on inductive type in Coq
  • Date: Mon, 19 Sep 2016 16:58:20 +0500
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=wilayatk AT gmail.com; spf=Pass smtp.mailfrom=wilayatk AT gmail.com; spf=None smtp.helo=postmaster AT mail-lf0-f51.google.com
  • Ironport-phdr: 9a23:uBh1pRc4GPbLA82rf8WNOsMklGMj4u6mDksu8pMizoh2WeGdxc6/Zh7h7PlgxGXEQZ/co6odzbGH6uawBSdbsN7B6ClEK80UEUddyI0/pE8JOIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0IufrymUrDbg8n/7e2u4ZqbO1wO32vkJ+MuZ07n5UWJ749N0NMkcv5wgjLy4VJwM9xMwm1pIV/B1z3d3eyXuKBZziJLpvg6/NRBW6ipN44xTLhfESh0ezttvJ6j5lH/Sl6E4WJZWWELmDJJBRLE5Vf0RMTfqCz/49V83CCLNNG+brA9X3z28KZvQQ7hlCQvODsw8WWRgct12vEI6Cm9rgByltaHKLqeM+BzK/vQ

Hello 
  I am defining three mutually recursive functions in Coq on list of events (trees), however, I get the termination error. Here is my definition:

Require Import List.

Inductive event : Type := node: list event -> event. 

Parameter listmax: list nat -> nat.
Parameter eventbool : forall (P:event->Prop) (e:event), {P e} + {~ P e}.
Parameter stronglysee : event -> event -> Prop. 

Fixpoint parentround (e: event) : nat :=
  match e with
 | node l =>  listmax (map round l)
 end
   
 with round e := match (eventbool roundinc e) with 
   | left _ => parentround e + 1
   | right _ => parentround e
   end    

 with roundinc e :=   
  exists S:list event, 
    (forall y, List.In y S /\ round y = parentround e /\ stronglysee e y).


Each call to round inside parentround gets an event which is the sub-term of original event and recursive calls to parentround inside roundinc gets event again a sub-term of original event. The call to round inside roundinc is a bit tricky. According to the definition of stronglysee, if  stronglysee e  y then it means y is a sub-term of e. To ensure, event e is decreasing in each recursive call, a relation can be defined on the function below: 

Fixpoint generation (e: event) : nat := 
 match e with 
 | node l => match l with
     | nil => 0
     | x::xs => 1 + listmax (map generation l)
     end
 end.

Where the generation of event in each call is decreasing. A lemma such as 
 Lemma ordersee: forall x y, stronglysee x y -> generation x > generation y.
 need to be proved. 

QUESTIONS: 
1) Can I instead define parentround as inductive type? Keeping in mind, the function returns a nat value, which will later be used in functions such as max : nat -> nat -> nat
2)  Is the approach 'accessibility predicates'  (as mentioned by Chlipala) suitable? The generation function above can be used in the order relation required, however, the reasoning might be very cumbersome as pointed in [https://www.irisa.fr/celtique/pichardie/papers/flops06.pdf]. 
3) Any other easy way to define this function in Coq? 

Thanks, 

Wilayat




Archive powered by MHonArc 2.6.18.

Top of Page