SETS.LOG 2.5 KB

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