Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Mutually recursive functions with a decreasing measure

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Mutually recursive functions with a decreasing measure


Chronological Thread 
  • From: Washington Ribeiro <wtonribeiro AT gmail.com>
  • To: coq-club AT inria.fr
  • Cc: Pierre Courtieu <pierre.courtieu AT gmail.com>
  • Subject: Re: [Coq-Club] Mutually recursive functions with a decreasing measure
  • Date: Tue, 22 Sep 2015 16:53:53 -0300
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=wtonribeiro AT gmail.com; spf=Pass smtp.mailfrom=wtonribeiro AT gmail.com; spf=None smtp.helo=postmaster AT mail-yk0-f179.google.com
  • Ironport-phdr: 9a23:jWjnBxCjkP9WZhUe94W4UyQJP3N1i/DPJgcQr6AfoPdwSP79oMbcNUDSrc9gkEXOFd2CrakU16yK6+u5BTdIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/ni6buo9aKP14ArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIZoGJ/3dKUgTLFeEC9ucyVsvJWq5lH/Sl6E4WJZWWELmDJJBRLE5Vf0RMTfqCz/49V0wymbO8LqSrZ8YzWo4qZxT1e8lzsAMSQ4+mzWkMtYg6dSoRbnrBt6ld2HKLqJPeZzK/uONegRQnBMC4MID3RM

Sorry Pierre, 

I didn't understand but my problem is that in my proofs I am using another structure (a term signature) to compare modulo AC. So the simplest way I see to do this is with nested recursion. There is no way to do proofs with simplification and Program Fixpoint definitions?

Best,
Washington



2015-09-22 10:31 GMT-03:00 Pierre Courtieu <pierre.courtieu AT gmail.com>:
Hi Washington,

2015-09-20 0:55 GMT+02:00 Washington Ribeiro <wtonribeiro AT gmail.com>:
Here is an example of the problem with defining recursive functions.  Is a recursive function that checks if two lists of naturals ar AC-equivalent.


Require Import List.
[...]

(* Here using Program Fixpoint one can defines a measure at the same time
 that has nested recursion *)
Program Fixpoint ac_rec2 (l l' : list nat) {measure (length l)} : Prop :=
match l,l' with

 | nil, nil => True

 | n1::l1, l2  => let R0 (i:nat) := (n1 == (nth i l2 0)) /\ 
                                    (ac_rec1 l1 (rem_ith i l2)) in 
                                     ac_aux R0 (length l2 - 1)

 | _ , _ => False

end.


There is a typo here, you should use ac_rec2. But it works anyway.
Why do you call this nested recursion?

 
Solve All Obligations with
split; intros; intro Q; case Q; clear Q; 
intros Q1 Q2; inversion Q1; inversion Q2.

(* Now isn't possible to simplify with non-ground terms *)
Lemma ac_ind_to_ac_rec2 : forall l l' , ac_ind l l' <-> ac_rec2 l l'.
Proof.
 intros. split; intro. induction H.
 compute. trivial. 
 compute. Admitted.

(* Defining a measure for the pair L *)
Definition left_length (L : list nat * list nat) := length (fst L).


(* And with Function it is possible to have a recursive function with 
 a decreasing measure but nested recursion isn't allowed *)

(* Output:
Toplevel input, characters 0-340:
Error: the term fun i : nat => n1 == nth i l2 0 /\ ac_rec3 (l1, rem_ith i l2) 
can not contain a recursive call to ac_rec3
*)

Function ac_rec3 (L : list nat * list nat) {measure left_length} : Prop :=
match L with
 | (nil, nil) => True
 | (n1::l1, l2)  => let R0 (i:nat) := (n1 == (nth i l2 0)) /\ 
                                      (ac_rec3 (l1, (rem_ith i l2))) in 
                                       ac_aux R0 (length l2 - 1)
 | (_ , _) => False
end.


Indeed Function does not support nested recursion. Actually here recursive calls are nested but not the decreasing argument so this is "gentle" nested recursion.

A remark here, Function supports multiple arguments, use the syntax (slightly different syntax in the curly brackets): 

Program Fixpoint ac_rec3 (l l' : list nat) {measure length l} : Prop :=
...




From: Washington Ribeiro <wtonribeiro AT gmail.com>
To: coq-club AT inria.fr
Subject: [Coq-Club] Mutually recursive functions with a decreasing measure
Date: Thu, 17 Sep 2015 09:47:36 -0300

Dear,

It's possible to define in Coq a mutually recursive function with a decreasing measure and with a automatically generated rewriting equation?

I've used three different kind of definitions as follow:

 

 

Muttually recursive

Decreasing measure

Rewriting equation

Fixpoint

Yes

No

Yes

Function

No

Yes

Yes

Program Fixpoint

Yes

Yes

No



So my problem is that I never have a definition with a automatically generated rewriting equation that allows to explicit a decreasing parameter and that is muttually recursive.

Best,
Washington





Archive powered by MHonArc 2.6.18.

Top of Page