From ok@atlas.otago.ac.nz Tue Dec 11 02:24:05 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.6/8.11.2) with ESMTP id fBB1O3521489
	for <prolog@swi.psy.uva.nl>; Tue, 11 Dec 2001 02:24:03 +0100 (MET)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id OAA502293;
	Tue, 11 Dec 2001 14:23:59 +1300 (NZDT)
Date: Tue, 11 Dec 2001 14:23:59 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200112110123.OAA502293@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, ss@alesig.de
Subject: Re:  [SWIPL] hello,problem with next of min

Sebastian Schneider <ss@alesig.de> wrote:
	i try the following:
	
	- find the min of two list

What do you mean?  What _is_ "the min of two list"?
What exactly did you _do_?

	- find the next min from two list without the first min

What do you mean?  What _is_ "the next min"?
What exactly did you _do_?  (See below.)

	- save all min
	
I haven't the least idea what this means.  What did you do?

	the first and the last works, but not the second, can anybody
	help me please?
	
Help us to help you.
	
"The" minimum element of a list is not terribly well defined.
What is the comparison?  Is it arithmetic comparison or term comparison
or something else?  If the smallest value occurs more than once, which
do you take (an important question when comparison doesn't examine
an entire term but just part of it)?

I'm assuming

    min([X|Xs], Min) :-
        min_loop(Xs, X, Min).

    min_loop([], Min, Min).
    min_loop([X|Xs], Min0, Min) :-
        ( X @< Min0 -> Min1 = X ; Min1 = Min0 ),
        min_loop(Xs, Min1, Min).

"The next min from a list without the first min"
could mean to find the next smallest element (_however_ many copies
of the first value there are) or it could mean to find the smallest
element (if the first/last/some other specified copy of the value
were removed).

/*  min_except(Xs, Avoid, Min) :-
        append(Before, [Avoid|After], Xs),    
        !,
        append(Before, After, Ys),
        min(Ys, Min).
*/
    min_except([X|Xs], X, Min) :- !,
        min(Xs, Min).
    min_except([X|Xs], Avoid, Min) :-
        min_except_loop(Xs, Avoid, X, Min).

    min_except_loop([], _, Min, Min).
    min_except_loop([X|Ys], X, Min0, Min) :- !,
        min_loop(Xs, Min0, Min).
    min_except_loop([Y|Ys], X, Min0, Min) :-
        ( Y @< Min0 -> Min1 = Y ; Min1 = Min0 ),
        min_except_loop(Ys, X, Min1, Min).

/*  min_above(Xs, Avoid, Min) :-
        findall(Y, (member(Y, Xs), Y @> Avoid), Ys),
        min(Ys, Min).
*/
    min_above([X|Xs], Avoid, Min) :-
        ( X @> Avoid ->
            min_above_loop(Xs, Avoid, X, Min)
        ;
	    min_above(Xs, Avoid, Min)
	).

    min_above_loop([], _, Min, Min).
    min_above_loop([X|Xs], Avoid, Min0, Min) :-
        ( X @=< Avoid ->
            min_above_loop(Xs, Avoid, Min0, Min)
	; X @< Min0 ->
	    min_above_loop(Xs, Avoid, X, Min)
	;
	    min_above_loop(Xs, Avoid, Min0, Min)
	).

How _two_ lists would be involved escapes me.

BEWARE!  This code has not been tested!

