|
From: Kris K. <kat...@gm...> - 2022-08-23 17:47:54
|
On Tue, Aug 23, 2022 at 05:08:20PM +0200, Robert Larice wrote:
> The value
> 16
> is not of type
> SEQUENCE
> [Condition of type TYPE-ERROR]
<snip>
> I think the (cddr f) from the above printout
> is the denominator of a polynom/polynom representation of f
> and this denominator with this testcase happens to be the
> plain number `16' which the code is not prepared to cope with.
<snip>
> But I've gone back quite some maxima revisions, down to something around
> 5_30 or so, and the misbehaviour was everywhere the same.
This is an old bug. I just tried 5.10.0 and it's present there as well.
Also it's easy to hit this bug:
(%i1) defint(1/((x+%i/2)*(x+1)),x,0,inf);
<lisp error>
(%i2) defint(1/((x+%i)*(x+1/2)),x,0,inf);
<lisp error>
(%i3) defint(1/((x+%i)*(x/2+1)),x,0,inf);
<lisp error>
etc. And it's easy to hit this when integrating from minf to inf too.
%I-OUT-OF-DENOM attempts to rewrite expressions by removing %i from the
denominator. Apparently this function is to work around some problems
in taylor, but also the comment says it "doesn't seem like a bad thing
to do in general".
Later on assumptions are made about the form of different expressions,
but the result of %I-OUT-OF-DENOM can be complicated enough to cause
problems.
Here's a patch that does a little additional work in %I-OUT-OF-DENOM.
Now SRATSIMP is called on the rewritten expression.
diff --git a/src/defint.lisp b/src/defint.lisp
index 917f0cd64..850196102 100644
--- a/src/defint.lisp
+++ b/src/defint.lisp
@@ -3359,13 +3359,12 @@ in the interval of integration.")
;; %i.
(let* ((den-conj (maxima-substitute (m- '$%i) '$%i denom))
(num ($num exp))
- (new-denom (sratsimp (m* denom den-conj))))
- ;; If the new denominator still contains %i, just give
- ;; up. Otherwise, multiply the numerator by the
- ;; conjugate and divide by the new denominator.
- (if (among '$%i new-denom)
+ (new-denom (sratsimp (m* denom den-conj)))
+ (new-exp (sratsimp (m// (m* num den-conj) new-denom))))
+ ;; If the new denominator still contains %i, just give up.
+ (if (among '$%i ($denom new-exp))
exp
- (setq exp (m// (m* num den-conj) new-denom)))))
+ new-exp)))
(t exp))))
;;; LL and UL must be real otherwise this routine return $UNKNOWN.
And here are the examples from above with this patch:
(%i5) defint(1/((x+%i/2)*(x+1)),x,0,inf);
(%o5) ((2*%i+4)*log(2)+(1-2*%i)*%pi)/5
(%i6) defint(1/((x+%i)*(x+1/2)),x,0,inf);
(%o6) -((4*%i+2)*log(2)+(%i-2)*%pi)/5
(%i7) defint(1/((x+%i)*(x/2+1)),x,0,inf);
(%o7) ((2*%i+4)*log(2)+(1-2*%i)*%pi)/5
These examples now follow a different path through ZMTORAT, so the
function POLYFORM which caused the lisp error is not even called.
And here is Barton's original example:
(%i21) g_poles: exp(%i * [phi, -phi, %pi-phi, %pi+phi])$
(%i22) g_integrant_1f: 1/apply("*", makelist(w - pole, pole, g_poles))$
(%i23) defint(subst(phi=%pi/3, g_integrant_1f), w, 0, inf) = subst(phi = %pi/3, %pi / 4 / sin(phi));
(%o23) %pi/(2*sqrt(3)) = %pi/(2*sqrt(3))
This example still eventually goes through POLYFORM, but now there is no
error.
This patch causes one test suite failure in the main test suite, but the
new result is equivalent and simpler (although not as simple as
possible).
Before:
(%i5) integrate((x-%i)/((x-2*%i)*(x^2+1)),x,0,inf);
(%o5) (6*%i*log(2)+6*%pi)/18
After:
(%i7) integrate((x-%i)/((x-2*%i)*(x^2+1)),x,0,inf);
(%o7) (2*%i*log(2)+2*%pi)/6
Cheers,
Kris Katterjohn
|