def __call__(self, x, coerce=True, hold=False, prec=None, dont_call_method_on_arg=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = exp(RealField(100)(2)); t 7.3890560989306502272304274606 sage: t.prec() 100 TESTS:: sage: exp(2,prec=100) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead. 7.3890560989306502272304274606 """ if prec is not None: from sage.misc.misc import deprecation deprecation("The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead.") x = GinacFunction.__call__(self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg) return x.n(prec) return GinacFunction.__call__(self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg)
def __call__(self, x, prec=None, coerce=True, hold=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = gamma(RealField(100)(2.5)); t 1.3293403881791370204736256125 sage: t.prec() 100 sage: gamma(6, prec=53) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead. 120.000000000000 TESTS:: sage: gamma(pi,prec=100) 2.2880377953400324179595889091 sage: gamma(3/4,prec=100) 1.2254167024651776451290983034 """ if prec is not None: from sage.misc.misc import deprecation deprecation( "The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead." ) import mpmath return mpmath_utils.call(mpmath.gamma, x, prec=prec) # this is a kludge to keep # sage: Q.<i> = NumberField(x^2+1) # sage: gamma(i) # working, since number field elements cannot be coerced into SR # without specifying an explicit embedding into CC any more try: res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold) except TypeError, err: # the __call__() method returns a TypeError for fast float arguments # as well, we only proceed if the error message says that # the arguments cannot be coerced to SR if not str(err).startswith("cannot coerce"): raise from sage.misc.misc import deprecation deprecation( "Calling symbolic functions with arguments that cannot be coerced into symbolic expressions is deprecated." ) parent = RR if prec is None else RealField(prec) try: x = parent(x) except (ValueError, TypeError): x = parent.complex_field()(x) res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold)
def __call__(self, x, prec=None, coerce=True, hold=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = gamma(RealField(100)(2.5)); t 1.3293403881791370204736256125 sage: t.prec() 100 sage: gamma(6, prec=53) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead. 120.000000000000 TESTS:: sage: gamma(pi,prec=100) 2.2880377953400324179595889091 sage: gamma(3/4,prec=100) 1.2254167024651776451290983034 """ if prec is not None: from sage.misc.misc import deprecation deprecation("The prec keyword argument is deprecated. Explicitly set the precision of the input, for example gamma(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., gamma(1).n(300), instead.") import mpmath return mpmath_utils.call(mpmath.gamma, x, prec=prec) # this is a kludge to keep # sage: Q.<i> = NumberField(x^2+1) # sage: gamma(i) # working, since number field elements cannot be coerced into SR # without specifying an explicit embedding into CC any more try: res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold) except TypeError, err: # the __call__() method returns a TypeError for fast float arguments # as well, we only proceed if the error message says that # the arguments cannot be coerced to SR if not str(err).startswith("cannot coerce"): raise from sage.misc.misc import deprecation deprecation("Calling symbolic functions with arguments that cannot be coerced into symbolic expressions is deprecated.") parent = RR if prec is None else RealField(prec) try: x = parent(x) except (ValueError, TypeError): x = parent.complex_field()(x) res = GinacFunction.__call__(self, x, coerce=coerce, hold=hold)
def __call__(self, x, coerce=True, hold=False, prec=None, dont_call_method_on_arg=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = exp(RealField(100)(2)); t 7.3890560989306502272304274606 sage: t.prec() 100 TESTS:: sage: exp(2,prec=100) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead. See http://trac.sagemath.org/7490 for details. 7.3890560989306502272304274606 Ensure that :trac:`13608` is fixed:: sage: import mpmath sage: a = mpmath.mpf('0.5') sage: exp(a) mpf('1.6487212707001282') sage: a.exp -1 """ if prec is not None: from sage.misc.superseded import deprecation deprecation( 7490, "The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead." ) x = GinacFunction.__call__( self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg) return x.n(prec) return GinacFunction.__call__( self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg)
def __call__(self, x, coerce=True, hold=False, prec=None, dont_call_method_on_arg=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = exp(RealField(100)(2)); t 7.3890560989306502272304274606 sage: t.prec() 100 TESTS:: sage: exp(2,prec=100) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead. 7.3890560989306502272304274606 """ if prec is not None: from sage.misc.misc import deprecation deprecation( "The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead." ) x = GinacFunction.__call__( self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg) return x.n(prec) return GinacFunction.__call__( self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg)
def __call__(self, x, coerce=True, hold=False, prec=None, dont_call_method_on_arg=False): """ Note that the ``prec`` argument is deprecated. The precision for the result is deduced from the precision of the input. Convert the input to a higher precision explicitly if a result with higher precision is desired.:: sage: t = exp(RealField(100)(2)); t 7.3890560989306502272304274606 sage: t.prec() 100 TESTS:: sage: exp(2,prec=100) doctest:...: DeprecationWarning: The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead. See http://trac.sagemath.org/7490 for details. 7.3890560989306502272304274606 Ensure that :trac:`13608` is fixed:: sage: import mpmath sage: a = mpmath.mpf('0.5') sage: exp(a) mpf('1.6487212707001282') sage: a.exp -1 """ if prec is not None: from sage.misc.superseded import deprecation deprecation(7490, "The prec keyword argument is deprecated. Explicitly set the precision of the input, for example exp(RealField(300)(1)), or use the prec argument to .n() for exact inputs, e.g., exp(1).n(300), instead.") x = GinacFunction.__call__(self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg) return x.n(prec) return GinacFunction.__call__(self, x, coerce=coerce, hold=hold, dont_call_method_on_arg=dont_call_method_on_arg)
def __call__(self, *args, **kwds): """ Return the logarithm of x to the given base. Calls the ``log`` method of the object x when computing the logarithm, thus allowing use of logarithm on any object containing a ``log`` method. In other words, log works on more than just real numbers. EXAMPLES:: sage: log(e^2) 2 To change the base of the logarithm, add a second parameter:: sage: log(1000,10) 3 You can use :class:`RDF<sage.rings.real_double.RealDoubleField_class>`, :class:`~sage.rings.real_mpfr.RealField` or ``n`` to get a numerical real approximation:: sage: log(1024, 2) 10 sage: RDF(log(1024, 2)) 10.0 sage: log(10, 4) log(10)/log(4) sage: RDF(log(10, 4)) 1.6609640474436813 sage: log(10, 2) log(10)/log(2) sage: n(log(10, 2)) 3.32192809488736 sage: log(10, e) log(10) sage: n(log(10, e)) 2.30258509299405 The log function works for negative numbers, complex numbers, and symbolic numbers too, picking the branch with angle between `-pi` and `pi`:: sage: log(-1+0*I) I*pi sage: log(CC(-1)) 3.14159265358979*I sage: log(-1.0) 3.14159265358979*I For input zero, the following behavior occurs:: sage: log(0) -Infinity sage: log(CC(0)) -infinity sage: log(0.0) -infinity The log function also works in finite fields as long as the argument lies in the multiplicative group generated by the base:: sage: F = GF(13); g = F.multiplicative_generator(); g 2 sage: a = F(8) sage: log(a,g); g^log(a,g) 3 8 sage: log(a,3) Traceback (most recent call last): ... ValueError: No discrete log of 8 found to base 3 sage: log(F(9), 3) 2 The log function also works for p-adics (see documentation for p-adics for more information):: sage: R = Zp(5); R 5-adic Ring with capped relative precision 20 sage: a = R(16); a 1 + 3*5 + O(5^20) sage: log(a) 3*5 + 3*5^2 + 3*5^4 + 3*5^5 + 3*5^6 + 4*5^7 + 2*5^8 + 5^9 + 5^11 + 2*5^12 + 5^13 + 3*5^15 + 2*5^16 + 4*5^17 + 3*5^18 + 3*5^19 + O(5^20) TESTS: Check if :trac:`10136` is fixed:: sage: log(x).operator() is log True sage: log(x).operator() is ln True sage: log(1000, 10, base=5) Traceback (most recent call last): ... TypeError: Symbolic function log must be called as log(x), log(x, base=b) or log(x, b) """ base = kwds.pop('base', None) if base is None: if len(args) == 1: return GinacFunction.__call__(self, *args, **kwds) # second argument is base base = args[1] args = args[:1] if len(args) != 1: raise TypeError("Symbolic function log must be called as " "log(x), log(x, base=b) or log(x, b)") try: return args[0].log(base) except (AttributeError, TypeError): return GinacFunction.__call__(self, *args, **kwds) / \ GinacFunction.__call__(self, base, **kwds)