Closed rtoy closed 3 months ago
Imported from SourceForge on 2024-07-03 00:21:42 Created by mitreude on 2009-11-02 03:46:39 Original: https://sourceforge.net/p/maxima/bugs/1806/#ea66
This problem occurs with version 5.19.2 of Maxima.
Imported from SourceForge on 2024-07-03 00:21:46 Created by rtoy on 2009-11-02 16:25:27 Original: https://sourceforge.net/p/maxima/bugs/1806/#31c7
Neat bug. But current cvs returns %pi/3 both times.
Do not know what has changed, but it seems current CVS has fixed this issue.
Marking as pending/worksforme
Imported from SourceForge on 2024-07-03 00:21:49 Created by rtoy on 2009-11-02 16:25:31 Original: https://sourceforge.net/p/maxima/bugs/1806/#974a
Imported from SourceForge on 2024-07-03 00:21:53 Created by crategus on 2009-11-03 22:21:52 Original: https://sourceforge.net/p/maxima/bugs/1806/#5d38
I can see this bug too with CLISP 2.44 and Maxima 5.19post on my Linux system:
(%i2) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o2) %pi/3 (%i3) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o3) 4*%pi/3
Evaluating this integral the package trgsmp is loaded:
(%i5) functions; (%o5) [trigonometricp(exp),trigsimp(x),trigsimp3(expn),trigsimp1(expn), improve(expn,subsofar,listoftrigsq),listoftrigsq(expn), specialunion(list1,list2),update(form,complement),expnlength(expr), argslength(args)]
When I kill the functions defined by this package the integral is correct again:
(%i6) kill(functions); (%o6) done (%i7) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o7) %pi/3
And the next evaluation is wrong again:
(%i8) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o8) 4*%pi/3
When I preload the package trgsmp I get the error immediately:
(%i11) kill(functions); (%o11) done (%i12) load(trgsmp); (%o12) "/usr/local/share/maxima/5.19post/share/trigonometry/trgsmp.mac" (%i13) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o13) 4*%pi/3
Reopening the bug report.
Dieter Kaiser
Imported from SourceForge on 2024-07-03 00:21:56 Created by crategus on 2009-11-03 22:21:52 Original: https://sourceforge.net/p/maxima/bugs/1806/#2260
Imported from SourceForge on 2024-07-03 00:22:00 Created by rtoy on 2009-11-04 17:01:53 Original: https://sourceforge.net/p/maxima/bugs/1806/#feea
Sorry, you are correct. My working tree had a fix for Bug 2880797. Why this makes a difference, I don't know.
Imported from SourceForge on 2024-07-03 00:22:03 Created by mitreude on 2009-11-04 20:45:58 Original: https://sourceforge.net/p/maxima/bugs/1806/#a1b6
OK, I examined the file trgsmp.mac and found that if I changed the order of simplification rules in the definition of the function trigsimp(),I can consistently get the correct answer. Here is what I did:
load(trgsmp)$ defrule(trigrule1,sec(a),1/cos(a))$ defrule(trigrule2,csc(a),1/sin(a))$ defrule(trigrule3,tan(a),sin(a)/cos(a))$ defrule(trigrule4,cot(a),cos(a)/sin(a))$ defrule(htrigrule1,sech(a),1/cosh(a))$ defrule(htrigrule2,csch(a),1/sinh(a))$ defrule(htrigrule3,tanh(a),sinh(a)/cosh(a))$ defrule(htrigrule4,coth(a),cosh(a)/sinh(a))$ trigsimp(x):=trigsimp3(ratsimp(apply1(x,trigrule4,trigrule1,trigrule2,trigrule3,trigrule4, htrigrule1,htrigrule2,htrigrule3,htrigrule4)))$ integrate(cot(x)^4,x,%pi/6,%pi/2);
It seems that the tangent simplification should not come first. Why this works on this particular problem, I don't have a clue. Also, might changing the simplification order cause a problem in an integral where Maxima previously found the correct answer? I have more questions than answers.
Mike Treuden
Imported from SourceForge on 2024-07-03 00:22:07 Created by rtoy on 2009-11-06 16:45:42 Original: https://sourceforge.net/p/maxima/bugs/1806/#776e
Just to note that trgsmp gets loaded because same-sheet-subs (in defint.lisp) calls trigsimp. The whole purpose (based on the comments) is to convert tan to sin/cos.
Also, on the first integrate, same-sheet-subs is called just once on atan(tan(x+%pi/6)) for x=0,%pi/3, and returns 4*%pi/3.
On the second integration, same-sheet-subs is called twice with the same arguments and same results.
Have not figured out anything more.
Imported from SourceForge on 2024-07-03 00:22:11 Created by rtoy on 2009-11-09 15:19:08 Original: https://sourceforge.net/p/maxima/bugs/1806/#c0dc
Some simple tests show that just applying the rule tan(a)=sin(a)/cos(a) in same-sheet-subs is enough to fix this problem. I do not know why running trigsimp itself causes problems or why, as mitreude says, changing the order of the rules in trgsmp makes it work. Especially in this case since the expression is atan(tan(x+%pi/6)).
Imported from SourceForge on 2024-07-03 00:22:14 Created by crategus on 2009-11-12 15:36:26 Original: https://sourceforge.net/p/maxima/bugs/1806/#f411
I think the routine atan-poles does not work correctly for expressions like atan(tan(x)). It does not take into account the cases where we have more than one pole in the interval and it add extra poles which are not present.
With triginverses set to ALL these bugs in atan-poles do not occur, because atan(tan(x)) is always simplified to x. The routine atan-poles therefore is never called.
This error in atan-poles is responsible for both bugs:
ID: 2890315 - integrate(cot(x)^4,x,%pi/6,%pi/2) ID: 2880797 - bad answer in integrate(sqrt(sin(t)^2+cos(t)^2),t,0,2*%pi)
I have no idea what can be done in the routine atan-poles, but we can add a test in the routine intsubs. We simplify look for a atan(tan(x)) expression, simplify it and call limit-subs to go on:
(t (setq rpart (sratsimp rpart)) (cond ((limit-subs rpart a b)) ---> ((eq (caar (cadr rpart)) '%tan) ---> ;; We have atan(tan(x)). We simplify it to x. ---> (limit-subs (cadr (cadr rpart)) a b)) (t (same-sheet-subs rpart a b)))))))))
With this extension we avoid to set the flag $triginverses. All works fine. The testsuite has no problems and the reported examples are correct:
(%i5) integrate(sin(x)^2+cos(x)^2,x,0,2*%pi); (%o5) 2*%pi (%i6) integrate(cot(x)^4,x,%pi/6,%pi/2); (%o6) %pi/3
Remark:
It does not help to avoid the usage of trigsimp in the routine same-sheet-subs. I have replaced the call with the following function:
(defun subst-tan-sin/cos (expr) (let (old new) (cond ((not (setq old (isinop expr '%tan))) expr) (t (let* ((arg (cadr old)) (new (div (simplify (list '(%sin) arg)) (simplify (list '(%cos) arg))))) (setq expr (maxima-substitute new old expr))) (subst-tan-sin/cos expr)))))
This is the change in the function same-sheet-subs:
(defun same-sheet-subs (exp ll ul &aux ans) (let* (;(exp (mfuncall '$trigsimp exp)) --> (exp (subst-tan-sin/cos exp)) (poles (atan-poles exp ll ul)))
With this replacement I always get wrong result for the integral integrate(cot(x)^4,x,%pi/6,%pi/2). This way I found that we have no problem with trigsimp, but with atan-poles.
Dieter Kaiser
Imported from SourceForge on 2024-07-03 00:21:41 Created by mitreude on 2009-11-01 15:54:12 Original: https://sourceforge.net/p/maxima/bugs/1806
The first time integrate(cot(x)^4,x,%pi/6,%pi/2) is executed, the answer of %pi/3 returned is correct. However, when the integral is computed again, an incorrect answer of 4*%pi/3 is returned.