]>
Book Contents Previous Section 8.0 Advanced Problem Solving Next Section 8.2 Polynomial Factorization Book Index

## 8.1 Numeric Functions

Axiom provides two basic floating-point types: Float and DoubleFloat. This section describes how to use numerical function:numeric operations defined on these types and the related complex types. numeric operations

As we mentioned in Chapter ugIntro , the Float type is a software implementation of floating-point numbers in which the exponent and the floating-point number significand may have any number of digits. number:floating-point See FloatXmpPage for detailed information about this domain. The DoubleFloat (see DoubleFloatXmpPage ) is usually a hardware implementation of floating point numbers, corresponding to machine double precision. The types Complex Float and Complex DoubleFloat are floating-point number:complex the corresponding software implementations of complex floating-point numbers. complex:floating-point number In this section the term floating-point type means any of these number:complex floating-point four types.

The floating-point types implement the basic elementary functions. These include (where $ means DoubleFloat, Float, Complex DoubleFloat, or Complex Float):

exp, log: $ -> $
sin, cos, tan, cot, sec, csc: $ -> $
asin, acos, atan, acot, asec, acsc: $ -> $
sinh, cosh, tanh, coth, sech, csch: $ -> $
asinh, acosh, atanh, acoth, asech, acsch: $ -> $
pi: () -> $
sqrt: $ -> $
nthRoot: ($, Integer) -> $
****Float: ($, Fraction Integer) -> $
****Float: ($,$) -> $

The handling of roots depends on whether the floating-point type root:numeric approximation is real or complex: for the real floating-point types, DoubleFloat and Float, if a real root exists the one with the same sign as the radicand is returned; for the complex floating-point types, the principal value is returned. principal value Also, for real floating-point types the inverse functions produce errors if the results are not real. This includes cases such as asin(1.2), log(-3.2), sqrt(-1.1).

The default floating-point type is Float so to evaluate functions using Float or Complex Float, just use normal decimal notation.

exp(3.1)

22.1979512814 41633405

Type: Float
exp(3.1 + 4.5 * %i)

-4.6792348860 969899118-21.6991659280 71731864 i

Type: Complex Float

To evaluate functions using DoubleFloat or Complex DoubleFloat, a declaration or conversion is required.

r: DFLOAT := 3.1; t: DFLOAT := 4.5; exp(r + t*%i)

-4.6792348860969906-21.699165928071732 i

Type: Complex DoubleFloat
exp(3.1::DFLOAT + 4.5::DFLOAT * %i)

-4.6792348860969906-21.699165928071732 i

Type: Complex DoubleFloat

A number of special functions are provided by the package DoubleFloatSpecialFunctions for the machine-precision special functions floating-point types. DoubleFloatSpecialFunctions The special functions provided are listed below, where F stands for the types DoubleFloat and Complex DoubleFloat. The real versions of the functions yield an error if the result is not real. function:special

Gamma: F->F
Γ(z) is the Euler gamma function, function:Gamma Γ(z), defined by Euler:gamma function Γ(z)=∫0∞t z-1 e-t dt.

Beta: F->F
Beta(u,v) is the Euler Beta function, function:Euler Beta B(u,v), defined by Euler:Beta function B(u,v)=∫0 1 t u-1(1-t)v-1 dt. This is related to Γ(z) by B(u,v)=Γ(u)Γ(v)Γ(u+v).

logGamma: F->F
logGamma(z) is the natural logarithm of Γ(z). This can often be computed even if Γ(z) cannot.

digamma: F->F
digamma(z), also called psi(z), psi @ is the function function:digamma defined by ψ(z)=Γ′(z)Γ(z)

polygamma: (NonNegativeInteger,F)->F
polygamma(n,z) is the n-th derivative of function:polygamma ψ(z), written ψ(n)(z).

besselJ: (F,F)->F
besselJ(v,z) is the Bessel function of the first kind, function:Bessel J μ(z). This function satisfies the differential equation z 2 w′′(z)+z w′(z)+(z 2-μ 2)w(z)=0.

besselY: (F,F)->F
besselY(v,z) is the Bessel function of the second kind, function:Bessel Y μ(z). This function satisfies the same differential equation as besselJ. The implementation simply uses the relation Y μ(z)=J μ(z)cos(μ π)-J-μ(z)sin(μ π)J μ(z)cos(μ π)-J-μ(z)sin(μ π).

besselI: (F,F)->F
besselI(v,z) is the modified Bessel function of the first kind, function:Bessel I μ(z). This function satisfies the differential equation z 2 w′′(z)+z w′(z)-(z 2+μ 2)w(z)=0.

besselK: (F,F)->F
besselK(v,z) is the modified Bessel function of the second kind, function:Bessel K μ(z). This function satisfies the same differential equation as besselI. Bessel function The implementation simply uses the relation K μ(z)=π I-μ(z)-I μ(z)2 sin(μ π)I-μ(z)-I μ(z)2 sin(μ π).

