Skip to content

Commit

Permalink
Trac #34186: Problem translating Fricas special function ellipticF to…
Browse files Browse the repository at this point in the history
… Sagemath

For reference: https://trac.sagemath.org/ticket/34058

There is still an issue with translation of Fricas special functions to
Sagemath.

Using sagemath 9.7 beta 5, Fricas returns antiderivative which has
`ellipticF` but this remains as is at Sagemath. But Sagemath  has no
such special function. It should be `elliptic_f`

{{{

>./sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 9.7.beta5, Release Date: 2022-07-10               │
│ Using Python 3.10.5. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: var('a b c x d')
(a, b, c, x, d)
sage: integrate((b*x^2+a)^(1/2)*(d*x^2+c)^(1/2),x, algorithm="fricas")
1/3*((b*d^2*x^2 + b*c*d + a*d^2)*sqrt(b*x^2 + a)*sqrt(d*x^2 +
c)*sqrt(b*d)*sqrt(-c/d) - (b^2*c^3 + a*b*c^2*d +
2*a*b*c*d^2)*x*ellipticF(sqrt(-c/d)/x, a*d/(b*c)) + (b^2*c^3 +
a*b*c^2*d)*x*elliptic_e(arcsin(sqrt(-c/d)/x),
a*d/(b*c)))/(sqrt(b*d)*b*d^2*x*sqrt(-c/d))
sage: ?ellipticF
Object `ellipticF` not found.

}}}

Thank you
--Nasser

URL: https://trac.sagemath.org/34186
Reported by: gh-nasser1
Ticket author(s): Martin Rubey
Reviewer(s): Frédéric Chapoton, Travis Scrimshaw
  • Loading branch information
Release Manager committed Aug 29, 2022
2 parents 8f6d1ac + c89110a commit 0175f5a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
45 changes: 44 additions & 1 deletion src/sage/functions/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,21 @@ def __init__(self):
sage: fricas(elliptic_e(x, y)).D(x).sage()/elliptic_e(x, y).diff(x) # optional - fricas
cos(x)/sqrt(-sin(x)^2 + 1)
Numerically::
sage: f = lambda x, y: elliptic_e(arcsin(x), y).subs(x=x, y=y) # optional - fricas
sage: g = lambda x, y: fricas.ellipticE(x, y).sage() # optional - fricas
sage: d = lambda x, y: f(x, y) - g(x, y) # optional - fricas
sage: [d(N(-pi/2+x), y) for x in range(1, 3) for y in range(-2,2)] # optional - fricas tol 1e-8
[0.000000000000000,
0.000000000000000,
0.000000000000000,
0.000000000000000,
5.55111512312578e-17,
0.000000000000000,
0.000000000000000,
0.000000000000000]
"""
BuiltinFunction.__init__(self, 'elliptic_e', nargs=2,
# Maple conversion left out since it uses
Expand Down Expand Up @@ -841,11 +856,39 @@ def __init__(self):
elliptic_f
sage: elliptic_f(x, 2)._sympy_()
elliptic_f(x, 2)
Check that :trac:`34186` is fixed::
sage: _ = var("x y")
sage: fricas(elliptic_f(x, y)) # optional - fricas
ellipticF(sin(x),y)
However, the conversion is only correct in the interval
`[-\pi/2, \pi/2]`::
sage: fricas(elliptic_f(x, y)).D(x).sage()/elliptic_f(x, y).diff(x) # optional - fricas
cos(x)/sqrt(-sin(x)^2 + 1)
Numerically::
sage: f = lambda x, y: elliptic_f(arcsin(x), y).subs(x=x, y=y) # optional - fricas
sage: g = lambda x, y: fricas.ellipticF(x, y).sage() # optional - fricas
sage: d = lambda x, y: f(x, y) - g(x, y) # optional - fricas
sage: [d(N(-pi/2+x), y) for x in range(1, 3) for y in range(-2,2)] # optional - fricas tol 1e-8
[0.000000000000000,
0.000000000000000,
0.000000000000000,
0.000000000000000,
5.55111512312578e-17,
0.000000000000000,
0.000000000000000,
0.000000000000000]
"""
BuiltinFunction.__init__(self, 'elliptic_f', nargs=2,
conversions=dict(mathematica='EllipticF',
maxima='elliptic_f',
# fricas='ellipticF', buggy
fricas='((x,y)+->ellipticF(sin(x), y))',
sympy='elliptic_f'))

def _eval_(self, z, m):
Expand Down
3 changes: 2 additions & 1 deletion src/sage/interfaces/fricas.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _register_symbols():
from sage.functions.hyperbolic import tanh, sinh, cosh, coth, sech, csch
from sage.functions.other import abs
from sage.functions.gamma import gamma
from sage.functions.special import elliptic_e
from sage.functions.special import elliptic_e, elliptic_f
from sage.misc.functional import symbolic_sum, symbolic_prod
from sage.rings.infinity import infinity
register_symbol(pi, {'fricas': 'pi'}, 0) # %pi::INFORM is %pi, but (pi) also exists
Expand All @@ -598,6 +598,7 @@ def _register_symbols():
register_symbol(gamma, {'fricas': 'Gamma'}, 1)
register_symbol(gamma, {'fricas': 'Gamma'}, 2)
register_symbol(lambda x, y: elliptic_e(asin(x), y), {'fricas': 'ellipticE'}, 2)
register_symbol(lambda x, y: elliptic_f(asin(x), y), {'fricas': 'ellipticF'}, 2)
register_symbol(lambda x, y: x + y, {'fricas': '+'}, 2)
register_symbol(lambda x, y: x - y, {'fricas': '-'}, 2)
register_symbol(lambda x, y: x * y, {'fricas': '*'}, 2)
Expand Down

0 comments on commit 0175f5a

Please sign in to comment.