Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Defining merge sort

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Defining merge sort


chronological Thread 
  • From: "Yevgeniy Makarov" <emakarov AT gmail.com>
  • To: coq-club AT pauillac.inria.fr
  • Subject: Re: [Coq-Club] Defining merge sort
  • Date: Wed, 7 Nov 2007 23:00:40 +0100
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GILrSFkPt5XYpFtZbFiJIOkaWoj8fJXJ40V71bCdXAO8OmLXjvpB/Q2IhTF60KdJipb1Sf4eOaUWPme9SNYluApBqqKbnB9Xw3HLLJXUh/Spitcp5sPJ9oD+kawCP93EYEY+lJf63sFO9vvOXOZWOsT6QBAGK0iRzIVYjxung0Q=
  • List-archive: <http://pauillac.inria.fr/pipermail/coq-club/>

Hello,

I followed Benjamin's hint, and here's my version of merge on lists of
natural numbers:

Require Import List.
Require Import Compare_dec.

Fixpoint merge (l1 : list nat) : list nat -> list nat :=
fix merge_helper (l2 : list nat) :=
match l1, l2 with
| nil, nil => nil
| nil, l => l
| l, nil => l
| x1 :: l1, x2 :: l2 =>
  if leb x1 x2
  then x1 :: merge l1 (x2 :: l2)
  else x2 :: merge_helper l2
end.

However, structural recursion won't work for the mergesort itself,
where one has to recur on halfs of the list, and there Function would
be handy.

Concerning Pierre Castéran's page for mergesort, it looks a little
strange since the traditional presentation of the algorithm does not
mention trees...

Evgeny





Archive powered by MhonArc 2.6.16.

Top of Page