(maxima.info)Gamma and factorial Functions
15.4 Gamma and factorial Functions
==================================
The gamma function and the related beta, psi and incomplete gamma
functions are defined in Abramowitz and Stegun, Handbook of Mathematical
Functions, Chapter 6.
-- Function: bffac (<expr>, <n>)
Bigfloat version of the factorial (shifted gamma) function. The
second argument is how many digits to retain and return, it's a
good idea to request a couple of extra.
-- Function: bfpsi (<n>, <z>, <fpprec>)
-- Function: bfpsi0 (<z>, <fpprec>)
'bfpsi' is the polygamma function of real argument <z> and integer
order <n>. 'bfpsi0' is the digamma function. 'bfpsi0 (<z>,
<fpprec>)' is equivalent to 'bfpsi (0, <z>, <fpprec>)'.
These functions return bigfloat values. <fpprec> is the bigfloat
precision of the return value.
-- Function: cbffac (<z>, <fpprec>)
Complex bigfloat factorial.
'load ("bffac")' loads this function.
-- Function: gamma (<z>)
The basic definition of the gamma function (A&S 6.1.1) is
inf
/
[ z - 1 - t
gamma(z) = I t %e dt
]
/
0
Maxima simplifies 'gamma' for positive integer and positive and
negative rational numbers. For half integral values the result is
a rational number times 'sqrt(%pi)'. The simplification for
integer values is controlled by 'factlim'. For integers greater
than 'factlim' the numerical result of the factorial function,
which is used to calculate 'gamma', will overflow. The
simplification for rational numbers is controlled by 'gammalim' to
avoid internal overflow. See 'factlim' and 'gammalim'.
For negative integers 'gamma' is not defined.
Maxima can evalute 'gamma' numerically for real and complex values
in float and bigfloat precision.
'gamma' has mirror symmetry.
When 'gamma_expand' is 'true', Maxima expands 'gamma' for arguments
'z+n' and 'z-n' where 'n' is an integer.
Maxima knows the derivate of 'gamma'.
Examples:
Simplification for integer, half integral, and rational numbers:
(%i1) map('gamma,[1,2,3,4,5,6,7,8,9]);
(%o1) [1, 1, 2, 6, 24, 120, 720, 5040, 40320]
(%i2) map('gamma,[1/2,3/2,5/2,7/2]);
sqrt(%pi) 3 sqrt(%pi) 15 sqrt(%pi)
(%o2) [sqrt(%pi), ---------, -----------, ------------]
2 4 8
(%i3) map('gamma,[2/3,5/3,7/3]);
2 1
2 gamma(-) 4 gamma(-)
2 3 3
(%o3) [gamma(-), ----------, ----------]
3 3 9
Numerical evaluation for real and complex values:
(%i4) map('gamma,[2.5,2.5b0]);
(%o4) [1.329340388179137, 1.3293403881791370205b0]
(%i5) map('gamma,[1.0+%i,1.0b0+%i]);
(%o5) [0.498015668118356 - .1549498283018107 %i,
4.9801566811835604272b-1 - 1.5494982830181068513b-1 %i]
'gamma' has mirror symmetry:
(%i6) declare(z,complex)$
(%i7) conjugate(gamma(z));
(%o7) gamma(conjugate(z))
Maxima expands 'gamma(z+n)' and 'gamma(z-n)', when 'gamma_expand'
is 'true':
(%i8) gamma_expand:true$
(%i9) [gamma(z+1),gamma(z-1),gamma(z+2)/gamma(z+1)];
gamma(z)
(%o9) [z gamma(z), --------, z + 1]
z - 1
The deriviative of 'gamma':
(%i10) diff(gamma(z),z);
(%o10) psi (z) gamma(z)
0
See also 'makegamma'.
The Euler-Mascheroni constant is '%gamma'.
-- Function: log_gamma (<z>)
The natural logarithm of the gamma function.
-- Function: gamma_incomplete_lower (<a>, <z>)
The lower incomplete gamma function (A&S 6.5.2):
z
/
[ a - 1 - t
gamma_incomplete_lower(a, z) = I t %e dt
]
/
0
See also 'gamma_incomplete' (upper incomplete gamma function).
-- Function: gamma_incomplete (<a>, <z>)
The incomplete upper gamma function (A&S 6.5.3):
inf
/
[ a - 1 - t
gamma_incomplete(a, z) = I t %e dt
]
/
z
See also 'gamma_expand' for controlling how 'gamma_incomplete' is
expressed in terms of elementary functions and 'erfc'.
Also see the related functions 'gamma_incomplete_regularized' and
'gamma_incomplete_generalized'.
-- Function: gamma_incomplete_regularized (<a>, <z>)
The regularized incomplete upper gamma function (A&S 6.5.1):
gamma_incomplete_regularized(a, z) =
gamma_incomplete(a, z)
----------------------
gamma(a)
See also 'gamma_expand' for controlling how 'gamma_incomplete' is
expressed in terms of elementary functions and 'erfc'.
Also see 'gamma_incomplete'.
-- Function: gamma_incomplete_generalized (<a>, <z1>, <z1>)
The generalized incomplete gamma function.
gamma_incomplete_generalized(a, z1, z2) =
z2
/
[ a - 1 - t
I t %e dt
]
/
z1
Also see 'gamma_incomplete' and 'gamma_incomplete_regularized'.
-- Option variable: gamma_expand
Default value: 'false'
'gamma_expand' controls expansion of 'gamma_incomplete'. When
'gamma_expand' is 'true', 'gamma_incomplete(v,z)' is expanded in
terms of 'z', 'exp(z)', and 'erfc(z)' when possible.
(%i1) gamma_incomplete(2,z);
(%o1) gamma_incomplete(2, z)
(%i2) gamma_expand:true;
(%o2) true
(%i3) gamma_incomplete(2,z);
- z
(%o3) (z + 1) %e
(%i4) gamma_incomplete(3/2,z);
- z sqrt(%pi) erfc(sqrt(z))
(%o4) sqrt(z) %e + -----------------------
2
-- Option variable: gammalim
Default value: 10000
'gammalim' controls simplification of the gamma function for
integral and rational number arguments. If the absolute value of
the argument is not greater than 'gammalim', then simplification
will occur. Note that the 'factlim' switch controls simplification
of the result of 'gamma' of an integer argument as well.
-- Function: makegamma (<expr>)
Transforms instances of binomial, factorial, and beta functions in
<expr> into gamma functions.
See also 'makefact'.
-- Function: beta (<a>, <b>)
The beta function is defined as 'gamma(a) gamma(b)/gamma(a+b)' (A&S
6.2.1).
Maxima simplifies the beta function for positive integers and
rational numbers, which sum to an integer. When
'beta_args_sum_to_integer' is 'true', Maxima simplifies also
general expressions which sum to an integer.
For <a> or <b> equal to zero the beta function is not defined.
In general the beta function is not defined for negative integers
as an argument. The exception is for <a=-n>, <n> a positive
integer and <b> a positive integer with <b<=n>, it is possible to
define an analytic continuation. Maxima gives for this case a
result.
When 'beta_expand' is 'true', expressions like 'beta(a+n,b)' and
'beta(a-n,b)' or 'beta(a,b+n)' and 'beta(a,b-n)' with 'n' an
integer are simplified.
Maxima can evaluate the beta function for real and complex values
in float and bigfloat precision. For numerical evaluation Maxima
uses 'log_gamma':
- log_gamma(b + a) + log_gamma(b) + log_gamma(a)
%e
Maxima knows that the beta function is symmetric and has mirror
symmetry.
Maxima knows the derivatives of the beta function with respect to
<a> or <b>.
To express the beta function as a ratio of gamma functions see
'makegamma'.
Examples:
Simplification, when one of the arguments is an integer:
(%i1) [beta(2,3),beta(2,1/3),beta(2,a)];
1 9 1
(%o1) [--, -, ---------]
12 4 a (a + 1)
Simplification for two rational numbers as arguments which sum to
an integer:
(%i2) [beta(1/2,5/2),beta(1/3,2/3),beta(1/4,3/4)];
3 %pi 2 %pi
(%o2) [-----, -------, sqrt(2) %pi]
8 sqrt(3)
When setting 'beta_args_sum_to_integer' to 'true' more general
expression are simplified, when the sum of the arguments is an
integer:
(%i3) beta_args_sum_to_integer:true$
(%i4) beta(a+1,-a+2);
%pi (a - 1) a
(%o4) ------------------
2 sin(%pi (2 - a))
The possible results, when one of the arguments is a negative
integer:
(%i5) [beta(-3,1),beta(-3,2),beta(-3,3)];
1 1 1
(%o5) [- -, -, - -]
3 6 3
'beta(a+n,b)' or 'beta(a-n)' with 'n' an integer simplifies when
'beta_expand' is 'true':
(%i6) beta_expand:true$
(%i7) [beta(a+1,b),beta(a-1,b),beta(a+1,b)/beta(a,b+1)];
a beta(a, b) beta(a, b) (b + a - 1) a
(%o7) [------------, ----------------------, -]
b + a a - 1 b
Beta is not defined, when one of the arguments is zero:
(%i7) beta(0,b);
beta: expected nonzero arguments; found 0, b
-- an error. To debug this try debugmode(true);
Numercial evaluation for real and complex arguments in float or
bigfloat precision:
(%i8) beta(2.5,2.3);
(%o8) .08694748611299981
(%i9) beta(2.5,1.4+%i);
(%o9) 0.0640144950796695 - .1502078053286415 %i
(%i10) beta(2.5b0,2.3b0);
(%o10) 8.694748611299969b-2
(%i11) beta(2.5b0,1.4b0+%i);
(%o11) 6.401449507966944b-2 - 1.502078053286415b-1 %i
Beta is symmetric and has mirror symmetry:
(%i14) beta(a,b)-beta(b,a);
(%o14) 0
(%i15) declare(a,complex,b,complex)$
(%i16) conjugate(beta(a,b));
(%o16) beta(conjugate(a), conjugate(b))
The derivative of the beta function wrt 'a':
(%i17) diff(beta(a,b),a);
(%o17) - beta(a, b) (psi (b + a) - psi (a))
0 0
-- Function: beta_incomplete (<a>, <b>, <z>)
The basic definition of the incomplete beta function (A&S 6.6.1) is
z
/
[ b - 1 a - 1
I (1 - t) t dt
]
/
0
This definition is possible for realpart(a)>0 and realpart(b)>0 and
abs(z)<1. For other values the incomplete beta function can be
defined through a generalized hypergeometric function:
gamma(a) hypergeometric_generalized([a, 1 - b], [a + 1], z) z
(See functions.wolfram.com for a complete definition of the
incomplete beta function.)
For negative integers a = -n and positive integers b=m with m<=n
the incomplete beta function is defined through
m - 1 k
==== (1 - m) z
n - 1 \ k
z > -----------
/ k! (n - k)
====
k = 0
Maxima uses this definition to simplify 'beta_incomplete' for <a> a
negative integer.
For <a> a positive integer, 'beta_incomplete' simplifies for any
argument <b> and <z> and for <b> a positive integer for any
argument <a> and <z>, with the exception of <a> a negative integer.
For z=0 and realpart(a)>0, 'beta_incomplete' has the specific value
zero. For <z=1> and realpart(b)>0, 'beta_incomplete' simplifies to
the beta function 'beta(a,b)'.
Maxima evaluates 'beta_incomplete' numerically for real and complex
values in float or bigfloat precision. For the numerical
evaluation an expansion of the incomplete beta function in
continued fractions is used.
When the option variable 'beta_expand' is 'true', Maxima expands
expressions like 'beta_incomplete(a+n,b,z)' and
'beta_incomplete(a-n,b,z)' where n is a positive integer.
Maxima knows the derivatives of 'beta_incomplete' with respect to
the variables <a>, <b> and <z> and the integral with respect to the
variable <z>.
Examples:
Simplification for <a> a positive integer:
(%i1) beta_incomplete(2,b,z);
b
1 - (1 - z) (b z + 1)
(%o1) ----------------------
b (b + 1)
Simplification for <b> a positive integer:
(%i2) beta_incomplete(a,2,z);
a
(a (1 - z) + 1) z
(%o2) ------------------
a (a + 1)
Simplification for <a> and <b> a positive integer:
(%i3) beta_incomplete(3,2,z);
3
(3 (1 - z) + 1) z
(%o3) ------------------
12
<a> is a negative integer and b<=(-a), Maxima simplifies:
(%i4) beta_incomplete(-3,1,z);
1
(%o4) - ----
3
3 z
For the specific values z=0 and z=1, Maxima simplifies:
(%i5) assume(a>0,b>0)$
(%i6) beta_incomplete(a,b,0);
(%o6) 0
(%i7) beta_incomplete(a,b,1);
(%o7) beta(a, b)
Numerical evaluation in float or bigfloat precision:
(%i8) beta_incomplete(0.25,0.50,0.9);
(%o8) 4.594959440269333
(%i9) fpprec:25$
(%i10) beta_incomplete(0.25,0.50,0.9b0);
(%o10) 4.594959440269324086971203b0
For abs(z)>1 'beta_incomplete' returns a complex result:
(%i11) beta_incomplete(0.25,0.50,1.7);
(%o11) 5.244115108584249 - 1.45518047787844 %i
Results for more general complex arguments:
(%i14) beta_incomplete(0.25+%i,1.0+%i,1.7+%i);
(%o14) 2.726960675662536 - .3831175704269199 %i
(%i15) beta_incomplete(1/2,5/4*%i,2.8+%i);
(%o15) 13.04649635168716 %i - 5.802067956270001
(%i16)
Expansion, when 'beta_expand' is 'true':
(%i23) beta_incomplete(a+1,b,z),beta_expand:true;
b a
a beta_incomplete(a, b, z) (1 - z) z
(%o23) -------------------------- - -----------
b + a b + a
(%i24) beta_incomplete(a-1,b,z),beta_expand:true;
b a - 1
beta_incomplete(a, b, z) (- b - a + 1) (1 - z) z
(%o24) -------------------------------------- - ---------------
1 - a 1 - a
Derivative and integral for 'beta_incomplete':
(%i34) diff(beta_incomplete(a, b, z), z);
b - 1 a - 1
(%o34) (1 - z) z
(%i35) integrate(beta_incomplete(a, b, z), z);
b a
(1 - z) z
(%o35) ----------- + beta_incomplete(a, b, z) z
b + a
a beta_incomplete(a, b, z)
- --------------------------
b + a
(%i36) factor(diff(%, z));
(%o36) beta_incomplete(a, b, z)
-- Function: beta_incomplete_regularized (<a>, <b>, <z>)
The regularized incomplete beta function (A&S 6.6.2), defined as
beta_incomplete_regularized(a, b, z) =
beta_incomplete(a, b, z)
------------------------
beta(a, b)
As for 'beta_incomplete' this definition is not complete. See
functions.wolfram.com for a complete definition of
'beta_incomplete_regularized'.
'beta_incomplete_regularized' simplifies <a> or <b> a positive
integer.
For z=0 and realpart(a)>0, 'beta_incomplete_regularized' has the
specific value 0. For <z=1> and realpart(b)>0,
'beta_incomplete_regularized' simplifies to 1.
Maxima can evaluate 'beta_incomplete_regularized' for real and
complex arguments in float and bigfloat precision.
When 'beta_expand' is 'true', Maxima expands
'beta_incomplete_regularized' for arguments a+n or a-n, where n is
an integer.
Maxima knows the derivatives of 'beta_incomplete_regularized' with
respect to the variables <a>, <b>, and <z> and the integral with
respect to the variable <z>.
Examples:
Simplification for <a> or <b> a positive integer:
(%i1) beta_incomplete_regularized(2,b,z);
b
(%o1) 1 - (1 - z) (b z + 1)
(%i2) beta_incomplete_regularized(a,2,z);
a
(%o2) (a (1 - z) + 1) z
(%i3) beta_incomplete_regularized(3,2,z);
3
(%o3) (3 (1 - z) + 1) z
For the specific values z=0 and z=1, Maxima simplifies:
(%i4) assume(a>0,b>0)$
(%i5) beta_incomplete_regularized(a,b,0);
(%o5) 0
(%i6) beta_incomplete_regularized(a,b,1);
(%o6) 1
Numerical evaluation for real and complex arguments in float and
bigfloat precision:
(%i7) beta_incomplete_regularized(0.12,0.43,0.9);
(%o7) .9114011367359802
(%i8) fpprec:32$
(%i9) beta_incomplete_regularized(0.12,0.43,0.9b0);
(%o9) 9.1140113673598075519946998779975b-1
(%i10) beta_incomplete_regularized(1+%i,3/3,1.5*%i);
(%o10) .2865367499935403 %i - 0.122995963334684
(%i11) fpprec:20$
(%i12) beta_incomplete_regularized(1+%i,3/3,1.5b0*%i);
(%o12) 2.8653674999354036142b-1 %i - 1.2299596333468400163b-1
Expansion, when 'beta_expand' is 'true':
(%i13) beta_incomplete_regularized(a+1,b,z);
b a
(1 - z) z
(%o13) beta_incomplete_regularized(a, b, z) - ------------
a beta(a, b)
(%i14) beta_incomplete_regularized(a-1,b,z);
(%o14) beta_incomplete_regularized(a, b, z)
b a - 1
(1 - z) z
- ----------------------
beta(a, b) (b + a - 1)
The derivative and the integral wrt <z>:
(%i15) diff(beta_incomplete_regularized(a,b,z),z);
b - 1 a - 1
(1 - z) z
(%o15) -------------------
beta(a, b)
(%i16) integrate(beta_incomplete_regularized(a,b,z),z);
(%o16) beta_incomplete_regularized(a, b, z) z
b a
(1 - z) z
a (beta_incomplete_regularized(a, b, z) - ------------)
a beta(a, b)
- -------------------------------------------------------
b + a
-- Function: beta_incomplete_generalized (<a>, <b>, <z1>, <z2>)
The basic definition of the generalized incomplete beta function is
z2
/
[ b - 1 a - 1
I (1 - t) t dt
]
/
z1
Maxima simplifies 'beta_incomplete_regularized' for <a> and <b> a
positive integer.
For realpart(a)>0 and z1=0 or z2=0, Maxima simplifies
'beta_incomplete_generalized' to 'beta_incomplete'. For
realpart(b)>0 and z1=1 or <z2=1>, Maxima simplifies to an
expression with 'beta' and 'beta_incomplete'.
Maxima evaluates 'beta_incomplete_regularized' for real and complex
values in float and bigfloat precision.
When 'beta_expand' is 'true', Maxima expands
'beta_incomplete_generalized' for a+n and a-n, <n> a positive
integer.
Maxima knows the derivative of 'beta_incomplete_generalized' with
respect to the variables <a>, <b>, <z1>, and <z2> and the integrals
with respect to the variables <z1> and <z2>.
Examples:
Maxima simplifies 'beta_incomplete_generalized' for <a> and <b> a
positive integer:
(%i1) beta_incomplete_generalized(2,b,z1,z2);
b b
(1 - z1) (b z1 + 1) - (1 - z2) (b z2 + 1)
(%o1) -------------------------------------------
b (b + 1)
(%i2) beta_incomplete_generalized(a,2,z1,z2);
a a
(a (1 - z2) + 1) z2 - (a (1 - z1) + 1) z1
(%o2) -------------------------------------------
a (a + 1)
(%i3) beta_incomplete_generalized(3,2,z1,z2);
2 2 2 2
(1 - z1) (3 z1 + 2 z1 + 1) - (1 - z2) (3 z2 + 2 z2 + 1)
(%o3) -----------------------------------------------------------
12
Simplification for specific values z1=0, z2=0, z1=1, or z2=1:
(%i4) assume(a > 0, b > 0)$
(%i5) beta_incomplete_generalized(a,b,z1,0);
(%o5) - beta_incomplete(a, b, z1)
(%i6) beta_incomplete_generalized(a,b,0,z2);
(%o6) - beta_incomplete(a, b, z2)
(%i7) beta_incomplete_generalized(a,b,z1,1);
(%o7) beta(a, b) - beta_incomplete(a, b, z1)
(%i8) beta_incomplete_generalized(a,b,1,z2);
(%o8) beta_incomplete(a, b, z2) - beta(a, b)
Numerical evaluation for real arguments in float or bigfloat
precision:
(%i9) beta_incomplete_generalized(1/2,3/2,0.25,0.31);
(%o9) .09638178086368676
(%i10) fpprec:32$
(%i10) beta_incomplete_generalized(1/2,3/2,0.25,0.31b0);
(%o10) 9.6381780863686935309170054689964b-2
Numerical evaluation for complex arguments in float or bigfloat
precision:
(%i11) beta_incomplete_generalized(1/2+%i,3/2+%i,0.25,0.31);
(%o11) - .09625463003205376 %i - .003323847735353769
(%i12) fpprec:20$
(%i13) beta_incomplete_generalized(1/2+%i,3/2+%i,0.25,0.31b0);
(%o13) - 9.6254630032054178691b-2 %i - 3.3238477353543591914b-3
Expansion for a+n or a-n, <n> a positive integer, when
'beta_expand' is 'true':
(%i14) beta_expand:true$
(%i15) beta_incomplete_generalized(a+1,b,z1,z2);
b a b a
(1 - z1) z1 - (1 - z2) z2
(%o15) -----------------------------
b + a
a beta_incomplete_generalized(a, b, z1, z2)
+ -------------------------------------------
b + a
(%i16) beta_incomplete_generalized(a-1,b,z1,z2);
beta_incomplete_generalized(a, b, z1, z2) (- b - a + 1)
(%o16) -------------------------------------------------------
1 - a
b a - 1 b a - 1
(1 - z2) z2 - (1 - z1) z1
- -------------------------------------
1 - a
Derivative wrt the variable <z1> and integrals wrt <z1> and <z2>:
(%i17) diff(beta_incomplete_generalized(a,b,z1,z2),z1);
b - 1 a - 1
(%o17) - (1 - z1) z1
(%i18) integrate(beta_incomplete_generalized(a,b,z1,z2),z1);
(%o18) beta_incomplete_generalized(a, b, z1, z2) z1
+ beta_incomplete(a + 1, b, z1)
(%i19) integrate(beta_incomplete_generalized(a,b,z1,z2),z2);
(%o19) beta_incomplete_generalized(a, b, z1, z2) z2
- beta_incomplete(a + 1, b, z2)
-- Option variable: beta_expand
Default value: false
When 'beta_expand' is 'true', 'beta(a,b)' and related functions are
expanded for arguments like a+n or a-n, where n is an integer.
-- Option variable: beta_args_sum_to_integer
Default value: false
When 'beta_args_sum_to_integer' is 'true', Maxima simplifies
'beta(a,b)', when the arguments <a> and <b> sum to an integer.
-- Function: psi [<n>](<x>)
The derivative of 'log (gamma (<x>))' of order '<n>+1'. Thus,
'psi[0](<x>)' is the first derivative, 'psi[1](<x>)' is the second
derivative, etc.
Maxima does not know how, in general, to compute a numerical value
of 'psi', but it can compute some exact values for rational args.
Several variables control what range of rational args 'psi' will
return an exact value, if possible. See 'maxpsiposint',
'maxpsinegint', 'maxpsifracnum', and 'maxpsifracdenom'. That is,
<x> must lie between 'maxpsinegint' and 'maxpsiposint'. If the
absolute value of the fractional part of <x> is rational and has a
numerator less than 'maxpsifracnum' and has a denominator less than
'maxpsifracdenom', 'psi' will return an exact value.
The function 'bfpsi' in the 'bffac' package can compute numerical
values.
-- Option variable: maxpsiposint
Default value: 20
'maxpsiposint' is the largest positive value for which 'psi[n](x)'
will try to compute an exact value.
-- Option variable: maxpsinegint
Default value: -10
'maxpsinegint' is the most negative value for which 'psi[n](x)'
will try to compute an exact value. That is if <x> is less than
'maxnegint', 'psi[n](<x>)' will not return simplified answer, even
if it could.
-- Option variable: maxpsifracnum
Default value: 6
Let <x> be a rational number less than one of the form 'p/q'. If
'p' is greater than 'maxpsifracnum', then 'psi[<n>](<x>)' will not
try to return a simplified value.
-- Option variable: maxpsifracdenom
Default value: 6
Let <x> be a rational number less than one of the form 'p/q'. If
'q' is greater than 'maxpsifracdenom', then 'psi[<n>](<x>)' will
not try to return a simplified value.
-- Function: makefact (<expr>)
Transforms instances of binomial, gamma, and beta functions in
<expr> into factorials.
See also 'makegamma'.
-- Function: numfactor (<expr>)
Returns the numerical factor multiplying the expression <expr>,
which should be a single term.
'content' returns the greatest common divisor (gcd) of all terms in
a sum.
(%i1) gamma (7/2);
15 sqrt(%pi)
(%o1) ------------
8
(%i2) numfactor (%);
15
(%o2) --
8
automatically generated by info2www version 1.2.2.9