Here is a proposed mechanism for deciding when
to apply even / odd function simplification
rules.
Notes
(1) My code does not use the sign of the
argument to decide when to use even / odd
function simplification.
(2) I thank Raymond for finding bug in my
first proposal.
(3) I changed all the trig simplifying
functions in trigi (but not the functions
in trigo). The test suite shows no errors with
my code. Timing mminusp*, try-even-fun-simp,
and try-odd-fun-simp shows mminusp* is slightly
slower.
(4) Examples (these are no different from
the way maxima currently works, I think).
(%i1) sin(x*y) + sin(-x*y);
(%o1) 0
(%i2) sin(u+n-k) + sin(k-u-n);
(%o2) 0
This one needs to be expanded to crunch to zero
(%i3) sin(u * (n-k)) + sin(u * (k-n));
(%o3) SIN((n - K) U) + SIN((K - n) U)
(%i4) expand(%);
(%o4) 0
It's possible to change neg so that this simplifies to zero
without expansion. But ...
(defun try-even-fun-simp (f x)
(let ((nx (neg x)))
(and (great nx x) `((,f simp) ,nx))))
(defun try-odd-fun-simp (f x)
(let ((nx (neg x)))
(and (great nx x) (neg `((,f simp) ,nx)))))
(defmfun simp-%sin (form y z)
(oneargcheck form)
(setq y (simpcheck (cadr form) z))
(cond ((floatp y) (sin y))
((and $numer (integerp y))
(sin (float y 2.0d0 )))
(($bfloatp y) ($bfloat form))
((and $%piargs (cond ((zerop1 y) 0) ((linearp y '$%pi)
(%piargs-sin\Cos y)))))
((and $%iargs (multiplep y '$%i)) (mul '$%i (cons-exp '%sinh
(coeff y '$%i 1))))
((and $triginverses (not (atom y))
(cond ((eq '%asin (setq z (caar y))) (cadr y))
((eq '%acos z) (sqrt1-x^2 (cadr y)))
((eq '%atan z) (div (cadr y) (sqrt1+x^2 (cadr y))))
((eq '%acot z) (div 1 (sqrt1+x^2 (cadr y))))
((eq '%asec z) (div (sqrtx^2-1 (cadr y)) (cadr y)))
((eq '%acsc z) (div 1 (cadr y)))
((eq '$atan2 z) (div (cadr y) (sq-sumsq (cadr y)
(caddr y)))))))
((and $trigexpand (trigexpand '%sin y)))
($exponentialize (exponentialize '%sin y))
((and $halfangles (halfangle '%sin y)))
;((and $trigsign (mminusp* y))
; (neg (cons-exp '%sin (neg y))))
((and $trigsign (try-odd-fun-simp '%sin y)))
(t (eqtest (list '(%sin) y) form))))
Barton
(%i5) build_info();
Maxima version: 5.9.1.1cvs
Maxima build date: 10:31 11/12/2004
host type: i686-pc-mingw32
lisp-implementation-type: Kyoto Common Lisp
lisp-implementation-version: GCL 2.6.5