Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong result of integral #21440

Open
dkrenn opened this issue Sep 6, 2016 · 9 comments
Open

wrong result of integral #21440

dkrenn opened this issue Sep 6, 2016 · 9 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Sep 6, 2016

sage: f1 = (2*cos(2*pi*x) - cos(4*pi*x)) / (5 - 4*cos(2*pi*x))
sage: integrate(f1, x, 0, 1)
23/24

but it should be 1/4:

sage: sage: numerical_integral(f1,0,1)
(0.24999999999999997, 4.6160077311221225e-15)

and

sage: e(x)=exp(2*pi*I*x)
sage: f2=real(e(x)/(2-e(-x)))
sage: (f1-f2).simplify_trig()  # f1 equals f2
0
sage: integrate(f2,x,0,1)
1/4

This was reported by Lukas Spiegelhofer on 8/10/2015 16:00:13 via "Sage Notebooks Bugreports".

Upstream: Reported upstream. Developers acknowledge bug.

Component: symbolics

Keywords: wrong result, integration

Issue created by migration from https://trac.sagemath.org/ticket/21440

@dkrenn dkrenn added this to the sage-7.4 milestone Sep 6, 2016
@mforets
Copy link
Mannequin

mforets mannequin commented Mar 19, 2017

Upstream: Reported upstream. No feedback yet.

@mforets
Copy link
Mannequin

mforets mannequin commented Mar 19, 2017

comment:1

see: https://sourceforge.net/p/maxima/bugs/3295/

@mforets
Copy link
Mannequin

mforets mannequin commented Mar 20, 2017

Changed upstream from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.

@simon-king-jena
Copy link
Member

comment:3

Is the following example an instance of the same bug, or a different problem?

sage: (cos(pi*x)*exp(-I*pi*x)).integral(x,-1/2,1/2)  # wrong
1
sage: F = (cos(pi*x)*exp(-I*pi*x)).integral(x); F(x=1/2)-F(x=-1/2)  # correct
1/2

@mforets
Copy link
Mannequin

mforets mannequin commented Oct 2, 2018

comment:4

Hmmm they look similar to me, although in your example the primitive computed by Maxima is correct, but for the case of the description also the primitive is wrong:

sage: f1 = (2*cos(2*pi*x) - cos(4*pi*x)) / (5 - 4*cos(2*pi*x))
sage: F1 = f1.integrate(x)
sage: F1(x=1) - F1(x=0)  # yet another result!
5/8
sage: F1_g = f1.integrate(x, algorithm="giac")
sage: F1_g(x=1) - F1_g(x=0)
1/4

@zimmermann6
Copy link

comment:5

I'm not sure integrate accepts inputs that take non-real values (it should be documented if yes or no):

sage: f(x)=cos(pi*x)*exp(-I*pi*x)
sage: f(1/4)
-1/2*I + 1/2

Note that:

sage: (cos(pi*x)*exp(-I*pi*x)).real().integral(x,-1/2,1/2) 
1/2

@fchapoton
Copy link
Contributor

comment:6

Well, the primitives given by various algo are all different:

sage: f1 = (2*cos(2*pi*x) - cos(4*pi*x)) / (5 - 4*cos(2*pi*x))                  
sage: i1=f1.integral(x,algorithm='maxima').simplify_trig()                      
sage: i2=f1.integral(x,algorithm='giac').simplify_trig()                        
sage: i3=f1.integral(x,algorithm='fricas').simplify_trig()                      
sage: g1 = f1.simplify_trig()                                                   
sage: j1=g1.integral(x,algorithm='maxima').simplify_trig()                      
sage: j2=g1.integral(x,algorithm='giac').simplify_trig()                        
sage: j3=g1.integral(x,algorithm='fricas').simplify_trig()                      
sage: i1                                                                        
1/48*(30*pi*x + 24*cos(pi*x)*sin(pi*x) + 40*arctan(3*sin(pi*x)/cos(pi*x)) - 24*arctan(sin(pi*x)/cos(pi*x)) - 17*arctan2(2*cos(pi*x)*sin(pi*x), 2*cos(pi*x)^2 - 3/2) + 17*arctan2(2*cos(pi*x)*sin(pi*x), 2*cos(pi*x)^2 - 3))/pi
sage: i2                                                                        
1/8*(2*pi*x + 4*cos(pi*x)*sin(pi*x) + arctan(2*cos(pi*x)*sin(pi*x)/(2*sin(pi*x)^2 + 1)))/pi
sage: i3                                                                        
1/16*(2*pi*x + 8*cos(pi*x)*sin(pi*x) + arctan(1/6*(10*sin(pi*x)^2 - 1)/(cos(pi*x)*sin(pi*x))))/pi
sage: j1                                                                        
1/8*(pi*x + 4*cos(pi*x)*sin(pi*x) + arctan(3*sin(pi*x)/cos(pi*x)))/pi
sage: j2                                                                        
1/8*(2*pi*x + 4*cos(pi*x)*sin(pi*x) + arctan(2*cos(pi*x)*sin(pi*x)/(2*sin(pi*x)^2 + 1)))/pi
sage: j3                                                                        
1/16*(2*pi*x + 8*cos(pi*x)*sin(pi*x) + arctan(1/6*(10*sin(pi*x)^2 - 1)/(cos(pi*x)*sin(pi*x))))/pi
sage: (i1-j1).simplify_trig()       # maxima is not coherent with itself                                            
1/48*(24*pi*x + 34*arctan(3*sin(pi*x)/cos(pi*x)) - 24*arctan(sin(pi*x)/cos(pi*x)) - 17*arctan2(2*cos(pi*x)*sin(pi*x), 2*cos(pi*x)^2 - 3/2) + 17*arctan2(2*cos(pi*x)*sin(pi*x), 2*cos(pi*x)^2 - 3))/pi
sage: (i2-j2).simplify_trig()       # giac is coherent with itself                                          
0
sage: (i3-j3).simplify_trig()       # fricas is coherent with itself                                            
0

and only "giac" returns a continuous primitive ! All the others have a jump at 1/2

@fchapoton
Copy link
Contributor

Attachment: bad_primitives.png

display of the bad primitives

@fchapoton
Copy link
Contributor

comment:7

Here is the picture, with mathematica_free result at the end, also not continuous

@mkoeppe mkoeppe removed this from the sage-7.4 milestone Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants