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 __init__(self): r""" Derivatives of the Riemann zeta function. EXAMPLES:: sage: zetaderiv(1, x) zetaderiv(1, x) sage: zetaderiv(1, x).diff(x) zetaderiv(2, x) sage: var('n') n sage: zetaderiv(n,x) zetaderiv(n, x) sage: zetaderiv(1, 4).n() -0.0689112658961254 sage: import mpmath; mpmath.diff(lambda x: mpmath.zeta(x), 4) mpf('-0.068911265896125382') TESTS:: sage: latex(zetaderiv(2,x)) \zeta^\prime\left(2, x\right) sage: a = loads(dumps(zetaderiv(2,x))) sage: a.operator() == zetaderiv True """ GinacFunction.__init__(self, "zetaderiv", nargs=2)
def __init__(self): r""" The hyperbolic cosine function. EXAMPLES:: sage: cosh(pi) cosh(pi) sage: cosh(3.1415) 11.5908832931176 sage: float(cosh(pi)) 11.591953275521519 sage: RR(cosh(1/2)) 1.12762596520638 sage: latex(cosh(x)) \cosh\left(x\right) sage: cosh(x)._sympy_() cosh(x) To prevent automatic evaluation, use the ``hold`` parameter:: sage: cosh(arcsinh(x),hold=True) cosh(arcsinh(x)) To then evaluate again, use the ``unhold`` method:: sage: cosh(arcsinh(x),hold=True).unhold() sqrt(x^2 + 1) """ GinacFunction.__init__(self, "cosh", latex_name=r"\cosh")
def __init__(self): r""" The hyperbolic sine function. EXAMPLES:: sage: sinh(pi) sinh(pi) sage: sinh(3.1415) 11.5476653707437 sage: float(sinh(pi)) 11.54873935725774... sage: RR(sinh(pi)) 11.5487393572577 sage: latex(sinh(x)) \sinh\left(x\right) sage: sinh(x)._sympy_() sinh(x) To prevent automatic evaluation, use the ``hold`` parameter:: sage: sinh(arccosh(x),hold=True) sinh(arccosh(x)) To then evaluate again, use the ``unhold`` method:: sage: sinh(arccosh(x),hold=True).unhold() sqrt(x + 1)*sqrt(x - 1) """ GinacFunction.__init__(self, "sinh", latex_name=r"\sinh")
def __init__(self): r""" The hyperbolic cotangent function. EXAMPLES:: sage: coth(pi) coth(pi) sage: coth(0) Infinity sage: coth(pi*I) Infinity sage: coth(pi*I/2) 0 sage: coth(7*pi*I/2) 0 sage: coth(8*pi*I/2) Infinity sage: coth(7.*pi*I/2) -I*cot(3.50000000000000*pi) sage: coth(3.1415) 1.00374256795520 sage: float(coth(pi)) 1.0037418731973213 sage: RR(coth(pi)) 1.00374187319732 sage: bool(diff(coth(x), x) == diff(1/tanh(x), x)) True sage: diff(coth(x), x) -1/sinh(x)^2 sage: latex(coth(x)) \operatorname{coth}\left(x\right) """ GinacFunction.__init__(self, "coth", latex_name=r"\operatorname{coth}")
def __init__(self): r""" The absolute value function. EXAMPLES:: sage: var('x y') (x, y) sage: abs(x) abs(x) sage: abs(x^2 + y^2) abs(x^2 + y^2) sage: abs(-2) 2 sage: sqrt(x^2) sqrt(x^2) sage: abs(sqrt(x)) abs(sqrt(x)) sage: complex(abs(3*I)) (3+0j) sage: f = sage.functions.other.Function_abs() sage: latex(f) \mathrm{abs} sage: latex(abs(x)) {\left| x \right|} """ GinacFunction.__init__(self, "abs", latex_name=r"\mathrm{abs}")
def __init__(self): r""" The hyperbolic cosecant function. EXAMPLES:: sage: csch(pi) csch(pi) sage: csch(3.1415) 0.0865975907592133 sage: float(csch(pi)) 0.0865895375300469... sage: RR(csch(pi)) 0.0865895375300470 sage: csch(0) Infinity sage: csch(pi*I) Infinity sage: csch(pi*I/2) -I sage: csch(7*pi*I/2) I sage: csch(7.*pi*I/2) -I*csc(3.50000000000000*pi) sage: bool(diff(csch(x), x) == diff(1/sinh(x), x)) True sage: diff(csch(x), x) -coth(x)*csch(x) sage: latex(csch(x)) {\rm csch}\left(x\right) """ GinacFunction.__init__(self, "csch", latex_name=r"{\rm csch}")
def __init__(self): r""" The hyperbolic secant function. EXAMPLES:: sage: sech(pi) sech(pi) sage: sech(3.1415) 0.0862747018248192 sage: float(sech(pi)) 0.0862667383340544... sage: RR(sech(pi)) 0.0862667383340544 sage: sech(0) 1 sage: sech(pi*I) -1 sage: sech(pi*I/2) Infinity sage: sech(7*pi*I/2) Infinity sage: sech(8*pi*I/2) 1 sage: sech(8.*pi*I/2) sec(4.00000000000000*pi) sage: bool(diff(sech(x), x) == diff(1/cosh(x), x)) True sage: diff(sech(x), x) -sech(x)*tanh(x) sage: latex(sech(x)) \operatorname{sech}\left(x\right) """ GinacFunction.__init__(self, "sech", latex_name=r"\operatorname{sech}",)
def __init__(self): r""" The inverse of the hyperbolic cosecant function. EXAMPLES:: sage: arccsch(2.0) 0.481211825059603 sage: arccsch(2) arccsch(2) sage: arccsch(1 + I*1.0) 0.530637530952518 - 0.452278447151191*I sage: arccsch(1).n(200) 0.88137358701954302523260932497979230902816032826163541075330 sage: float(arccsch(1)) 0.881373587019543 sage: diff(acsch(x), x) -1/(sqrt(x^2 + 1)*x) sage: latex(arccsch(x)) \operatorname{arccsch}\left(x\right) """ GinacFunction.__init__(self, "arccsch", latex_name=r"\operatorname{arccsch}", conversions=dict(maxima='acsch'))
def __init__(self): r""" The inverse of the hyperbolic secant function. EXAMPLES:: sage: arcsech(0.5) 1.31695789692482 sage: arcsech(1/2) arcsech(1/2) sage: arcsech(1 + I*1.0) 0.530637530952518 - 1.11851787964371*I sage: arcsech(1/2).n(200) 1.3169578969248167086250463473079684440269819714675164797685 sage: float(arcsech(1/2)) 1.3169578969248168 sage: diff(asech(x), x) -1/(sqrt(-x^2 + 1)*x) sage: latex(arcsech(x)) \operatorname{arcsech}\left(x\right) """ GinacFunction.__init__(self, "arcsech", latex_name=r"\operatorname{arcsech}", conversions=dict(maxima='asech'))
def __init__(self): r""" The hyperbolic sine function. EXAMPLES:: sage: sinh(pi) sinh(pi) sage: sinh(3.1415) 11.5476653707437 sage: float(sinh(pi)) 11.54873935725774... sage: RR(sinh(pi)) 11.5487393572577 sage: latex(sinh(x)) \sinh\left(x\right) To prevent automatic evaluation, use the ``hold`` parameter:: sage: sinh(arccosh(x),hold=True) sinh(arccosh(x)) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: sinh(arccosh(x),hold=True).simplify() sqrt(x + 1)*sqrt(x - 1) """ GinacFunction.__init__(self, "sinh", latex_name=r"\sinh")
def __init__(self): """ The cosine function. EXAMPLES:: sage: cos(pi) -1 sage: cos(x).subs(x==pi) -1 sage: cos(2).n(100) -0.41614683654714238699756822950 sage: loads(dumps(cos)) cos We can prevent evaluation using the ``hold`` parameter:: sage: cos(0,hold=True) cos(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = cos(0,hold=True); a.simplify() 1 TESTS:: sage: conjugate(cos(x)) cos(conjugate(x)) """ GinacFunction.__init__(self, "cos", latex_name=r"\cos", conversions=dict(maxima='cos',mathematica='Cos'))
def __init__(self): """ The arcsine function. EXAMPLES:: sage: arcsin(0.5) 0.523598775598299 sage: arcsin(1/2) 1/6*pi sage: arcsin(1 + 1.0*I) 0.666239432492515 + 1.06127506190504*I We can delay evaluation using the ``hold`` parameter:: sage: arcsin(0,hold=True) arcsin(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arcsin(0,hold=True); a.simplify() 0 ``conjugate(arcsin(x))==arcsin(conjugate(x))``, unless on the branch cuts which run along the real axis outside the interval [-1, +1].:: sage: conjugate(arcsin(x)) conjugate(arcsin(x)) sage: var('y', domain='positive') y sage: conjugate(arcsin(y)) conjugate(arcsin(y)) sage: conjugate(arcsin(y+I)) conjugate(arcsin(y + I)) sage: conjugate(arcsin(1/16)) arcsin(1/16) sage: conjugate(arcsin(2)) conjugate(arcsin(2)) sage: conjugate(arcsin(-2)) -conjugate(arcsin(2)) TESTS:: sage: arcsin(x)._sympy_() asin(x) sage: arcsin(x).operator() arcsin sage: asin(complex(1,1)) (0.6662394324925152+1.0612750619050357j) Check that :trac:`22823` is fixed:: sage: bool(asin(SR(2.1)) == NaN) True sage: asin(SR(2.1)).is_real() False """ GinacFunction.__init__(self, 'arcsin', latex_name=r"\arcsin", conversions=dict(maxima='asin', sympy='asin', fricas="asin", giac="asin"))
def __init__(self): """ The arctangent function. EXAMPLES:: sage: arctan(1/2) arctan(1/2) sage: RDF(arctan(1/2)) # rel tol 1e-15 0.46364760900080615 sage: arctan(1 + I) arctan(I + 1) sage: arctan(1/2).n(100) 0.46364760900080611621425623146 We can delay evaluation using the ``hold`` parameter:: sage: arctan(0,hold=True) arctan(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arctan(0,hold=True); a.simplify() 0 ``conjugate(arctan(x))==arctan(conjugate(x))``, unless on the branch cuts which run along the imaginary axis outside the interval [-I, +I].:: sage: conjugate(arctan(x)) conjugate(arctan(x)) sage: var('y', domain='positive') y sage: conjugate(arctan(y)) arctan(y) sage: conjugate(arctan(y+I)) conjugate(arctan(y + I)) sage: conjugate(arctan(1/16)) arctan(1/16) sage: conjugate(arctan(-2*I)) conjugate(arctan(-2*I)) sage: conjugate(arctan(2*I)) conjugate(arctan(2*I)) sage: conjugate(arctan(I/2)) arctan(-1/2*I) TESTS:: sage: arctan(x).operator() arctan Check that :trac:`19918` is fixed:: sage: arctan(-x).subs(x=oo) -1/2*pi sage: arctan(-x).subs(x=-oo) 1/2*pi """ GinacFunction.__init__(self, "arctan", latex_name=r'\arctan', conversions=dict(maxima='atan', sympy='atan'))
def __init__(self): r""" The hyperbolic cosine function. EXAMPLES:: sage: cosh(pi) cosh(pi) sage: cosh(3.1415) 11.5908832931176 sage: float(cosh(pi)) 11.591953275521519 sage: RR(cosh(1/2)) 1.12762596520638 sage: latex(cosh(x)) \cosh\left(x\right) To prevent automatic evaluation, use the ``hold`` parameter:: sage: cosh(arcsinh(x),hold=True) cosh(arcsinh(x)) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: cosh(arcsinh(x),hold=True).simplify() sqrt(x^2 + 1) """ GinacFunction.__init__(self, "cosh", latex_name=r"\cosh")
def __init__(self): r""" The Heaviside step function, ``heaviside(x)``. INPUT: - ``x`` - a real number or a symbolic expression EXAMPLES:: sage: heaviside(-1) 0 sage: heaviside(1) 1 sage: heaviside(0) heaviside(0) sage: heaviside(x) heaviside(x) sage: latex(heaviside(x)) H\left(x\right) sage: heaviside(x)._sympy_() Heaviside(x) sage: heaviside(x)._giac_() Heaviside(x) sage: h(x) = heaviside(x) sage: h(pi).numerical_approx() 1.00000000000000 """ GinacFunction.__init__(self, "heaviside", latex_name="H", conversions=dict(maxima='hstep', mathematica='HeavisideTheta', sympy='Heaviside', giac='Heaviside'))
def __init__(self): """ The sine function. EXAMPLES:: sage: sin(0) 0 sage: sin(x).subs(x==0) 0 sage: sin(2).n(100) 0.90929742682568169539601986591 sage: loads(dumps(sin)) sin We can prevent evaluation using the ``hold`` parameter:: sage: sin(0,hold=True) sin(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = sin(0,hold=True); a.simplify() 0 TESTS:: sage: conjugate(sin(x)) sin(conjugate(x)) """ GinacFunction.__init__(self, "sin", latex_name=r"\sin", conversions=dict(maxima='sin',mathematica='Sin'))
def __init__(self): r""" The hyperbolic tangent function. EXAMPLES:: sage: tanh(pi) tanh(pi) sage: tanh(3.1415) 0.996271386633702 sage: float(tanh(pi)) 0.99627207622075 sage: tan(3.1415/4) 0.999953674278156 sage: tanh(pi/4) tanh(1/4*pi) sage: RR(tanh(1/2)) 0.462117157260010 :: sage: CC(tanh(pi + I*e)) 0.997524731976164 - 0.00279068768100315*I sage: ComplexField(100)(tanh(pi + I*e)) 0.99752473197616361034204366446 - 0.0027906876810031453884245163923*I sage: CDF(tanh(pi + I*e)) # rel tol 2e-15 0.9975247319761636 - 0.002790687681003147*I To prevent automatic evaluation, use the ``hold`` parameter:: sage: tanh(arcsinh(x),hold=True) tanh(arcsinh(x)) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: tanh(arcsinh(x),hold=True).simplify() x/sqrt(x^2 + 1) TESTS:: sage: latex(tanh(x)) \tanh\left(x\right) sage: tanh(x)._sympy_() tanh(x) Check that real/imaginary parts are correct (:trac:`20098`):: sage: tanh(1+2*I).n() 1.16673625724092 - 0.243458201185725*I sage: tanh(1+2*I).real().n() 1.16673625724092 sage: tanh(1+2*I).imag().n() -0.243458201185725 sage: tanh(x).real() sinh(2*real_part(x))/(cos(2*imag_part(x)) + cosh(2*real_part(x))) sage: tanh(x).imag() sin(2*imag_part(x))/(cos(2*imag_part(x)) + cosh(2*real_part(x))) """ GinacFunction.__init__(self, "tanh", latex_name=r"\tanh")
def __init__(self): r""" The unit step function, ``unit_step(x)``. INPUT: - ``x`` - a real number or a symbolic expression EXAMPLES:: sage: unit_step(-1) 0 sage: unit_step(1) 1 sage: unit_step(0) 1 sage: unit_step(x) unit_step(x) sage: latex(unit_step(x)) \mathrm{u}\left(x\right) TESTS:: sage: t = loads(dumps(unit_step(x)+1)); t unit_step(x) + 1 sage: t.subs(x=0) 2 """ GinacFunction.__init__(self, "unit_step", latex_name=r"\mathrm{u}", conversions=dict(mathematica='UnitStep'))
def __init__(self): r""" The cotangent function. EXAMPLES:: sage: cot(pi/4) 1 sage: RR(cot(pi/4)) 1.00000000000000 sage: cot(1/2) cot(1/2) sage: cot(0.5) 1.83048772171245 sage: latex(cot(x)) \cot\left(x\right) We can prevent evaluation using the ``hold`` parameter:: sage: cot(pi/4,hold=True) cot(1/4*pi) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = cot(pi/4,hold=True); a.simplify() 1 EXAMPLES:: sage: cot(pi/4) 1 sage: cot(x).subs(x==pi/4) 1 sage: cot(pi/7) cot(1/7*pi) sage: cot(x) cot(x) sage: n(cot(pi/4),100) 1.0000000000000000000000000000 sage: float(cot(1)) 0.64209261593433... sage: bool(diff(cot(x), x) == diff(1/tan(x), x)) True sage: diff(cot(x), x) -cot(x)^2 - 1 TESTS: Test complex input:: sage: cot(complex(1,1)) # rel tol 1e-15 (0.21762156185440273-0.8680141428959249j) sage: cot(1.+I) 0.217621561854403 - 0.868014142895925*I """ GinacFunction.__init__(self, "cot", latex_name=r"\cot")
def __init__(self): """ The cosine function. EXAMPLES:: sage: cos(pi) -1 sage: cos(x).subs(x==pi) -1 sage: cos(2).n(100) -0.41614683654714238699756822950 sage: loads(dumps(cos)) cos sage: cos(x)._sympy_() cos(x) We can prevent evaluation using the ``hold`` parameter:: sage: cos(0,hold=True) cos(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = cos(0,hold=True); a.simplify() 1 If possible, the argument is also reduced modulo the period length `2\pi`, and well-known identities are directly evaluated:: sage: k = var('k', domain='integer') sage: cos(1 + 2*k*pi) cos(1) sage: cos(k*pi) cos(pi*k) sage: cos(pi/3 + 2*k*pi) 1/2 TESTS:: sage: conjugate(cos(x)) cos(conjugate(x)) sage: cos(complex(1,1)) # rel tol 1e-15 (0.8337300251311491-0.9888977057628651j) Check that :trac:`20752` is fixed:: sage: cos(3*pi+41/42*pi) cos(1/42*pi) sage: cos(-5*pi+1/42*pi) -cos(1/42*pi) sage: cos(pi-1/42*pi) -cos(1/42*pi) """ GinacFunction.__init__(self, 'cos', latex_name=r"\cos", conversions=dict(maxima='cos',mathematica='Cos',giac='cos'))
def __init__(self): r""" The inverse of the hyperbolic sine function. EXAMPLES:: sage: asinh arcsinh sage: asinh(0.5) 0.481211825059603 sage: asinh(1/2) arcsinh(1/2) sage: asinh(1 + I*1.0) 1.06127506190504 + 0.666239432492515*I To prevent automatic evaluation use the ``hold`` argument:: sage: asinh(-2,hold=True) arcsinh(-2) To then evaluate again, use the ``unhold`` method:: sage: asinh(-2,hold=True).unhold() -arcsinh(2) ``conjugate(asinh(x))==asinh(conjugate(x))`` unless on the branch cuts which run along the imaginary axis outside the interval [-I, +I].:: sage: conjugate(asinh(x)) conjugate(arcsinh(x)) sage: var('y', domain='positive') y sage: conjugate(asinh(y)) arcsinh(y) sage: conjugate(asinh(y+I)) conjugate(arcsinh(y + I)) sage: conjugate(asinh(1/16)) arcsinh(1/16) sage: conjugate(asinh(I/2)) arcsinh(-1/2*I) sage: conjugate(asinh(2*I)) conjugate(arcsinh(2*I)) TESTS:: sage: asinh(x).operator() arcsinh sage: latex(asinh(x)) \operatorname{arsinh}\left(x\right) sage: asinh(x)._sympy_() asinh(x) """ GinacFunction.__init__(self, "arcsinh", latex_name=r"\operatorname{arsinh}", conversions=dict(maxima='asinh', sympy='asinh', fricas='asinh', giac='asinh'))
def __init__(self): r""" The polylog function `\text{Li}_n(z) = \sum_{k=1}^{\infty} z^k / k^n`. INPUT: - ``n`` - object - ``z`` - object EXAMPLES:: sage: polylog(1, x) -log(-x + 1) sage: polylog(2,1) 1/6*pi^2 sage: polylog(2,x^2+1) polylog(2, x^2 + 1) sage: polylog(4,0.5) polylog(4, 0.500000000000000) sage: f = polylog(4, 1); f 1/90*pi^4 sage: f.n() 1.08232323371114 sage: polylog(4, 2).n() 2.42786280675470 - 0.174371300025453*I sage: complex(polylog(4,2)) (2.4278628067547032-0.17437130002545306j) sage: float(polylog(4,0.5)) 0.5174790616738993 sage: z = var('z') sage: polylog(2,z).series(z==0, 5) 1*z + 1/4*z^2 + 1/9*z^3 + 1/16*z^4 + Order(z^5) sage: loads(dumps(polylog)) polylog sage: latex(polylog(5, x)) {\rm Li}_{5}(x) TESTS: Check if #8459 is fixed:: sage: t = maxima(polylog(5,x)).sage(); t polylog(5, x) sage: t.operator() == polylog True sage: t.subs(x=.5).n() 0.508400579242269 """ GinacFunction.__init__(self, "polylog", nargs=2)
def __init__(self): """ The tangent function. EXAMPLES:: sage: tan(pi) 0 sage: tan(3.1415) -0.0000926535900581913 sage: tan(3.1415/4) 0.999953674278156 sage: tan(pi/4) 1 sage: tan(1/2) tan(1/2) sage: RR(tan(1/2)) 0.546302489843790 We can prevent evaluation using the ``hold`` parameter:: sage: tan(pi/4,hold=True) tan(1/4*pi) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = tan(pi/4,hold=True); a.simplify() 1 If possible, the argument is also reduced modulo the period length `\pi`, and well-known identities are directly evaluated:: sage: k = var('k', domain='integer') sage: tan(1 + 2*k*pi) tan(1) sage: tan(k*pi) 0 TESTS:: sage: tan(x)._sympy_() tan(x) sage: conjugate(tan(x)) tan(conjugate(x)) sage: tan(complex(1,1)) # rel tol 1e-15 (0.2717525853195118+1.0839233273386946j) Check that :trac:`19791` is fixed:: sage: tan(2+I).imag().n() 1.16673625724092 """ GinacFunction.__init__(self, 'tan', latex_name=r"\tan")
def __init__(self): """ The arccosine function. EXAMPLES:: sage: arccos(0.5) 1.04719755119660 sage: arccos(1/2) 1/3*pi sage: arccos(1 + 1.0*I) 0.904556894302381 - 1.06127506190504*I sage: arccos(3/4).n(100) 0.72273424781341561117837735264 We can delay evaluation using the ``hold`` parameter:: sage: arccos(0,hold=True) arccos(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arccos(0,hold=True); a.simplify() 1/2*pi ``conjugate(arccos(x))==arccos(conjugate(x))``, unless on the branch cuts, which run along the real axis outside the interval [-1, +1].:: sage: conjugate(arccos(x)) conjugate(arccos(x)) sage: var('y', domain='positive') y sage: conjugate(arccos(y)) conjugate(arccos(y)) sage: conjugate(arccos(y+I)) conjugate(arccos(y + I)) sage: conjugate(arccos(1/16)) arccos(1/16) sage: conjugate(arccos(2)) conjugate(arccos(2)) sage: conjugate(arccos(-2)) pi - conjugate(arccos(2)) TESTS:: sage: arccos(x)._sympy_() acos(x) sage: arccos(x).operator() arccos sage: acos(complex(1,1)) (0.9045568943023814-1.0612750619050357j) """ GinacFunction.__init__(self, 'arccos', latex_name=r"\arccos", conversions=dict(maxima='acos', sympy='acos'))
def __init__(self): r""" Riemann zeta function at s with s a real or complex number. INPUT: - ``s`` - real or complex number If s is a real number the computation is done using the MPFR library. When the input is not real, the computation is done using the PARI C library. EXAMPLES:: sage: zeta(x) zeta(x) sage: zeta(2) 1/6*pi^2 sage: zeta(2.) 1.64493406684823 sage: RR = RealField(200) sage: zeta(RR(2)) 1.6449340668482264364724151666460251892189499012067984377356 sage: zeta(I) zeta(I) sage: zeta(I).n() 0.00330022368532410 - 0.418155449141322*I It is possible to use the ``hold`` argument to prevent automatic evaluation:: sage: zeta(2,hold=True) zeta(2) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = zeta(2,hold=True); a.simplify() 1/6*pi^2 TESTS:: sage: latex(zeta(x)) \zeta(x) sage: a = loads(dumps(zeta(x))) sage: a.operator() == zeta True sage: zeta(1) Infinity sage: zeta(x).subs(x=1) Infinity """ GinacFunction.__init__(self, "zeta")
def __init__(self): r""" The inverse of the hyperbolic tangent function. EXAMPLES:: sage: atanh(0.5) 0.549306144334055 sage: atanh(1/2) 1/2*log(3) sage: atanh(1 + I*1.0) 0.402359478108525 + 1.01722196789785*I To prevent automatic evaluation use the ``hold`` argument:: sage: atanh(-1/2,hold=True) arctanh(-1/2) To then evaluate again, use the ``unhold`` method:: sage: atanh(-1/2,hold=True).unhold() -1/2*log(3) ``conjugate(arctanh(x))==arctanh(conjugate(x))`` unless on the branch cuts which run along the real axis outside the interval [-1, +1].:: sage: conjugate(atanh(x)) conjugate(arctanh(x)) sage: var('y', domain='positive') y sage: conjugate(atanh(y)) conjugate(arctanh(y)) sage: conjugate(atanh(y+I)) conjugate(arctanh(y + I)) sage: conjugate(atanh(1/16)) 1/2*log(17/15) sage: conjugate(atanh(I/2)) arctanh(-1/2*I) sage: conjugate(atanh(-2*I)) arctanh(2*I) TESTS:: sage: atanh(x).operator() arctanh sage: latex(atanh(x)) \operatorname{artanh}\left(x\right) sage: atanh(x)._sympy_() atanh(x) """ GinacFunction.__init__(self, "arctanh", latex_name=r"\operatorname{artanh}", conversions=dict(maxima='atanh', sympy='atanh', fricas='atanh', giac='atanh'))
def __init__(self): """ TESTS:: sage: from sage.functions.log import logb sage: loads(dumps(logb)) log """ GinacFunction.__init__(self, 'log', ginac_name='logb', nargs=2, latex_name=r'\log', conversions=dict(maxima='log'))
def __init__(self): """ TESTS:: sage: loads(dumps(exp)) exp sage: maxima(exp(x))._sage_() e^x """ GinacFunction.__init__(self, "exp", latex_name=r"\exp", conversions=dict(maxima='exp', fricas='exp'))
def __init__(self): r""" The dilogarithm function `\text{Li}_2(z) = \sum_{k=1}^{\infty} z^k / k^2`. This is simply an alias for polylog(2, z). EXAMPLES:: sage: dilog(1) 1/6*pi^2 sage: dilog(1/2) 1/12*pi^2 - 1/2*log(2)^2 sage: dilog(x^2+1) dilog(x^2 + 1) sage: dilog(-1) -1/12*pi^2 sage: dilog(-1.1) -0.890838090262283 sage: float(dilog(1)) 1.6449340668482262 sage: var('z') z sage: dilog(z).diff(z, 2) log(-z + 1)/z^2 - 1/((z - 1)*z) sage: dilog(z).series(z==1/2, 3) (1/12*pi^2 - 1/2*log(2)^2) + (-2*log(1/2))*(z - 1/2) + (2*log(1/2) + 2)*(z - 1/2)^2 + Order(1/8*(2*z - 1)^3) sage: latex(dilog(z)) {\rm Li}_2\left(z\right) TESTS: ``conjugate(dilog(x))==dilog(conjugate(x))`` unless on the branch cuts which run along the positive real axis beginning at 1.:: sage: conjugate(dilog(x)) conjugate(dilog(x)) sage: var('y',domain='positive') y sage: conjugate(dilog(y)) conjugate(dilog(y)) sage: conjugate(dilog(1/19)) dilog(1/19) sage: conjugate(dilog(1/2*I)) dilog(-1/2*I) sage: dilog(conjugate(1/2*I)) dilog(-1/2*I) sage: conjugate(dilog(2)) conjugate(dilog(2)) """ GinacFunction.__init__(self, 'dilog', conversions=dict(maxima='li[2]'))
def __init__(self): r""" The Gamma function. This is defined by .. MATH:: \Gamma(z) = \int_0^\infty t^{z-1}e^{-t} dt for complex input `z` with real part greater than zero, and by analytic continuation on the rest of the complex plane (except for negative integers, which are poles). It is computed by various libraries within Sage, depending on the input type. EXAMPLES:: sage: from sage.functions.gamma import gamma1 sage: gamma1(CDF(0.5,14)) -4.0537030780372815e-10 - 5.773299834553605e-10*I sage: gamma1(CDF(I)) -0.15494982830181067 - 0.49801566811835607*I Recall that `\Gamma(n)` is `n-1` factorial:: sage: gamma1(11) == factorial(10) True sage: gamma1(6) 120 sage: gamma1(1/2) sqrt(pi) sage: gamma1(-1) Infinity sage: gamma1(I) gamma(I) sage: gamma1(x/2)(x=5) 3/4*sqrt(pi) sage: gamma1(float(6)) # For ARM: rel tol 3e-16 120.0 sage: gamma(6.) 120.000000000000 sage: gamma1(x) gamma(x) :: sage: gamma1(pi) gamma(pi) sage: gamma1(i) gamma(I) sage: gamma1(i).n() -0.154949828301811 - 0.498015668118356*I sage: gamma1(int(5)) 24 :: sage: conjugate(gamma(x)) gamma(conjugate(x)) :: sage: plot(gamma1(x),(x,1,5)) Graphics object consisting of 1 graphics primitive To prevent automatic evaluation use the ``hold`` argument:: sage: gamma1(1/2,hold=True) gamma(1/2) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: gamma1(1/2,hold=True).simplify() sqrt(pi) TESTS: sage: gamma(x)._sympy_() gamma(x) We verify that we can convert this function to Maxima and convert back to Sage:: sage: z = var('z') sage: maxima(gamma1(z)).sage() gamma(z) sage: latex(gamma1(z)) \Gamma\left(z\right) Test that :trac:`5556` is fixed:: sage: gamma1(3/4) gamma(3/4) sage: gamma1(3/4).n(100) 1.2254167024651776451290983034 Check that negative integer input works:: sage: (-1).gamma() Infinity sage: (-1.).gamma() NaN sage: CC(-1).gamma() Infinity sage: RDF(-1).gamma() NaN sage: CDF(-1).gamma() Infinity Check if :trac:`8297` is fixed:: sage: latex(gamma(1/4)) \Gamma\left(\frac{1}{4}\right) Test pickling:: sage: loads(dumps(gamma(x))) gamma(x) Check that the implementations roughly agrees (note there might be difference of several ulp on more complicated entries):: sage: import mpmath sage: float(gamma(10.)) == gamma(10.r) == float(gamma(mpmath.mpf(10))) True sage: float(gamma(8.5)) == gamma(8.5r) == float(gamma(mpmath.mpf(8.5))) True Check that ``QQbar`` half integers work with the ``pi`` formula:: sage: gamma(QQbar(1/2)) sqrt(pi) sage: gamma(QQbar(-9/2)) -32/945*sqrt(pi) .. SEEALSO:: :meth:`gamma` """ GinacFunction.__init__(self, 'gamma', latex_name=r"\Gamma", ginac_name='gamma', conversions={ 'mathematica': 'Gamma', 'maple': 'GAMMA', 'sympy': 'gamma', 'fricas': 'Gamma', 'giac': 'Gamma' })
def __init__(self): r""" Riemann zeta function at s with s a real or complex number. INPUT: - ``s`` - real or complex number If s is a real number the computation is done using the MPFR library. When the input is not real, the computation is done using the PARI C library. EXAMPLES:: sage: zeta(x) zeta(x) sage: zeta(2) 1/6*pi^2 sage: zeta(2.) 1.64493406684823 sage: RR = RealField(200) sage: zeta(RR(2)) 1.6449340668482264364724151666460251892189499012067984377356 sage: zeta(I) zeta(I) sage: zeta(I).n() 0.00330022368532410 - 0.418155449141322*I It is possible to use the ``hold`` argument to prevent automatic evaluation:: sage: zeta(2,hold=True) zeta(2) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = zeta(2,hold=True); a.simplify() 1/6*pi^2 Check that :trac:`15846` is resolved:: sage: zeta(x).series(x==1, 1) 1*(x - 1)^(-1) + (euler_gamma + log(2) + log(pi) + 2*zetaderiv(1, 0)) + Order(x - 1) sage: zeta(x).residue(x==1) 1 TESTS:: sage: latex(zeta(x)) \zeta(x) sage: a = loads(dumps(zeta(x))) sage: a.operator() == zeta True sage: zeta(1) Infinity sage: zeta(x).subs(x=1) Infinity """ GinacFunction.__init__(self, "zeta")
def __init__(self): r""" Returns the complex conjugate of the input. It is possible to prevent automatic evaluation using the ``hold`` parameter:: sage: conjugate(I,hold=True) conjugate(I) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: conjugate(I,hold=True).simplify() -I TESTS:: sage: x,y = var('x,y') sage: x.conjugate() conjugate(x) sage: latex(conjugate(x)) \overline{x} sage: f = function('f') sage: latex(f(x).conjugate()) \overline{f\left(x\right)} sage: f = function('psi',x,y) sage: latex(f.conjugate()) \overline{\psi\left(x, y\right)} sage: x.conjugate().conjugate() x sage: x.conjugate().operator() conjugate sage: x.conjugate().operator() == conjugate True Check if #8755 is fixed:: sage: conjugate(sqrt(-3)) conjugate(sqrt(-3)) sage: conjugate(sqrt(3)) sqrt(3) sage: conjugate(sqrt(x)) conjugate(sqrt(x)) sage: conjugate(x^2) conjugate(x)^2 sage: var('y',domain='positive') y sage: conjugate(sqrt(y)) sqrt(y) Check if #10964 is fixed:: sage: z= I*sqrt(-3); z I*sqrt(-3) sage: conjugate(z) -I*conjugate(sqrt(-3)) sage: var('a') a sage: conjugate(a*sqrt(-2)*sqrt(-3)) conjugate(a)*conjugate(sqrt(-3))*conjugate(sqrt(-2)) """ GinacFunction.__init__(self, "conjugate")
def __init__(self): r""" Return the beta function. This is defined by .. MATH:: \operatorname{B}(p,q) = \int_0^1 t^{p-1}(1-t)^{q-1} dt for complex or symbolic input `p` and `q`. Note that the order of inputs does not matter: `\operatorname{B}(p,q)=\operatorname{B}(q,p)`. GiNaC is used to compute `\operatorname{B}(p,q)`. However, complex inputs are not yet handled in general. When GiNaC raises an error on such inputs, we raise a NotImplementedError. If either input is 1, GiNaC returns the reciprocal of the other. In other cases, GiNaC uses one of the following formulas: .. MATH:: \operatorname{B}(p,q) = \frac{\Gamma(p)\Gamma(q)}{\Gamma(p+q)} or .. MATH:: \operatorname{B}(p,q) = (-1)^q \operatorname{B}(1-p-q, q). For numerical inputs, GiNaC uses the formula .. MATH:: \operatorname{B}(p,q) = \exp[\log\Gamma(p)+\log\Gamma(q)-\log\Gamma(p+q)] INPUT: - ``p`` - number or symbolic expression - ``q`` - number or symbolic expression OUTPUT: number or symbolic expression (if input is symbolic) EXAMPLES:: sage: beta(3,2) 1/12 sage: beta(3,1) 1/3 sage: beta(1/2,1/2) beta(1/2, 1/2) sage: beta(-1,1) -1 sage: beta(-1/2,-1/2) 0 sage: ex = beta(x/2,3) sage: set(ex.operands()) == set([1/2*x, 3]) True sage: beta(.5,.5) 3.14159265358979 sage: beta(1,2.0+I) 0.400000000000000 - 0.200000000000000*I sage: ex = beta(3,x+I) sage: set(ex.operands()) == set([x+I, 3]) True The result is symbolic if exact input is given:: sage: ex = beta(2,1+5*I); ex beta(... sage: set(ex.operands()) == set([1+5*I, 2]) True sage: beta(2, 2.) 0.166666666666667 sage: beta(I, 2.) -0.500000000000000 - 0.500000000000000*I sage: beta(2., 2) 0.166666666666667 sage: beta(2., I) -0.500000000000000 - 0.500000000000000*I sage: beta(x, x)._sympy_() beta(x, x) Test pickling:: sage: loads(dumps(beta)) beta Check that :trac:`15196` is fixed:: sage: beta(-1.3,-0.4) -4.92909641669610 """ GinacFunction.__init__(self, 'beta', nargs=2, latex_name=r"\operatorname{B}", conversions=dict(maxima='beta', mathematica='Beta', sympy='beta', fricas='Beta', giac='Beta'))
def __init__(self): r""" The inverse of the hyperbolic cosine function. EXAMPLES:: sage: acosh(1/2) arccosh(1/2) sage: acosh(1 + I*1.0) 1.06127506190504 + 0.904556894302381*I sage: float(acosh(2)) 1.3169578969248168 sage: cosh(float(acosh(2))) 2.0 sage: acosh(complex(1, 2)) # abs tol 1e-15 (1.5285709194809982+1.1437177404024204j) .. warning:: If the input is in the complex field or symbolic (which includes rational and integer input), the output will be complex. However, if the input is a real decimal, the output will be real or `NaN`. See the examples for details. :: sage: acosh(0.5) NaN sage: acosh(1/2) arccosh(1/2) sage: acosh(1/2).n() NaN sage: acosh(CC(0.5)) 1.04719755119660*I sage: acosh(0) 1/2*I*pi sage: acosh(-1) I*pi To prevent automatic evaluation use the ``hold`` argument:: sage: acosh(-1,hold=True) arccosh(-1) To then evaluate again, use the ``unhold`` method:: sage: acosh(-1,hold=True).unhold() I*pi ``conjugate(arccosh(x))==arccosh(conjugate(x))`` unless on the branch cut which runs along the real axis from +1 to -inf.:: sage: conjugate(acosh(x)) conjugate(arccosh(x)) sage: var('y', domain='positive') y sage: conjugate(acosh(y)) conjugate(arccosh(y)) sage: conjugate(acosh(y+I)) conjugate(arccosh(y + I)) sage: conjugate(acosh(1/16)) conjugate(arccosh(1/16)) sage: conjugate(acosh(2)) arccosh(2) sage: conjugate(acosh(I/2)) arccosh(-1/2*I) TESTS:: sage: acosh(x).operator() arccosh sage: latex(acosh(x)) \operatorname{arcosh}\left(x\right) sage: acosh(x)._sympy_() acosh(x) """ GinacFunction.__init__(self, "arccosh", latex_name=r"\operatorname{arcosh}", conversions=dict(maxima='acosh', sympy='acosh', fricas='acosh', giac='acosh', mathematica='ArcCosh'))
def __init__(self): r""" Derivatives of the digamma function `\psi(x)`. T EXAMPLES:: sage: from sage.functions.gamma import psi2 sage: psi2(2, x) psi(2, x) sage: psi2(2, x).derivative(x) psi(3, x) sage: n = var('n') sage: psi2(n, x).derivative(x) psi(n + 1, x) :: sage: psi2(0, x) psi(x) sage: psi2(-1, x) log(gamma(x)) sage: psi2(3, 1) 1/15*pi^4 :: sage: psi2(2, .5).n() -16.8287966442343 sage: psi2(2, .5).n(100) -16.828796644234319995596334261 TESTS:: sage: psi2(n, x).derivative(n) Traceback (most recent call last): ... RuntimeError: cannot diff psi(n,x) with respect to n sage: latex(psi2(2,x)) \psi\left(2, x\right) sage: loads(dumps(psi2(2,x)+1)) psi(2, x) + 1 sage: psi(2, x)._sympy_() polygamma(2, x) sage: psi(2, x)._fricas_() # optional - fricas polygamma(2,x) Fixed conversion:: sage: psi(2,x)._maple_init_() 'Psi(2,x)' """ GinacFunction.__init__(self, "psi", nargs=2, latex_name=r'\psi', conversions=dict(mathematica='PolyGamma', sympy='polygamma', maple='Psi', giac='Psi', fricas='polygamma'))
def __init__(self): r""" The exponential function, `\exp(x) = e^x`. EXAMPLES:: sage: exp(-1) e^(-1) sage: exp(2) e^2 sage: exp(2).n(100) 7.3890560989306502272304274606 sage: exp(x^2 + log(x)) e^(x^2 + log(x)) sage: exp(x^2 + log(x)).simplify() x*e^(x^2) sage: exp(2.5) 12.1824939607035 sage: exp(float(2.5)) 12.182493960703473 sage: exp(RDF('2.5')) 12.182493960703473 sage: exp(I*pi/12) (1/4*I + 1/4)*sqrt(6) - (1/4*I - 1/4)*sqrt(2) To prevent automatic evaluation, use the ``hold`` parameter:: sage: exp(I*pi,hold=True) e^(I*pi) sage: exp(0,hold=True) e^0 To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: exp(0,hold=True).simplify() 1 :: sage: exp(pi*I/2) I sage: exp(pi*I) -1 sage: exp(8*pi*I) 1 sage: exp(7*pi*I/2) -I For the sake of simplification, the argument is reduced modulo the period of the complex exponential function, `2\pi i`:: sage: k = var('k', domain='integer') sage: exp(2*k*pi*I) 1 sage: exp(log(2) + 2*k*pi*I) 2 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 sage: exp(2).n(100) 7.3890560989306502272304274606 TESTS:: sage: latex(exp(x)) e^{x} sage: latex(exp(sqrt(x))) e^{\sqrt{x}} sage: latex(exp) \exp sage: latex(exp(sqrt(x))^x) \left(e^{\sqrt{x}}\right)^{x} sage: latex(exp(sqrt(x)^x)) e^{\left(\sqrt{x}^{x}\right)} sage: exp(x)._sympy_() exp(x) Test conjugates:: sage: conjugate(exp(x)) e^conjugate(x) Test simplifications when taking powers of exp (:trac:`7264`):: sage: var('a,b,c,II') (a, b, c, II) sage: model_exp = exp(II)**a*(b) sage: sol1_l={b: 5.0, a: 1.1} sage: model_exp.subs(sol1_l) 5.00000000000000*(e^II)^1.10000000000000 :: sage: exp(3)^II*exp(x) (e^3)^II*e^x sage: exp(x)*exp(x) e^(2*x) sage: exp(x)*exp(a) e^(a + x) sage: exp(x)*exp(a)^2 e^(2*a + x) Another instance of the same problem (:trac:`7394`):: sage: 2*sqrt(e) 2*sqrt(e) Check that :trac:`19918` is fixed:: sage: exp(-x^2).subs(x=oo) 0 sage: exp(-x).subs(x=-oo) +Infinity """ GinacFunction.__init__(self, "exp", latex_name=r"\exp", conversions=dict(maxima='exp', fricas='exp'))
def __init__(self): r""" The cotangent function. EXAMPLES:: sage: cot(pi/4) 1 sage: RR(cot(pi/4)) 1.00000000000000 sage: cot(1/2) cot(1/2) sage: cot(0.5) 1.83048772171245 sage: latex(cot(x)) \cot\left(x\right) sage: cot(x)._sympy_() cot(x) We can prevent evaluation using the ``hold`` parameter:: sage: cot(pi/4,hold=True) cot(1/4*pi) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = cot(pi/4,hold=True); a.simplify() 1 EXAMPLES:: sage: cot(pi/4) 1 sage: cot(x).subs(x==pi/4) 1 sage: cot(pi/7) cot(1/7*pi) sage: cot(x) cot(x) sage: n(cot(pi/4),100) 1.0000000000000000000000000000 sage: float(cot(1)) 0.64209261593433... sage: bool(diff(cot(x), x) == diff(1/tan(x), x)) True sage: diff(cot(x), x) -cot(x)^2 - 1 TESTS:: sage: cot(float(0)) Infinity sage: cot(SR(0)) Infinity sage: cot(float(0.1)) 9.966644423259238 sage: type(_) <... 'float'> sage: cot(float(0)) Infinity sage: cot(SR(0)) Infinity sage: cot(float(0.1)) 9.966644423259238 sage: type(_) <... 'float'> Test complex input:: sage: cot(complex(1,1)) # rel tol 1e-15 (0.21762156185440273-0.8680141428959249j) sage: cot(1.+I) 0.217621561854403 - 0.868014142895925*I """ GinacFunction.__init__(self, 'cot', latex_name=r"\cot")
def __init__(self): r""" The natural logarithm of x. See `log?` for more information about its behavior. EXAMPLES:: sage: ln(e^2) 2 sage: ln(2) log(2) sage: ln(10) log(10) :: sage: ln(RDF(10)) 2.302585092994046 sage: ln(2.718) 0.999896315728952 sage: ln(2.0) 0.693147180559945 sage: ln(float(-1)) 3.141592653589793j sage: ln(complex(-1)) 3.141592653589793j The ``hold`` parameter can be used to prevent automatic evaluation:: sage: log(-1,hold=True) log(-1) sage: log(-1) I*pi sage: I.log(hold=True) log(I) sage: I.log(hold=True).simplify() 1/2*I*pi TESTS:: sage: latex(x.log()) \log\left(x\right) sage: latex(log(1/4)) \log\left(\frac{1}{4}\right) sage: log(x)._sympy_() log(x) sage: loads(dumps(ln(x)+1)) log(x) + 1 ``conjugate(log(x))==log(conjugate(x))`` unless on the branch cut which runs along the negative real axis.:: sage: conjugate(log(x)) conjugate(log(x)) sage: var('y', domain='positive') y sage: conjugate(log(y)) log(y) sage: conjugate(log(y+I)) conjugate(log(y + I)) sage: conjugate(log(-1)) -I*pi sage: log(conjugate(-1)) I*pi Check if float arguments are handled properly.:: sage: from sage.functions.log import function_log as log sage: log(float(5)) 1.6094379124341003 sage: log(float(0)) -inf sage: log(float(-1)) 3.141592653589793j sage: log(x).subs(x=float(-1)) 3.141592653589793j :trac:`22142`:: sage: log(QQbar(sqrt(2))) log(1.414213562373095?) sage: log(QQbar(sqrt(2))*1.) 0.346573590279973 sage: polylog(QQbar(sqrt(2)),3) polylog(1.414213562373095?, 3) """ GinacFunction.__init__(self, 'log', latex_name=r'\log', conversions=dict(maxima='log', fricas='log', mathematica='Log'))
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)
def __init__(self): r""" Riemann zeta function at s with s a real or complex number. INPUT: - ``s`` - real or complex number If s is a real number the computation is done using the MPFR library. When the input is not real, the computation is done using the PARI C library. EXAMPLES:: sage: zeta(x) zeta(x) sage: zeta(2) 1/6*pi^2 sage: zeta(2.) 1.64493406684823 sage: RR = RealField(200) sage: zeta(RR(2)) 1.6449340668482264364724151666460251892189499012067984377356 sage: zeta(I) zeta(I) sage: zeta(I).n() 0.00330022368532410 - 0.418155449141322*I sage: zeta(sqrt(2)) zeta(sqrt(2)) sage: zeta(sqrt(2)).n() # rel tol 1e-10 3.02073767948603 It is possible to use the ``hold`` argument to prevent automatic evaluation:: sage: zeta(2,hold=True) zeta(2) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = zeta(2,hold=True); a.simplify() 1/6*pi^2 The Laurent expansion of `\zeta(s)` at `s=1` is implemented by means of the :wikipedia:`Stieltjes constants <Stieltjes_constants>`:: sage: s = SR('s') sage: zeta(s).series(s==1, 2) 1*(s - 1)^(-1) + euler_gamma + (-stieltjes(1))*(s - 1) + Order((s - 1)^2) Generally, the Stieltjes constants occur in the Laurent expansion of `\zeta`-type singularities:: sage: zeta(2*s/(s+1)).series(s==1, 2) 2*(s - 1)^(-1) + (euler_gamma + 1) + (-1/2*stieltjes(1))*(s - 1) + Order((s - 1)^2) TESTS:: sage: latex(zeta(x)) \zeta(x) sage: a = loads(dumps(zeta(x))) sage: a.operator() == zeta True sage: zeta(x)._sympy_() zeta(x) sage: zeta(1) Infinity sage: zeta(x).subs(x=1) Infinity Check that :trac:`19799` is resolved:: sage: zeta(pi) zeta(pi) sage: zeta(pi).n() # rel tol 1e-10 1.17624173838258 Check that :trac:`20082` is fixed:: sage: zeta(x).series(x==pi, 2) (zeta(pi)) + (zetaderiv(1, pi))*(-pi + x) + Order((pi - x)^2) sage: (zeta(x) * 1/(1 - exp(-x))).residue(x==2*pi*I) zeta(2*I*pi) Check that the right infinities are returned (:trac:`19439`):: sage: zeta(1.0) +infinity sage: zeta(SR(1.0)) Infinity """ GinacFunction.__init__(self, 'zeta', conversions={'giac': 'Zeta'})
def __init__(self): r""" The inverse of the hyperbolic cosine function. EXAMPLES:: sage: arccosh(1/2) arccosh(1/2) sage: arccosh(1 + I*1.0) 1.06127506190504 + 0.904556894302381*I sage: float(arccosh(2)) 1.3169578969248168 sage: cosh(float(arccosh(2))) 2.0 .. warning:: If the input is in the complex field or symbolic (which includes rational and integer input), the output will be complex. However, if the input is a real decimal, the output will be real or `NaN`. See the examples for details. :: sage: arccosh(0.5) NaN sage: arccosh(1/2) arccosh(1/2) sage: arccosh(1/2).n() NaN sage: arccosh(CC(0.5)) 1.04719755119660*I sage: arccosh(0) 1/2*I*pi sage: arccosh(-1) I*pi To prevent automatic evaluation use the ``hold`` argument:: sage: arccosh(-1,hold=True) arccosh(-1) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: arccosh(-1,hold=True).simplify() I*pi ``conjugate(arccosh(x))==arccosh(conjugate(x))`` unless on the branch cut which runs along the real axis from +1 to -inf.:: sage: conjugate(arccosh(x)) conjugate(arccosh(x)) sage: var('y', domain='positive') y sage: conjugate(arccosh(y)) conjugate(arccosh(y)) sage: conjugate(arccosh(y+I)) conjugate(arccosh(y + I)) sage: conjugate(arccosh(1/16)) conjugate(arccosh(1/16)) sage: conjugate(arccosh(2)) arccosh(2) sage: conjugate(arccosh(I/2)) arccosh(-1/2*I) TESTS:: sage: arccosh(x).operator() arccosh sage: latex(arccosh(x)) {\rm arccosh}\left(x\right) """ GinacFunction.__init__(self, "arccosh", latex_name=r"{\rm arccosh}", conversions=dict(maxima='acosh', sympy='acosh'))
def __init__(self): r""" The principal branch of the log gamma function. Note that for `x < 0`, ``log(gamma(x))`` is not, in general, equal to ``log_gamma(x)``. It is computed by the ``log_gamma`` function for the number type, or by ``lgamma`` in Ginac, failing that. Gamma is defined for complex input `z` with real part greater than zero, and by analytic continuation on the rest of the complex plane (except for negative integers, which are poles). EXAMPLES: Numerical evaluation happens when appropriate, to the appropriate accuracy (see :trac:`10072`):: sage: log_gamma(6) log(120) sage: log_gamma(6.) 4.78749174278205 sage: log_gamma(6).n() 4.78749174278205 sage: log_gamma(RealField(100)(6)) 4.7874917427820459942477009345 sage: log_gamma(2.4 + I) -0.0308566579348816 + 0.693427705955790*I sage: log_gamma(-3.1) 0.400311696703985 - 12.5663706143592*I sage: log_gamma(-1.1) == log(gamma(-1.1)) False Symbolic input works (see :trac:`10075`):: sage: log_gamma(3*x) log_gamma(3*x) sage: log_gamma(3 + I) log_gamma(I + 3) sage: log_gamma(3 + I + x) log_gamma(x + I + 3) Check that :trac:`12521` is fixed:: sage: log_gamma(-2.1) 1.53171380819509 - 9.42477796076938*I sage: log_gamma(CC(-2.1)) 1.53171380819509 - 9.42477796076938*I sage: log_gamma(-21/10).n() 1.53171380819509 - 9.42477796076938*I sage: exp(log_gamma(-1.3) + log_gamma(-0.4) - ....: log_gamma(-1.3 - 0.4)).real_part() # beta(-1.3, -0.4) -4.92909641669610 In order to prevent evaluation, use the ``hold`` argument; to evaluate a held expression, use the ``n()`` numerical evaluation method:: sage: log_gamma(SR(5), hold=True) log_gamma(5) sage: log_gamma(SR(5), hold=True).n() 3.17805383034795 TESTS:: sage: log_gamma(-2.1 + I) -1.90373724496982 - 7.18482377077183*I sage: log_gamma(pari(6)) 4.78749174278205 sage: log_gamma(x)._sympy_() loggamma(x) sage: log_gamma(CC(6)) 4.78749174278205 sage: log_gamma(CC(-2.5)) -0.0562437164976741 - 9.42477796076938*I sage: log_gamma(RDF(-2.5)) -0.056243716497674054 - 9.42477796076938*I sage: log_gamma(CDF(-2.5)) -0.056243716497674054 - 9.42477796076938*I sage: log_gamma(float(-2.5)) (-0.056243716497674054-9.42477796076938j) sage: log_gamma(complex(-2.5)) (-0.056243716497674054-9.42477796076938j) ``conjugate(log_gamma(x)) == log_gamma(conjugate(x))`` unless on the branch cut, which runs along the negative real axis.:: sage: conjugate(log_gamma(x)) conjugate(log_gamma(x)) sage: var('y', domain='positive') y sage: conjugate(log_gamma(y)) log_gamma(y) sage: conjugate(log_gamma(y + I)) conjugate(log_gamma(y + I)) sage: log_gamma(-2) +Infinity sage: conjugate(log_gamma(-2)) +Infinity """ GinacFunction.__init__(self, "log_gamma", latex_name=r'\log\Gamma', conversions=dict(mathematica='LogGamma', maxima='log_gamma', sympy='loggamma', fricas='logGamma'))
def __init__(self): """ The arccosine function. EXAMPLES:: sage: arccos(0.5) 1.04719755119660 sage: arccos(1/2) 1/3*pi sage: arccos(1 + 1.0*I) 0.904556894302381 - 1.06127506190504*I sage: arccos(3/4).n(100) 0.72273424781341561117837735264 We can delay evaluation using the ``hold`` parameter:: sage: arccos(0,hold=True) arccos(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arccos(0,hold=True); a.simplify() 1/2*pi ``conjugate(arccos(x))==arccos(conjugate(x))``, unless on the branch cuts, which run along the real axis outside the interval [-1, +1].:: sage: conjugate(arccos(x)) conjugate(arccos(x)) sage: var('y', domain='positive') y sage: conjugate(arccos(y)) conjugate(arccos(y)) sage: conjugate(arccos(y+I)) conjugate(arccos(y + I)) sage: conjugate(arccos(1/16)) arccos(1/16) sage: conjugate(arccos(2)) conjugate(arccos(2)) sage: conjugate(arccos(-2)) pi - conjugate(arccos(2)) TESTS:: sage: arccos(x)._sympy_() acos(x) sage: arccos(x).operator() arccos sage: acos(complex(1,1)) (0.9045568943023814-1.0612750619050357j) sage: acos(SR(2.1)) 1.37285914424258*I """ GinacFunction.__init__(self, 'arccos', latex_name=r"\arccos", conversions=dict(maxima='acos', sympy='acos', mathematica='ArcCos', fricas='acos', giac='acos'))
def __init__(self): r""" The polylog function `\text{Li}_s(z) = \sum_{k=1}^{\infty} z^k / k^s`. This definition is valid for arbitrary complex order `s` and for all complex arguments `z` with `|z| < 1`; it can be extended to `|z| \ge 1` by the process of analytic continuation. So the function may have a discontinuity at `z=1` which can cause a `NaN` value returned for floating point arguments. EXAMPLES:: sage: polylog(2.7, 0) 0 sage: polylog(2, 1) 1/6*pi^2 sage: polylog(2, -1) -1/12*pi^2 sage: polylog(3, -1) -3/4*zeta(3) sage: polylog(2, I) I*catalan - 1/48*pi^2 sage: polylog(4, 1/2) polylog(4, 1/2) sage: polylog(4, 0.5) 0.517479061673899 sage: polylog(1, x) -log(-x + 1) sage: polylog(2,x^2+1) dilog(x^2 + 1) sage: f = polylog(4, 1); f 1/90*pi^4 sage: f.n() 1.08232323371114 sage: polylog(4, 2).n() 2.42786280675470 - 0.174371300025453*I sage: complex(polylog(4,2)) (2.4278628067547032-0.17437130002545306j) sage: float(polylog(4,0.5)) 0.5174790616738993 sage: z = var('z') sage: polylog(2,z).series(z==0, 5) 1*z + 1/4*z^2 + 1/9*z^3 + 1/16*z^4 + Order(z^5) sage: loads(dumps(polylog)) polylog sage: latex(polylog(5, x)) {\rm Li}_{5}(x) sage: polylog(x, x)._sympy_() polylog(x, x) TESTS: Check if :trac:`8459` is fixed:: sage: t = maxima(polylog(5,x)).sage(); t polylog(5, x) sage: t.operator() == polylog True sage: t.subs(x=.5).n() 0.50840057924226... Check if :trac:`18386` is fixed:: sage: polylog(2.0, 1) 1.64493406684823 sage: polylog(2, 1.0) NaN sage: polylog(2.0, 1.0) NaN """ GinacFunction.__init__(self, "polylog", nargs=2)
def __init__(self): """ The arcsine function. EXAMPLES:: sage: arcsin(0.5) 0.523598775598299 sage: arcsin(1/2) 1/6*pi sage: arcsin(1 + 1.0*I) 0.666239432492515 + 1.06127506190504*I We can delay evaluation using the ``hold`` parameter:: sage: arcsin(0,hold=True) arcsin(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arcsin(0,hold=True); a.simplify() 0 ``conjugate(arcsin(x))==arcsin(conjugate(x))``, unless on the branch cuts which run along the real axis outside the interval [-1, +1].:: sage: conjugate(arcsin(x)) conjugate(arcsin(x)) sage: var('y', domain='positive') y sage: conjugate(arcsin(y)) conjugate(arcsin(y)) sage: conjugate(arcsin(y+I)) conjugate(arcsin(y + I)) sage: conjugate(arcsin(1/16)) arcsin(1/16) sage: conjugate(arcsin(2)) conjugate(arcsin(2)) sage: conjugate(arcsin(-2)) -conjugate(arcsin(2)) TESTS:: sage: arcsin(x)._sympy_() asin(x) sage: arcsin(x).operator() arcsin sage: asin(complex(1,1)) (0.6662394324925152+1.0612750619050357j) sage: asin(SR(2.1)) 1.57079632679490 - 1.37285914424258*I """ GinacFunction.__init__(self, 'arcsin', latex_name=r"\arcsin", conversions=dict(maxima='asin', sympy='asin', mathematica='ArcSin', fricas="asin", giac="asin"))
def __init__(self): r""" Returns the factorial of `n`. INPUT: - ``n`` - any complex argument (except negative integers) or any symbolic expression OUTPUT: an integer or symbolic expression EXAMPLES:: sage: x = var('x') sage: factorial(0) 1 sage: factorial(4) 24 sage: factorial(10) 3628800 sage: factorial(6) == 6*5*4*3*2 True sage: f = factorial(x + factorial(x)); f factorial(x + factorial(x)) sage: f(x=3) 362880 sage: factorial(x)^2 factorial(x)^2 To prevent automatic evaluation use the ``hold`` argument:: sage: factorial(5,hold=True) factorial(5) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: factorial(5,hold=True).simplify() 120 We can also give input other than nonnegative integers. For other nonnegative numbers, the :func:`gamma` function is used:: sage: factorial(1/2) 1/2*sqrt(pi) sage: factorial(3/4) gamma(7/4) sage: factorial(2.3) 2.68343738195577 But negative input always fails:: sage: factorial(-32) Traceback (most recent call last): ... ValueError: factorial -- self = (-32) must be nonnegative TESTS: We verify that we can convert this function to Maxima and bring it back into Sage.:: sage: z = var('z') sage: factorial._maxima_init_() 'factorial' sage: maxima(factorial(z)) z! sage: _.sage() factorial(z) sage: k = var('k') sage: factorial(k) factorial(k) sage: factorial(3.14) 7.173269190187... Test latex typesetting:: sage: latex(factorial(x)) x! sage: latex(factorial(2*x)) \left(2 \, x\right)! sage: latex(factorial(sin(x))) \sin\left(x\right)! sage: latex(factorial(sqrt(x+1))) \left(\sqrt{x + 1}\right)! sage: latex(factorial(sqrt(x))) \sqrt{x}! sage: latex(factorial(x^(2/3))) \left(x^{\frac{2}{3}}\right)! sage: latex(factorial) {\rm factorial} """ GinacFunction.__init__(self, "factorial", latex_name='{\\rm factorial}', conversions=dict(maxima='factorial', mathematica='Factorial'))
def __init__(self): r""" The cosine function. EXAMPLES:: sage: cos(pi) -1 sage: cos(x).subs(x==pi) -1 sage: cos(2).n(100) -0.41614683654714238699756822950 sage: loads(dumps(cos)) cos sage: cos(x)._sympy_() cos(x) We can prevent evaluation using the ``hold`` parameter:: sage: cos(0,hold=True) cos(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = cos(0,hold=True); a.simplify() 1 If possible, the argument is also reduced modulo the period length `2\pi`, and well-known identities are directly evaluated:: sage: k = var('k', domain='integer') sage: cos(1 + 2*k*pi) cos(1) sage: cos(k*pi) cos(pi*k) sage: cos(pi/3 + 2*k*pi) 1/2 TESTS:: sage: conjugate(cos(x)) cos(conjugate(x)) sage: cos(complex(1,1)) # rel tol 1e-15 (0.8337300251311491-0.9888977057628651j) Check that :trac:`20752` is fixed:: sage: cos(3*pi+41/42*pi) cos(1/42*pi) sage: cos(-5*pi+1/42*pi) -cos(1/42*pi) sage: cos(pi-1/42*pi) -cos(1/42*pi) """ GinacFunction.__init__(self, 'cos', latex_name=r"\cos", conversions=dict(maxima='cos', mathematica='Cos', giac='cos', fricas='cos', sympy='cos'))
def __init__(self): r""" The dilogarithm function `\text{Li}_2(z) = \sum_{k=1}^{\infty} z^k / k^2`. This is simply an alias for polylog(2, z). EXAMPLES:: sage: dilog(1) 1/6*pi^2 sage: dilog(1/2) 1/12*pi^2 - 1/2*log(2)^2 sage: dilog(x^2+1) dilog(x^2 + 1) sage: dilog(-1) -1/12*pi^2 sage: dilog(-1.0) -0.822467033424113 sage: dilog(-1.1) -0.890838090262283 sage: dilog(1/2) 1/12*pi^2 - 1/2*log(2)^2 sage: dilog(.5) 0.582240526465012 sage: dilog(1/2).n() 0.582240526465012 sage: var('z') z sage: dilog(z).diff(z, 2) log(-z + 1)/z^2 - 1/((z - 1)*z) sage: dilog(z).series(z==1/2, 3) (1/12*pi^2 - 1/2*log(2)^2) + (-2*log(1/2))*(z - 1/2) + (2*log(1/2) + 2)*(z - 1/2)^2 + Order(1/8*(2*z - 1)^3) sage: latex(dilog(z)) {\rm Li}_2\left(z\right) Dilog has a branch point at `1`. Sage's floating point libraries may handle this differently from the symbolic package:: sage: dilog(1) 1/6*pi^2 sage: dilog(1.) 1.64493406684823 sage: dilog(1).n() 1.64493406684823 sage: float(dilog(1)) 1.6449340668482262 TESTS: ``conjugate(dilog(x))==dilog(conjugate(x))`` unless on the branch cuts which run along the positive real axis beginning at 1.:: sage: conjugate(dilog(x)) conjugate(dilog(x)) sage: var('y',domain='positive') y sage: conjugate(dilog(y)) conjugate(dilog(y)) sage: conjugate(dilog(1/19)) dilog(1/19) sage: conjugate(dilog(1/2*I)) dilog(-1/2*I) sage: dilog(conjugate(1/2*I)) dilog(-1/2*I) sage: conjugate(dilog(2)) conjugate(dilog(2)) Check that return type matches argument type where possible (:trac:`18386`):: sage: dilog(0.5) 0.582240526465012 sage: dilog(-1.0) -0.822467033424113 sage: y = dilog(RealField(13)(0.5)) sage: parent(y) Real Field with 13 bits of precision sage: dilog(RealField(13)(1.1)) 1.96 - 0.300*I sage: parent(_) Complex Field with 13 bits of precision """ GinacFunction.__init__(self, 'dilog', conversions=dict(maxima='li[2]', magma='Dilog', fricas='(x+->dilog(1-x))'))
def __init__(self): r""" The polylog function `\text{Li}_s(z) = \sum_{k=1}^{\infty} z^k / k^s`. The first argument is `s` (usually an integer called the weight) and the second argument is `z` : ``polylog(s, z)``. This definition is valid for arbitrary complex numbers `s` and `z` with `|z| < 1`. It can be extended to `|z| \ge 1` by the process of analytic continuation, with a branch cut along the positive real axis from `1` to `+\infty`. A `NaN` value may be returned for floating point arguments that are on the branch cut. EXAMPLES:: sage: polylog(2.7, 0) 0.000000000000000 sage: polylog(2, 1) 1/6*pi^2 sage: polylog(2, -1) -1/12*pi^2 sage: polylog(3, -1) -3/4*zeta(3) sage: polylog(2, I) I*catalan - 1/48*pi^2 sage: polylog(4, 1/2) polylog(4, 1/2) sage: polylog(4, 0.5) 0.517479061673899 sage: polylog(1, x) -log(-x + 1) sage: polylog(2,x^2+1) dilog(x^2 + 1) sage: f = polylog(4, 1); f 1/90*pi^4 sage: f.n() 1.08232323371114 sage: polylog(4, 2).n() 2.42786280675470 - 0.174371300025453*I sage: complex(polylog(4,2)) (2.4278628067547032-0.17437130002545306j) sage: float(polylog(4,0.5)) 0.5174790616738993 sage: z = var('z') sage: polylog(2,z).series(z==0, 5) 1*z + 1/4*z^2 + 1/9*z^3 + 1/16*z^4 + Order(z^5) sage: loads(dumps(polylog)) polylog sage: latex(polylog(5, x)) {\rm Li}_{5}(x) sage: polylog(x, x)._sympy_() polylog(x, x) TESTS: Check if :trac:`8459` is fixed:: sage: t = maxima(polylog(5,x)).sage(); t polylog(5, x) sage: t.operator() == polylog True sage: t.subs(x=.5).n() 0.50840057924226... Check if :trac:`18386` is fixed:: sage: polylog(2.0, 1) 1.64493406684823 sage: polylog(2, 1.0) 1.64493406684823 sage: polylog(2.0, 1.0) 1.64493406684823 sage: polylog(2, RealBallField(100)(1/3)) [0.36621322997706348761674629766... +/- ...] sage: polylog(2, ComplexBallField(100)(4/3)) [2.27001825336107090380391448586 +/- ...] + [-0.90377988538400159956755721265 +/- ...]*I sage: polylog(2, CBF(1/3)) [0.366213229977063 +/- ...] sage: parent(_) Complex ball field with 53 bits of precision sage: polylog(2, CBF(1)) [1.644934066848226 +/- ...] sage: parent(_) Complex ball field with 53 bits of precision sage: polylog(1,-1) # known bug -log(2) Check for :trac:`21907`:: sage: bool(x*polylog(x,x)==0) False """ GinacFunction.__init__(self, "polylog", nargs=2, conversions=dict(mathematica='PolyLog', magma='Polylog', matlab='polylog', sympy='polylog'))
def __init__(self): r""" The exponential function, `\exp(x) = e^x`. EXAMPLES:: sage: exp(-1) e^(-1) sage: exp(2) e^2 sage: exp(2).n(100) 7.3890560989306502272304274606 sage: exp(x^2 + log(x)) e^(x^2 + log(x)) sage: exp(x^2 + log(x)).simplify() x*e^(x^2) sage: exp(2.5) 12.1824939607035 sage: exp(float(2.5)) 12.182493960703473 sage: exp(RDF('2.5')) 12.1824939607 To prevent automatic evaluation, use the ``hold`` parameter:: sage: exp(I*pi,hold=True) e^(I*pi) sage: exp(0,hold=True) e^0 To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: exp(0,hold=True).simplify() 1 :: sage: exp(pi*I/2) I sage: exp(pi*I) -1 sage: exp(8*pi*I) 1 sage: exp(7*pi*I/2) -I TEST:: sage: latex(exp(x)) e^{x} sage: latex(exp(sqrt(x))) e^{\sqrt{x}} sage: latex(exp) \exp sage: latex(exp(sqrt(x))^x) \left(e^{\sqrt{x}}\right)^{x} sage: latex(exp(sqrt(x)^x)) e^{\left(\sqrt{x}^{x}\right)} Test conjugates:: sage: conjugate(exp(x)) e^conjugate(x) Test simplifications when taking powers of exp, #7264:: sage: var('a,b,c,II') (a, b, c, II) sage: model_exp = exp(II)**a*(b) sage: sol1_l={b: 5.0, a: 1.1} sage: model_exp.subs(sol1_l) 5.00000000000000*(e^II)^1.10000000000000 :: sage: exp(3)^II*exp(x) (e^3)^II*e^x sage: exp(x)*exp(x) e^(2*x) sage: exp(x)*exp(a) e^(a + x) sage: exp(x)*exp(a)^2 e^(2*a + x) Another instance of the same problem, #7394:: sage: 2*sqrt(e) 2*sqrt(e) """ GinacFunction.__init__(self, "exp", latex_name=r"\exp", conversions=dict(maxima='exp'))
def __init__(self): r""" The Gamma function. This is defined by `\Gamma(z) = \int_0^\infty t^{z-1}e^{-t} dt` for complex input `z` with real part greater than zero, and by analytic continuation on the rest of the complex plane (except for negative integers, which are poles). It is computed by various libraries within Sage, depending on the input type. EXAMPLES:: sage: from sage.functions.other import gamma1 sage: gamma1(CDF(0.5,14)) -4.05370307804e-10 - 5.77329983455e-10*I sage: gamma1(CDF(I)) -0.154949828302 - 0.498015668118*I Recall that `\Gamma(n)` is `n-1` factorial:: sage: gamma1(11) == factorial(10) True sage: gamma1(6) 120 sage: gamma1(1/2) sqrt(pi) sage: gamma1(-1) Infinity sage: gamma1(I) gamma(I) sage: gamma1(x/2)(x=5) 3/4*sqrt(pi) sage: gamma1(float(6)) 120.0 sage: gamma1(x) gamma(x) :: sage: gamma1(pi) gamma(pi) sage: gamma1(i) gamma(I) sage: gamma1(i).n() -0.154949828301811 - 0.498015668118356*I sage: gamma1(int(5)) 24 :: sage: conjugate(gamma(x)) gamma(conjugate(x)) :: sage: plot(gamma1(x),(x,1,5)) To prevent automatic evaluation use the ``hold`` argument:: sage: gamma1(1/2,hold=True) gamma(1/2) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: gamma1(1/2,hold=True).simplify() sqrt(pi) TESTS: We verify that we can convert this function to Maxima and convert back to Sage:: sage: z = var('z') sage: maxima(gamma1(z)).sage() gamma(z) sage: latex(gamma1(z)) \Gamma\left(z\right) Test that Trac ticket 5556 is fixed:: sage: gamma1(3/4) gamma(3/4) sage: gamma1(3/4).n(100) 1.2254167024651776451290983034 Check that negative integer input works:: sage: (-1).gamma() Infinity sage: (-1.).gamma() NaN sage: CC(-1).gamma() Infinity sage: RDF(-1).gamma() NaN sage: CDF(-1).gamma() Infinity Check if #8297 is fixed:: sage: latex(gamma(1/4)) \Gamma\left(\frac{1}{4}\right) """ GinacFunction.__init__(self, "gamma", latex_name=r'\Gamma', ginac_name='tgamma', conversions={ 'mathematica': 'Gamma', 'maple': 'GAMMA' })
def __init__(self): """ The arctangent function. EXAMPLES:: sage: arctan(1/2) arctan(1/2) sage: RDF(arctan(1/2)) # rel tol 1e-15 0.46364760900080615 sage: arctan(1 + I) arctan(I + 1) sage: arctan(1/2).n(100) 0.46364760900080611621425623146 We can delay evaluation using the ``hold`` parameter:: sage: arctan(0,hold=True) arctan(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = arctan(0,hold=True); a.simplify() 0 ``conjugate(arctan(x))==arctan(conjugate(x))``, unless on the branch cuts which run along the imaginary axis outside the interval [-I, +I].:: sage: conjugate(arctan(x)) conjugate(arctan(x)) sage: var('y', domain='positive') y sage: conjugate(arctan(y)) arctan(y) sage: conjugate(arctan(y+I)) conjugate(arctan(y + I)) sage: conjugate(arctan(1/16)) arctan(1/16) sage: conjugate(arctan(-2*I)) conjugate(arctan(-2*I)) sage: conjugate(arctan(2*I)) conjugate(arctan(2*I)) sage: conjugate(arctan(I/2)) arctan(-1/2*I) TESTS:: sage: arctan(x)._sympy_() atan(x) sage: arctan(x).operator() arctan sage: atan(complex(1,1)) (1.0172219678978514+0.4023594781085251j) Check that :trac:`19918` is fixed:: sage: arctan(-x).subs(x=oo) -1/2*pi sage: arctan(-x).subs(x=-oo) 1/2*pi """ GinacFunction.__init__(self, 'arctan', latex_name=r"\arctan", conversions=dict(maxima='atan', sympy='atan', mathematica='ArcTan', fricas='atan', giac='atan'))
def __init__(self): r""" Return the binomial coefficient .. math:: \binom{x}{m} = x (x-1) \cdots (x-m+1) / m! which is defined for `m \in \ZZ` and any `x`. We extend this definition to include cases when `x-m` is an integer but `m` is not by .. math:: \binom{x}{m}= \binom{x}{x-m} If `m < 0`, return `0`. INPUT: - ``x``, ``m`` - numbers or symbolic expressions. Either ``m`` or ``x-m`` must be an integer, else the output is symbolic. OUTPUT: number or symbolic expression (if input is symbolic) EXAMPLES:: sage: binomial(5,2) 10 sage: binomial(2,0) 1 sage: binomial(1/2, 0) 1 sage: binomial(3,-1) 0 sage: binomial(20,10) 184756 sage: binomial(-2, 5) -6 sage: binomial(RealField()('2.5'), 2) 1.87500000000000 sage: n=var('n'); binomial(n,2) 1/2*(n - 1)*n sage: n=var('n'); binomial(n,n) 1 sage: n=var('n'); binomial(n,n-1) n sage: binomial(2^100, 2^100) 1 :: sage: k, i = var('k,i') sage: binomial(k,i) binomial(k, i) We can use a ``hold`` parameter to prevent automatic evaluation, but only using method notation:: sage: SR(5).binomial(3, hold=True) binomial(5, 3) sage: SR(5).binomial(3, hold=True).simplify() 10 TESTS: We verify that we can convert this function to Maxima and bring it back into Sage. :: sage: n,k = var('n,k') sage: maxima(binomial(n,k)) binomial(n,k) sage: _.sage() binomial(n, k) sage: sage.functions.other.binomial._maxima_init_() # temporary workaround until we can get symbolic binomial to import in global namespace, if that's desired 'binomial' """ GinacFunction.__init__(self, "binomial", nargs=2, conversions=dict(maxima='binomial', mathematica='Binomial'))
def __init__(self): r""" The natural logarithm of x. See `log?` for more information about its behavior. EXAMPLES:: sage: ln(e^2) 2 sage: ln(2) log(2) sage: ln(10) log(10) :: sage: ln(RDF(10)) 2.30258509299 sage: ln(2.718) 0.999896315728952 sage: ln(2.0) 0.693147180559945 sage: ln(float(-1)) 3.141592653589793j sage: ln(complex(-1)) 3.141592653589793j We do not currently support a ``hold`` parameter in functional notation:: sage: log(SR(-1),hold=True) Traceback (most recent call last): ... TypeError: log() got an unexpected keyword argument 'hold' This is possible with method notation:: sage: I.log(hold=True) log(I) sage: I.log(hold=True).simplify() 1/2*I*pi TESTS:: sage: latex(x.log()) \log\left(x\right) sage: latex(log(1/4)) \log\left(\frac{1}{4}\right) sage: loads(dumps(ln(x)+1)) log(x) + 1 ``conjugate(log(x))==log(conjugate(x))`` unless on the branch cut which runs along the negative real axis.:: sage: conjugate(log(x)) conjugate(log(x)) sage: var('y', domain='positive') y sage: conjugate(log(y)) log(y) sage: conjugate(log(y+I)) conjugate(log(y + I)) sage: conjugate(log(-1)) -I*pi sage: log(conjugate(-1)) I*pi Check if float arguments are handled properly.:: sage: from sage.functions.log import function_log as log sage: log(float(5)) 1.6094379124341003 sage: log(float(0)) -inf sage: log(float(-1)) 3.141592653589793j sage: log(x).subs(x=float(-1)) 3.141592653589793j """ GinacFunction.__init__(self, 'log', latex_name=r'\log', conversions=dict(maxima='log'))
def __init__(self): r""" The polylog function `\text{Li}_s(z) = \sum_{k=1}^{\infty} z^k / k^s`. This definition is valid for arbitrary complex order `s` and for all complex arguments `z` with `|z| < 1`; it can be extended to `|z| \ge 1` by the process of analytic continuation. So the function may have a discontinuity at `z=1` which can cause a `NaN` value returned for floating point arguments. EXAMPLES:: sage: polylog(2.7, 0) 0.000000000000000 sage: polylog(2, 1) 1/6*pi^2 sage: polylog(2, -1) -1/12*pi^2 sage: polylog(3, -1) -3/4*zeta(3) sage: polylog(2, I) I*catalan - 1/48*pi^2 sage: polylog(4, 1/2) polylog(4, 1/2) sage: polylog(4, 0.5) 0.517479061673899 sage: polylog(1, x) -log(-x + 1) sage: polylog(2,x^2+1) dilog(x^2 + 1) sage: f = polylog(4, 1); f 1/90*pi^4 sage: f.n() 1.08232323371114 sage: polylog(4, 2).n() 2.42786280675470 - 0.174371300025453*I sage: complex(polylog(4,2)) (2.4278628067547032-0.17437130002545306j) sage: float(polylog(4,0.5)) 0.5174790616738993 sage: z = var('z') sage: polylog(2,z).series(z==0, 5) 1*z + 1/4*z^2 + 1/9*z^3 + 1/16*z^4 + Order(z^5) sage: loads(dumps(polylog)) polylog sage: latex(polylog(5, x)) {\rm Li}_{5}(x) sage: polylog(x, x)._sympy_() polylog(x, x) TESTS: Check if :trac:`8459` is fixed:: sage: t = maxima(polylog(5,x)).sage(); t polylog(5, x) sage: t.operator() == polylog True sage: t.subs(x=.5).n() 0.50840057924226... Check if :trac:`18386` is fixed:: sage: polylog(2.0, 1) 1.64493406684823 sage: polylog(2, 1.0) 1.64493406684823 sage: polylog(2.0, 1.0) 1.64493406684823 sage: BF = RealBallField(100) sage: polylog(2, BF(1/3)) [0.36621322997706348761674629766... +/- ...] sage: polylog(2, BF(4/3)) [2.27001825336107090380391448586 +/- 5.64e-30] + [-0.90377988538400159956755721265 +/- 8.39e-30]*I sage: parent(_) Complex ball field with 100 bits of precision sage: polylog(2, CBF(1/3)) [0.366213229977063 +/- ...] sage: parent(_) Complex ball field with 53 bits of precision sage: polylog(2, CBF(1)) [1.644934066848226 +/- ...] sage: parent(_) Complex ball field with 53 bits of precision """ GinacFunction.__init__(self, "polylog", nargs=2)
def __init__(self): """ The modified arctangent function. Returns the arc tangent (measured in radians) of `y/x`, where unlike ``arctan(y/x)``, the signs of both ``x`` and ``y`` are considered. In particular, this function measures the angle of a ray through the origin and `(x,y)`, with the positive `x`-axis the zero mark, and with output angle `\theta` being between `-\pi<\theta<=\pi`. Hence, ``arctan2(y,x) = arctan(y/x)`` only for `x>0`. One may consider the usual arctan to measure angles of lines through the origin, while the modified function measures rays through the origin. Note that the `y`-coordinate is by convention the first input. EXAMPLES: Note the difference between the two functions:: sage: arctan2(1,-1) 3/4*pi sage: arctan(1/-1) -1/4*pi This is consistent with Python and Maxima:: sage: maxima.atan2(1,-1) 3*%pi/4 sage: math.atan2(1,-1) 2.356194490192345 More examples:: sage: arctan2(1,0) 1/2*pi sage: arctan2(2,3) arctan(2/3) sage: arctan2(-1,-1) -3/4*pi Of course we can approximate as well:: sage: arctan2(-1/2,1).n(100) -0.46364760900080611621425623146 sage: arctan2(2,3).n(100) 0.58800260354756755124561108063 We can delay evaluation using the ``hold`` parameter:: sage: arctan2(-1/2,1,hold=True) arctan2(-1/2, 1) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: arctan2(-1/2,1,hold=True).simplify() -arctan(1/2) The function also works with numpy arrays as input:: sage: import numpy sage: a = numpy.linspace(1, 3, 3) sage: b = numpy.linspace(3, 6, 3) sage: atan2(a, b) array([ 0.32175055, 0.41822433, 0.46364761]) sage: atan2(1,a) array([ 0.78539816, 0.46364761, 0.32175055]) sage: atan2(a, 1) array([ 0.78539816, 1.10714872, 1.24904577]) TESTS:: sage: x,y = var('x,y') sage: arctan2(y,x).operator() arctan2 Check if #8565 is fixed:: sage: atan2(-pi,0) -1/2*pi Check if #8564 is fixed:: sage: arctan2(x,x)._sympy_() atan2(x, x) Check if numerical evaluation works #9913:: sage: arctan2(0, -log(2)).n() 3.14159265358979 Check if atan2(0,0) throws error of :trac:`11423`:: sage: atan2(0,0) Traceback (most recent call last): ... RuntimeError: arctan2_eval(): arctan2(0,0) encountered sage: atan2(0,0,hold=True) arctan2(0, 0) sage: atan2(0,0,hold=True).n() Traceback (most recent call last): ... ValueError: arctan2(0,0) undefined """ GinacFunction.__init__(self, "arctan2", nargs=2, latex_name=r'\arctan', conversions=dict(maxima='atan2', sympy='atan2'))
def __init__(self): r""" The sine function. EXAMPLES:: sage: sin(0) 0 sage: sin(x).subs(x==0) 0 sage: sin(2).n(100) 0.90929742682568169539601986591 sage: loads(dumps(sin)) sin sage: sin(x)._sympy_() sin(x) We can prevent evaluation using the ``hold`` parameter:: sage: sin(0,hold=True) sin(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = sin(0,hold=True); a.simplify() 0 If possible, the argument is also reduced modulo the period length `2\pi`, and well-known identities are directly evaluated:: sage: k = var('k', domain='integer') sage: sin(1 + 2*k*pi) sin(1) sage: sin(k*pi) 0 TESTS:: sage: conjugate(sin(x)) sin(conjugate(x)) sage: sin(complex(1,1)) # rel tol 1e-15 (1.2984575814159773+0.6349639147847361j) sage: sin(pi/5) 1/4*sqrt(-2*sqrt(5) + 10) sage: sin(pi/8) 1/2*sqrt(-sqrt(2) + 2) sage: sin(pi/24) 1/4*sqrt(-2*sqrt(6) - 2*sqrt(2) + 8) sage: sin(pi/30) -1/8*sqrt(5) + 1/4*sqrt(-3/2*sqrt(5) + 15/2) - 1/8 sage: sin(104*pi/105) sin(1/105*pi) sage: cos(pi/8) 1/2*sqrt(sqrt(2) + 2) sage: cos(pi/10) 1/4*sqrt(2*sqrt(5) + 10) sage: cos(pi/12) 1/4*sqrt(6) + 1/4*sqrt(2) sage: cos(pi/15) 1/8*sqrt(5) + 1/4*sqrt(3/2*sqrt(5) + 15/2) - 1/8 sage: cos(pi/24) 1/4*sqrt(2*sqrt(6) + 2*sqrt(2) + 8) sage: cos(104*pi/105) -cos(1/105*pi) sage: tan(pi/5) sqrt(-2*sqrt(5) + 5) sage: tan(pi/8) sqrt(2) - 1 sage: tan(pi/10) 1/5*sqrt(-10*sqrt(5) + 25) sage: tan(pi/16) -sqrt(2) + sqrt(2*sqrt(2) + 4) - 1 sage: tan(pi/20) sqrt(5) - sqrt(2*sqrt(5) + 5) + 1 sage: tan(pi/24) sqrt(6) - sqrt(3) + sqrt(2) - 2 sage: tan(104*pi/105) -tan(1/105*pi) sage: cot(104*pi/105) -cot(1/105*pi) sage: sec(104*pi/105) -sec(1/105*pi) sage: csc(104*pi/105) csc(1/105*pi) sage: all(sin(rat*pi).n(200)-sin(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/30,7/30,11/30,13/30,1/8,3/8,1/24,5/24,7/24,11/24]) True sage: all(cos(rat*pi).n(200)-cos(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/10,3/10,1/12,5/12,1/15,2/15,4/15,7/15,1/8,3/8,1/24,5/24,11/24]) True sage: all(tan(rat*pi).n(200)-tan(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/10,3/10,1/20,3/20,7/20,9/20,1/8,3/8,1/16,3/16,5/16,7/16,1/24,5/24,7/24,11/24]) True Check that :trac:`20456` is fixed:: sage: assume(x>0) sage: sin(pi*x) sin(pi*x) sage: forget() Check that :trac:`20752` is fixed:: sage: sin(3*pi+41/42*pi) -sin(1/42*pi) sage: sin(-5*pi+1/42*pi) -sin(1/42*pi) sage: sin(pi-1/42*pi) sin(1/42*pi) """ GinacFunction.__init__(self, 'sin', latex_name=r"\sin", conversions=dict(maxima='sin', mathematica='Sin', giac='sin', fricas='sin', sympy='sin'))
def __init__(self): """ The sine function. EXAMPLES:: sage: sin(0) 0 sage: sin(x).subs(x==0) 0 sage: sin(2).n(100) 0.90929742682568169539601986591 sage: loads(dumps(sin)) sin We can prevent evaluation using the ``hold`` parameter:: sage: sin(0,hold=True) sin(0) To then evaluate again, we currently must use Maxima via :meth:`sage.symbolic.expression.Expression.simplify`:: sage: a = sin(0,hold=True); a.simplify() 0 TESTS:: sage: conjugate(sin(x)) sin(conjugate(x)) sage: sin(complex(1,1)) # rel tol 1e-15 (1.2984575814159773+0.6349639147847361j) sage: sin(pi/5) 1/4*sqrt(-2*sqrt(5) + 10) sage: sin(pi/8) 1/2*sqrt(-sqrt(2) + 2) sage: sin(pi/24) 1/4*sqrt(-2*sqrt(6) - 2*sqrt(2) + 8) sage: sin(pi/30) -1/8*sqrt(5) + 1/4*sqrt(-3/2*sqrt(5) + 15/2) - 1/8 sage: cos(pi/8) 1/2*sqrt(sqrt(2) + 2) sage: cos(pi/10) 1/2*sqrt(1/2*sqrt(5) + 5/2) sage: cos(pi/12) 1/12*sqrt(6)*(sqrt(3) + 3) sage: cos(pi/15) 1/8*sqrt(5) + 1/4*sqrt(3/2*sqrt(5) + 15/2) - 1/8 sage: cos(pi/24) 1/4*sqrt(2*sqrt(6) + 2*sqrt(2) + 8) sage: tan(pi/5) sqrt(-2*sqrt(5) + 5) sage: tan(pi/8) sqrt(2) - 1 sage: tan(pi/10) sqrt(-2/5*sqrt(5) + 1) sage: tan(pi/16) -sqrt(2) + sqrt(2*sqrt(2) + 4) - 1 sage: tan(pi/20) sqrt(5) - 1/2*sqrt(8*sqrt(5) + 20) + 1 sage: tan(pi/24) sqrt(6) - sqrt(3) + sqrt(2) - 2 sage: all(sin(rat*pi).n(200)-sin(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/30,7/30,11/30,13/30,1/8,3/8,1/24,5/24,7/24,11/24]) True sage: all(cos(rat*pi).n(200)-cos(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/10,3/10,1/12,5/12,1/15,2/15,4/15,7/15,1/8,3/8,1/24,5/24,11/24]) True sage: all(tan(rat*pi).n(200)-tan(rat*pi,hold=True).n(200) < 1e-30 for rat in [1/5,2/5,1/10,3/10,1/20,3/20,7/20,9/20,1/8,3/8,1/16,3/16,5/16,7/16,1/24,5/24,7/24,11/24]) True """ GinacFunction.__init__(self, "sin", latex_name=r"\sin", conversions=dict(maxima='sin',mathematica='Sin'))