Ticket #9706: trac_9706-review-ts.patch

File trac_9706-review-ts.patch, 8.1 KB (added by tscrim, 7 years ago)
  • sage/functions/orthogonal_polys.py

    # HG changeset patch
    # User Travis Scrimshaw <tscrim@ucdavis.edu>
    # Date 1386801612 28800
    # Node ID db238405761a61348ed3a4d320bad97c6d97059f
    # Parent 7732df38ae56db13a4605731e6c229c2f385b120
    #9706: review patch.
    
    diff --git a/sage/functions/orthogonal_polys.py b/sage/functions/orthogonal_polys.py
    a b class OrthogonalPolynomial(BuiltinFuncti 
    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::
    class OrthogonalPolynomial(BuiltinFuncti 
    471471        """
    472472        return super(OrthogonalPolynomial,self).__call__(n, *args, **kwds)
    473473
    474    
    475 
    476474class 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,
    class ChebyshevPolynomial(OrthogonalPoly 
    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::
    class ChebyshevPolynomial(OrthogonalPoly 
    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
    class Func_chebyshev_T(ChebyshevPolynomi 
    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        """
    class Func_chebyshev_T(ChebyshevPolynomi 
    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
    class Func_chebyshev_T(ChebyshevPolynomi 
    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.
    class Func_chebyshev_T(ChebyshevPolynomi 
    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)
    class Func_chebyshev_T(ChebyshevPolynomi 
    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
    class Func_chebyshev_T(ChebyshevPolynomi 
    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
    894883chebyshev_T = Func_chebyshev_T()
    895884
    class Func_chebyshev_U(ChebyshevPolynomi 
    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        """
    class Func_chebyshev_U(ChebyshevPolynomi 
    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
    class Func_chebyshev_U(ChebyshevPolynomi 
    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
    class Func_chebyshev_U(ChebyshevPolynomi 
    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
    class Func_chebyshev_U(ChebyshevPolynomi 
    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
    class Func_chebyshev_U(ChebyshevPolynomi 
    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
    11711156chebyshev_U = Func_chebyshev_U()
    11721157