Пример #1
0
    def _eval_(self, n, z):
        """
        EXAMPLES::

            sage: lambert_w(6.0)
            1.43240477589830
            sage: lambert_w(1)
            lambert_w(1)
            sage: lambert_w(x+1)
            lambert_w(x + 1)

        There are three special values which are automatically simplified::

            sage: lambert_w(0)
            0
            sage: lambert_w(e)
            1
            sage: lambert_w(-1/e)
            -1
            sage: lambert_w(SR(0))
            0

        The special values only hold on the principal branch::

            sage: lambert_w(1,e)
            lambert_w(1, e)
            sage: lambert_w(1, e.n())
            -0.532092121986380 + 4.59715801330257*I

        TESTS:

        When automatic simplication occurs, the parent of the output value should be
        either the same as the parent of the input, or a Sage type::

            sage: parent(lambert_w(int(0)))
            <type 'int'>
            sage: parent(lambert_w(Integer(0)))
            Integer Ring
            sage: parent(lambert_w(e))
            Integer Ring
        """
        if not isinstance(z, Expression):
            if is_inexact(z):
                return self._evalf_(n,
                                    z,
                                    parent=sage_structure_coerce_parent(z))
            elif n == 0 and z == 0:
                return sage_structure_coerce_parent(z)(Integer(0))
        elif n == 0:
            if z.is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(0))
            elif (z - const_e).is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(1))
            elif (z + 1 / const_e).is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(-1))
        return None
Пример #2
0
    def _eval_(self, n, z):
        """
        EXAMPLES::

            sage: lambert_w(6.0)
            1.43240477589830
            sage: lambert_w(1)
            lambert_w(1)
            sage: lambert_w(x+1)
            lambert_w(x + 1)

        There are three special values which are automatically simplified::

            sage: lambert_w(0)
            0
            sage: lambert_w(e)
            1
            sage: lambert_w(-1/e)
            -1
            sage: lambert_w(SR(0))
            0

        The special values only hold on the principal branch::

            sage: lambert_w(1,e)
            lambert_w(1, e)
            sage: lambert_w(1, e.n())
            -0.532092121986380 + 4.59715801330257*I

        TESTS:

        When automatic simplication occurs, the parent of the output value should be
        either the same as the parent of the input, or a Sage type::

            sage: parent(lambert_w(int(0)))
            <type 'int'>
            sage: parent(lambert_w(Integer(0)))
            Integer Ring
            sage: parent(lambert_w(e))
            Integer Ring
        """
        if not isinstance(z, Expression):
            if is_inexact(z):
                return self._evalf_(n, z, parent=sage_structure_coerce_parent(z))
            elif n == 0 and z == 0:
                return sage_structure_coerce_parent(z)(Integer(0))
        elif n == 0:
            if z.is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(0))
            elif (z-const_e).is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(1))
            elif (z+1/const_e).is_trivial_zero():
                return sage_structure_coerce_parent(z)(Integer(-1))
        return None
Пример #3
0
    def _evalf_(self, n, z, parent=None, algorithm=None):
        """
        EXAMPLES::

            sage: N(lambert_w(1))
            0.567143290409784
            sage: lambert_w(RealField(100)(1))
            0.56714329040978387299996866221

        SciPy is used to evaluate for float, RDF, and CDF inputs::

            sage: lambert_w(RDF(1))
            0.5671432904097838
        """
        R = parent or sage_structure_coerce_parent(z)
        if R is float or R is complex or R is RDF or R is CDF:
            import scipy.special
            return scipy.special.lambertw(z, n)
        else:
            import mpmath
            return mpmath_utils.call(mpmath.lambertw, z, n, parent=R)
Пример #4
0
    def _evalf_(self, n, z, parent=None, algorithm=None):
        """
        EXAMPLES::

            sage: N(lambert_w(1))
            0.567143290409784
            sage: lambert_w(RealField(100)(1))
            0.56714329040978387299996866221

        SciPy is used to evaluate for float, RDF, and CDF inputs::

            sage: lambert_w(RDF(1))
            0.56714329041
        """
        R = parent or sage_structure_coerce_parent(z)
        if R is float or R is complex or R is RDF or R is CDF:
            import scipy.special
            return scipy.special.lambertw(z, n)
        else:
            import mpmath
            return mpmath_utils.call(mpmath.lambertw, z, n, parent=R)