airyAi: F->F
airyAi(z) is the Airy function Ai(z). function:Airy Ai This function satisfies the differential equation w′′(z)-z w(z)=0. The implementation simply uses the relation Ai(-z)=1 3 1 3 z(J-1/3(2 3 2 3 z 3/2)+J 1/3(2 3 2 3 z 3/2)).

airyBi: F->F
airyBi(z) is the Airy function Bi(z). function:Airy Bi This function satisfies the same differential equation as airyAi. Airy function The implementation simply uses the relation Bi(-z)=1 3 1 3 3 z(J-1/3(2 3 2 3 z 3/2)-J 1/3(2 3 2 3 z 3/2)).

hypergeometric0F1: (F,F)->F
hypergeometric0F1(c,z) is the hypergeometric function function:hypergeometric F 1 0(;c;z).

The above special functions are defined only for small floating-point types. If you give Float arguments, they are converted to DoubleFloat by Axiom.

Gamma(0.5)**2

3.14159265358979

Type: DoubleFloat
a := 2.1; b := 1.1; besselI(a + %i*b, b*a + 1)

2.489481690673867-2.365846713181643 i

Type: Complex DoubleFloat

A number of additional operations may be used to compute numerical values. These are special polynomial functions that can be evaluated for values in any commutative ring R, and in particular for values in any floating-point type. The following operations are provided by the package OrthogonalPolynomialFunctions: OrthogonalPolynomialFunctions

chebyshevT: (NonNegativeInteger,R)->R
chebyshevT(n,z) is the n-th Chebyshev polynomial of the first kind, T n(z). These are defined by 1-t z 1-2 t z+t 2=∑n=0∞T n(z)t n.

chebyshevU: (NonNegativeInteger,R)->R
chebyshevU(n,z) is the n-th Chebyshev polynomial of the second kind, U n(z). These are defined by 1 1-2 t z+t 2=∑n=0∞U n(z)t n.

hermiteH: (NonNegativeInteger,R)->R
hermiteH(n,z) is the n-th Hermite polynomial, H n(z). These are defined by e 2 t z-t 2=∑n=0∞H n(z)t n n!.

laguerreL: (NonNegativeInteger,R)->R
laguerreL(n,z) is the n-th Laguerre polynomial, L n(z). These are defined by e-t z 1-t 1-t=∑n=0∞L n(z)t n n!.

laguerreL: (NonNegativeInteger,NonNegativeInteger,R)->R
laguerreL(m,n,z) is the associated Laguerre polynomial L n m(z). This is the m-th derivative of L n(z).

legendreP: (NonNegativeInteger,R)->R
legendreP(n,z) is the n-th Legendre polynomial, P n(z). These are defined by 1 1-2 t z+t 2=∑n=0∞P n(z)t n.

These operations require non-negative integers for the indices, but otherwise the argument can be given as desired.

[chebyshevT(i, z) for i in 0..5]

[1,z,2 z 2-1,4 z 3-3 z,8 z 4-8 z 2+1,16 z 5-20 z 3+5 z]

Type: List Polynomial Integer

The expression chebyshevT(n,z) evaluates to the n-th Chebyshev polynomial:Chebyshev:of the first kind polynomial of the first kind.

chebyshevT(3, 5.0 + 6.0*%i)

-1675.0+918.0 i

Type: Complex Float
chebyshevT(3, 5.0::DoubleFloat)

485.0

Type: DoubleFloat

The expression chebyshevU(n,z) evaluates to the n-th Chebyshev polynomial:Chebyshev:of the second kind polynomial of the second kind.

[chebyshevU(i, z) for i in 0..5]

[1,2 z,4 z 2-1,8 z 3-4 z,16 z 4-12 z 2+1,32 z 5-32 z 3+6 z]

Type: List Polynomial Integer
chebyshevU(3, 0.2)

-0.736

Type: Float

The expression hermiteH(n,z) evaluates to the n-th Hermite polynomial:Hermite polynomial.

[hermiteH(i, z) for i in 0..5]

[1,2 z,4 z 2-2,8 z 3-12 z,16 z 4-48 z 2+12,32 z 5-160 z 3+120 z]

Type: List Polynomial Integer
hermiteH(100, 1.0)

-0.1448706729 337934088 E 93

Type: Float

The expression laguerreL(n,z) evaluates to the n-th Laguerre polynomial:Laguerre polynomial.

[laguerreL(i, z) for i in 0..4]

[1,-z+1,z 2-4 z+2,-z 3+9 z 2-18 z+6,z 4-16 z 3+72 z 2-96 z+24]

Type: List Polynomial Integer
laguerreL(4, 1.2)

-13.0944

Type: Float
[laguerreL(j, 3, z) for j in 0..4]

[-z 3+9 z 2-18 z+6,-3 z 2+18 z-18,-6 z+18,-6,0]

Type: List Polynomial Integer
laguerreL(1, 3, 2.1)

