Ticket #4102: bessel_2.patch

File bessel_2.patch, 10.3 KB (added by eviatarbach, 8 years ago)
  • doc/en/reference/functions/index.rst

    # HG changeset patch
    # User Eviatar Bach <eviatarbach@gmail.com>
    # Date 1371504787 25200
    # Branch bessel
    # Node ID 4bbd99ed8b181b3bf5cba868ff17a4b12d2b52db
    # Parent  099567438c218d9efd28b3d06dbeb287305900e5
    Trac 4102: adding to manual, fixing identity, adding SymPy conversions
    
    diff --git a/doc/en/reference/functions/index.rst b/doc/en/reference/functions/index.rst
    a b  
    44.. toctree::
    55   :maxdepth: 2
    66
     7   sage/functions/bessel
    78   sage/functions/log
    89   sage/functions/hyperbolic
    910   sage/functions/transcendental
  • sage/functions/bessel.py

    diff --git a/sage/functions/bessel.py b/sage/functions/bessel.py
    a b  
    22Bessel Functions
    33
    44This module provides symbolic Bessel Functions. These functions use the
    5 `mpmath Library`_ for numerical evaluation and Maxima, GiNaC, Pynac for
     5`mpmath library`_ for numerical evaluation and Maxima, GiNaC, Pynac for
    66symbolics.
    77
    88The main objects which are exported from this module are:
    99
    10  * `bessel_J` - The Bessel J function
    11  * `bessel_Y` - The Bessel J function
    12  * `bessel_I` - The Bessel J function
    13  * `bessel_K` - The Bessel J function
    14  * `Bessel`   - A factory function for producing Bessel functions of
    15    various kinds and orders.
     10 * ``bessel_J`` -- The Bessel J function
     11 * ``bessel_Y`` -- The Bessel Y function
     12 * ``bessel_I`` -- The Bessel I function
     13 * ``bessel_K`` -- The Bessel K function
     14 * ``Bessel``   -- A factory function for producing Bessel functions of
     15   various kinds and orders
    1616
    1717-  Bessel functions, first defined by the Swiss mathematician
    1818   Daniel Bernoulli and named after Friedrich Bessel, are canonical
     
    2020
    2121   .. math::
    2222
    23          x^2 \frac{d^2 y}{dx^2} + x \frac{dy}{dx} + (x^2 - \nu^2)y = 0,
     23         x^2 \frac{d^2 y}{dx^2} + x \frac{dy}{dx} + \left(x^2 - \nu^2\right)y =
     24         0,
    2425
    25    for an arbitrary real number `\nu` (the order).
     26   for an arbitrary complex number `\nu` (the order).
    2627
    2728-  In this module, `J_\nu` denotes the unique solution of Bessel's equation
    2829   which is non-singular at `x = 0`. This function is known as the Bessel
     
    138139
    139140AUTHORS:
    140141
    141     - Benjamin Jones (2012-12-27): initial version.
     142    - Benjamin Jones (2012-12-27): initial version
    142143
    143144    - Some of the documentation here has been adapted from David Joyner's
    144145      original documentation of Sage's special functions module (2006).
     
    201202    .. math::
    202203
    203204        J_\nu(x) = \sum_{k=0}^\infty \frac{(-1)^k}{k! \Gamma(k+\nu+1)}
    204         (\frac{x}{2})^{2k+\nu}
     205        \left(\frac{x}{2}\right)^{2k+\nu}
    205206
    206207    The parameter `\nu` is called the order and may be any real or
    207     complex number, however the integer and half-integer values are most
     208    complex number; however, integer and half-integer values are most
    208209    common. It is defined for all complex numbers `x` when `\nu`
    209210    is an integer or greater than zero and it diverges as `x \to 0`
    210211    for negative non-integer values of `\nu`.
     
    220221
    221222    .. math::
    222223
    223         J_\nu(x) = \frac{x^n}{2^\nu \Gamma(\nu + 1)} {}_0F_1(\nu +
    224         1, -\frac{x^2}{4}).
     224        J_\nu(x) = \frac{x^n}{2^\nu \Gamma(\nu + 1)} {}_0F_1\left(\nu +
     225        1, -\frac{x^2}{4}\right).
    225226
    226227    EXAMPLES::
    227228
     
    288289            bessel_J
    289290        """
    290291        BuiltinFunction.__init__(self, "bessel_J", nargs=2,
    291                                  conversions=dict(maxima='bessel_j',
    292                                                   mathematica='BesselJ'))
     292                                 conversions=dict(mathematica='BesselJ',
     293                                                  maxima='bessel_j',
     294                                                  sympy='besselj'))
    293295
    294296    # remove after deprecation period
    295297    def __call__(self, *args, **kwds):
    296298        """
    297         Custom `__call__` method which uses the old Bessel function code if the
    298         `algorithm` or `prec` arguments are used. This should be removed after
    299         the deprecation period.
     299        Custom ``__call__`` method which uses the old Bessel function code if
     300        the ``algorithm`` or ``prec`` arguments are used. This should be
     301        removed after the deprecation period.
    300302
    301303        EXAMPLES::
    302304
     
    355357            sage: derivative(f, z)
    356358            z |--> 1/2*bessel_J(9, z) - 1/2*bessel_J(11, z)
    357359        """
    358         return (bessel_J(n-1, x) - bessel_J(n+1, x))/Integer(2)
     360        return (bessel_J(n - 1, x) - bessel_J(n + 1, x)) / Integer(2)
    359361
    360362    def _print_latex_(self, n, z):
    361363        """
     
    448450            bessel_Y(0, x)
    449451        """
    450452        BuiltinFunction.__init__(self, "bessel_Y", nargs=2,
    451                                  conversions=dict(maxima='bessel_y',
    452                                                   mathematica='BesselY'))
     453                                 conversions=dict(mathematica='BesselY',
     454                                                  maxima='bessel_y',
     455                                                  sympy='bessely'))
    453456
    454457    # remove after deprecation period
    455458    def __call__(self, *args, **kwds):
    456459        """
    457         Custom `__call__` method which uses the old Bessel function code if the
    458         `algorithm` or `prec` arguments are used. This should be removed after
    459         the deprecation period.
     460        Custom ``__call__`` method which uses the old Bessel function code if
     461        the ``algorithm`` or ``prec`` arguments are used. This should be
     462        removed after the deprecation period.
    460463
    461464        EXAMPLES::
    462465
     
    514517            sage: derivative(f, x)
    515518            x |--> 1/2*bessel_Y(9, x) - 1/2*bessel_Y(11, x)
    516519        """
    517         return (bessel_Y(n-1, x) - bessel_Y(n+1, x))/Integer(2)
     520        return (bessel_Y(n - 1, x) - bessel_Y(n + 1, x)) / Integer(2)
    518521
    519522    def _print_latex_(self, n, z):
    520523        """
     
    611614            bessel_I(1, x)
    612615        """
    613616        BuiltinFunction.__init__(self, "bessel_I", nargs=2,
    614                                  conversions=dict(maxima='bessel_i',
    615                                                   mathematica='BesselI'))
     617                                 conversions=dict(mathematica='BesselI',
     618                                                  maxima='bessel_i',
     619                                                  sympy='besseli'))
    616620
    617621    # remove after deprecation period
    618622    def __call__(self, *args, **kwds):
    619623        """
    620         Custom `__call__` method which uses the old Bessel function code if the
    621         `algorithm` or `prec` arguments are used. This should be removed after
    622         the deprecation period.
     624        Custom ``__call__`` method which uses the old Bessel function code if
     625        the ``algorithm`` or ``prec`` arguments are used. This should be
     626        removed after the deprecation period.
    623627
    624628        EXAMPLES::
    625629
     
    658662            return self._evalf_(n, x, parent(n))
    659663
    660664        # special identities
    661         if n == Integer(1)/Integer(2):
    662             return sqrt(2/(pi*x))*sinh(x)
    663         elif n == -Integer(1)/Integer(2):
    664             return sqrt(2/(pi*x))*cosh(x)
     665        if n == Integer(1) / Integer(2):
     666            return sqrt(2 / (pi * x)) * sinh(x)
     667        elif n == -Integer(1) / Integer(2):
     668            return sqrt(2 / (pi * x)) * cosh(x)
    665669
    666670        return None  # leaves the expression unevaluated
    667671
     
    677681
    678682    def _derivative_(self, n, x, diff_param=None):
    679683        """
    680         Return the derivative of the Bessel I function `I_n(x)` with repect
     684        Return the derivative of the Bessel I function `I_n(x)` with respect
    681685        to `x`.
    682686
    683687        EXAMPLES::
     
    686690            sage: derivative(f, x)
    687691            z |--> 1/2*bessel_I(9, x) + 1/2*bessel_I(11, x)
    688692        """
    689         return (bessel_I(n-1, x) + bessel_I(n+1, x))/Integer(2)
     693        return (bessel_I(n - 1, x) + bessel_I(n + 1, x)) / Integer(2)
    690694
    691695    def _print_latex_(self, n, z):
    692696        """
     
    799803            bessel_K
    800804        """
    801805        BuiltinFunction.__init__(self, "bessel_K", nargs=2,
    802                                  conversions=dict(maxima='bessel_k',
    803                                                   mathematica='BesselK'))
     806                                 conversions=dict(mathematica='BesselK',
     807                                                  maxima='bessel_k',
     808                                                  sympy='besselk'))
    804809
    805810    # remove after deprecation period
    806811    def __call__(self, *args, **kwds):
    807812        """
    808         Custom `__call__` method which uses the old Bessel function code if the
    809         `algorithm` or `prec` arguments are used. This should be removed after
    810         the deprecation period.
     813        Custom ``__call__`` method which uses the old Bessel function code if
     814        the ``algorithm`` or ``prec`` arguments are used. This should be
     815        removed after the deprecation period.
    811816
    812817        EXAMPLES::
    813818
     
    843848            return self._evalf_(n, x, parent(n))
    844849
    845850        # special identity
    846         if n == Integer(1)/Integer(2) and x > 0:
    847             return sqrt(pi/2)*exp(-x)*x**(Integer(1)/Integer(2))
     851        if n == Integer(1) / Integer(2) and x > 0:
     852            return sqrt(pi / 2) * exp(-x) * x ** (-Integer(1) / Integer(2))
    848853
    849854        return None  # leaves the expression unevaluated
    850855
     
    870875            sage: derivative(f, x)
    871876            x |--> 1/2*bessel_K(9, x) + 1/2*bessel_K(11, x)
    872877        """
    873         return (bessel_K(n-1, x) + bessel_K(n+1, x))/Integer(2)
     878        return (bessel_K(n - 1, x) + bessel_K(n + 1, x)) / Integer(2)
    874879
    875880    def _print_latex_(self, n, z):
    876881        """
     
    902907          function
    903908        - ``Bessel()`` -- order is unspecified, type is 'J'
    904909
    905     where `order` can be any integer and T must be one of the strings 'I', 'J',
    906     'K', or 'Y'.
     910    where ``order`` can be any integer and T must be one of the strings 'I',
     911    'J', 'K', or 'Y'.
    907912
    908913    See the EXAMPLES below.
    909914
     
    10491054        _system = 'mpmath'
    10501055
    10511056    # return the function
    1052     # TODO remove assertions
    1053     assert _type in ['I', 'J', 'K', 'Y']
    1054     assert _order is None or _order in RR
    1055     assert _nargs == 1 or _nargs == 2
    1056     assert _system == 'mpmath'
    1057 
    1058     # TODO what to do with _system?
    10591057    _f = bessel_type_dict[_type]
    10601058    if _nargs == 1:
    10611059        return lambda x: _f(_order, x)