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

Commit bb227b6

Browse files
Travis Scrimshawvbraun
Travis Scrimshaw
authored andcommitted
#9706: review patch.
1 parent 51fcd6b commit bb227b6

File tree

1 file changed

+23
-38
lines changed

1 file changed

+23
-38
lines changed

src/sage/functions/orthogonal_polys.py

+23-38
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def _eval_special_values_(self, *args):
443443

444444
def _eval_(self, n, *args):
445445
"""
446-
The _eval_ method decides which evaluation suits best
446+
The :meth:`_eval_()` method decides which evaluation suits best
447447
for the given input, and returns a proper value.
448448
449449
EXAMPLES::
@@ -471,19 +471,15 @@ def __call__(self, n, *args, **kwds):
471471
"""
472472
return super(OrthogonalPolynomial,self).__call__(n, *args, **kwds)
473473

474-
475-
476474
class ChebyshevPolynomial(OrthogonalPolynomial):
477475
"""
478-
Super class for Chebyshev polynomials of the first and second kind.
476+
Abstract base class for Chebyshev polynomials of the first and second kind.
479477
480478
EXAMPLES::
481479
482480
sage: chebyshev_T(3,x)
483481
4*x^3 - 3*x
484-
485482
"""
486-
487483
def __call__(self, n, *args, **kwds):
488484
"""
489485
This overides the call method from SageObject to avoid problems with coercions,
@@ -518,11 +514,10 @@ def __call__(self, n, *args, **kwds):
518514
pass
519515

520516
return super(ChebyshevPolynomial,self).__call__(n, *args, **kwds)
521-
522517

523518
def _eval_(self, n, x):
524519
"""
525-
The _eval_ method decides which evaluation suits best
520+
The :meth:`_eval_()` method decides which evaluation suits best
526521
for the given input, and returns a proper value.
527522
528523
EXAMPLES::
@@ -563,8 +558,7 @@ def _eval_(self, n, x):
563558
# Expanded symbolic expression only for small values of n
564559
if is_Expression(x) and n.abs() < 32:
565560
return self.eval_formula(n, x)
566-
else:
567-
return self.eval_algebraic(n, x)
561+
return self.eval_algebraic(n, x)
568562

569563
if is_Expression(x) or is_Expression(n):
570564
# Check for known identities
@@ -617,9 +611,9 @@ def __init__(self):
617611
sage: chebyshev_T2(1,x)
618612
x
619613
"""
620-
super(Func_chebyshev_T,self).__init__("chebyshev_T", nargs=2,
621-
conversions=dict(maxima='chebyshev_t',
622-
mathematica='ChebyshevT'))
614+
ChebyshevPolynomial.__init__(self, "chebyshev_T", nargs=2,
615+
conversions=dict(maxima='chebyshev_t',
616+
mathematica='ChebyshevT'))
623617

624618
def _eval_special_values_(self, n, x):
625619
"""
@@ -711,7 +705,7 @@ def _evalf_(self, n, x, **kwds):
711705
real_parent = CC
712706

713707
if not is_RealField(real_parent) and not is_ComplexField(real_parent):
714-
raise TypeError("cannot evaluate chebyshev_T with parent %s"%real_parent)
708+
raise TypeError("cannot evaluate chebyshev_T with parent {}".format(real_parent))
715709

716710
from sage.libs.mpmath.all import call as mpcall
717711
from sage.libs.mpmath.all import chebyt as mpchebyt
@@ -730,11 +724,9 @@ def _maxima_init_evaled_(self, n, x):
730724
'x'
731725
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
732726
chebyshev_t(n,chebyshev_t(n,x))
733-
734727
"""
735728
return maxima.eval('chebyshev_t({0},{1})'.format(n._maxima_init_(), x._maxima_init_()))
736729

737-
738730
def eval_formula(self, n, x):
739731
"""
740732
Evaluate ``chebyshev_T`` using an explicit formula.
@@ -762,7 +754,6 @@ def eval_formula(self, n, x):
762754
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
763755
sage: chebyshev_T.eval_algebraic(10,x).expand()
764756
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
765-
766757
"""
767758
if n < 0:
768759
return self.eval_formula(-n, x)
@@ -814,16 +805,15 @@ def eval_algebraic(self, n, x):
814805
"""
815806
if n == 0:
816807
return parent(x).one()
817-
if n > 0:
818-
return self._eval_recursive_(n, x)[0]
819-
else:
808+
if n < 0:
820809
return self._eval_recursive_(-n, x)[0]
810+
return self._eval_recursive_(n, x)[0]
821811

