Package org.apfloat
Class ApcomplexMath
java.lang.Object
org.apfloat.ApcomplexMath
Various mathematical functions for arbitrary precision complex numbers.
- Version:
- 1.11.0
- Author:
- Mikko Tommila
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic Apfloat
Absolute value.static Apcomplex
Inverse cosine.static Apcomplex
Inverse hyperbolic cosine.static Apcomplex
Arithmetic-geometric mean.static Apcomplex[]
All values of the positive integer root.static Apfloat
Angle of the complex vector in the complex plane.static Apcomplex
Inverse sine.static Apcomplex
Inverse hyperbolic sine.static Apcomplex
Inverse tangent.static Apcomplex
Inverse hyperbolic tangent.static Apcomplex
Binomial coefficient.static Apcomplex
Cube root.static Apcomplex
Cosine.static Apcomplex
Hyperbolic cosine.static Apcomplex
Digamma function.static Apcomplex
Exponent function.static Apcomplex
Gamma function.static Apcomplex
Incomplete gamma function.static Apcomplex
Generalized incomplete gamma function.static Apcomplex
Confluent hypergeometric function 0F1.static Apcomplex
hypergeometric1F1
(Apcomplex a, Apcomplex b, Apcomplex z) Kummer confluent hypergeometric function 1F1.static Apcomplex
hypergeometric2F1
(Apcomplex a, Apcomplex b, Apcomplex c, Apcomplex z) Hypergeometric function 2F1.static Apcomplex
inverseRoot
(Apcomplex z, long n) Inverse positive integer root.static Apcomplex
inverseRoot
(Apcomplex z, long n, long k) Inverse positive integer root.static Apcomplex
Natural logarithm.static Apcomplex
Logarithm in arbitrary base.static Apcomplex
Logarithm of the gamma function.static Apcomplex
Deprecated.static Apfloat
Norm.static Apcomplex
Integer power.static Apcomplex
Arbitrary power.static Apcomplex
Product of numbers.static Apcomplex
Positive integer root.static Apcomplex
Positive integer root.static Apcomplex
Multiply by a power of the radix.static Apcomplex
Sine.static Apcomplex
Hyperbolic sine.static Apcomplex
Square root.static Apcomplex
Sum of numbers.static Apcomplex
Tangent.static Apcomplex
Hyperbolic tangent.static Apfloat
Returns the unit in the last place of the argument, considering the scale and precision.static Apcomplex
Lambert W function.static Apcomplex
Lambert W function for the specified branch.static Apcomplex
Riemann zeta function.static Apcomplex
Hurwitz zeta function.
-
Method Details
-
negate
Deprecated.UseApcomplex.negate()
.Negative value.- Parameters:
z
- The argument.- Returns:
-z
.- Throws:
ApfloatRuntimeException
-
abs
Absolute value.- Parameters:
z
- The argument.- Returns:
sqrt(x2 + y2)
, wherez = x + i y
.- Throws:
ApfloatRuntimeException
-
norm
Norm. Square of the magnitude.- Parameters:
z
- The argument.- Returns:
x2 + y2
, wherez = x + i y
.- Throws:
ApfloatRuntimeException
-
arg
Angle of the complex vector in the complex plane.- Parameters:
z
- The argument.- Returns:
arctan(y / x)
from the appropriate branch, wherez = x + i y
.- Throws:
ArithmeticException
- Ifz
is zero.ApfloatRuntimeException
-
scale
Multiply by a power of the radix.- Parameters:
z
- The argument.scale
- The scaling factor.- Returns:
z * z.radix()scale
.- Throws:
ApfloatRuntimeException
-
pow
public static Apcomplex pow(Apcomplex z, long n) throws ArithmeticException, ApfloatRuntimeException Integer power.- Parameters:
z
- Base of the power operator.n
- Exponent of the power operator.- Returns:
z
to then
:th power, that iszn
.- Throws:
ArithmeticException
- If bothz
andn
are zero.ApfloatRuntimeException
-
sqrt
Square root.- Parameters:
z
- The argument.- Returns:
- Square root of
z
. - Throws:
ApfloatRuntimeException
-
cbrt
Cube root.- Parameters:
z
- The argument.- Returns:
- Cube root of
z
. - Throws:
ApfloatRuntimeException
-
root
public static Apcomplex root(Apcomplex z, long n) throws ArithmeticException, ApfloatRuntimeException Positive integer root. The branch that has the smallest angle and same sign of imaginary part asz
is always chosen.- Parameters:
z
- The argument.n
- Which root to take.- Returns:
n
:th root ofz
, that isz1/n
.- Throws:
ArithmeticException
- Ifn
is zero.ApfloatRuntimeException
-
root
public static Apcomplex root(Apcomplex z, long n, long k) throws ArithmeticException, ApfloatRuntimeException Positive integer root. The specified branch counting from the smallest angle and same sign of imaginary part asz
is chosen.- Parameters:
z
- The argument.n
- Which root to take.k
- Which branch to take.- Returns:
n
:th root ofz
, that isz1/nei2πsk/n
wheres
is the signum of the imaginary part ofz
.- Throws:
ArithmeticException
- Ifn
is zero.ApfloatRuntimeException
- Since:
- 1.5
-
inverseRoot
public static Apcomplex inverseRoot(Apcomplex z, long n) throws ArithmeticException, ApfloatRuntimeException Inverse positive integer root. The branch that has the smallest angle and different sign of imaginary part thanz
is always chosen.- Parameters:
z
- The argument.n
- Which inverse root to take.- Returns:
- Inverse
n
:th root ofz
, that isz-1/n
. - Throws:
ArithmeticException
- Ifz
orn
is zero.ApfloatRuntimeException
-
inverseRoot
public static Apcomplex inverseRoot(Apcomplex z, long n, long k) throws ArithmeticException, ApfloatRuntimeException Inverse positive integer root. The specified branch counting from the smallest angle and different sign of imaginary part thanz
is chosen.- Parameters:
z
- The argument.n
- Which inverse root to take.k
- Which branch to take.- Returns:
- Inverse
n
:th root ofz
, that isz-1/ne-i2πk/n
. - Throws:
ArithmeticException
- Ifz
orn
is zero.ApfloatRuntimeException
-
allRoots
public static Apcomplex[] allRoots(Apcomplex z, int n) throws ArithmeticException, ApfloatRuntimeException All values of the positive integer root.Returns all of the
n
values of the root, in the order of the angle, starting from the smallest angle and same sign of imaginary part asz
.- Parameters:
z
- The argument.n
- Which root to take.- Returns:
- All values of the
n
:th root ofz
, that isz1/n
, in the order of the angle. - Throws:
ArithmeticException
- Ifn
is zero.ApfloatRuntimeException
- Since:
- 1.5
-
agm
Arithmetic-geometric mean.- Parameters:
a
- First argument.b
- Second argument.- Returns:
- Arithmetic-geometric mean of
a
andb
. - Throws:
ApfloatRuntimeException
-
log
Natural logarithm.The logarithm is calculated using the arithmetic-geometric mean. See the Borweins' book for the formula.
- Parameters:
z
- The argument.- Returns:
- Natural logarithm of
z
. - Throws:
ArithmeticException
- Ifz
is zero.ApfloatRuntimeException
-
log
public static Apcomplex log(Apcomplex z, Apcomplex w) throws ArithmeticException, ApfloatRuntimeException Logarithm in arbitrary base.- Parameters:
z
- The argument.w
- The base.- Returns:
- Base-
w
logarithm ofz
. - Throws:
ArithmeticException
- Ifz
orw
is zero.ApfloatRuntimeException
- Since:
- 1.6
-
exp
Exponent function. Calculated using Newton's iteration for the inverse of logarithm.- Parameters:
z
- The argument.- Returns:
ez
.- Throws:
ApfloatRuntimeException
-
pow
Arbitrary power. Calculated usinglog()
andexp()
.- Parameters:
z
- The base.w
- The exponent.- Returns:
zw
.- Throws:
ArithmeticException
- If bothz
andw
are zero.ApfloatRuntimeException
-
acos
Inverse cosine. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse cosine of
z
. - Throws:
ApfloatRuntimeException
-
acosh
Inverse hyperbolic cosine. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse hyperbolic cosine of
z
. - Throws:
ApfloatRuntimeException
-
asin
Inverse sine. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse sine of
z
. - Throws:
ApfloatRuntimeException
-
asinh
Inverse hyperbolic sine. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse hyperbolic sine of
z
. - Throws:
ApfloatRuntimeException
-
atan
Inverse tangent. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse tangent of
z
. - Throws:
ArithmeticException
- Ifz == i
.ApfloatRuntimeException
-
atanh
Inverse hyperbolic tangent. Calculated usinglog()
.- Parameters:
z
- The argument.- Returns:
- Inverse hyperbolic tangent of
z
. - Throws:
ArithmeticException
- Ifz
is 1 or -1.ApfloatRuntimeException
-
cos
Cosine. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Cosine of
z
. - Throws:
ApfloatRuntimeException
-
cosh
Hyperbolic cosine. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Hyperbolic cosine of
z
. - Throws:
ApfloatRuntimeException
-
sin
Sine. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Sine of
z
. - Throws:
ApfloatRuntimeException
-
sinh
Hyperbolic sine. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Hyperbolic sine of
z
. - Throws:
ApfloatRuntimeException
-
tan
Tangent. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Tangent of
z
. - Throws:
ArithmeticException
- Ifz
is π/2 + n π where n is an integer.ApfloatRuntimeException
-
tanh
Hyperbolic tangent. Calculated usingexp()
.- Parameters:
z
- The argument.- Returns:
- Hyperbolic tangent of
z
. - Throws:
ArithmeticException
- Ifz
is i (π/2 + n π) where n is an integer.ApfloatRuntimeException
-
w
Lambert W function. The W function gives the solution to the equationW eW = z
. Also known as the product logarithm.This function gives the solution to the principal branch, W0.
- Parameters:
z
- The argument.- Returns:
W0(z)
.- Throws:
ApfloatRuntimeException
- Since:
- 1.8.0
-
w
Lambert W function for the specified branch.- Parameters:
z
- The argument.k
- The branch.- Returns:
Wk(z)
.- Throws:
ArithmeticException
- Ifz
is zero andk
is not zero.ApfloatRuntimeException
- Since:
- 1.8.0
- See Also:
-
product
Product of numbers. The precision used in the multiplications is only what is needed for the end result. This method may perform significantly better than simply multiplying the numbers sequentially.If there are no arguments, the return value is
1
.- Parameters:
z
- The argument(s).- Returns:
- The product of the given numbers.
- Throws:
ApfloatRuntimeException
- Since:
- 1.3
-
sum
Sum of numbers. The precision used in the additions is only what is needed for the end result. This method may perform significantly better than simply adding the numbers sequentially.If there are no arguments, the return value is
0
.- Parameters:
z
- The argument(s).- Returns:
- The sum of the given numbers.
- Throws:
ApfloatRuntimeException
- Since:
- 1.3
-
gamma
Gamma function.- Parameters:
z
- The argument.- Returns:
Γ(z)
- Throws:
ArithmeticException
- Ifz
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.9.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. The asymptotic complexity is at least O(n2log n) and it is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the gamma function.
-
gamma
public static Apcomplex gamma(Apcomplex a, Apcomplex z) throws ArithmeticException, ApfloatRuntimeException Incomplete gamma function.- Parameters:
a
- The first argument.z
- The second argument.- Returns:
Γ(a, z)
- Throws:
ArithmeticException
- If the real part ofa
is nonpositive andz
is zero.ApfloatRuntimeException
- Since:
- 1.10.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. The asymptotic complexity is at least O(n2log n) and it is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the incomplete gamma function.
-
gamma
public static Apcomplex gamma(Apcomplex a, Apcomplex z0, Apcomplex z1) throws ArithmeticException, ApfloatRuntimeException Generalized incomplete gamma function.This function is defined as:
Γ(a, z0, z1) = Γ(a, z0) - Γ(a, z1)
The lower gamma function can be calculated with:
γ(a, z) = Γ(a, 0, z)
- Parameters:
a
- The first argument.z0
- The second argument.z1
- The third argument.- Returns:
Γ(a, z0, z1)
- Throws:
ArithmeticException
- If the real part ofa
is nonpositive and eitherz0
orz1
is zero. For the lower gamma function ifa
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.10.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. The asymptotic complexity is at least O(n2log n) and it is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the incomplete gamma function.
-
logGamma
Logarithm of the gamma function. Note that this function has a different branch structure thanlog(gamma(z))
.- Parameters:
z
- The argument.- Returns:
logΓ(z)
- Throws:
ArithmeticException
- Ifz
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. The asymptotic complexity is at least O(n2log n) and it is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the gamma function.
-
digamma
Digamma function.- Parameters:
z
- The argument.- Returns:
ψ(z)
- Throws:
ArithmeticException
- Ifz
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. The asymptotic complexity is at least O(n2log n) and it is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the digamma function.
-
binomial
public static Apcomplex binomial(Apcomplex n, Apcomplex k) throws ArithmeticException, ApfloatRuntimeException Binomial coefficient. Calculated using thegamma(Apcomplex)
function.- Parameters:
n
- The first argument.k
- The second argument.- Returns:
- Throws:
ArithmeticException
- Ifn
is a negative integer andk
is noninteger.ApfloatRuntimeException
- Since:
- 1.11.0
-
zeta
Riemann zeta function.- Parameters:
s
- The argument.- Returns:
ζ(s)
- Throws:
ArithmeticException
- Ifs
is1
.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. It is impractically slow beyond a precision of a few hundred digits. At the time of implementation no generic fast algorithm is known for the zeta function.
-
zeta
public static Apcomplex zeta(Apcomplex s, Apcomplex a) throws ArithmeticException, ApfloatRuntimeException Hurwitz zeta function.- Parameters:
s
- The first argument.a
- The second argument.- Returns:
ζ(s, a)
- Throws:
ArithmeticException
- Ifs
is1
or ifa
is a nonpositive integer.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. It is impractically slow beyond a precision of a few hundred digits. At the time of implementation no generic fast algorithm is known for the zeta function.
-
hypergeometric0F1
public static Apcomplex hypergeometric0F1(Apcomplex a, Apcomplex z) throws ArithmeticException, ApfloatRuntimeException Confluent hypergeometric function 0F1.- Parameters:
a
- The first argument.z
- The second argument.- Returns:
- 0F1(; a; z)
- Throws:
ArithmeticException
- If the function value is not finite.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. It is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the function.
-
hypergeometric1F1
public static Apcomplex hypergeometric1F1(Apcomplex a, Apcomplex b, Apcomplex z) throws ArithmeticException, ApfloatRuntimeException Kummer confluent hypergeometric function 1F1. Also known as the confluent hypergeometric function of the first kind.- Parameters:
a
- The first argument.b
- The second argument.z
- The third argument.- Returns:
- 1F1(a; b; z)
- Throws:
ArithmeticException
- If the function value is not finite.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. It is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the function.
-
hypergeometric2F1
public static Apcomplex hypergeometric2F1(Apcomplex a, Apcomplex b, Apcomplex c, Apcomplex z) throws ArithmeticException, ApfloatRuntimeException Hypergeometric function 2F1. Also known as the Gaussian or ordinary hypergeometric function.- Parameters:
a
- The first argument.b
- The second argument.c
- The third argument.z
- The fourth argument.- Returns:
- 2F1(a, b; c; z)
- Throws:
ArithmeticException
- If the function value is not finite.ApfloatRuntimeException
- Since:
- 1.11.0
- Implementation notes:
- This implementation is slow, meaning that it isn't a fast algorithm. It is impractically slow beyond a precision of a few thousand digits. At the time of implementation no generic fast algorithm is known for the function.
-
ulp
Returns the unit in the last place of the argument, considering the scale and precision. This is maximum of the ulps of the real and imaginary part of the argument. If the precision of the argument is infinite, zero is returned.- Parameters:
z
- The argument.- Returns:
- The ulp of the argument.
- Since:
- 1.10.0
-
Apcomplex.negate()
.