## #2510 keepfloat:true gives weird integral errors a lot

None
open
nobody
5
2014-08-16
2012-11-29
kcrisman
No

(%i1) keepfloat:true;
(%o1) true
(%i2) integrate(exp(-5.3*x),x,0,1);

Maxima encountered a Lisp error:

Argument V is not a INTEGER: 1.0

Automatically continuing.
To enable the Lisp debugger set debugger-hook to nil.

This seems to happen a lot in similar situations.

(%i6) f:sin(t)^2/(1.5+1cos(t))^2;
2
sin (t)
(%o6) ---------------
2
(cos(t) + 1.5)
(%i8) integrate(f,t,0,2
%pi);

rat: replaced 1.5 by 3/2 = 1.5

rat: replaced 1.5 by 3/2 = 1.5

rat: replaced 1.5 by 3/2 = 1.5

rat: replaced 1.5 by 3/2 = 1.5

rat: replaced 1.5 by 3/2 = 1.5
(2 sqrt(5) - 6) %pi
(%o8) - -------------------
sqrt(5)
(%i10) keepfloat:true;
(%o10) true
(%i11) integrate(f,t,0,2*%pi);

Maxima encountered a Lisp error:

The value 4.0 is not of type INTEGER.

Automatically continuing.
To enable the Lisp debugger set debugger-hook to nil.

## Discussion

• Robert Dodier - 2012-11-29

keepfloat causes trouble and has no strong motivation. If one wants floating point results, why not apply float after the fact?

integrate and any other functions currently troubled by keepfloat should rationalize everything and ignore keepfloat. (Or maybe, just maybe, replace floats by symbols, do the calculation, then replace them again in the output. That sounds like its own kind of trouble, though.)

I'm in favor of getting rid of keepfloat. I'll raise the issue on the mailing list.

• kcrisman - 2012-11-29

Well, don't give up the ship! I know that Sage has keepfloat:true by default because Maxima's replacing of floats was way too aggressive. See http://trac.sagemath.org/sage_trac/ticket/2400 for this.

(%i2) integrate(%e^(-x^2),x,0,.1);

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced 0.1 by 1/10 = 0.1

rat: replaced .05623145800914245 by 6383492/113521723 = .05623145800914244
6383492 sqrt(%pi)
(%o2) -----------------
113521723

(%i3) integrate(%e^(-x^2),x,0,1/10);
1
sqrt(%pi) erf(--)
10
(%o3) -----------------
2
(%i5) erf(.1)/2;
(%o5) .05623145800914245
(%i6) float(6383492/113521723);
(%o6) .05623145800914244

Before it was 2066*sqrt(pi)/36741, so maybe things have been getting better with keepfloat:false lately? In which case we could just switch back.

• kcrisman - 2013-06-26

Here is a very simple version of this bug indeed. While this is a great rational approximation to the answer, I'm still not sure what the "right" behavior is; maybe it's user error to put the -1.0 in (implying only a float accuracy)?

```(%i1) display2d:false;

(%o1) false
(%i2) keepfloat:true;

(%o2) true
(%i3) integrate(%e^(-1.0*x),x,0,1);

Maxima encountered a Lisp error:

In function GCD, the value of the second argument is
1.0
which is not of the expected type INTEGER

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i4) keepfloat:false;

(%o4) false
(%i5) integrate(%e^(-1.0*x),x,0,1);

rat: replaced 1.0 by 1/1 = 1.0

rat: replaced -1.0 by -1/1 = -1.0

rat: replaced -1.0 by -1/1 = -1.0

rat: replaced -1.0 by -1/1 = -1.0

rat: replaced -1.0 by -1/1 = -1.0

rat: replaced -1.0 by -1/1 = -1.0

rat: replaced -.3678794411714423 by -10391023/28245729 = -.3678794411714422
(%o5) 17854706/28245729
(%i6) float(17854706/28245729)
;

(%o6) .6321205588285578
(%i7) float(-%e^(-1)+1);

(%o7) .6321205588285577
```

See http://trac.sagemath.org/sage_trac/ticket/14821, where this came up again.

• Robert Dodier - 2013-08-01
• labels: --> Lisp Core - Integration
• Group: --> None

## Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks