sets.tst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. %% sets.tst
  2. %% Author: F.J.Wright@Maths.QMW.ac.uk
  3. %% Date: 20 Feb 1994
  4. %% Test of REDUCE sets package, based on the examples on page 51 of
  5. %% the "Maple V Language Reference Manual"
  6. %% by Char, Geddes, Gonnet, Leong, Monagan and Watt (Springer, 1991).
  7. %% The output (especially of symbolic set expressions) looks better
  8. %% using PSL-REDUCE under MS-Windows or X in graphics mode.
  9. %% Note that REDUCE supports n-ary symbolic infix operators,
  10. %% does not require any special quoting to use an infix operator
  11. %% as a prefix operator, and supports member as an infix operator.
  12. %% However, REDUCE ALWAYS requires evalb to explicitly evaluate a
  13. %% Boolean expression outside of a conditional statement.
  14. %% Maple 5.2 does not provide any subset predicates.
  15. clear a, b, c, x, y, z;
  16. s := {x,y} union {y,z};
  17. % s := {x,y,z}
  18. t := union({x,y},{y,z});
  19. % t := {x,y,z}
  20. evalb(s = t);
  21. % true
  22. evalb(s set_eq t);
  23. % true
  24. evalb(member(y, s));
  25. % true
  26. evalb(y member s);
  27. % true
  28. evalb(y member {x*y, y*z});
  29. % false
  30. evalb(x*y member {x*y, y*z});
  31. % true
  32. {3,4} union a union {3,7} union b;
  33. % {3,4,7} union a union b
  34. {x,y,z} minus {y,z,w};
  35. % {x}
  36. a minus b;
  37. % a\b
  38. a\b;
  39. % a\b
  40. minus(a,a);
  41. % {}
  42. {x,y,z} intersect {y,z,w};
  43. % {y,z}
  44. intersect(a,c,b,a);
  45. % a intersection b intersection c
  46. %% End of Maple examples.
  47. (a union b) intersect c where set_distribution_rule;
  48. % a intersection c union b intersection c
  49. algebraic procedure power_set s;
  50. %% Power set of a set as an algebraic list (inefficiently):
  51. if s = {} then {{}} else
  52. {s} union for each el in s join power_set(s\{el});
  53. power_set{};
  54. power_set{1};
  55. power_set{1,2};
  56. power_set{1,2,3};
  57. evalb 1;
  58. % true
  59. evalb 0;
  60. % false
  61. evalb(a = a);
  62. % true
  63. evalb(a = b);
  64. % false
  65. evalb(2 member {1,2} union {2,3});
  66. % true
  67. evalb({2} member {1,2} union {2,3});
  68. % false
  69. evalb({1,3} subset {1,2} union {2,3});
  70. % true
  71. evalb(a subset a union b);
  72. % true
  73. evalb(a subset_eq a union b);
  74. % true
  75. evalb(a set_eq a union b);
  76. % false
  77. evalb(a\b subset a union c);
  78. % true
  79. mkset{1,2,1};
  80. % {1,2}
  81. end;