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 integral of sqrt(1-cos(x)) #24587

Open
sagetrac-tmonteil mannequin opened this issue Jan 23, 2018 · 11 comments
Open

Wrong integral of sqrt(1-cos(x)) #24587

sagetrac-tmonteil mannequin opened this issue Jan 23, 2018 · 11 comments

Comments

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Jan 23, 2018

As reported on this ask question:

sage: integral(sqrt(1-cos(x)), x, 0, 2*pi)
0

This comes from the following wrong primitive

sage: integral(sqrt(1-cos(x)), x, algorithm='maxima')
-2*sqrt(2)/sqrt(sin(x)^2/(cos(x) + 1)^2 + 1)

where Fricas find a correct answer:

-2*(cos(x) + 1)*sqrt(-cos(x) + 1)/sin(x)

See Maxima bug 3659.

Upstream: Reported upstream. No feedback yet.

CC: @EmmanuelCharpentier @sagetrac-mafra @kcrisman

Component: symbolics

Keywords: integrate

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

@sagetrac-tmonteil sagetrac-tmonteil mannequin added this to the sage-8.2 milestone Jan 23, 2018
@mantepse
Copy link
Contributor

comment:2

#25220 fixes the problem with FriCAS.

@fchapoton

This comment has been minimized.

@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor

Changed keywords from none to integrate

@fchapoton
Copy link
Contributor

comment:6

This should be upstreamed to maxima. Karl-Dieter, would you do so, please ?

@kcrisman
Copy link
Member

comment:7

Interestingly, this may not necessarily be a problem with domain:complex. Can you just confirm that the Fricas antiderivative makes more sense at this graphic? It's been a while since I've had to deal with branch cuts and I feel like that is part of the question here - but the way in which the graphs are different between pi and 2pi is definitely a problem. BUT Maxima gives the correct answer to the definite integral between pi and 2pi with either setting of domain.

@kcrisman
Copy link
Member

comment:8

Okay, it is domain:complex, but more subtly.

(%i1) integrate(sqrt(1-cos(x)), x, %pi, 2*%pi);
                                      3/2
(%o1)                                2
(%i2) integrate(sqrt(1-cos(x)), x, 0, 2*%pi);  
                                      5/2
(%o2)                                2
(%i3) domain:complex;
(%o3)                               complex
(%i4) integrate(sqrt(1-cos(x)), x, %pi, 2*%pi);
                                      3/2
(%o4)                                2
(%i5) integrate(sqrt(1-cos(x)), x, 0, 2*%pi);
(%o5)                                  0

This I am more confident about reporting upstream.

@kcrisman
Copy link
Member

Upstream: Reported upstream. No feedback yet.

@kcrisman

This comment has been minimized.

@fchapoton
Copy link
Contributor

comment:10

No reaction upstream, it seems. Their primitive is plain wrong ; Fricas is right.

@EmmanuelCharpentier
Copy link
Mannequin

EmmanuelCharpentier mannequin commented Jan 5, 2022

comment:11

I forgot this one...

Replying to @fchapoton:

No reaction upstream, it seems. Their primitive is plain wrong ; Fricas is right.

More or less :

  • None of maxima, giac, fricas, mathematica has a term proportional to the length if the interval of integration ; all of them are periodic, which is wrong for the integral of a non-negative function positive almost everywhere on its period.

  • sympy doesn't integrate this.

  • fricas' result can be differentiated and simplified back to sqrt(1-cos(x)) ; others' can't.

  • giac, fricas and mathematica give results numerically close to the numerical integration up to a constant plus a discontinuity at 2kpi ;maxima is just plain wrong.

To summarize, contemplate :

sage: Num=lambda t:numerical_integral(lambda u:sqrt(1-cos(u)),0,t)[0]
sage: Max=sqrt(1-cos(x)).integrate(x, algorithm="maxima").function(x)
sage: Max=sqrt(1-cos(x)).integrate(x, algorithm="maxima").function(x)
sage: Giac=sqrt(1-cos(x)).integrate(x, algorithm="giac").function(x)
sage: Fricas=sqrt(1-cos(x)).integrate(x, algorithm="fricas").function(x)
sage: Mathematica=sqrt(1-cos(x)).integrate(x, algorithm="mathematica_free").function(x)
sage: plot([Num, Max, Giac, Fricas, Mathematica], (0, 4*pi), legend_label=["Numerical", "Maxima", "Giac", "Fricas", "Mathematica"])

It seems that up to the "branch cut", fricas, giac and mathematica give numerically correctly answer, only fricas' being (easily) checkable by differentiation and simplification.

BTW : when the result of an integration is a periodic function, shouldn't a term adding (floor(number of periods in the integration interval)*(integral on one period) be added to the result ? If so, how to implement this ?

@mkoeppe mkoeppe removed this from the sage-8.2 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

4 participants