Open rtoy opened 2 months ago
Imported from SourceForge on 2024-07-04 23:14:03 Created by robert_dodier on 2019-09-01 06:10:40 Original: https://sourceforge.net/p/maxima/bugs/3571/#0dbe
I think several examples of problems for which integrate
fails when the integrand contains floats have been observed. My own opinion is that integrate
should substitute rationals for floats always (ignoring keepfloat
, float
, numer
or anything else which introduces floats).
Imported from SourceForge on 2024-07-04 23:14:06 Created by msoegtropintel on 2019-09-01 06:53:26 Original: https://sourceforge.net/p/maxima/bugs/3571/#985a
Since this is not an issue with marginal precision I would say that this is simply a bug which should be fixed. I don't see why such a computation should fail with floats.
Imported from SourceForge on 2024-07-04 23:14:10 Created by peterpall on 2019-09-01 17:58:35 Original: https://sourceforge.net/p/maxima/bugs/3571/#0dbe/5329
solve() already converts floats to rationals before trying to find a solution, which in 99% of the cases is the optimum solution, at least for the problems I try to use it for => I am all for making integrate do the same.
Imported from SourceForge on 2024-07-04 23:14:13 Created by robert_dodier on 2019-11-07 04:45:09 Original: https://sourceforge.net/p/maxima/bugs/3571/#985a/a86d
I agree this is a bug and it should be fixed. The difficulty is that Maxima handles floats in symbolic expressions very poorly; there are numerous known bugs related to that. The idea for a solution which I suggested above is modify the integration code to convert any floats to rationals and then to adjust the relevant flags to prevent any more floats from entering the picture.
Another approach is to substitute a gensym for each distinct float value, carry out the integration, then substitute the corresponding float value for each gensym at the end, potentially making declarations about each gensym to match the float value. I don't know, without trying it, whether that's a plausible solution.
Imported from SourceForge on 2024-07-04 23:14:17 Created by robert_dodier on 2019-11-07 04:50:36 Original: https://sourceforge.net/p/maxima/bugs/3571/#9aca
To add to the examples already posted, I've observed the following.
(%i12) :lisp (trace $defint)
;; Tracing function $DEFINT.
($DEFINT)
(%i12) 'integrate(sqrt(1+cos(x)),x,0,2*%pi),float;
2 %pi
/
[ 0.5
(%o12) I (cos(x) + 1) dx
]
/
0
(%i13) %,nouns;
1. Trace: ($DEFINT '((MEXPT SIMP) ((MPLUS SIMP) 1 ((%COS SIMP) $X)) 0.5) '$X '0 '((MTIMES SIMP) 2 $%PI))
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
1. Trace: $DEFINT ==> ((RAT SIMP) 22619537 3998607)
22619537
(%o13) --------
3998607
(%i14) float(%);
(%o14) 5.656854249492386
(%i15) 'integrate(sqrt(1+cos(x)),x,0,2*%pi),float;
2 %pi
/
[ 0.5
(%o15) I (cos(x) + 1) dx
]
/
0
(%i16) %,nouns,float;
1. Trace: ($DEFINT '((MEXPT SIMP) ((MPLUS SIMP) 1 ((%COS SIMP) $X)) 0.5) '$X '0 '((MTIMES SIMP) 2 $%PI))
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
rat: replaced 0.5 by 1/2 = 0.5
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 -0.5 by -1/2 = -0.5
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
rat: replaced -0.5 by -1/2 = -0.5
rat: replaced 2.82842712474619 by 22619537/7997214 = 2.828427124746193
1. Trace: $DEFINT ==> 0
(%o16) 0
From this it appears it's not just the presence of the floating point value 0.5 in the integrand, but that the float
flag is enabled while evaluating the integral (via defint
which is the function to handle definite integrals).
The messages about converting floats to rationals within defint
are different in each case, which suggests that defint
is going down a different path when float
is enabled. The next thing to investigate is what is defint
doing differently when float
is enabled.
Imported from SourceForge on 2024-07-04 23:14:20 Created by peterpall on 2019-11-07 06:58:15 Original: https://sourceforge.net/p/maxima/bugs/3571/#7f1f
I personally would opt for automatically running rat () on floats: Some integrals give drastically different results depending on the range some numbers in the input term are in. And if we replace floats by symbols their value is temporarily lost. Additionally solve rationalizing numbers never has caused someone to complain to me.
Imported from SourceForge on 2024-07-04 23:14:02 Created by msoegtropintel on 2019-07-28 13:01:57 Original: https://sourceforge.net/p/maxima/bugs/3571
The integral "integrate(sqrt(1+cos(x)),x,0,2*%pi)" gives wrong results if evaluated with ",float". The analytic result is correct. See the following script:
This was tested on an intermediate version with info: