unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Keith Wright <kwright@gis.net>
Subject: Re: sorting by a partial order
Date: Wed, 30 Oct 2002 01:34:45 -0500	[thread overview]
Message-ID: <200210300634.g9U6Yj401336@fcs9.free-comp-shop.com> (raw)
In-Reply-To: <E186jRf-0003pY-00@giblet> (message from Thien-Thi Nguyen on Tue, 29 Oct 2002 19:23:03 -0800)

> From: Thien-Thi Nguyen <ttn@giblet.glug.org>
> 
>    From: prj@po.cwru.edu (Paul Jarc)
> 
>    I have a two-place predicate that defines a partial order (i.e., it is
>    possible that neither is A less than B nor is B less than A).
> 
> this use of "partial order" is different from what i've read
> about in the sorting literature.  a "poset" (partial order set)
> is not defined by a predicate if the number of "places" in that
> predicate is less than the number of items in the set, even
> though the set may indeed be in partial order.  i guess i'm
> confused about the word "defines" here.

I don't know what you have been reading, but Paul's use of "poset"
is in exact agreement with the standard mathematical definition
for most of a century, to wit: a poset is a set 'S' together
with a binary relation '<=' which is reflexive (x<=x),
antisymetric (if x<=y & y<=x then x=y), and transitive
(if x<=y & y<=z then x<=y).  I can't define "defines" to somebody
confused about definitions.

>    I want to sort a sequence of items according to that predicate, so
>    that if A occurs before B in the result, then B is not less than A
>    according to the predicate.

Knuth, Art of Computer Programming Vol 1, Fundamental Algorithms, 2.2.3
calls this a topological sort.  I'm not sure if anybody else does.

>    * Can sort, stable-sort, sort-list, etc., deal with a partial order
>      for the less procedure, or must it be a full ordering?
> 
> here i am again confused about using "partial order" to describe the
> predicate.

I'm not confused, but I don't know the answer.  A glance at the
source---the comments say it uses quick sort, which works by
recursively choosing an item and partitioning the array into those
less than and those greater (or not less than) the chosen item.
My guess is that would not work unless given a total order.
At best it would take very careful programming to make it work,
so if the author, who writes beautiful comments, does not brag
about doing it, it's probably because he never thought of doing it.

>    * My predicate is actually not quite a partial order because it is
>      not transitive.  Is there any existing code for constructing the
>      transitive closure of a relation?

I think that's harder than sorting (in terms of running time, not
programming difficulty).  The algoriths are short, the problem
is the form in which the data is presented and how you need the
answer.  Knuth's algorithm does the topological sort on any set
of pairs which generates the partial order as its transitive
closure.  It is surely more efficent to do this, starting with
as few pairs as possible, than to try to pump it up to the transitive
closure before beginning.  You do need to be able to store a
table of size proportional to the number of pairs of item related
by <= and to loop through all items, is that a problem?

-- 
     -- Keith Wright  <kwright@free-comp-shop.com>

Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
         ---  Food, Shelter, Source code.  ---


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2002-10-30  6:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-29 20:33 sorting by a partial order Paul Jarc
2002-10-30  3:23 ` Thien-Thi Nguyen
2002-10-30  6:34   ` Keith Wright [this message]
2002-10-30  7:27     ` Thien-Thi Nguyen
2002-10-30  7:43       ` Thien-Thi Nguyen
2002-10-30 17:12     ` Paul Jarc
2002-10-31 10:22       ` rm
2002-10-31 17:41         ` Paul Jarc
2002-11-06 13:12       ` Mikael Djurfeldt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200210300634.g9U6Yj401336@fcs9.free-comp-shop.com \
    --to=kwright@gis.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).