822812
def _eval_recursive_(self, n, x, both=False):
823813
"""
824-
If ``both=True``, compute `(T(n,x), T(n-1,x))` using a
814+
If ``both=True``, compute ``(T(n,x), T(n-1,x))`` using a
825815
recursive formula.
826-
If ``both=False``, return instead a tuple `(T(n,x), False)`.
816+
If ``both=False``, return instead a tuple ``(T(n,x), False)``.
827817
828818
EXAMPLES::
829819
@@ -888,8 +878,7 @@ def _derivative_(self, n, x, diff_param):
888878
raise NotImplementedError("derivative w.r.t. to the index is not supported yet")
889879
elif diff_param == 1:
890880
return n*chebyshev_U(n-1, x)
891-
else:
892-
raise ValueError("illegal differentiation parameter %s"%diff_param)
881+
raise ValueError("illegal differentiation parameter {}".format(diff_param))
893882

894883
chebyshev_T = Func_chebyshev_T()
895884

@@ -920,9 +909,9 @@ def __init__(self):
920909
sage: chebyshev_U2(1,x)
921910
2*x
922911
"""
923-
OrthogonalPolynomial.__init__(self, "chebyshev_U", nargs=2,
924-
conversions=dict(maxima='chebyshev_u',
925-
mathematica='ChebyshevU'))
912+
ChebyshevPolynomial.__init__(self, "chebyshev_U", nargs=2,
913+
conversions=dict(maxima='chebyshev_u',
914+
mathematica='ChebyshevU'))
926915

927916
def eval_formula(self, n, x):
928917
"""
@@ -1005,24 +994,22 @@ def eval_algebraic(self, n, x):
1005994
"""
1006995
if n == -1:
1007996
return parent(x).zero()
1008-
if n >= 0:
1009-
return self._eval_recursive_(n, x)[0]
1010-
else:
997+
if n < 0:
1011998
return -self._eval_recursive_(-n-2, x)[0]
999+
return self._eval_recursive_(n, x)[0]
10121000

10131001
def _eval_recursive_(self, n, x, both=False):
10141002
"""
1015-
If ``both=True``, compute `(U(n,x), U(n-1,x))` using a
1003+
If ``both=True``, compute ``(U(n,x), U(n-1,x))`` using a
10161004
recursive formula.
1017-
If ``both=False``, return instead a tuple `(U(n,x), False)`.
1005+
If ``both=False``, return instead a tuple ``(U(n,x), False)``.
10181006
10191007
EXAMPLES::
10201008
10211009
sage: chebyshev_U._eval_recursive_(3, x)
10221010
(4*((2*x + 1)*(2*x - 1) - 2*x^2)*x, False)
10231011
sage: chebyshev_U._eval_recursive_(3, x, True)
10241012
(4*((2*x + 1)*(2*x - 1) - 2*x^2)*x, ((2*x + 1)*(2*x - 1) + 2*x)*((2*x + 1)*(2*x - 1) - 2*x))
1025-
10261013
"""
10271014
if n == 0:
10281015
return parent(x).one(), 2*x
@@ -1081,7 +1068,7 @@ def _evalf_(self, n, x, **kwds):
10811068
real_parent = CC
10821069

10831070
if not is_RealField(real_parent) and not is_ComplexField(real_parent):
1084-
raise TypeError("cannot evaluate chebyshev_U with parent %s"%real_parent)
1071+
raise TypeError("cannot evaluate chebyshev_U with parent {}".format(real_parent))
10851072

10861073
from sage.libs.mpmath.all import call as mpcall
10871074
from sage.libs.mpmath.all import chebyu as mpchebyu
@@ -1142,7 +1129,6 @@ def _eval_numpy_(self, n, x):
11421129
from scipy.special import eval_chebyu
11431130
return eval_chebyu(n, x)
11441131

1145-
11461132
def _derivative_(self, n, x, diff_param):
11471133
"""
11481134
Return the derivative of :class:`chebyshev_U` in form of the Chebyshev
@@ -1164,9 +1150,8 @@ def _derivative_(self, n, x, diff_param):
11641150
if diff_param == 0:
11651151
raise NotImplementedError("derivative w.r.t. to the index is not supported yet")
11661152
elif diff_param == 1:
1167-
return ((n+1)*chebyshev_T(n+1, x) - x*chebyshev_U(n,x))/(x*x-1)
1168-
else:
1169-
raise ValueError("illegal differentiation parameter %s"%diff_param)
1153+
return ((n+1)*chebyshev_T(n+1, x) - x*chebyshev_U(n,x)) / (x*x-1)
1154+
raise ValueError("illegal differentiation parameter {}".format(diff_param))
11701155

11711156
chebyshev_U = Func_chebyshev_U()
11721157

0 commit comments

Comments
 (0)