File r36/xlog/SETS.LOG artifact 945cc552d6 on branch master


REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...


%% 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;
(TIME:  sets 120 120)


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