Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Defining recursive functions

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Defining recursive functions


chronological Thread 
  • From: Taral <taralx AT gmail.com>
  • To: "Ashish Darbari" <ashish AT darbari.org>
  • Cc: coq-club AT pauillac.inria.fr
  • Subject: Re: [Coq-Club] Defining recursive functions
  • Date: Wed, 31 Dec 2008 15:14:20 -0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=PCF0Pv8vS8MpunC/gAPEb/rNumw2oKmi8X0AlOait4+7j2bqFZrLSYG24e1DeXuR1g 6rQjhYJkrdR+Zv8OcGY/vsywMKVeQtUoiJ6/hv116/ctw3jDjqrMFL/MblgvqMVwWaQN 0rzalPb5rBnuI8wVCnx4e+2qJEu2yagRiqLFM=
  • List-archive: <http://pauillac.inria.fr/pipermail/coq-club/>

On Wed, Dec 31, 2008 at 1:09 PM, Ashish Darbari
<ashish_darbariuk AT yahoo.co.uk>
 wrote:
> Is there a way to define functions like these (using Fixpoint) by
> providing a measure function like (length l1 + length l2) which will
> decrease in each call.

You want Program Fixpoint. But you still have to merge the recursive 
arguments:

Definition lsum (l : list Z * list Z) := match l with (l1, l2) =>
length l1 + length l2 end.

Program Fixpoint snarf (l: list Z * list Z) (acc:list Z) {measure lsum
l} : list Z :=
  match l with
    | (nil,_) => (acc)
    | (_,nil) => (acc)
    | ((x::xs),(y::ys)) =>
      match Z_eq_dec x y with
        | left _ => snarf (xs, ys) (x::acc)
        | right _ =>
          match Z_le_gt_dec x y with
            | left _ => snarf (xs, y::ys) (x::acc)
            | right _ => snarf (x::xs, ys) acc
      end
  end
end.

(Does anyone know why this breaks if the arguments are in the original
order? It appears to be a bug in Program.)

-- 
Taral 
<taralx AT gmail.com>
"Please let me know if there's any further trouble I can give you."
    -- Unknown





Archive powered by MhonArc 2.6.16.

Top of Page