1 (kill(all), load(multiadditive), 0);
4 (declare(f,threadable),0);
49 is(args(f(4.5)) = [4.5]);
52 is(args(f(4.5b0, x, a=b)) = [4.5b0, x, a=b]);
55 is(op(f(rat(x))) = f);
58 is(args(f(rat(x)))= [x])$
61 is(args(f(false)) = [false]);
64 (matchdeclare(x, mapatom),0);
67 (tellsimpafter(f(x),5),0);
73 (declare(g,multiadditive, f, multiadditive),0);
85 is(args(g(4.5)) = [4.5])$
98 g(a,c) + g(a,d) + g(b,c) + g(b,d)$
100 is(op(g(a*b)) = g) and is(args(g(a*b)) = [a*b]);
109 (declare([f,g],multiplicative),0);
121 f(set(a+b*c,x,x^^2));
124 (declare(h,involution),0);
151 is(args(h(8)) = [8]);
163 (matchfix("{{","}}"),0);
166 (declare("{{",multiadditive),0);
175 (declare(p, idempotent),0);
190 (mypos(e) := block([prederror : false], sign(e) = 'pos),0);
193 (declare(myabs, idempotent, myabs, multiplicative),0);
196 (declare(myabs, evenfun),0);
199 (matchdeclare(e, mypos),0);
202 (tellsimpafter(myabs(e),e),0);
214 myabs(xp * myabs(z));
217 myabs(x) - myabs(-x);
220 (remove(f,threadable, f, multiadditive, g, multiadditive, h,involution, p,idempotent),0);
223 (remove(myabs,[idempotent, multiplicative,evenfun]),0);
229 (declare(f, symmetric),0);
235 29 * f(-a,b) - 29 * f(b,-a);
238 f(a,b,c) + f(c,b,a) + f(a,c,b) + f(a,c,b) + f(b,a,c) + f(c,b,a);
244 (declare(g, antisymmetric),0);
250 s * g(z,y,x) + s * g(x,y,z);
256 (remove(f, symmetric, g, antisymmetric),0);
259 (define_opproperty (identity, simplify_identity),
260 simplify_identity(e) := first(e),
262 declare ([f, g], identity));
271 /* same as identity property, but with lambda expression */
272 define_opproperty (identity1, lambda ([e], first(e)));
275 (kill (f1, g1), declare ([f1, g1], identity1));
278 [f1(t + 10), g1(3*u) - f1(2*u)];
281 /* tests for bilinear declaration */
288 if not member (bilinear, opproperties) then load (bilinear),
289 declare ("foo", bilinear));
292 (kill(a, b, c, d, e, f),
293 (a + b) foo (c + d));
294 a foo c + a foo d + b foo c + b foo d;
296 (%pi*a - c/2) foo (d - 2*e - f^^2);
297 %pi*(a foo d) - 2*%pi*(a foo e) - %pi*(a foo (f^^2)) - (c foo d)/2 + (c foo e) + (c foo (f^^2))/2;
299 declare ("foo", symmetric);
305 declare ("foo", scalar);
308 ((a foo b)*c) foo ((c foo d)*e);
309 (a foo b)*(c foo d)*(c foo e);
311 /* verify later declarations don't interfere with earlier ones */
313 (%pi*a - c/2) foo (d - 2*e - f^^2);
314 %pi*(a foo d) - 2*%pi*(a foo e) - %pi*(a foo (f^^2)) - (c foo d)/2 + (c foo e) + (c foo (f^^2))/2;
319 /* bilinear, symmetric, scalar all together */
321 (c/(a foo f)) foo ((c foo (a + b))*e);
322 ((a foo c) + (b foo c))*(c foo e)/(a foo f);
324 (3*a - c/(a foo f)) foo ((c foo (a + b))*e);
325 3*((a foo c) + (b foo c))*(a foo e) - ((a foo c) + (b foo c))*(c foo e)/(a foo f);
327 (3*a + c/(a foo f)) foo (d + (c foo (a + b))*e);
328 3*(a foo d) + (c foo d)/(a foo f) + 3*((a foo c) + (b foo c))*(a foo e) + ((a foo c) + (b foo c))*(c foo e)/(a foo f);
330 (kill (S), declare (S, scalar));
333 /* I want to test 1234 + 5*(3*a - c/(a foo f)) foo (d - (c foo (a + b))*e)
334 * Work up to it step by step.
342 (3*a) foo (S*((c foo (a + b))*e));
343 3*S*(c foo a + c foo b)*(a foo e);
346 (3*a) foo (d + S*((c foo (a + b))*e));
347 3*(a foo d) + 3*S*(c foo a + c foo b)*(a foo e);
350 (S*(c/(a foo f))) foo d;
351 S*(c foo d)/(a foo f);
354 (S*(c/(a foo f))) foo (S*((c foo (a + b))*e));
355 S^2*(c foo a + c foo b)*(c foo e)/(a foo f);
359 (S*(c/(a foo f))) foo (d + (S*((c foo (a + b))*e)));
360 S*(c foo d)/(a foo f) + S^2*(c foo a + c foo b)*(c foo e)/(a foo f);
364 (3*a + (S*(c/(a foo f)))) foo (d + (S*((c foo (a + b))*e)));
365 3*(a foo d) + 3*S*(c foo a + c foo b)*(a foo e) + S*(c foo d)/(a foo f) + S^2*(c foo a + c foo b)*(c foo e)/(a foo f);
367 /* same as preceding, but with fewer parentheses */
368 (3*a + S*c/(a foo f)) foo (d + S*(c foo (a + b))*e);
369 3*(a foo d) + 3*S*(c foo a + c foo b)*(a foo e) + S*(c foo d)/(a foo f) + S^2*(c foo a + c foo b)*(c foo e)/(a foo f);
371 /* same as preceding, now let S = -1 */
372 subst (S = -1, (3*a + S*c/(a foo f)) foo (d + S*(c foo (a + b))*e));
373 ''(myfoilsubst : subst (S = -1, 3*(a foo d) + 3*S*(c foo a + c foo b)*(a foo e) + S*(c foo d)/(a foo f) + S^2*(c foo a + c foo b)*(c foo e)/(a foo f)));
375 /* same as preceding, rewrite with minus signs;
376 * test via ratsimp since I can't get simplified forms to agree
378 ratsimp ((3*a - c/(a foo f)) foo (d - (c foo (a + b))*e) - myfoilsubst);
381 /* what I was trying to test to start with */
382 ratsimp (1234 + 5*(3*a - c/(a foo f)) foo (d - (c foo (a + b))*e) - (1234 + 5*myfoilsubst));