I've been tinkering with set operations on symbolic arguments. The
general plan is to make union, intersection, etc. simplifications of
noun expressions. A function $FOO just returns %FOO which is then
simplified, except for elementp -- more about that later.
Mostly it has been pretty obvious so far. Union, intersection, and
symmetric difference are declared as n-ary, symmetric operators so the
general simplifier does part of the work. Any literal sets among the
arguments are combined and symbolic arguments are reduced if possible.
(%i1) union (A, B, union (C, D, B), E);
(%o1) union(A, B, C, D, E)
(%i2) intersection (X, {1, 2, 4, 5}, {2, 5}, Y);
(%o2) intersection({2, 5}, X, Y)
(%i3) symmdifference (X, X);
(%o3) {}
(%i4) symmdifference (X, X, X);
(%o4) X
(%i5) symmdifference (X, X, X, Y, Y, Y);
(%o5) symmdifference(X, Y)
'intersection() acts as a universal set in intersection and elementp
(haven't gotten to union yet).
(%i10) 'elementp (x, 'intersection (A, B));
(%o10) elementp(x, intersection(A, B))
(%i11) 'elementp (x, 'intersection ());
(%o11) true
(%i12) 'elementp (x, {});
(%o12) false
elementp is an interesting problem. How to handle elementp(x, S) where S
is a literal set? If x is a symbol, how to distinguish x as a variable
from x as an actual element of S? The compromise I've come to so far is
to let the verb elementp act like a programming function while the noun
elementp acts like a mathematical function which simplifies under
certain conditions. At present 'elementp(x, S) simplifies to true/false
if x is a constant according to constantp(x) (and in some other
circumstances as well).
(%i6) elementp (x, S);
(%o6) elementp(x, S)
(%i7) elementp (1, S);
(%o7) elementp(1, S)
(%i8) elementp (x, {1, 2, 3});
(%o8) false
(%i9) 'elementp (x, {1, 2, 3});
(%o9) elementp(x, {1, 2, 3})
(%i13) 'elementp (%pi, {1, 2, 3});
(%o13) false
(%i14) 'elementp (3, {1, 2, 3});
(%o14) true
Yes, that stuff about distinguishing noun/verb forms of elementp is
maybe a little too involved. Other ideas?
Anyway I am curious to know if there is any interest in this general
approach. I'll put the code on a branch or something. Of course, so far
I've just scratched the surface; there is much more that could be done.
best,
Robert Dodier