I am defining three mutually recursive functions on inductive type event, using two different ways: using with and fix keywords, however, Coq complains about principal argument and The reference ... was not found in ..., respectively. Two implementations of the functions are the following:
Require Import List.
Parameter max: list nat -> nat.
Inductive event : Type := node: list event -> event.
Parameter eventbool : forall (P:event->Prop) (e:event), {P e} + {~ P e}.
Definition event_sumbool_b (e: event) (p: event -> Prop) : bool :=
if eventbool p e then true else false.
Fixpoint parentround (e: event) : nat :=
match e with
| node l => max (rounds l)
end
with rounds l :=
match l with
| nil => 0::nil
| h::tl => round h:: rounds tl
end
with round e :=
if event_sumbool_b e roundinc then parentround e + 1 else parentround e
with roundinc e :=
exists S:list event, (forall y, List.In y S /\ round y = parentround e).
Coq complains Recursive call to round has principal argument equal to "h" instead of "tl". Even though, h in calling round is a sub-term of e. Following the idea in Recursive definitions over an inductive type, I replaced parentround with the following:
Fixpoint parentround (e: event) : nat :=
let round :=
( fix round (e: event) : nat :=
if event_sumbool_b e roundinc then parentround e + 1 else parentround e
) in
let roundinc :=
( fix roundinc (e: event) : Prop :=
exists S:list event, (forall y, List.In y S /\ round y = parentround e)
) in
match e with
| node l => max (rounds l)
end
with rounds l :=
match l with
| nil => 0::nil
| h::tl => round h:: rounds tl
end.
It now complains about missing definition of roundinc.
Please help me defining these three mutually recursive functions parentround, round and roundinc.
EDIT There is a fourth function rounds in the definition, however, it is not problematic so far.
round
function: it doesn't callparentround
on a sub-term ofe
, but directly one
. I don't think this is allowed. – Vinzroundinc
, the call toround y
is not decreasing, it should be something likeround l
wheree = node l
– Vinzround
is called from withinrounds
where the sub-term ofe
(which ish
) is passed (renaminge
inround
makes no difference). When it is called from withinroundinc
, as you pointed it out,y
is not decreasing. Actually, the real function is using a complex predicatestronglysee
ony
ande
, which include thaty
is a sub-event ofe
. The problem now, in addition, is: even if we include that predicate inroundinc
, Coq does not understand automatically, thaty
is indeed a sub-term ofe
. – Khan