6.57

Type: Float

The expression polynomial:Legendre legendreP(n,z) evaluates to the n-th Legendre polynomial,

[legendreP(i,z) for i in 0..5]

[1,z,3 2 z 2-1 2,5 2 z 3-3 2 z,35 8 z 4-15 4 z 2+3 8,63 8 z 5-35 4 z 3+15 8 z]

Type: List Polynomial Fraction Integer
legendreP(3, 3.0*%i)

-72.0 i

Type: Complex Float

Finally, three number-theoretic polynomial operations may be evaluated. number theory The following operations are provided by the package NumberTheoreticPolynomialFunctions. NumberTheoreticPolynomialFunctions.

bernoulliB: (NonNegativeInteger,R)->R
bernoulliB(n,z) is the n-th Bernoulli polynomial, polynomial:Bernoulli B n(z). These are defined by t e z t e t-1=∑n=0∞B n(z)t n n!.

eulerE: (NonNegativeInteger,R)->R
eulerE(n,z) is the n-th Euler polynomial, Euler:polynomial E n(z). These are defined by polynomial:Euler 2 e z t e t+1=∑n=0∞E n(z)t n n!.

cyclotomic: (NonNegativeInteger,R)->R
cyclotomic(n,z) is the n-th cyclotomic polynomial . This is the polynomial whose roots are precisely the primitive n-th roots of unity. Euler:totient function This polynomial has degree given by the Euler totient function function:totient .

The expression bernoulliB(n,z) evaluates to the n-th Bernoulli polynomial:Bernouilli polynomial.

bernoulliB(3, z)

z 3-3 2 z 2+1 2 z

Type: Polynomial Fraction Integer
bernoulliB(3, 0.7 + 0.4 * %i)

-0.138-0.116 i

Type: Complex Float

The expression polynomial:Euler eulerE(n,z) evaluates to the n-th Euler polynomial.

eulerE(3, z)

z 3-3 2 z 2+1 4

Type: Polynomial Fraction Integer
eulerE(3, 0.7 + 0.4 * %i)

-0.238-0.316 i

Type: Complex Float

The expression polynomial:cyclotomic cyclotomic(n,z) evaluates to the n-th cyclotomic polynomial. cyclotomic polynomial

cyclotomic(3, z)

z 2+z+1

Type: Polynomial Integer
cyclotomic(3, (-1.0 + 0.0 * %i)**(2/3))

0.0

Type: Complex Float

Drawing complex functions in Axiom is presently somewhat awkward compared to drawing real functions. It is necessary to use the draw operations that operate on functions rather than expressions.

This is the complex exponential function (rotated interactively). function:complex exponential When this is displayed in color, the height is the value of the real part of the function and the color is the imaginary part. Red indicates large negative imaginary values, green indicates imaginary values near zero and blue/violet indicates large positive imaginary values.

draw((x,y)+-> real exp complex(x,y), -2..2, -2*%pi..2*%pi, colorFunction == (x, y) +-> imag exp complex(x,y), title=="exp(x+%i*y)", style=="smooth")

This is the complex arctangent function. function:complex arctangent Again, the height is the real part of the function value but here the color indicates the function value's phase. The position of the branch cuts are clearly visible and one can see that the function is real only for a real argument.

vp := draw((x,y) +-> real atan complex(x,y), -%pi..%pi, -%pi..%pi, colorFunction==(x,y) +->argument atan complex(x,y), title=="atan(x+%i*y)", style=="shade"); rotate(vp,-160,-45); vp

This is the complex Gamma function.

draw((x,y) +-> max(min(real Gamma complex(x,y),4),-4), -%pi..%pi, -%pi..%pi, style=="shade", colorFunction == (x,y) +-> argument Gamma complex(x,y), title == "Gamma(x+%i*y)", var1Steps == 50, var2Steps== 50)

This shows the real Beta function near the origin.

draw(Beta(x,y)/100, x=-1.6..1.7, y = -1.6..1.7, style=="shade", title=="Beta(x,y)", var1Steps==40, var2Steps==40)

This is the Bessel function for index in the range -6..4 and argument x in the range 2..14.

draw((alpha,x) +-> min(max(besselJ(alpha, x+8), -6), 6), -6..4, -6..6, title=="besselJ(alpha,x)", style=="shade", var1Steps==40, var2Steps==40)

This is the modified Bessel function evaluated for various real values of the index and fixed argument x=5.

draw(besselI(alpha, 5), alpha = -12..12, unit==[5,20])

This is similar to the last example except the index takes on complex values in a 6 x 6 rectangle centered on the origin.

draw((x,y) +-> real besselI(complex(x/20, y/20),5), -60..60, -60..60, colorFunction == (x,y)+-> argument besselI(complex(x/20,y/20),5), title=="besselI(x+i*y,5)", style=="shade")
Book Contents Previous Section 8.0 Advanced Problem Solving Next Section 8.2 Polynomial Factorization Book Index