File r37/packages/misc/sets.rlg artifact eb010a8ac2 part of check-in 12412d85b9


Mon Jan  4 00:00:48 MET 1999
REDUCE 3.7, 15-Jan-99 ...

1: 1: 
2: 2: 2: 2: 2: 2: 2: 2: 2: 
3: 3: %% sets.tst

%% Author: F.J.Wright@Maths.QMW.ac.uk
%% Date: 20 Feb 1994

%% Test of REDUCE sets package, based on the examples on page 51 of
%% the "Maple V Language Reference Manual"
%% by Char, Geddes, Gonnet, Leong, Monagan and Watt (Springer, 1991).

%% The output (especially of symbolic set expressions) looks better
%% using PSL-REDUCE under MS-Windows or X in graphics mode.

%% Note that REDUCE supports n-ary symbolic infix operators,
%% does not require any special quoting to use an infix operator
%% as a prefix operator, and supports member as an infix operator.
%% However, REDUCE ALWAYS requires  evalb  to explicitly evaluate a
%% Boolean expression outside of a conditional statement.
%% Maple 5.2 does not provide any subset predicates.

clear a, b, c, x, y, z;



s := {x,y} union {y,z};


s := {x,y,z}

% s := {x,y,z}

t := union({x,y},{y,z});


t := {x,y,z}

% t := {x,y,z}

evalb(s = t);


true

% true

evalb(s set_eq t);


true

% true

evalb(member(y, s));


true

% true

evalb(y member s);


true

% true

evalb(y member {x*y, y*z});


false

% false

evalb(x*y member {x*y, y*z});


true

% true

{3,4} union a union {3,7} union b;


{3,4,7} union a union b

% {3,4,7} union a union b

{x,y,z} minus {y,z,w};


{x}

% {x}

a minus b;


a\b

% a\b

a\b;


a\b

% a\b

minus(a,a);


{}

% {}

{x,y,z} intersect {y,z,w};


{y,z}

% {y,z}

intersect(a,c,b,a);


a intersection b intersection c

% a intersection b intersection c

%% End of Maple examples.

(a union b) intersect c where set_distribution_rule;


a intersection c union b intersection c

% a intersection c union b intersection c

algebraic procedure power_set s;
   %% Power set of a set as an algebraic list (inefficiently):
   if s = {} then {{}} else
      {s} union for each el in s join power_set(s\{el});


power_set


power_set{};


{{}}

power_set{1};


{{1},{}}

power_set{1,2};


{{2},{1,2},{1},{}}

power_set{1,2,3};


{{3},{2,3},{2},{1,3},{1,2,3},{1,2},{1},{}}



evalb 1;


true

% true

evalb 0;


false

% false

evalb(a = a);


true

% true

evalb(a = b);


false

% false

evalb(2 member {1,2} union {2,3});


true

% true

evalb({2} member {1,2} union {2,3});


false

% false

evalb({1,3} subset {1,2} union {2,3});


true

% true

evalb(a subset a union b);


true

% true

evalb(a subset_eq a union b);


true

% true

evalb(a set_eq a union b);


false

% false

evalb(a\b subset a union c);


true

% true

mkset{1,2,1};


{1,2}

% {1,2}

end;

4: 4: 4: 4: 4: 4: 4: 4: 4: 

Time for test: 20 ms
5: 5: 
Quitting
Mon Jan  4 00:00:49 MET 1999


REDUCE Historical
REDUCE Sourceforge Project | Historical SVN Repository | GitHub Mirror | SourceHut Mirror | NotABug Mirror | Chisel Mirror | Chisel RSS ]