Other functions¶
-
class
sage.functions.other.
Function_Order
¶ Bases:
sage.symbolic.function.GinacFunction
The order function.
This function gives the order of magnitude of some expression, similar to \(O\)-terms.
EXAMPLES:
sage: x = SR('x') sage: x.Order() Order(x) sage: (x^2 + x).Order() Order(x^2 + x) sage: x.Order()._sympy_() O(x)
-
class
sage.functions.other.
Function_abs
¶ Bases:
sage.symbolic.function.GinacFunction
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)) sqrt(abs(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|} sage: abs(x)._sympy_() Abs(x)
Test pickling:
sage: loads(dumps(abs(x))) abs(x)
-
class
sage.functions.other.
Function_arg
¶ Bases:
sage.symbolic.function.BuiltinFunction
The argument function for complex numbers.
EXAMPLES:
sage: arg(3+i) arctan(1/3) sage: arg(-1+i) 3/4*pi sage: arg(2+2*i) 1/4*pi sage: arg(2+x) arg(x + 2) sage: arg(2.0+i+x) arg(x + 2.00000000000000 + 1.00000000000000*I) sage: arg(-3) pi sage: arg(3) 0 sage: arg(0) 0 sage: latex(arg(x)) {\rm arg}\left(x\right) sage: maxima(arg(x)) atan2(0,_SAGE_VAR_x) sage: maxima(arg(2+i)) atan(1/2) sage: maxima(arg(sqrt(2)+i)) atan(1/sqrt(2)) sage: arg(x)._sympy_() arg(x) sage: arg(2+i) arctan(1/2) sage: arg(sqrt(2)+i) arg(sqrt(2) + I) sage: arg(sqrt(2)+i).simplify() arctan(1/2*sqrt(2))
-
class
sage.functions.other.
Function_beta
¶ Bases:
sage.symbolic.function.GinacFunction
Return the beta function. This is defined by
\[\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:
\[\operatorname{B}(p,q) = \frac{\Gamma(p)\Gamma(q)}{\Gamma(p+q)}\]or
\[\operatorname{B}(p,q) = (-1)^q \operatorname{B}(1-p-q, q).\]For numerical inputs, GiNaC uses the formula
\[\operatorname{B}(p,q) = \exp[\log\Gamma(p)+\log\Gamma(q)-\log\Gamma(p+q)]\]INPUT:
p
- number or symbolic expressionq
- 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 ticket #15196 is fixed:
sage: beta(-1.3,-0.4) -4.92909641669610
-
class
sage.functions.other.
Function_binomial
¶ Bases:
sage.symbolic.function.GinacFunction
Return the binomial coefficient
\[\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
\[\binom{x}{m}= \binom{x}{x-m}\]If \(m < 0\), return \(0\).
INPUT:
x
,m
- numbers or symbolic expressions. Eitherm
orx-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:sage: SR(5).binomial(3, hold=True) binomial(5, 3) sage: SR(5).binomial(3, hold=True).simplify() 10
sage: n,k = var('n,k') sage: maxima(binomial(n,k)) binomial(_SAGE_VAR_n,_SAGE_VAR_k) sage: _.sage() binomial(n, k) sage: _._sympy_() binomial(n, k) sage: binomial._maxima_init_() 'binomial'
For polynomials:
sage: y = polygen(QQ, 'y') sage: binomial(y, 2).parent() Univariate Polynomial Ring in y over Rational Field
Test pickling:
sage: loads(dumps(binomial(n,k))) binomial(n, k)
-
class
sage.functions.other.
Function_ceil
¶ Bases:
sage.symbolic.function.BuiltinFunction
The ceiling function.
The ceiling of \(x\) is computed in the following manner.
- The
x.ceil()
method is called and returned if it is there. If it is not, then Sage checks if \(x\) is one of Python’s native numeric data types. If so, then it calls and returnsInteger(int(math.ceil(x)))
. - Sage tries to convert \(x\) into a
RealIntervalField
with 53 bits of precision. Next, the ceilings of the endpoints are computed. If they are the same, then that value is returned. Otherwise, the precision of theRealIntervalField
is increased until they do match up or it reachesmaximum_bits
of precision. - If none of the above work, Sage returns a
Expression
object.
EXAMPLES:
sage: a = ceil(2/5 + x) sage: a ceil(x + 2/5) sage: a(x=4) 5 sage: a(x=4.0) 5 sage: ZZ(a(x=3)) 4 sage: a = ceil(x^3 + x + 5/2); a ceil(x^3 + x + 5/2) sage: a.simplify() ceil(x^3 + x + 1/2) + 2 sage: a(x=2) 13
sage: ceil(sin(8)/sin(2)) 2
sage: ceil(5.4) 6 sage: type(ceil(5.4)) <type 'sage.rings.integer.Integer'>
sage: ceil(factorial(50)/exp(1)) 11188719610782480504630258070757734324011354208865721592720336801 sage: ceil(SR(10^50 + 10^(-50))) 100000000000000000000000000000000000000000000000001 sage: ceil(SR(10^50 - 10^(-50))) 100000000000000000000000000000000000000000000000000 sage: ceil(sec(e)) -1 sage: latex(ceil(x)) \left \lceil x \right \rceil sage: ceil(x)._sympy_() ceiling(x)
sage: import numpy sage: a = numpy.linspace(0,2,6) sage: ceil(a) array([ 0., 1., 1., 2., 2., 2.])
Test pickling:
sage: loads(dumps(ceil)) ceil
- The
-
class
sage.functions.other.
Function_conjugate
¶ Bases:
sage.symbolic.function.GinacFunction
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
sage.symbolic.expression.Expression.simplify()
:sage: conjugate(I,hold=True).simplify() -I
-
class
sage.functions.other.
Function_factorial
¶ Bases:
sage.symbolic.function.GinacFunction
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
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
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
-
class
sage.functions.other.
Function_floor
¶ Bases:
sage.symbolic.function.BuiltinFunction
The floor function.
The floor of \(x\) is computed in the following manner.
- The
x.floor()
method is called and returned if it is there. If it is not, then Sage checks if \(x\) is one of Python’s native numeric data types. If so, then it calls and returnsInteger(int(math.floor(x)))
. - Sage tries to convert \(x\) into a
RealIntervalField
with 53 bits of precision. Next, the floors of the endpoints are computed. If they are the same, then that value is returned. Otherwise, the precision of theRealIntervalField
is increased until they do match up or it reachesmaximum_bits
of precision. - If none of the above work, Sage returns a
symbolic
Expression
object.
EXAMPLES:
sage: floor(5.4) 5 sage: type(floor(5.4)) <type 'sage.rings.integer.Integer'> sage: var('x') x sage: a = floor(5.4 + x); a floor(x + 5.40000000000000) sage: a.simplify() floor(x + 0.4000000000000004) + 5 sage: a(x=2) 7
sage: floor(cos(8)/cos(2)) 0
sage: floor(factorial(50)/exp(1)) 11188719610782480504630258070757734324011354208865721592720336800 sage: floor(SR(10^50 + 10^(-50))) 100000000000000000000000000000000000000000000000000 sage: floor(SR(10^50 - 10^(-50))) 99999999999999999999999999999999999999999999999999 sage: floor(int(10^50)) 100000000000000000000000000000000000000000000000000
sage: import numpy sage: a = numpy.linspace(0,2,6) sage: floor(a) array([ 0., 0., 0., 1., 1., 2.]) sage: floor(x)._sympy_() floor(x)
Test pickling:
sage: loads(dumps(floor)) floor
- The
-
class
sage.functions.other.
Function_frac
¶ Bases:
sage.symbolic.function.BuiltinFunction
The fractional part function \(\{x\}\).
frac(x)
is defined as \(\{x\} = x - \lfloor x\rfloor\).EXAMPLES:
sage: frac(5.4) 0.400000000000000 sage: type(frac(5.4)) <type 'sage.rings.real_mpfr.RealNumber'> sage: frac(456/123) 29/41 sage: var('x') x sage: a = frac(5.4 + x); a frac(x + 5.40000000000000) sage: frac(cos(8)/cos(2)) cos(8)/cos(2) sage: latex(frac(x)) \operatorname{frac}\left(x\right) sage: frac(x)._sympy_() frac(x)
Test pickling:
sage: loads(dumps(floor)) floor
-
class
sage.functions.other.
Function_gamma
¶ Bases:
sage.symbolic.function.GinacFunction
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.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
sage.symbolic.expression.Expression.simplify()
:sage: gamma1(1/2,hold=True).simplify() sqrt(pi)
See also
-
class
sage.functions.other.
Function_gamma_inc
¶ Bases:
sage.symbolic.function.BuiltinFunction
The upper incomplete gamma function.
It is defined by the integral
\[\Gamma(a,z)=\int_z^\infty t^{a-1}e^{-t}\,\mathrm{d}t\]EXAMPLES:
sage: gamma_inc(CDF(0,1), 3) 0.0032085749933691158 + 0.012406185811871568*I sage: gamma_inc(RDF(1), 3) 0.049787068367863944 sage: gamma_inc(3,2) gamma(3, 2) sage: gamma_inc(x,0) gamma(x) sage: latex(gamma_inc(3,2)) \Gamma\left(3, 2\right) sage: loads(dumps((gamma_inc(3,2)))) gamma(3, 2) sage: i = ComplexField(30).0; gamma_inc(2, 1 + i) 0.70709210 - 0.42035364*I sage: gamma_inc(2., 5) 0.0404276819945128 sage: x,y=var('x,y') sage: gamma_inc(x,y).diff(x) diff(gamma(x, y), x) sage: (gamma_inc(x,x+1).diff(x)).simplify() -(x + 1)^(x - 1)*e^(-x - 1) + D[0](gamma)(x, x + 1)
See also
-
class
sage.functions.other.
Function_gamma_inc_lower
¶ Bases:
sage.symbolic.function.BuiltinFunction
The lower incomplete gamma function.
It is defined by the integral
\[\Gamma(a,z)=\int_0^z t^{a-1}e^{-t}\,\mathrm{d}t\]EXAMPLES:
sage: gamma_inc_lower(CDF(0,1), 3) -0.1581584032951798 - 0.5104218539302277*I sage: gamma_inc_lower(RDF(1), 3) 0.950212931632136 sage: gamma_inc_lower(3, 2, hold=True) gamma_inc_lower(3, 2) sage: gamma_inc_lower(3, 2) -10*e^(-2) + 2 sage: gamma_inc_lower(x, 0) 0 sage: latex(gamma_inc_lower(x, x)) \gamma\left(x, x\right) sage: loads(dumps((gamma_inc_lower(x, x)))) gamma_inc_lower(x, x) sage: i = ComplexField(30).0; gamma_inc_lower(2, 1 + i) 0.29290790 + 0.42035364*I sage: gamma_inc_lower(2., 5) 0.959572318005487
Interfaces to other software:
sage: import sympy sage: sympy.sympify(gamma_inc_lower(x,x)) lowergamma(x, x) sage: maxima(gamma_inc_lower(x,x)) gamma_greek(_SAGE_VAR_x,_SAGE_VAR_x)
-
class
sage.functions.other.
Function_imag_part
¶ Bases:
sage.symbolic.function.GinacFunction
Returns the imaginary part of the (possibly complex) input.
It is possible to prevent automatic evaluation using the
hold
parameter:sage: imag_part(I,hold=True) imag_part(I)
To then evaluate again, we currently must use Maxima via
sage.symbolic.expression.Expression.simplify()
:sage: imag_part(I,hold=True).simplify() 1
-
class
sage.functions.other.
Function_limit
¶ Bases:
sage.symbolic.function.BuiltinFunction
Placeholder symbolic limit function that is only accessible internally.
This function is called to create formal wrappers of limits that Maxima can’t compute:
sage: a = lim(exp(x^2)*(1-erf(x)), x=infinity); a -limit((erf(x) - 1)*e^(x^2), x, +Infinity)
EXAMPLES:
sage: from sage.functions.other import symbolic_limit as slimit sage: slimit(1/x, x, +oo) limit(1/x, x, +Infinity) sage: var('minus,plus') (minus, plus) sage: slimit(1/x, x, +oo) limit(1/x, x, +Infinity) sage: slimit(1/x, x, 0, plus) limit(1/x, x, 0, plus) sage: slimit(1/x, x, 0, minus) limit(1/x, x, 0, minus)
-
class
sage.functions.other.
Function_log_gamma
¶ Bases:
sage.symbolic.function.GinacFunction
The principal branch of the log gamma function. Note that for \(x < 0\),
log(gamma(x))
is not, in general, equal tolog_gamma(x)
.It is computed by the
log_gamma
function for the number type, or bylgamma
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 ticket #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 ticket #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 ticket #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 then()
numerical evaluation method:sage: log_gamma(SR(5), hold=True) log_gamma(5) sage: log_gamma(SR(5), hold=True).n() 3.17805383034795
-
class
sage.functions.other.
Function_prod
¶ Bases:
sage.symbolic.function.BuiltinFunction
Placeholder symbolic product function that is only accessible internally.
EXAMPLES:
sage: from sage.functions.other import symbolic_product as sprod sage: r = sprod(x, x, 1, 10); r product(x, x, 1, 10) sage: r.unhold() 3628800
-
class
sage.functions.other.
Function_psi1
¶ Bases:
sage.symbolic.function.GinacFunction
The digamma function, \(\psi(x)\), is the logarithmic derivative of the gamma function.
\[\psi(x) = \frac{d}{dx} \log(\Gamma(x)) = \frac{\Gamma'(x)}{\Gamma(x)}\]EXAMPLES:
sage: from sage.functions.other import psi1 sage: psi1(x) psi(x) sage: psi1(x).derivative(x) psi(1, x)
sage: psi1(3) -euler_gamma + 3/2
sage: psi(.5) -1.96351002602142 sage: psi(RealField(100)(.5)) -1.9635100260214234794409763330
-
class
sage.functions.other.
Function_psi2
¶ Bases:
sage.symbolic.function.GinacFunction
Derivatives of the digamma function \(\psi(x)\). T
EXAMPLES:
sage: from sage.functions.other 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
-
class
sage.functions.other.
Function_real_part
¶ Bases:
sage.symbolic.function.GinacFunction
Returns the real part of the (possibly complex) input.
It is possible to prevent automatic evaluation using the
hold
parameter:sage: real_part(I,hold=True) real_part(I)
To then evaluate again, we currently must use Maxima via
sage.symbolic.expression.Expression.simplify()
:sage: real_part(I,hold=True).simplify() 0
EXAMPLES:
sage: z = 1+2*I sage: real(z) 1 sage: real(5/3) 5/3 sage: a = 2.5 sage: real(a) 2.50000000000000 sage: type(real(a)) <type 'sage.rings.real_mpfr.RealLiteral'> sage: real(1.0r) 1.0 sage: real(complex(3, 4)) 3.0
Sage can recognize some expressions as real and accordingly return the identical argument:
sage: SR.var('x', domain='integer').real_part() x sage: SR.var('x', domain='integer').imag_part() 0 sage: real_part(sin(x)+x) x + sin(x) sage: real_part(x*exp(x)) x*e^x sage: imag_part(sin(x)+x) 0 sage: real_part(real_part(x)) x sage: forget()
-
class
sage.functions.other.
Function_sqrt
¶ Bases:
object
-
class
sage.functions.other.
Function_sum
¶ Bases:
sage.symbolic.function.BuiltinFunction
Placeholder symbolic sum function that is only accessible internally.
EXAMPLES:
sage: from sage.functions.other import symbolic_sum as ssum sage: r = ssum(x, x, 1, 10); r sum(x, x, 1, 10) sage: r.unhold() 55
-
sage.functions.other.
gamma
(a, *args, **kwds)¶ Gamma and upper incomplete gamma functions in one symbol.
Recall that \(\Gamma(n)\) is \(n-1\) factorial:
sage: gamma(11) == factorial(10) True sage: gamma(6) 120 sage: gamma(1/2) sqrt(pi) sage: gamma(-4/3) gamma(-4/3) sage: gamma(-1) Infinity sage: gamma(0) Infinity
sage: gamma_inc(3,2) gamma(3, 2) sage: gamma_inc(x,0) gamma(x)
sage: gamma(5, hold=True) gamma(5) sage: gamma(x, 0, hold=True) gamma(x, 0)
sage: gamma(CDF(I)) -0.15494982830181067 - 0.49801566811835607*I sage: gamma(CDF(0.5,14)) -4.0537030780372815e-10 - 5.773299834553605e-10*I
Use
numerical_approx
to get higher precision from symbolic expressions:sage: gamma(pi).n(100) 2.2880377953400324179595889091 sage: gamma(3/4).n(100) 1.2254167024651776451290983034
The precision for the result is also 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
The gamma function only works with input that can be coerced to the Symbolic Ring:
sage: Q.<i> = NumberField(x^2+1) sage: gamma(i) Traceback (most recent call last): ... TypeError: cannot coerce arguments: no canonical coercion from Number Field in i with defining polynomial x^2 + 1 to Symbolic Ring
-
sage.functions.other.
incomplete_gamma
(*args, **kwds)¶ - Deprecated name for
sage.functions.other.Function_gamma_inc()
.
-
sage.functions.other.
psi
(x, *args, **kwds)¶ The digamma function, \(\psi(x)\), is the logarithmic derivative of the gamma function.
\[\psi(x) = \frac{d}{dx} \log(\Gamma(x)) = \frac{\Gamma'(x)}{\Gamma(x)}\]We represent the \(n\)-th derivative of the digamma function with \(\psi(n, x)\) or \(psi(n, x)\).
EXAMPLES:
sage: psi(x) psi(x) sage: psi(.5) -1.96351002602142 sage: psi(3) -euler_gamma + 3/2 sage: psi(1, 5) 1/6*pi^2 - 205/144 sage: psi(1, x) psi(1, x) sage: psi(1, x).derivative(x) psi(2, x)
sage: psi(3, hold=True) psi(3) sage: psi(1, 5, hold=True) psi(1, 5)
-
sage.functions.other.
sqrt
(x, *args, **kwds)¶ INPUT:
x
- a numberprec
- integer (default: None): if None, returns an exact square root; otherwise returns a numerical square root if necessary, to the given bits of precision.extend
- bool (default: True); this is a place holder, and is always ignored or passed to the sqrt function for x, since in the symbolic ring everything has a square root.all
- bool (default: False); if True, return all square roots of self, instead of just one.
EXAMPLES:
sage: sqrt(-1) I sage: sqrt(2) sqrt(2) sage: sqrt(2)^2 2 sage: sqrt(4) 2 sage: sqrt(4,all=True) [2, -2] sage: sqrt(x^2) sqrt(x^2)
For a non-symbolic square root, there are a few options. The best is to numerically approximate afterward:
sage: sqrt(2).n() 1.41421356237310 sage: sqrt(2).n(prec=100) 1.4142135623730950488016887242
Or one can input a numerical type.
sage: sqrt(2.) 1.41421356237310 sage: sqrt(2.000000000000000000000000) 1.41421356237309504880169 sage: sqrt(4.0) 2.00000000000000To prevent automatic evaluation, one can use the
hold
parameter after coercing to the symbolic ring:sage: sqrt(SR(4),hold=True) sqrt(4) sage: sqrt(4,hold=True) Traceback (most recent call last): ... TypeError: _do_sqrt() got an unexpected keyword argument 'hold'
This illustrates that the bug reported in trac ticket #6171 has been fixed:
sage: a = 1.1 sage: a.sqrt(prec=100) # this is supposed to fail Traceback (most recent call last): ... TypeError: sqrt() got an unexpected keyword argument 'prec' sage: sqrt(a, prec=100) 1.0488088481701515469914535137 sage: sqrt(4.00, prec=250) 2.0000000000000000000000000000000000000000000000000000000000000000000000000
One can use numpy input as well:
sage: import numpy sage: a = numpy.arange(2,5) sage: sqrt(a) array([ 1.41421356, 1.73205081, 2. ])