ó
¡¼™\c           @  sC  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z d d l	 m
 Z
 d d l m Z d d l m Z m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& e d ƒ Z' d e f d „  ƒ  YZ( d e( f d „  ƒ  YZ) d „  Z* d e( f d „  ƒ  YZ+ d e( f d „  ƒ  YZ, d e( f d „  ƒ  YZ- d e f d „  ƒ  YZ. d e f d „  ƒ  YZ/ d  e( f d! „  ƒ  YZ0 d" e f d# „  ƒ  YZ1 d$ e( f d% „  ƒ  YZ2 d& e( f d' „  ƒ  YZ3 d( e( f d) „  ƒ  YZ4 d* S(+   s™   
This module mainly implements special orthogonal polynomials.

See also functions.combinatorial.numbers which contains some
combinatorial polynomials.

iÿÿÿÿ(   t   print_functiont   division(   t   Rational(   t   Functiont   ArgumentIndexError(   t   S(   t   Dummy(   t   binomialt	   factorialt   RisingFactorial(   t   re(   t   exp(   t   floor(   t   sqrt(   t   cos(   t   gamma(   t   hyper(   t   jacobi_polyt   gegenbauer_polyt   chebyshevt_polyt   chebyshevu_polyt   laguerre_polyt   hermite_polyt   legendre_polyt   xt   OrthogonalPolynomialc           B  s&   e  Z d  Z e d „  ƒ Z d „  Z RS(   s+   Base class for orthogonal polynomials.
    c         C  s;   | j  r7 | d k r7 |  j t | ƒ t ƒ j t | ƒ Sd  S(   Ni    (   t
   is_integert   _ortho_polyt   intt   _xt   subs(   t   clst   nR   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   _eval_at_order)   s    c         C  s$   |  j  |  j d |  j d j ƒ  ƒ S(   Ni    i   (   t   funct   argst	   conjugate(   t   self(    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   _eval_conjugate.   s    (   t   __name__t
   __module__t   __doc__t   classmethodR!   R&   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR   %   s   t   jacobic           B  s;   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z d „  Z RS(   sÜ  
    Jacobi polynomial :math:`P_n^{\left(\alpha, \beta\right)}(x)`

    jacobi(n, alpha, beta, x) gives the nth Jacobi polynomial
    in x, :math:`P_n^{\left(\alpha, \beta\right)}(x)`.

    The Jacobi polynomials are orthogonal on :math:`[-1, 1]` with respect
    to the weight :math:`\left(1-x\right)^\alpha \left(1+x\right)^\beta`.

    Examples
    ========

    >>> from sympy import jacobi, S, conjugate, diff
    >>> from sympy.abc import n,a,b,x

    >>> jacobi(0, a, b, x)
    1
    >>> jacobi(1, a, b, x)
    a/2 - b/2 + x*(a/2 + b/2 + 1)
    >>> jacobi(2, a, b, x)   # doctest:+SKIP
    (a**2/8 - a*b/4 - a/8 + b**2/8 - b/8 + x**2*(a**2/8 + a*b/4 + 7*a/8 +
    b**2/8 + 7*b/8 + 3/2) + x*(a**2/4 + 3*a/4 - b**2/4 - 3*b/4) - 1/2)

    >>> jacobi(n, a, b, x)
    jacobi(n, a, b, x)

    >>> jacobi(n, a, a, x)
    RisingFactorial(a + 1, n)*gegenbauer(n,
        a + 1/2, x)/RisingFactorial(2*a + 1, n)

    >>> jacobi(n, 0, 0, x)
    legendre(n, x)

    >>> jacobi(n, S(1)/2, S(1)/2, x)
    RisingFactorial(3/2, n)*chebyshevu(n, x)/factorial(n + 1)

    >>> jacobi(n, -S(1)/2, -S(1)/2, x)
    RisingFactorial(1/2, n)*chebyshevt(n, x)/factorial(n)

    >>> jacobi(n, a, b, -x)
    (-1)**n*jacobi(n, b, a, x)

    >>> jacobi(n, a, b, 0)
    2**(-n)*gamma(a + n + 1)*hyper((-b - n, -n), (a + 1,), -1)/(factorial(n)*gamma(a + 1))
    >>> jacobi(n, a, b, 1)
    RisingFactorial(a + 1, n)/factorial(n)

    >>> conjugate(jacobi(n, a, b, x))
    jacobi(n, conjugate(a), conjugate(b), conjugate(x))

    >>> diff(jacobi(n,a,b,x), x)
    (a/2 + b/2 + n/2 + 1/2)*jacobi(n - 1, a + 1, b + 1, x)

    See Also
    ========

    gegenbauer,
    chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly,
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Jacobi_polynomials
    .. [2] http://mathworld.wolfram.com/JacobiPolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/JacobiP/
    c         C  sÔ  | | k rÝ | t  j k rC t t  j | ƒ t | ƒ t | | ƒ S| t  j k r_ t | | ƒ S| t  j k r t d t  j | ƒ t | d ƒ t | | ƒ St | d | ƒ t d | d | ƒ t | | t  j | ƒ Sn» | | k r;t	 | | d ƒ t	 | d ƒ d | | d d | | d t
 | | | ƒ S| | k r˜t	 | | d ƒ t	 | d ƒ d | | d d | | d t
 | | | ƒ S| j s½| j ƒ  rÌt  j | t | | | | ƒ S| t  j k r1d | t	 | | d ƒ t	 | d ƒ t | ƒ t | | | g | d g d ƒ S| t  j k r[t | d | ƒ t | ƒ S| t  j k rÐ| j rº| | d | j r—t d ƒ ‚ n  t | | | d | ƒ t  j SqÐn t | | | | ƒ Sd  S(   Ni   i   i   iÿÿÿÿs,   Error. a + b + 2*n should not be an integer.(   R   t   HalfR	   R   t
   chebyshevtt   Zerot   legendret
   chebyshevut
   gegenbauerR   t   assoc_legendret	   is_Numbert   could_extract_minus_signt   NegativeOneR+   R   t   Onet   Infinityt   is_positiveR   t
   ValueErrorR   (   R   R    t   at   bR   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   eval„   s4    '/@QP	2$	&i   c   
   	   C  sb  d d l  m } | d k r. t |  | ƒ ‚ n0| d k r|  j \ } } } } t d ƒ } d | | | | d } | | d | d t | | d | | ƒ | | t | | | d | | ƒ }	 | | t | | | | ƒ |	 t | | | | ƒ | d | d f ƒ S| d k rø|  j \ } } } } t d ƒ } d | | | | d } d | | | | d | d t | | d | | ƒ | | t | | | d | | ƒ }	 | | t | | | | ƒ |	 t | | | | ƒ | d | d f ƒ S| d k rO|  j \ } } } } t j | | | d t | d | d | d | ƒ St |  | ƒ ‚ d  S(	   Niÿÿÿÿ(   t   Sumi   i   t   ki    i   i   (	   t   sympyR=   R   R#   R   R	   R+   R   R,   (
   R%   t   argindexR=   R    R:   R;   R   R>   t   f1t   f2(    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   fdiff­   s*    ,(D7)D6c   	      K  sÃ   d d l  m } | j s( | j t k r7 t d ƒ ‚ n  t d ƒ } t | | ƒ t | | | d | ƒ t | | d | | ƒ t | ƒ d | d | } d t | ƒ | | | d | f ƒ S(   Niÿÿÿÿ(   R=   s*   Error: n should be a non-negative integer.R>   i   i   i    (	   R?   R=   t   is_negativeR   t   FalseR9   R   R	   R   (	   R%   R    R:   R;   R   t   kwargsR=   R>   t   kern(    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   _eval_rewrite_as_polynomialÉ   s    \c         C  s=   |  j  \ } } } } |  j | | j ƒ  | j ƒ  | j ƒ  ƒ S(   N(   R#   R"   R$   (   R%   R    R:   R;   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR&   Ó   s    (   R'   R(   R)   R*   R<   RC   RH   R&   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR+   6   s
   L)	
c         C  s   t  d ƒ | | d t |  | d ƒ t |  | d ƒ d |  | | d t |  ƒ t |  | | d ƒ } t |  | | | ƒ t | ƒ S(   s  
    Jacobi polynomial :math:`P_n^{\left(\alpha, \beta\right)}(x)`

    jacobi_normalized(n, alpha, beta, x) gives the nth Jacobi polynomial
    in x, :math:`P_n^{\left(\alpha, \beta\right)}(x)`.

    The Jacobi polynomials are orthogonal on :math:`[-1, 1]` with respect
    to the weight :math:`\left(1-x\right)^\alpha \left(1+x\right)^\beta`.

    This functions returns the polynomials normilzed:

    .. math::

        \int_{-1}^{1}
          P_m^{\left(\alpha, \beta\right)}(x)
          P_n^{\left(\alpha, \beta\right)}(x)
          (1-x)^{\alpha} (1+x)^{\beta} \mathrm{d}x
        = \delta_{m,n}

    Examples
    ========

    >>> from sympy import jacobi_normalized
    >>> from sympy.abc import n,a,b,x

    >>> jacobi_normalized(n, a, b, x)
    jacobi(n, a, b, x)/sqrt(2**(a + b + 1)*gamma(a + n + 1)*gamma(b + n + 1)/((a + b + 2*n + 1)*factorial(n)*gamma(a + b + n + 1)))

    See Also
    ========

    gegenbauer,
    chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly,
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Jacobi_polynomials
    .. [2] http://mathworld.wolfram.com/JacobiPolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/JacobiP/
    i   i   (   R   R   R   R+   R   (   R    R:   R;   R   t   nfactor(    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   jacobi_normalizedØ   s    5pR1   c           B  s;   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z d „  Z RS(   sþ  
    Gegenbauer polynomial :math:`C_n^{\left(\alpha\right)}(x)`

    gegenbauer(n, alpha, x) gives the nth Gegenbauer polynomial
    in x, :math:`C_n^{\left(\alpha\right)}(x)`.

    The Gegenbauer polynomials are orthogonal on :math:`[-1, 1]` with
    respect to the weight :math:`\left(1-x^2\right)^{\alpha-\frac{1}{2}}`.

    Examples
    ========

    >>> from sympy import gegenbauer, conjugate, diff
    >>> from sympy.abc import n,a,x
    >>> gegenbauer(0, a, x)
    1
    >>> gegenbauer(1, a, x)
    2*a*x
    >>> gegenbauer(2, a, x)
    -a + x**2*(2*a**2 + 2*a)
    >>> gegenbauer(3, a, x)
    x**3*(4*a**3/3 + 4*a**2 + 8*a/3) + x*(-2*a**2 - 2*a)

    >>> gegenbauer(n, a, x)
    gegenbauer(n, a, x)
    >>> gegenbauer(n, a, -x)
    (-1)**n*gegenbauer(n, a, x)

    >>> gegenbauer(n, a, 0)
    2**n*sqrt(pi)*gamma(a + n/2)/(gamma(a)*gamma(1/2 - n/2)*gamma(n + 1))
    >>> gegenbauer(n, a, 1)
    gamma(2*a + n)/(gamma(2*a)*gamma(n + 1))

    >>> conjugate(gegenbauer(n, a, x))
    gegenbauer(n, conjugate(a), conjugate(x))

    >>> diff(gegenbauer(n, a, x), x)
    2*a*gegenbauer(n - 1, a + 1, x)

    See Also
    ========

    jacobi,
    chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gegenbauer_polynomials
    .. [2] http://mathworld.wolfram.com/GegenbauerPolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/GegenbauerC3/
    c         C  s­  | j  r t j S| t j k r, t | | ƒ S| t j k rH t | | ƒ S| t j k r^ t j S| j s™| t j k rŸ t	 | ƒ t j k t
 k r˜ t j Sd  Sn  | j ƒ  rÇ t j | t | | | ƒ S| t j k r*d | t t j ƒ t | t j | ƒ t d | d ƒ t | d ƒ t | ƒ S| t j k rgt d | | ƒ t d | ƒ t | d ƒ S| t j k r©| j r–t | | ƒ t j Sq©n t | | | ƒ Sd  S(   Ni   i   (   RD   R   R.   R,   R/   R6   R0   R5   R3   R
   t   Truet   ComplexInfinityt   NoneR4   R1   R   t   PiR   R7   R8   R	   R   (   R   R    R:   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   W  s0    		)+.	i   c   
      C  se  d d l  m } | d k r. t |  | ƒ ‚ n3| d k r|  j \ } } } t d ƒ } d d d | | | | | | d | | | } d | d | d | d | d | d d | | d | } | t | | | ƒ | t | | | ƒ }	 | |	 | d | d f ƒ S| d k rR|  j \ } } } d | t | d | d | ƒ St |  | ƒ ‚ d  S(   Niÿÿÿÿ(   R=   i   i   R>   i    i   (   R?   R=   R   R#   R   R1   (
   R%   R@   R=   R    R:   R   R>   t   factor1t   factor2RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   ‚  s     +* c         K  s‡   d d l  m } t d ƒ } d | t | | | ƒ d | | d | t | ƒ t | d | ƒ } | | | d t | d ƒ f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i    (   R?   R=   R   R	   R   R   (   R%   R    R:   R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   ˜  s
    ,c         C  s1   |  j  \ } } } |  j | | j ƒ  | j ƒ  ƒ S(   N(   R#   R"   R$   (   R%   R    R:   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR&   Ÿ  s    (   R'   R(   R)   R*   R<   RC   RH   R&   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR1     s
   >+	R-   c           B  s>   e  Z d  Z e e ƒ Z e d „  ƒ Z d d „ Z d „  Z	 RS(   s…  
    Chebyshev polynomial of the first kind, :math:`T_n(x)`

    chebyshevt(n, x) gives the nth Chebyshev polynomial (of the first
    kind) in x, :math:`T_n(x)`.

    The Chebyshev polynomials of the first kind are orthogonal on
    :math:`[-1, 1]` with respect to the weight :math:`\frac{1}{\sqrt{1-x^2}}`.

    Examples
    ========

    >>> from sympy import chebyshevt, chebyshevu, diff
    >>> from sympy.abc import n,x
    >>> chebyshevt(0, x)
    1
    >>> chebyshevt(1, x)
    x
    >>> chebyshevt(2, x)
    2*x**2 - 1

    >>> chebyshevt(n, x)
    chebyshevt(n, x)
    >>> chebyshevt(n, -x)
    (-1)**n*chebyshevt(n, x)
    >>> chebyshevt(-n, x)
    chebyshevt(n, x)

    >>> chebyshevt(n, 0)
    cos(pi*n/2)
    >>> chebyshevt(n, -1)
    (-1)**n

    >>> diff(chebyshevt(n, x), x)
    n*chebyshevu(n - 1, x)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Chebyshev_polynomial
    .. [2] http://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html
    .. [3] http://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html
    .. [4] http://functions.wolfram.com/Polynomials/ChebyshevT/
    .. [5] http://functions.wolfram.com/Polynomials/ChebyshevU/
    c         C  sÌ   | j  sž | j ƒ  r. t j | t | | ƒ S| j ƒ  rH t | | ƒ S| t j k ro t t j t j | ƒ S| t j	 k r… t j	 S| t j
 k rÈ t j
 Sn* | j r¸ |  j | | ƒ S|  j | | ƒ Sd  S(   N(   R3   R4   R   R5   R-   R.   R   R,   RN   R6   R7   RD   R!   (   R   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   é  s    	
	i   c         C  sa   | d k r t  |  | ƒ ‚ n? | d k rN |  j \ } } | t | d | ƒ St  |  | ƒ ‚ d  S(   Ni   i   (   R   R#   R0   (   R%   R@   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC     s    c         K  so   d d l  m } t d ƒ } t | d | ƒ | d d | | | d | } | | | d t | d ƒ f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i   i    (   R?   R=   R   R   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH     s    3(
   R'   R(   R)   t   staticmethodR   R   R*   R<   RC   RH   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR-   ¨  s
   =R0   c           B  s>   e  Z d  Z e e ƒ Z e d „  ƒ Z d d „ Z d „  Z	 RS(   s©  
    Chebyshev polynomial of the second kind, :math:`U_n(x)`

    chebyshevu(n, x) gives the nth Chebyshev polynomial of the second
    kind in x, :math:`U_n(x)`.

    The Chebyshev polynomials of the second kind are orthogonal on
    :math:`[-1, 1]` with respect to the weight :math:`\sqrt{1-x^2}`.

    Examples
    ========

    >>> from sympy import chebyshevt, chebyshevu, diff
    >>> from sympy.abc import n,x
    >>> chebyshevu(0, x)
    1
    >>> chebyshevu(1, x)
    2*x
    >>> chebyshevu(2, x)
    4*x**2 - 1

    >>> chebyshevu(n, x)
    chebyshevu(n, x)
    >>> chebyshevu(n, -x)
    (-1)**n*chebyshevu(n, x)
    >>> chebyshevu(-n, x)
    -chebyshevu(n - 2, x)

    >>> chebyshevu(n, 0)
    cos(pi*n/2)
    >>> chebyshevu(n, 1)
    n + 1

    >>> diff(chebyshevu(n, x), x)
    (-x*chebyshevu(n, x) + (n + 1)*chebyshevt(n + 1, x))/(x**2 - 1)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Chebyshev_polynomial
    .. [2] http://mathworld.wolfram.com/ChebyshevPolynomialoftheFirstKind.html
    .. [3] http://mathworld.wolfram.com/ChebyshevPolynomialoftheSecondKind.html
    .. [4] http://functions.wolfram.com/Polynomials/ChebyshevT/
    .. [5] http://functions.wolfram.com/Polynomials/ChebyshevU/
    c         C  s  | j  sÀ | j ƒ  r. t j | t | | ƒ S| j ƒ  rf | t j k rP t j St | d | ƒ Sn  | t j k r t t j t j | ƒ S| t j	 k r§ t j	 | S| t j
 k rt j
 SnH | j rø | t j k rß t j S|  j | d | ƒ Sn |  j | | ƒ Sd  S(   Ni   (   R3   R4   R   R5   R0   R.   R   R,   RN   R6   R7   RD   R!   (   R   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   U  s$    	
	i   c         C  s‚   | d k r t  |  | ƒ ‚ n` | d k ro |  j \ } } | d t | d | ƒ | t | | ƒ | d d St  |  | ƒ ‚ d  S(   Ni   i   (   R   R#   R-   R0   (   R%   R@   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   t  s    6c         K  s‡   d d l  m } t d ƒ } t j | t | | ƒ d | | d | t | ƒ t | d | ƒ } | | | d t | d ƒ f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i    (   R?   R=   R   R   R5   R   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH     s    K(
   R'   R(   R)   RQ   R   R   R*   R<   RC   RH   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR0     s
   =t   chebyshevt_rootc           B  s   e  Z d  Z e d „  ƒ Z RS(   sC  
    chebyshev_root(n, k) returns the kth root (indexed from zero) of
    the nth Chebyshev polynomial of the first kind; that is, if
    0 <= k < n, chebyshevt(n, chebyshevt_root(n, k)) == 0.

    Examples
    ========

    >>> from sympy import chebyshevt, chebyshevt_root
    >>> chebyshevt_root(3, 2)
    -sqrt(3)/2
    >>> chebyshevt(3, chebyshevt_root(3, 2))
    0

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly
    c         C  sR   d | k o | | k  s1 t  d | | f ƒ ‚ n  t t j d | d d | ƒ S(   Ni    s+   must have 0 <= k < n, got k = %s and n = %si   i   (   R9   R   R   RN   (   R   R    R>   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   §  s    (   R'   R(   R)   R*   R<   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRR   ‡  s   t   chebyshevu_rootc           B  s   e  Z d  Z e d „  ƒ Z RS(   s-  
    chebyshevu_root(n, k) returns the kth root (indexed from zero) of the
    nth Chebyshev polynomial of the second kind; that is, if 0 <= k < n,
    chebyshevu(n, chebyshevu_root(n, k)) == 0.

    Examples
    ========

    >>> from sympy import chebyshevu, chebyshevu_root
    >>> chebyshevu_root(3, 2)
    -sqrt(2)/2
    >>> chebyshevu(3, chebyshevu_root(3, 2))
    0

    See Also
    ========

    chebyshevt, chebyshevt_root, chebyshevu,
    legendre, assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly
    c         C  sN   d | k o | | k  s1 t  d | | f ƒ ‚ n  t t j | d | d ƒ S(   Ni    s+   must have 0 <= k < n, got k = %s and n = %si   (   R9   R   R   RN   (   R   R    R>   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   Ï  s    (   R'   R(   R)   R*   R<   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRS   ¯  s   R/   c           B  s>   e  Z d  Z e e ƒ Z e d „  ƒ Z d d „ Z d „  Z	 RS(   sY  
    legendre(n, x) gives the nth Legendre polynomial of x, :math:`P_n(x)`

    The Legendre polynomials are orthogonal on [-1, 1] with respect to
    the constant weight 1. They satisfy :math:`P_n(1) = 1` for all n; further,
    :math:`P_n` is odd for odd n and even for even n.

    Examples
    ========

    >>> from sympy import legendre, diff
    >>> from sympy.abc import x, n
    >>> legendre(0, x)
    1
    >>> legendre(1, x)
    x
    >>> legendre(2, x)
    3*x**2/2 - 1/2
    >>> legendre(n, x)
    legendre(n, x)
    >>> diff(legendre(n,x), x)
    n*(x*legendre(n, x) - legendre(n - 1, x))/(x**2 - 1)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
    assoc_legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Legendre_polynomial
    .. [2] http://mathworld.wolfram.com/LegendrePolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/LegendreP/
    .. [4] http://functions.wolfram.com/Polynomials/LegendreP2/
    c         C  sò   | j  sÄ | j ƒ  r. t j | t | | ƒ S| j ƒ  rO t | t j | ƒ S| t j k r• t t j ƒ t	 t j
 | d ƒ t	 t j | d ƒ S| t j k r« t j S| t j k rî t j Sn* | j rÞ | t j } n  |  j | | ƒ Sd  S(   Ni   (   R3   R4   R   R5   R/   R6   R.   R   RN   R   R,   R7   RD   R!   (   R   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<     s    	7
	i   c         C  s~   | d k r t  |  | ƒ ‚ n\ | d k rk |  j \ } } | | d d | t | | ƒ t | d | ƒ St  |  | ƒ ‚ d  S(   Ni   i   (   R   R#   R/   (   R%   R@   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   &  s    2c         K  sq   d d l  m } t d ƒ } d | t | | ƒ d d | d | | d | d | } | | | d | f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i   i    (   R?   R=   R   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   2  s    ?(
   R'   R(   R)   RQ   R   R   R*   R<   RC   RH   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR/   Û  s
   /R2   c           B  sJ   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d d „ Z d „  Z d „  Z RS(   s,  
    assoc_legendre(n,m, x) gives :math:`P_n^m(x)`, where n and m are
    the degree and order or an expression which is related to the nth
    order Legendre polynomial, :math:`P_n(x)` in the following manner:

    .. math::
        P_n^m(x) = (-1)^m (1 - x^2)^{\frac{m}{2}}
                   \frac{\mathrm{d}^m P_n(x)}{\mathrm{d} x^m}

    Associated Legendre polynomial are orthogonal on [-1, 1] with:

    - weight = 1            for the same m, and different n.
    - weight = 1/(1-x**2)   for the same n, and different m.

    Examples
    ========

    >>> from sympy import assoc_legendre
    >>> from sympy.abc import x, m, n
    >>> assoc_legendre(0,0, x)
    1
    >>> assoc_legendre(1,0, x)
    x
    >>> assoc_legendre(1,1, x)
    -sqrt(1 - x**2)
    >>> assoc_legendre(n,m,x)
    assoc_legendre(n, m, x)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre,
    hermite,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Associated_Legendre_polynomials
    .. [2] http://mathworld.wolfram.com/LegendrePolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/LegendreP/
    .. [4] http://functions.wolfram.com/Polynomials/LegendreP2/
    c         C  sO   t  | t d t ƒj t | f ƒ } d | d t d t | d ƒ | j ƒ  S(   Nt   polysiÿÿÿÿi   i   (   R   R   RK   t   diffR   t   as_expr(   R   R    t   mt   P(    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR!   o  s    $c         C  sQ  | j  ƒ  rE t j | t | | ƒ t | | ƒ t | | | ƒ S| d k r^ t | | ƒ S| d k r« d | t t j ƒ t d | | d ƒ t d | | d ƒ S| j	 rM| j	 rM| j
 rM| j
 rM| j rñ t d |  | f ƒ ‚ n  t | ƒ | k rt d |  | | f ƒ ‚ n  |  j t | ƒ t t | ƒ ƒ ƒ j t | ƒ Sd  S(   Ni    i   i   s3   %s : 1st index must be nonnegative integer (got %r)s9   %s : abs('2nd index') must be <= '1st index' (got %r, %r)(   R4   R   R5   R   R2   R/   R   RN   R   R3   R   RD   R9   t   absR!   R   R   R   (   R   R    RW   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   t  s    9A$	i   c         C  s±   | d k r t  |  | ƒ ‚ n | d k r< t  |  | ƒ ‚ nq | d k rž |  j \ } } } d | d d | | t | | | ƒ | | t | d | | ƒ St  |  | ƒ ‚ d  S(   Ni   i   i   (   R   R#   R2   (   R%   R@   R    RW   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   …  s    Dc         K  sÁ   d d l  m } t d ƒ } t d | d | ƒ d | t | | ƒ t | ƒ t | d | | ƒ d | | | | d | } d | d | d | | | d t | | t j ƒ f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i   i    (   R?   R=   R   R   R   R   R,   (   R%   R    RW   R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   ”  s    jc         C  s1   |  j  \ } } } |  j | | j ƒ  | j ƒ  ƒ S(   N(   R#   R"   R$   (   R%   R    RW   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR&   ›  s    (	   R'   R(   R)   R*   R!   R<   RC   RH   R&   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR2   9  s   4	t   hermitec           B  s>   e  Z d  Z e e ƒ Z e d „  ƒ Z d d „ Z d „  Z	 RS(   sÔ  
    hermite(n, x) gives the nth Hermite polynomial in x, :math:`H_n(x)`

    The Hermite polynomials are orthogonal on :math:`(-\infty, \infty)`
    with respect to the weight :math:`\exp\left(-x^2\right)`.

    Examples
    ========

    >>> from sympy import hermite, diff
    >>> from sympy.abc import x, n
    >>> hermite(0, x)
    1
    >>> hermite(1, x)
    2*x
    >>> hermite(2, x)
    4*x**2 - 2
    >>> hermite(n, x)
    hermite(n, x)
    >>> diff(hermite(n,x), x)
    2*n*hermite(n - 1, x)
    >>> hermite(n, -x)
    (-1)**n*hermite(n, x)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    laguerre, assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Hermite_polynomial
    .. [2] http://mathworld.wolfram.com/HermitePolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/HermiteH/
    c         C  s°   | j  s€ | j ƒ  r. t j | t | | ƒ S| t j k rg d | t t j ƒ t t j	 | d ƒ S| t j
 k r¬ t j
 Sn, | j rœ t d | ƒ ‚ n |  j | | ƒ Sd  S(   Ni   s0   The index n must be nonnegative integer (got %r)(   R3   R4   R   R5   RZ   R.   R   RN   R   R6   R7   RD   R9   R!   (   R   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   Ö  s    	*
	i   c         C  se   | d k r t  |  | ƒ ‚ nC | d k rR |  j \ } } d | t | d | ƒ St  |  | ƒ ‚ d  S(   Ni   i   (   R   R#   RZ   (   R%   R@   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   ê  s    c         K  s€   d d l  m } t d ƒ } d | t | ƒ t | d | ƒ d | | d | } t | ƒ | | | d t | d ƒ f ƒ S(   Niÿÿÿÿ(   R=   R>   i   i    (   R?   R=   R   R   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   õ  s    :(
   R'   R(   R)   RQ   R   R   R*   R<   RC   RH   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRZ   ¤  s
   .t   laguerrec           B  s>   e  Z d  Z e e ƒ Z e d „  ƒ Z d d „ Z d „  Z	 RS(   s  
    Returns the nth Laguerre polynomial in x, :math:`L_n(x)`.

    Parameters
    ==========

    n : int
        Degree of Laguerre polynomial. Must be ``n >= 0``.

    Examples
    ========

    >>> from sympy import laguerre, diff
    >>> from sympy.abc import x, n
    >>> laguerre(0, x)
    1
    >>> laguerre(1, x)
    1 - x
    >>> laguerre(2, x)
    x**2/2 - 2*x + 1
    >>> laguerre(3, x)
    -x**3/6 + 3*x**2/2 - 3*x + 1

    >>> laguerre(n, x)
    laguerre(n, x)

    >>> diff(laguerre(n, x), x)
    -assoc_laguerre(n - 1, 1, x)

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    assoc_laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Laguerre_polynomial
    .. [2] http://mathworld.wolfram.com/LaguerrePolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/LaguerreL/
    .. [4] http://functions.wolfram.com/Polynomials/LaguerreL3/
    c         C  s±   | j  s | j ƒ  r1 t | ƒ t | d | ƒ S| t j k rG t j S| t j k r] t j S| t j k r­ t j	 | t j Sn, | j
 r t d | ƒ ‚ n |  j | | ƒ Sd  S(   Ni   s0   The index n must be nonnegative integer (got %r)(   R3   R4   R   R[   R   R.   R6   t   NegativeInfinityR7   R5   RD   R9   R!   (   R   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   9  s    		i   c         C  sa   | d k r t  |  | ƒ ‚ n? | d k rN |  j \ } } t | d d | ƒ St  |  | ƒ ‚ d  S(   Ni   i   (   R   R#   t   assoc_laguerre(   R%   R@   R    R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   P  s    c         K  s   d d l  m } | j s( | j t k r7 t d ƒ ‚ n  t d ƒ } t | | ƒ t | ƒ d | | } | | | d | f ƒ S(   Niÿÿÿÿ(   R=   s*   Error: n should be a non-negative integer.R>   i   i    (	   R?   R=   RD   R   RE   R9   R   R	   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   [  s    &(
   R'   R(   R)   RQ   R   R   R*   R<   RC   RH   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR[      s
   5R]   c           B  s;   e  Z d  Z e d „  ƒ Z d d „ Z d „  Z d „  Z RS(   s2  
    Returns the nth generalized Laguerre polynomial in x, :math:`L_n(x)`.

    Parameters
    ==========

    n : int
        Degree of Laguerre polynomial. Must be ``n >= 0``.

    alpha : Expr
        Arbitrary expression. For ``alpha=0`` regular Laguerre
        polynomials will be generated.

    Examples
    ========

    >>> from sympy import laguerre, assoc_laguerre, diff
    >>> from sympy.abc import x, n, a
    >>> assoc_laguerre(0, a, x)
    1
    >>> assoc_laguerre(1, a, x)
    a - x + 1
    >>> assoc_laguerre(2, a, x)
    a**2/2 + 3*a/2 + x**2/2 + x*(-a - 2) + 1
    >>> assoc_laguerre(3, a, x)
    a**3/6 + a**2 + 11*a/6 - x**3/6 + x**2*(a/2 + 3/2) +
        x*(-a**2/2 - 5*a/2 - 3) + 1

    >>> assoc_laguerre(n, a, 0)
    binomial(a + n, a)

    >>> assoc_laguerre(n, a, x)
    assoc_laguerre(n, a, x)

    >>> assoc_laguerre(n, 0, x)
    laguerre(n, x)

    >>> diff(assoc_laguerre(n, a, x), x)
    -assoc_laguerre(n - 1, a + 1, x)

    >>> diff(assoc_laguerre(n, a, x), a)
    Sum(assoc_laguerre(_k, a, x)/(-a + n), (_k, 0, n - 1))

    See Also
    ========

    jacobi, gegenbauer,
    chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
    legendre, assoc_legendre,
    hermite,
    laguerre,
    sympy.polys.orthopolys.jacobi_poly
    sympy.polys.orthopolys.gegenbauer_poly
    sympy.polys.orthopolys.chebyshevt_poly
    sympy.polys.orthopolys.chebyshevu_poly
    sympy.polys.orthopolys.hermite_poly
    sympy.polys.orthopolys.legendre_poly
    sympy.polys.orthopolys.laguerre_poly

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Laguerre_polynomial#Assoc_laguerre_polynomials
    .. [2] http://mathworld.wolfram.com/AssociatedLaguerrePolynomial.html
    .. [3] http://functions.wolfram.com/Polynomials/LaguerreL/
    .. [4] http://functions.wolfram.com/Polynomials/LaguerreL3/
    c         C  sÍ   | t  j k r t | | ƒ S| j s | t  j k rE t | | | ƒ S| t  j k ru | t  j k ru t  j | t  j S| t  j k rÉ | t  j k rÉ t  j Sn, | j r¹ t	 d | ƒ ‚ n t
 | | | ƒ Sd  S(   Ns0   The index n must be nonnegative integer (got %r)(   R   R.   R[   R3   R   R7   R5   R\   RD   R9   R   (   R   R    t   alphaR   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR<   ª  s    	
	i   c         C  sÐ   d d l  m } | d k r. t |  | ƒ ‚ nž | d k r† |  j \ } } } t d ƒ } | t | | | ƒ | | | d | d f ƒ S| d k r½ |  j \ } } } t | d | d | ƒ St |  | ƒ ‚ d  S(   Niÿÿÿÿ(   R=   i   i   R>   i    i   (   R?   R=   R   R#   R   R]   (   R%   R@   R=   R    R^   R   R>   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRC   À  s    .c         K  s©   d d l  m } | j s( | j t k r7 t d ƒ ‚ n  t d ƒ } t | | ƒ t | t	 d ƒ t
 | ƒ | | } t | t	 d ƒ t
 | ƒ | | | d | f ƒ S(   Niÿÿÿÿ(   R=   s*   Error: n should be a non-negative integer.R>   i   i    (   R?   R=   RD   R   RE   R9   R   R	   R   R^   R   (   R%   R    R   RF   R=   R>   RG   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyRH   Ñ  s    4c         C  s1   |  j  \ } } } |  j | | j ƒ  | j ƒ  ƒ S(   N(   R#   R"   R$   (   R%   R    R^   R   (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR&   Û  s    (   R'   R(   R)   R*   R<   RC   RH   R&   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyR]   e  s
   C	
N(5   R)   t
   __future__R    R   t
   sympy.coreR   t   sympy.core.functionR   R   t   sympy.core.singletonR   t   sympy.core.symbolR   t(   sympy.functions.combinatorial.factorialsR   R   R	   t$   sympy.functions.elementary.complexesR
   t&   sympy.functions.elementary.exponentialR   t#   sympy.functions.elementary.integersR   t(   sympy.functions.elementary.miscellaneousR   t(   sympy.functions.elementary.trigonometricR   t'   sympy.functions.special.gamma_functionsR   t   sympy.functions.special.hyperR   t   sympy.polys.orthopolysR   R   R   R   R   R   R   R   R   R+   RJ   R1   R-   R0   RR   RS   R/   R2   RZ   R[   R]   (    (    (    sB   lib/python2.7/site-packages/sympy/functions/special/polynomials.pyt   <module>   s8   4
¢	?‘ls(,^k\e