coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Julien Forest <forest AT ensiie.fr>
- Cc: "Ashish Darbari" <ashish AT darbari.org>, coq-club AT pauillac.inria.fr
- Subject: Re: [Coq-Club] Defining recursive functions
- Date: Thu, 1 Jan 2009 18:21:23 +0100
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:cc:subject:message-id:in-reply-to:references :organization:x-mailer:mime-version:content-type :content-transfer-encoding; b=c0Fw9rOzkC1ZBq10eZJeZIhUk7w2DexwgE+iM35nTUTp7ATPiLtNNJFMj8hy9AzmXZ DVvjCmu6NfHi81lUS5Z7zE/ag9uuRgEX/JcqXSg6DIKeNwSJMYbZcO5GDx8dr94X37cy 92C+W9ghzN5X5qoVl7J9jfzAaD6tzNUSSbm9U=
- List-archive: <http://pauillac.inria.fr/pipermail/coq-club/>
- Organization: CNAM
Happy new year to all of you.
Dear Ashish, you can use Function to define your function:
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 := *)
Require Import Recdef.
Function snarf (acc:list Z) (l1_l2: list Z * list Z){measure lsum l1_l2}:list
Z
:=
match l1_l2 with
| (nil,_) => acc
| (_,nil) => acc
| ((x::xs),(y::ys)) =>
match Z_eq_dec x y with
| left _ => snarf (x::acc) (xs,ys)
| right _ =>
match Z_le_gt_dec x y with
| left _ => snarf (x::acc) (xs,y::ys)
| right _ => snarf acc (x::xs, ys)
end
end
end.
Proof.
abstract(intros; simpl;omega).
abstract(intros; simpl;omega).
abstract(intros; simpl;omega).
Defined.
On Wed, 31 Dec 2008 15:14:20 -0800
Taral
<taralx AT gmail.com>
wrote:
> 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
>
> --------------------------------------------------------
> Bug reports: http://logical.futurs.inria.fr/coq-bugs
> Archives: http://pauillac.inria.fr/pipermail/coq-club
> http://pauillac.inria.fr/bin/wilma/coq-club
> Info: http://pauillac.inria.fr/mailman/listinfo/coq-club
- Re: [Coq-Club] Defining recursive functions, Taral
- Re: [Coq-Club] Defining recursive functions, Matthieu Sozeau
- Re: [Coq-Club] Defining recursive functions, Julien Forest
- <Possible follow-ups>
- Re: [Coq-Club] Defining recursive functions,
muad
- Re: [Coq-Club] Defining recursive functions, Ashish Darbari
- Re: [Coq-Club] Defining recursive functions, vsiles
Archive powered by MhonArc 2.6.16.