coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Pierre Courtieu <pierre.courtieu AT gmail.com>
- To: Coq Club <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] Mutually recursive functions with a decreasing measure
- Date: Tue, 22 Sep 2015 15:31:15 +0200
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=pierre.courtieu AT gmail.com; spf=Pass smtp.mailfrom=pierre.courtieu AT gmail.com; spf=None smtp.helo=postmaster AT mail-wi0-f169.google.com
- Ironport-phdr: 9a23:1BzpFxD6lNx3nKI32YaeUyQJP3N1i/DPJgcQr6AfoPdwSP78oMbcNUDSrc9gkEXOFd2CrakU16yK6+u+BCQp2tWojjMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3DwdpPOO9QteU1JTrkbzqsMOOKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6WZgyWrlAYT29exhFPGk3O6Azwdpb3qCrz8ORnjnq0J8rzGIg1VC644u9ATwLylCYKKnZt6GDakNZ9yqlcvQi9phFi64HRaYCRcvF5e/WOLpshWWNdU5MJBGR6CYSmYt5KVrJZMA==
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 timethat 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)) inac_aux R0 (length l2 - 1)| _ , _ => Falseend.
There is a typo here, you should use ac_rec2. But it works anyway.
Why do you call this nested recursion?
Solve All Obligations withsplit; 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 witha 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))) inac_aux R0 (length l2 - 1)| (_ , _) => Falseend.
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 :=
...
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
- [Coq-Club] Mutually recursive functions with a decreasing measure, Washington Ribeiro, 09/17/2015
- <Possible follow-up(s)>
- [Coq-Club] Mutually recursive functions with a decreasing measure, Washington Ribeiro, 09/20/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Pierre Courtieu, 09/22/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Washington Ribeiro, 09/22/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Pierre Courtieu, 09/23/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Washington Ribeiro, 09/23/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Pierre Courtieu, 09/23/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Washington Ribeiro, 09/22/2015
- Re: [Coq-Club] Mutually recursive functions with a decreasing measure, Pierre Courtieu, 09/22/2015
Archive powered by MHonArc 2.6.18.