computing e.g. {1,2}+1



You didn't say what you wanted for set-set arithmetic. One problem without much of
a workaround, I think, is set(a,b)-set(a,b) --> 0, not set(0). 

You might be able to do most of what you would like by substitution; something like
the unredacted:

(%i1) set_arith(e) := subst("+" = lambda([[s]], block([sets : [], acc : 0],  
  for sk in s do (if setp(sk) then push(sk,sets) else acc : acc + sk),  
   sets : apply('cartesian_product, sets),
   sets : disjoin(0, map(lambda([s], set_arith(xreduce("+", s))), sets)),
   if emptyp(sets) then acc else map(lambda([w], set_arith(w+acc)), sets))), e)$

 (%i2) load(basic)$

 (%i3) setp(e) := not mapatom(e) and op(e)='set$

 (%i4) set_arith(4*a+6*b + 1);
 (%o4) 6*b+4*a+1

 (%i5) set_arith(5 + set(x,y));
 (%o5) {x+5,y+5}

 (%i6) set_arith(7 + set(a,b) + set(c,d,e));
 (%o6) {c+a+7,c+b+7,d+a+7,d+b+7,e+a+7,e+b+7}

Not handled, but could be:

 (%i14) set_arith(7 + set(a,b)  + set(a,b));
 (%o14) 2*{a,b}+7

Nonideal, I guess.

 (%i15) set_arith(7 + set(a,b)  - set(a,b));
 (%o15) 7

--Barton


we have e.g.

1+[[1,2],3,[[3,[4,5]]]];
?[[2,3],4,[[4,[5,6]]]]

which is enormously helpful. Now it would be great if the same
would apply also to sets and the combination of sets and lists,
so that for example

1+{[1,2],3,{4,5}};

would yield

{[2,3],4,{5,6}}