Subject: Bug in integrate caused by global special X
From: Dieter Kaiser
Date: Sun, 11 Jul 2010 14:39:47 +0200
I think we have a surprising bug. I have recognized it, when looking at
the following integral:
(%i1) defint(exp(cos(x))*cos(sin(x)),x,0,2*%pi);
Attempt to integrate wrt a number: 0
-- an error. To debug this try: debugmode(true);
This bug seems to be not present in Maxima 5.21. But if I rebuilt Maxima
5.21 on my system with SBCL I get it too. The bug is very subtle.
When we trace the function $integrate we see that $integrate is called
with wrong arguments:
(%i2) defint(exp(cos(x))*cos(sin(x)),x,0,2*%pi);
0: ($INTEGRATE ((MTIMES SIMP) ((RAT SIMP) 1 2) $%E) 0)
Attempt to integrate wrt a number: 0
-- an error. To debug this try: debugmode(true);
I think the bug is caused by the global special X. I do not know the
place where the symbol 'X is declared to be a special, but this
declaration is the reason for the problem.
In the routine monstertrig and trigint in sin.lisp the algorithm
substitute the variable of integration with the symbol 'X. Then rischint
is called to get a solution.
In the routine hypertrigint1 in risch.lisp the algorithm looks if the
solution from risch contains noun forms of an integral and passes such
expressions back to the integrator. This is done with a call to meval.
At this point the symbols 'X which has been substituted into the
expressions are evaluated and because X is a global special the actual
value of X is inserted. The evaluation with a wrong value for the symbol
'X causes a wrong expression for the integral.
Remark: Because the routines $integrate and $defint have the symbol 'X
in the argument list for the variable of integration, the variable X is
initialized with a meaningful value and in a lot of cases we do not see
this bug. But I do not oversee at what places this value might be
changed.
Because of this I had a look if we have further variables with one char
which are declared to be special. I have found the following symbols:
'l, 't, 'x.
I think the best is to replace the substitution with the symbol 'X in
the algorithm of sinint with a more general working mechanism like a
genvar. Perhaps we can find the place where X is declared to be special
and remove the declaration.
Dieter Kaiser