@@ -443,7 +443,7 @@ def _eval_special_values_(self, *args):
443
443
444
444
def _eval_ (self , n , * args ):
445
445
"""
446
- The _eval_ method decides which evaluation suits best
446
+ The :meth:` _eval_()` method decides which evaluation suits best
447
447
for the given input, and returns a proper value.
448
448
449
449
EXAMPLES::
@@ -471,19 +471,15 @@ def __call__(self, n, *args, **kwds):
471
471
"""
472
472
return super (OrthogonalPolynomial ,self ).__call__ (n , * args , ** kwds )
473
473
474
-
475
-
476
474
class ChebyshevPolynomial (OrthogonalPolynomial ):
477
475
"""
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.
479
477
480
478
EXAMPLES::
481
479
482
480
sage: chebyshev_T(3,x)
483
481
4*x^3 - 3*x
484
-
485
482
"""
486
-
487
483
def __call__ (self , n , * args , ** kwds ):
488
484
"""
489
485
This overides the call method from SageObject to avoid problems with coercions,
@@ -518,11 +514,10 @@ def __call__(self, n, *args, **kwds):
518
514
pass
519
515
520
516
return super (ChebyshevPolynomial ,self ).__call__ (n , * args , ** kwds )
521
-
522
517
523
518
def _eval_ (self , n , x ):
524
519
"""
525
- The _eval_ method decides which evaluation suits best
520
+ The :meth:` _eval_()` method decides which evaluation suits best
526
521
for the given input, and returns a proper value.
527
522
528
523
EXAMPLES::
@@ -563,8 +558,7 @@ def _eval_(self, n, x):
563
558
# Expanded symbolic expression only for small values of n
564
559
if is_Expression (x ) and n .abs () < 32 :
565
560
return self .eval_formula (n , x )
566
- else :
567
- return self .eval_algebraic (n , x )
561
+ return self .eval_algebraic (n , x )
568
562
569
563
if is_Expression (x ) or is_Expression (n ):
570
564
# Check for known identities
@@ -617,9 +611,9 @@ def __init__(self):
617
611
sage: chebyshev_T2(1,x)
618
612
x
619
613
"""
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' ))
623
617
624
618
def _eval_special_values_ (self , n , x ):
625
619
"""
@@ -711,7 +705,7 @@ def _evalf_(self, n, x, **kwds):
711
705
real_parent = CC
712
706
713
707
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 ) )
715
709
716
710
from sage .libs .mpmath .all import call as mpcall
717
711
from sage .libs .mpmath .all import chebyt as mpchebyt
@@ -730,11 +724,9 @@ def _maxima_init_evaled_(self, n, x):
730
724
'x'
731
725
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
732
726
chebyshev_t(n,chebyshev_t(n,x))
733
-
734
727
"""
735
728
return maxima .eval ('chebyshev_t({0},{1})' .format (n ._maxima_init_ (), x ._maxima_init_ ()))
736
729
737
-
738
730
def eval_formula (self , n , x ):
739
731
"""
740
732
Evaluate ``chebyshev_T`` using an explicit formula.
@@ -762,7 +754,6 @@ def eval_formula(self, n, x):
762
754
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
763
755
sage: chebyshev_T.eval_algebraic(10,x).expand()
764
756
512*x^10 - 1280*x^8 + 1120*x^6 - 400*x^4 + 50*x^2 - 1
765
-
766
757
"""
767
758
if n < 0 :
768
759
return self .eval_formula (- n , x )
@@ -814,16 +805,15 @@ def eval_algebraic(self, n, x):
814
805
"""
815
806
if n == 0 :
816
807
return parent (x ).one ()
817
- if n > 0 :
818
- return self ._eval_recursive_ (n , x )[0 ]
819
- else :
808
+ if n < 0 :
820
809
return self ._eval_recursive_ (- n , x )[0 ]
810
+ return self ._eval_recursive_ (n , x )[0 ]
821
811
822
812
def _eval_recursive_ (self , n , x , both = False ):
823
813
"""
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
825
815
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)` `.
827
817
828
818
EXAMPLES::
829
819
@@ -888,8 +878,7 @@ def _derivative_(self, n, x, diff_param):
888
878
raise NotImplementedError ("derivative w.r.t. to the index is not supported yet" )
889
879
elif diff_param == 1 :
890
880
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 ))
893
882
894
883
chebyshev_T = Func_chebyshev_T ()
895
884
@@ -920,9 +909,9 @@ def __init__(self):
920
909
sage: chebyshev_U2(1,x)
921
910
2*x
922
911
"""
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' ))
926
915
927
916
def eval_formula (self , n , x ):
928
917
"""
@@ -1005,24 +994,22 @@ def eval_algebraic(self, n, x):
1005
994
"""
1006
995
if n == - 1 :
1007
996
return parent (x ).zero ()
1008
- if n >= 0 :
1009
- return self ._eval_recursive_ (n , x )[0 ]
1010
- else :
997
+ if n < 0 :
1011
998
return - self ._eval_recursive_ (- n - 2 , x )[0 ]
999
+ return self ._eval_recursive_ (n , x )[0 ]
1012
1000
1013
1001
def _eval_recursive_ (self , n , x , both = False ):
1014
1002
"""
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
1016
1004
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)` `.
1018
1006
1019
1007
EXAMPLES::
1020
1008
1021
1009
sage: chebyshev_U._eval_recursive_(3, x)
1022
1010
(4*((2*x + 1)*(2*x - 1) - 2*x^2)*x, False)
1023
1011
sage: chebyshev_U._eval_recursive_(3, x, True)
1024
1012
(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
-
1026
1013
"""
1027
1014
if n == 0 :
1028
1015
return parent (x ).one (), 2 * x
@@ -1081,7 +1068,7 @@ def _evalf_(self, n, x, **kwds):
1081
1068
real_parent = CC
1082
1069
1083
1070
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 ) )
1085
1072
1086
1073
from sage .libs .mpmath .all import call as mpcall
1087
1074
from sage .libs .mpmath .all import chebyu as mpchebyu
@@ -1142,7 +1129,6 @@ def _eval_numpy_(self, n, x):
1142
1129
from scipy .special import eval_chebyu
1143
1130
return eval_chebyu (n , x )
1144
1131
1145
-
1146
1132
def _derivative_ (self , n , x , diff_param ):
1147
1133
"""
1148
1134
Return the derivative of :class:`chebyshev_U` in form of the Chebyshev
@@ -1164,9 +1150,8 @@ def _derivative_(self, n, x, diff_param):
1164
1150
if diff_param == 0 :
1165
1151
raise NotImplementedError ("derivative w.r.t. to the index is not supported yet" )
1166
1152
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 ))
1170
1155
1171
1156
chebyshev_U = Func_chebyshev_U ()
1172
1157
0 commit comments