Beispiel #1
0
    def __init__(self,
                 name,
                 conversions=None,
                 latex=None,
                 mathml="",
                 domain='complex'):
        """
        EXAMPLES::

            sage: from sage.symbolic.constants import Constant
            sage: p = Constant('p')
            sage: loads(dumps(p))
            p
        """
        self._conversions = conversions if conversions is not None else {}
        self._latex = latex if latex is not None else name
        self._mathml = mathml
        self._name = name
        self._domain = domain

        for system, value in self._conversions.items():
            setattr(self, "_%s_" % system,
                    partial(self._generic_interface, value))
            setattr(self, "_%s_init_" % system,
                    partial(self._generic_interface_init, value))

        from sage.symbolic.constants_c import PynacConstant
        self._pynac = PynacConstant(self._name, self._latex, self._domain)
        self._serial = self._pynac.serial()
        constants_table[self._serial] = self
        constants_name_table[self._name] = self

        from sage.symbolic.pynac import register_symbol
        register_symbol(self.expression(), self._conversions)
Beispiel #2
0
    def __init__(self, name, conversions=None, latex=None, mathml="",
                 domain='complex'):
        """
        EXAMPLES::

            sage: from sage.symbolic.constants import Constant
            sage: p = Constant('p')
            sage: loads(dumps(p))
            p
        """
        self._conversions = conversions if conversions is not None else {}
        self._latex = latex if latex is not None else name
        self._mathml = mathml
        self._name = name
        self._domain = domain

        for system, value in self._conversions.items():
            setattr(self, "_%s_"%system, partial(self._generic_interface, value))
            setattr(self, "_%s_init_"%system, partial(self._generic_interface_init, value))

        from sage.symbolic.constants_c import PynacConstant
        self._pynac = PynacConstant(self._name, self._latex, self._domain)
        self._serial = self._pynac.serial()
        constants_table[self._serial] = self
        constants_name_table[self._name] = self
        
        from sage.symbolic.pynac import register_symbol
        register_symbol(self.expression(), self._conversions)
Beispiel #3
0
            H_{x}
            sage: latex(harmonic_number(x,2))
            H_{{x},{2}}
        """
        if m == 1:
            return r"H_{%s}" % z
        else:
            return r"H_{{%s},{%s}}" % (z, m)

harmonic_number = Function_harmonic_number_generalized()

def _swap_harmonic(a,b): return harmonic_number(b,a)

from sage.symbolic.pynac import register_symbol

register_symbol(_swap_harmonic,{'maxima':'gen_harmonic_number'})
register_symbol(_swap_harmonic,{'maple':'harmonic'})

class Function_harmonic_number(BuiltinFunction):
    r"""
    Harmonic number function, defined by:

    .. math::

        H_{n}=H_{n,1}=\sum_{k=1}^n\frac1k

        H_{s}=\int_0^1\frac{1-x^s}{1-x}

    See the docstring for :meth:`Function_harmonic_number_generalized`.

    This class exists as callback for ``harmonic_number`` returned by Maxima.
Beispiel #4
0
        if isinstance(x, float):
            return math.sqrt(x)
        elif type(x).__module__ == 'numpy':
            from numpy import sqrt
            return sqrt(x)
        try:
            return x.sqrt(*args, **kwds)
        # The following includes TypeError to catch cases where sqrt
        # is called with a "prec" keyword, for example, but the sqrt
        # method for x doesn't accept such a keyword.
        except (AttributeError, TypeError):
            pass
        return _do_sqrt(x, *args, **kwds)

# register sqrt in pynac symbol_table for conversion back from other systems
register_symbol(sqrt, dict(mathematica='Sqrt'))
symbol_table['functions']['sqrt'] = sqrt
    
Function_sqrt = type('deprecated_sqrt', (),
        {'__call__': staticmethod(sqrt),
            '__setstate__': lambda x, y: None})

class Function_arg(BuiltinFunction):
    def __init__(self):
        r"""
        The argument function for complex numbers.

        EXAMPLES::

            sage: arg(3+i)
            arctan(1/3)
Beispiel #5
0
        return math.sqrt(x)
    elif type(x).__module__ == 'numpy':
        from numpy import sqrt
        return sqrt(x)
    try:
        return x.sqrt(*args, **kwds)
    # The following includes TypeError to catch cases where sqrt
    # is called with a "prec" keyword, for example, but the sqrt
    # method for x doesn't accept such a keyword.
    except (AttributeError, TypeError):
        pass
    return _do_sqrt(x, *args, **kwds)


# register sqrt in pynac symbol_table for conversion back from other systems
register_symbol(sqrt, dict(mathematica='Sqrt'))
symbol_table['functions']['sqrt'] = sqrt

Function_sqrt = type('deprecated_sqrt', (), {
    '__call__': staticmethod(sqrt),
    '__setstate__': lambda x, y: None
})


class Function_arg(BuiltinFunction):
    def __init__(self):
        r"""
        The argument function for complex numbers.

        EXAMPLES::