multiset ordering



Hello,

I'm trying to extend the usual strict order on natural numbers
to multiset (or bag) of numbers (special sets where duplicates are
allowed).

There are various way to define the multiset-extension of an
order; I choose the transitive closure of the relation

`the bag X is greater then the bag Y iff Y is obtained from
X replacing a single element with a finite (eventually empty)
collection of smaller elements`,

as I read in a paper of N. Dershowitz,
http://www.cs.tau.ac.il/%7Enachumd/papers/Orderings4TRS.pdf ,
pag. 289.

It seems to be allright, but my code doesn't work on
some inputs. Here is it:

%*************************************************
% ORDERING FOR MULTISETS OF NATURAL NUMBERS
%*************************************************

% gt_all(A,B) means `the element A is greater of
% every element in the list B`

gt_all(S,[]).
gt_all(S,[T|Ts]):-
S > T,
gt_all(S,Ts).

% gt_ms_onestep(X,Y) means `Y is obtained from
% X replacing a single element with a finite collection
% (eventually empty) of smaller elements`.

gt_ms_onestep(X,Y):-
select(Pivot,X,Rest),
permutation(Y,Yperm),
append(Yi,Rest,Yperm),
gt_all(Pivot,Yi).

% The following is the transitive closure of the
% relation above.

gt_ms(X,Y):- gt_ms_onestep(X,Y).
gt_ms(X,Y):-
gt_ms_onestep(X,Y1),
gt_ms(Y1,Y).
%***********************************************

But I got from my swi-prolog interpreter:

?- gt_ms([3],[3]).
ERROR: Arguments are not sufficiently instantiated

Can somebody find out why?
I think gt_ms_onestep works well, the problem is
in the two other predicates.

Best regards,
Giovanni Gherdovich

.



Relevant Pages

  • Re: multiset ordering
    ... multiSet:= Bag new. ... The second line assigns a new Bag to the ... Linked Lists, Arrays - whatever you want. ...
    (comp.lang.prolog)
  • Re: TreeSet and HashSet
    ... For a multiset (bag, or whatever you call it) the question would be "which ... I don't think that has any more similarity to a mapping operation than asking ... have to leave a few classes for programmers to write or we'd be out of jobs. ...
    (comp.lang.java.programmer)
  • Re: multiset ordering
    ... This is a Prolog group so I hesitate to put much Smalltalk ... He said a "multiset" was a ... to multiset (or bag) of numbers (special sets where duplicates are ...
    (comp.lang.prolog)