Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
22325: remove all _maxima_init_evaled_; move doctests to _init_
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Feb 8, 2017
1 parent 375d4ee commit 43a927b
Showing 1 changed file with 28 additions and 127 deletions.
155 changes: 28 additions & 127 deletions src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,6 @@ def __init__(self, name, nargs=2, latex_name=None, conversions={}):
super(OrthogonalFunction,self).__init__(name=name, nargs=nargs,
latex_name=latex_name, conversions=conversions)

def _maxima_init_evaled_(self, *args):
r"""
Return a string which represents this function evaluated at
``n, x`` in Maxima.
EXAMPLES::
sage: from sage.functions.orthogonal_polys import OrthogonalFunction
sage: P = OrthogonalFunction('testo_P')
sage: P._maxima_init_evaled_(2, 5) is None
True
"""
return None

def eval_formula(self, *args):
"""
Evaluate this polynomial using an explicit formula.
Expand Down Expand Up @@ -465,8 +451,6 @@ def __call__(self, *args, **kwds):
return self.eval_pari(*args, **kwds)
elif algorithm == 'recursive':
return self.eval_recursive(*args, **kwds)
elif algorithm == 'maxima':
return self._maxima_init_evaled_(*args, **kwds)

return super(OrthogonalFunction,self).__call__(*args, **kwds)

Expand Down Expand Up @@ -606,12 +590,18 @@ def __init__(self):
EXAMPLES::
sage: var('n, x')
(n, x)
sage: from sage.functions.orthogonal_polys import Func_chebyshev_T
sage: chebyshev_T2 = Func_chebyshev_T()
sage: chebyshev_T2(1,x)
x
sage: chebyshev_T(x, x)._sympy_()
chebyshevt(x, x)
sage: maxima(chebyshev_T(1,x, hold=True))
_SAGE_VAR_x
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
chebyshev_t(_SAGE_VAR_n,chebyshev_t(_SAGE_VAR_n,_SAGE_VAR_x))
"""
ChebyshevFunction.__init__(self, 'chebyshev_T', nargs=2,
conversions=dict(maxima='chebyshev_t',
Expand Down Expand Up @@ -733,21 +723,6 @@ def _evalf_(self, n, x, **kwds):

return mpcall(mpchebyt, n, x, parent=real_parent)

def _maxima_init_evaled_(self, n, x):
"""
Evaluate the Chebyshev polynomial ``self`` with maxima.
EXAMPLES::
sage: var('n, x')
(n, x)
sage: chebyshev_T._maxima_init_evaled_(1,x)
'_SAGE_VAR_x'
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
chebyshev_t(_SAGE_VAR_n,chebyshev_t(_SAGE_VAR_n,_SAGE_VAR_x))
"""
return maxima.eval('chebyshev_t({0},{1})'.format(n._maxima_init_(), x._maxima_init_()))

def eval_formula(self, n, x):
"""
Evaluate ``chebyshev_T`` using an explicit formula.
Expand Down Expand Up @@ -924,12 +899,18 @@ def __init__(self):
EXAMPLES::
sage: var('n, x')
(n, x)
sage: from sage.functions.orthogonal_polys import Func_chebyshev_U
sage: chebyshev_U2 = Func_chebyshev_U()
sage: chebyshev_U2(1,x)
2*x
sage: chebyshev_U(x, x)._sympy_()
chebyshevu(x, x)
sage: maxima(chebyshev_U(2,x, hold=True))
3*((-(8*(1-_SAGE_VAR_x))/3)+(4*(1-_SAGE_VAR_x)^2)/3+1)
sage: maxima(chebyshev_U(n,x, hold=True))
chebyshev_u(_SAGE_VAR_n,_SAGE_VAR_x)
"""
ChebyshevFunction.__init__(self, 'chebyshev_U', nargs=2,
conversions=dict(maxima='chebyshev_u',
Expand Down Expand Up @@ -1063,23 +1044,6 @@ def _eval_recursive_(self, n, x, both=False):
else:
return 2*a*(b-x*a), both and (b+a)*(b-a)

def _maxima_init_evaled_(self, n, x):
"""
Uses maxima to evaluate ``self``.
EXAMPLES::
sage: var('n, x')
(n, x)
sage: maxima(chebyshev_U(5,x))
32*_SAGE_VAR_x^5-32*_SAGE_VAR_x^3+6*_SAGE_VAR_x
sage: maxima(chebyshev_U(n,x))
chebyshev_u(_SAGE_VAR_n,_SAGE_VAR_x)
sage: maxima(chebyshev_U(2,x))
4*_SAGE_VAR_x^2-1
"""
return maxima.eval('chebyshev_u({0},{1})'.format(n._maxima_init_(), x._maxima_init_()))

def _evalf_(self, n, x, **kwds):
"""
Evaluate :class:`chebyshev_U` numerically with mpmath.
Expand Down Expand Up @@ -1355,6 +1319,8 @@ def __init__(self):
sage: loads(dumps(legendre_Q))
legendre_Q
sage: maxima(legendre_Q(20,x, hold=True))._sage_().coefficient(x,10)
-29113619535/131072*log(-(x + 1)/(x - 1))
"""
BuiltinFunction.__init__(self, "legendre_Q", nargs=2, latex_name=r"Q",
conversions={'maxima':'legendre_q', 'mathematica':'LegendreQ',
Expand All @@ -1376,11 +1342,6 @@ def _eval_(self, n, x, *args, **kwds):
-0.511424110789061 + 1.34356195297194*I
sage: legendre_Q(-1,x)
Infinity
NOTE::
Maxima (``algorithm='maxima'``) will output the complex
conjugate of the correct result, see :trac:`16813`.
"""
ret = self._eval_special_values_(n, x)
if ret is not None:
Expand All @@ -1391,24 +1352,6 @@ def _eval_(self, n, x, *args, **kwds):
return SR(unsigned_infinity);
return self.eval_formula(n, x)

def _maxima_init_evaled_(self, n, x):
"""
Return a string which represents this function evaluated at
``n, x`` in Maxima.
NOTE::
Maxima will output the complex conjugate of the
correct result, see :trac:`16813`.
EXAMPLES::
sage: legendre_Q._maxima_init_evaled_(20,x).coefficient(x,10)
-29113619535/131072*log(-(x + 1)/(x - 1))
"""
_init()
return sage_eval(maxima.eval('legendre_q(%s,x)'%ZZ(n)), locals={'x':x})

def _eval_special_values_(self, n, x):
"""
Special values known.
Expand Down Expand Up @@ -1589,6 +1532,8 @@ def __init__(self):
sage: loads(dumps(gen_legendre_P))
gen_legendre_P
sage: maxima(gen_legendre_P(20,6,x, hold=True))._sage_().expand().coefficient(x,10)
2508866163428625/128
"""
BuiltinFunction.__init__(self, "gen_legendre_P", nargs=3, latex_name=r"P",
conversions={'maxima':'assoc_legendre_p', 'mathematica':'LegendreP',
Expand Down Expand Up @@ -1617,19 +1562,6 @@ def _eval_(self, n, m, x, *args, **kwds):
and (x in ZZ or not SR(x).is_numeric())):
return self.eval_poly(n, m, x)

def _maxima_init_evaled_(self, n, m, x, **kwds):
"""
Return a string which represents this function evaluated at
``n, m, x`` in Maxima.
EXAMPLES::
sage: gen_legendre_P._maxima_init_evaled_(20,6,x).expand().coefficient(x,10)
2508866163428625/128
"""
_init()
return sage_eval(maxima.eval('assoc_legendre_p(%s,%s,x)'%(ZZ(n),ZZ(m))), locals={'x':x})

def _eval_special_values_(self, n, m, x):
"""
Special values known.
Expand Down Expand Up @@ -1746,6 +1678,8 @@ def __init__(self):
sage: loads(dumps(gen_legendre_Q))
gen_legendre_Q
sage: maxima(gen_legendre_Q(2,1,3, hold=True))._sage_().simplify_full()
1/4*sqrt(2)*(36*pi - 36*I*log(2) + 25*I)
"""
BuiltinFunction.__init__(self, "gen_legendre_Q", nargs=3, latex_name=r"Q",
conversions={'maxima':'assoc_legendre_q', 'mathematica':'LegendreQ',
Expand All @@ -1768,20 +1702,6 @@ def _eval_(self, n, m, x, *args, **kwds):
and (x in ZZ or not SR(x).is_numeric())):
return self.eval_recursive(n, m, x)

def _maxima_init_evaled_(self, n, m, x, **kwds):
"""
Return a string which represents this function evaluated at
``n, m, x`` in Maxima.
EXAMPLES::
sage: gen_legendre_Q._maxima_init_evaled_(2,1,3)
-3*sqrt(-2)*(3*I*pi + 3*log(2)) + 25/4*sqrt(-2)
"""
if m <= n:
_init()
return sage_eval(maxima.eval('assoc_legendre_q(%s,%s,x)'%(ZZ(n),ZZ(m))), locals={'x':x})

def _eval_special_values_(self, n, m, x):
"""
Special values known.
Expand Down Expand Up @@ -2130,30 +2050,20 @@ def __init__(self):
EXAMPLES::
sage: n,x = var('n,x')
sage: loads(dumps(laguerre))
laguerre
sage: laguerre(x, x)._sympy_()
laguerre(x, x)
sage: maxima(laguerre(1, x, hold=True))
1-_SAGE_VAR_x
sage: maxima(laguerre(n, laguerre(n, x)))
laguerre(_SAGE_VAR_n,laguerre(_SAGE_VAR_n,_SAGE_VAR_x))
"""
OrthogonalFunction.__init__(self, "laguerre", nargs=2, latex_name=r"L",
conversions={'maxima':'laguerre', 'mathematica':'LaguerreL',
'maple':'LaguerreL', 'sympy':'laguerre'})

def _maxima_init_evaled_(self, n, x):
"""
Evaluate the Laguerre polynomial ``self`` with maxima.
EXAMPLES::
sage: var('n, x')
(n, x)
sage: laguerre._maxima_init_evaled_(1,x)
'1-_SAGE_VAR_x'
sage: maxima(laguerre(n, laguerre(n, x)))
laguerre(_SAGE_VAR_n,laguerre(_SAGE_VAR_n,_SAGE_VAR_x))
"""
return maxima.eval('laguerre({0},{1})'.format(n._maxima_init_(), x._maxima_init_()))

def _eval_(self, n, x, *args, **kwds):
r"""
Return an evaluation of this Laguerre polynomial expression.
Expand Down Expand Up @@ -2289,29 +2199,20 @@ def __init__(self):
EXAMPLES::
sage: a,n,x = var('a, n, x')
sage: loads(dumps(gen_laguerre))
gen_laguerre
sage: gen_laguerre(x, x, x)._sympy_()
assoc_laguerre(x, x, x)
sage: maxima(gen_laguerre(1,2,x, hold=True))
3*(1-_SAGE_VAR_x/3)
sage: maxima(gen_laguerre(n, a, gen_laguerre(n, a, x)))
gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,_SAGE_VAR_x))
"""
OrthogonalFunction.__init__(self, "gen_laguerre", nargs=3, latex_name=r"L",
conversions={'maxima':'gen_laguerre', 'mathematica':'LaguerreL',
'maple':'LaguerreL', 'sympy':'assoc_laguerre'})

def _maxima_init_evaled_(self, n, a, x):
"""
Evaluate the Laguerre polynomial ``self`` with maxima.
EXAMPLES::
sage: a,n,x = var('a, n, x')
sage: gen_laguerre._maxima_init_evaled_(1,2,x)
'3*(1-_SAGE_VAR_x/3)'
sage: maxima(gen_laguerre(n, a, gen_laguerre(n, a, x)))
gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,_SAGE_VAR_x))
"""
return maxima.eval('gen_laguerre({0},{1},{2})'.format(n._maxima_init_(), a._maxima_init_(), x._maxima_init_()))

def _eval_(self, n, a, x, *args, **kwds):
r"""
Return an evaluation of this Laguerre polynomial expression.
Expand Down

0 comments on commit 43a927b

Please sign in to comment.