Consider this:
(C1) display2d:false;
(D1) FALSE
(C2) tan(%pi/2+x);
(D2) -COT(x)
(C3) tan(%pi/2+%pi*x);
(D3) TAN(%PI*x+%PI/2)
(C4) %,trigexpand;
Division by 0
-- an error. Quitting. To debug this try
DEBUGMODE(TRUE);)
d3 should have been expanded into -cot(%pi*x) instead
of getting a division by zero error.
Robert Dodier
2006-03-26
Logged In: YES
user_id=501686
For the record, same problem observed in maxima 5.9.3.
Robert Dodier
2006-03-26
Robert Dodier
2006-08-27
Rupert Swarbrick
2007-12-26
Logged In: YES
user_id=1673565
Originator: NO
Hi, a bit more information: the error's caused by a (div 1 0) which gets returned in %piargs-tan/cot, called by simp-%tan.
You can reproduce more simply by just calling
tan(%pi/2), trigexpand;
I'm trying to work out what the functions are _supposed_ to do. Maybe then I'll be able to fix it!
Rupert Swarbrick
2007-12-27
Logged In: YES
user_id=1673565
Originator: NO
Ah. Of course tan(pi/2) = infinity ...
Rupert Swarbrick
2007-12-27
Logged In: YES
user_id=1673565
Originator: NO
So the first thing that's wrong is that %piargs-tan/cot shouldn't return non-nil for stuff like tan(pi/2) as they aren't defined, let alone simplifiable. Here's an amended and reformatted version with variables renamed and a possible bug due to reuse of variable names eliminated too (I think)
(defun %piargs-tan/cot (x)
(displa x)
(let ((coeff (linearize (coefficient x '$%pi 1)))
(zl-rem (coefficient x '$%pi 0))
(sin-of-coeff-pi) (cos-of-coeff-pi))
(cond
((and (zerop1 zl-rem)
(setq sin-of-coeff-pi
(%piargs coeff nil))
(not (zerop1
(setq cos-of-coeff-pi
(%piargs (cons (car coeff)
(rplus 1//2 (cdr coeff))) nil)))))
;; sin-of-coeff-pi and cos-of-coeff-pi are only non-nil if they
;; are constants that %piargs-offset could compute, and we just
;; checked that cos-of-coeff-pi was nonzero. Thus we can just
;; return their quotient.
(div sin-of-coeff-pi cos-of-coeff-pi))
((not (mevenp (car coeff))) nil)
((integerp (setq x (mmod (cdr coeff) 2)))
(cons-exp '%tan zl-rem))
((or (alike1 1//2 x)
(alike1 '((rat) 3 2) x))
(neg (cons-exp '%cot zl-rem))))))
Rupert Swarbrick
2007-12-28
Logged In: YES
user_id=1673565
Originator: NO
I think I've posted a patch onto the mailing list that fixes this. I can't work out how to attach files here, so the link is: http://thread.gmane.org/gmane.comp.mathematics.maxima.general/19076
Dan Gildea
2008-03-26
Logged In: YES
user_id=1797506
Originator: NO
The proposed patch disables the following simplification:
(%i1) declare(n, integer);
(%o1) done
(%i2) tan(n*2*%pi);
(%o2) 0
However, it almost fixes bugs 903190, 1553866 and 1755550.
Dan Gildea
2008-04-13
Dan Gildea
2008-04-13
Logged In: YES
user_id=1797506
Originator: NO
Fixed in trigi.lisp rev 1.30
(%i29) tan(%pi/2+%pi*x);
(%o29) -cot(%pi*x)
(%i30) declare(n, integer);
(%o30) done
(%i31) tan(n*2*%pi);
(%o31) 0