Documentation
¶
Overview ¶
Package complexanalysis provides numerical tools for complex analysis using only the Go standard library.
It is organised into a few areas:
- Elementary and inverse functions on complex128 with well-defined principal branches (see elementary.go): Sqrt, Cbrt, Exp, Log, Pow, the trigonometric and hyperbolic families, and their inverses.
- Special functions (see special.go): the complex Gamma and LogGamma via the Lanczos approximation, Digamma, Beta, the error functions Erf/Erfc, the Riemann Zeta function via Borwein's algorithm, and the combinatorial Factorial, RisingFactorial and Binomial.
- Numerical contour integration and its consequences (see contour.go): IntegrateCircle, IntegrateSegment, IntegratePolygon and the general ContourIntegral; Residue, ResidueSimplePole and ResidueOrderM; the CauchyIntegralValue and CauchyDerivative formulas; the WindingNumber; and the ArgumentPrinciple with CountZeros.
- Conformal maps (see conformal.go): the Mobius transformation type with composition, inversion and fixed points, together with the CrossRatio, the CayleyTransform and the JoukowskiMap.
- Laurent and Taylor coefficient extraction and numeric analytic continuation (see laurent.go): LaurentCoefficient, TaylorCoefficient, PowerSeriesEval and AnalyticContinuation.
Every function that samples an analytic function does so by evaluating a user-supplied Function. Contour methods use the composite trapezoidal rule on a circular contour, which converges geometrically for functions that are analytic in an annulus, so modest sample counts (a few hundred points) give near machine-precision results.
The package is deterministic and depends only on math and math/cmplx.
Index ¶
- func Abs(z complex128) float64
- func Acos(z complex128) complex128
- func Acosh(z complex128) complex128
- func AnalyticContinuation(f Function, from, to complex128, order int, radius float64, n int) complex128
- func AnalyticContinuationPath(f Function, path []complex128, order int, radius float64, n int) complex128
- func ApproxEqual(a, b complex128, tol float64) bool
- func Arg(z complex128) float64
- func ArgumentPrinciple(f Function, center complex128, radius float64, n int) complex128
- func Asin(z complex128) complex128
- func Asinh(z complex128) complex128
- func Atan(z complex128) complex128
- func Atanh(z complex128) complex128
- func Beta(a, b complex128) complex128
- func Binomial(z complex128, k int) complex128
- func CauchyDerivative(f Function, z0, center complex128, k int, radius float64, n int) complex128
- func CauchyIntegralValue(f Function, z0, center complex128, radius float64, n int) complex128
- func CayleyTransform(z complex128) complex128
- func Cbrt(z complex128) complex128
- func Conj(z complex128) complex128
- func ContourIntegral(f Function, gamma func(float64) complex128, n int) complex128
- func Cos(z complex128) complex128
- func Cosh(z complex128) complex128
- func Cot(z complex128) complex128
- func Coth(z complex128) complex128
- func CountZeros(f Function, center complex128, radius float64, n int) int
- func CrossRatio(z, z1, z2, z3 complex128) complex128
- func Csc(z complex128) complex128
- func Digamma(z complex128) complex128
- func Erf(z complex128) complex128
- func Erfc(z complex128) complex128
- func Exp(z complex128) complex128
- func Factorial(z complex128) complex128
- func Gamma(z complex128) complex128
- func Im(z complex128) float64
- func IntegrateCircle(f Function, center complex128, radius float64, n int) complex128
- func IntegratePolygon(f Function, vertices []complex128, nPerEdge int) complex128
- func IntegrateSegment(f Function, a, b complex128, n int) complex128
- func InverseCayleyTransform(w complex128) complex128
- func IsZero(z complex128, tol float64) bool
- func JoukowskiMap(z complex128) complex128
- func LaurentCoefficient(f Function, center complex128, k int, radius float64, n int) complex128
- func LaurentCoefficients(f Function, center complex128, lo, hi int, radius float64, n int) []complex128
- func Log(z complex128) complex128
- func LogBranch(z complex128, k int) complex128
- func LogGamma(z complex128) complex128
- func NthRoots(z complex128, n int) []complex128
- func Polar(r, theta float64) complex128
- func Pow(z, w complex128) complex128
- func PowerSeriesEval(coeffs []complex128, center, z complex128) complex128
- func Re(z complex128) float64
- func Reciprocal(z complex128) complex128
- func Rect(re, im float64) complex128
- func Residue(f Function, z0 complex128, radius float64, n int) complex128
- func ResidueOrderM(f Function, z0 complex128, m int, radius float64, n int) complex128
- func ResidueSimplePole(f Function, z0 complex128, eps float64) complex128
- func RisingFactorial(z complex128, n int) complex128
- func Sec(z complex128) complex128
- func Sign(z complex128) complex128
- func Sin(z complex128) complex128
- func Sinh(z complex128) complex128
- func Sqrt(z complex128) complex128
- func Tan(z complex128) complex128
- func Tanh(z complex128) complex128
- func TaylorCoefficient(f Function, center complex128, k int, radius float64, n int) complex128
- func TaylorCoefficients(f Function, center complex128, count int, radius float64, n int) []complex128
- func WindingNumber(gamma func(float64) complex128, z0 complex128, n int) int
- func Zeta(s complex128) complex128
- type Function
- type Mobius
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Acosh ¶
func Acosh(z complex128) complex128
Acosh returns the principal inverse hyperbolic cosine of z.
func AnalyticContinuation ¶
func AnalyticContinuation(f Function, from, to complex128, order int, radius float64, n int) complex128
AnalyticContinuation returns the value of f at the point to, reconstructed from its Taylor expansion about the point from. It computes the Taylor coefficients up to the given order on a circle of the given radius about from, then sums the truncated series at to. The step |to-from| should be smaller than the radius of convergence for the series to be accurate.
func AnalyticContinuationPath ¶
func AnalyticContinuationPath(f Function, path []complex128, order int, radius float64, n int) complex128
AnalyticContinuationPath continues f numerically along the given path of centers and returns the reconstructed value at the final point. Starting from path[0], it repeatedly forms the Taylor expansion of f about the current center (using a circle of the given radius and n points, to the given order) and evaluates it at the next path point, which becomes the new center. This mirrors classical analytic continuation along a chain of overlapping disks. It returns 0 for an empty path and f(path[0]) for a single point.
func ApproxEqual ¶
func ApproxEqual(a, b complex128, tol float64) bool
ApproxEqual reports whether |a-b| <= tol.
func Arg ¶
func Arg(z complex128) float64
Arg returns the principal argument of z in the interval (-pi, pi].
func ArgumentPrinciple ¶
func ArgumentPrinciple(f Function, center complex128, radius float64, n int) complex128
ArgumentPrinciple returns the value of 1/(2*pi*i) * integral of f'(z)/f(z) around the positively oriented circle of the given center and radius. By the argument principle this equals the number of zeros minus the number of poles of f inside the circle, counted with multiplicity. The derivative f' is approximated by central finite differences. The exact count is returned by CountZeros after rounding.
func Asinh ¶
func Asinh(z complex128) complex128
Asinh returns the principal inverse hyperbolic sine of z.
func Atanh ¶
func Atanh(z complex128) complex128
Atanh returns the principal inverse hyperbolic tangent of z.
func Beta ¶
func Beta(a, b complex128) complex128
Beta returns the Euler beta function B(a, b) = Gamma(a)Gamma(b)/Gamma(a+b), evaluated through LogGamma to remain stable for moderately large arguments.
func Binomial ¶
func Binomial(z complex128, k int) complex128
Binomial returns the generalized binomial coefficient C(z, k) = Gamma(z+1)/(Gamma(k+1)Gamma(z-k+1)) for a non-negative integer k, evaluated as a falling-factorial product so it is exact for polynomial z.
func CauchyDerivative ¶
func CauchyDerivative(f Function, z0, center complex128, k int, radius float64, n int) complex128
CauchyDerivative evaluates the k-th derivative of f at z0 using the Cauchy integral formula for derivatives, f^(k)(z0) = k!/(2*pi*i) * integral of f(z)/(z-z0)^(k+1) around the circle of the given center and radius. The point z0 must lie strictly inside the circle and f must be analytic there. k == 0 returns f(z0). It panics if k < 0.
func CauchyIntegralValue ¶
func CauchyIntegralValue(f Function, z0, center complex128, radius float64, n int) complex128
CauchyIntegralValue evaluates f at the point z0 inside a circle of the given center and radius using the Cauchy integral formula, f(z0) = 1/(2*pi*i) * integral of f(z)/(z-z0) around the circle. The point z0 must lie strictly inside the circle and f must be analytic there.
func CayleyTransform ¶
func CayleyTransform(z complex128) complex128
CayleyTransform returns the value of the Cayley transform (z-i)/(z+i), which maps the upper half-plane conformally onto the open unit disk.
func Cbrt ¶
func Cbrt(z complex128) complex128
Cbrt returns the principal cube root of z, exp(Log(z)/3), which is real and positive for real positive z.
func ContourIntegral ¶
func ContourIntegral(f Function, gamma func(float64) complex128, n int) complex128
ContourIntegral approximates the integral of f along a general contour given by the parametrization gamma over t in [0, 1]. The derivative gamma'(t) is estimated by central finite differences, and the composite trapezoidal rule with n subintervals is used. If the contour is closed (gamma(0) == gamma(1)), the periodic trapezoidal rule is highly accurate. It panics if n <= 0.
func Coth ¶
func Coth(z complex128) complex128
Coth returns the hyperbolic cotangent of z, cosh(z)/sinh(z).
func CountZeros ¶
func CountZeros(f Function, center complex128, radius float64, n int) int
CountZeros returns the number of zeros of an analytic function f inside the circle of the given center and radius, counted with multiplicity, by rounding the argument-principle integral. It assumes f has no poles inside the circle and no zeros on it.
func CrossRatio ¶
func CrossRatio(z, z1, z2, z3 complex128) complex128
CrossRatio returns the cross-ratio (z-z1)(z2-z3) / ((z-z3)(z2-z1)) of the four points. The cross-ratio is invariant under every Mobius transformation.
func Digamma ¶
func Digamma(z complex128) complex128
Digamma returns the logarithmic derivative of the gamma function, psi(z) = Gamma'(z)/Gamma(z), using recurrence to raise the real part and then the standard asymptotic expansion.
func Erf ¶
func Erf(z complex128) complex128
Erf returns the error function of z, 2/sqrt(pi) times the integral of exp(-t^2) from 0 to z, summed from its Taylor series. The series converges for every z but loses precision for large |z| (roughly |z| > 6); within that range it is accurate to about 1e-12.
func Erfc ¶
func Erfc(z complex128) complex128
Erfc returns the complementary error function 1 - Erf(z).
func Factorial ¶
func Factorial(z complex128) complex128
Factorial returns z! defined as Gamma(z+1); for a non-negative integer z it equals the ordinary factorial.
func Gamma ¶
func Gamma(z complex128) complex128
Gamma returns the value of the Euler gamma function at z, computed with the Lanczos approximation and the reflection formula for Re(z) < 0.5. It is accurate to roughly 1e-13 relative error away from the poles at the non-positive integers.
func IntegrateCircle ¶
func IntegrateCircle(f Function, center complex128, radius float64, n int) complex128
IntegrateCircle approximates the contour integral of f around the positively oriented circle of the given center and radius, using the composite trapezoidal rule with n sample points. Because the integrand is periodic, this rule converges geometrically when f is analytic in an annulus around the circle. It panics if n <= 0 or radius <= 0.
func IntegratePolygon ¶
func IntegratePolygon(f Function, vertices []complex128, nPerEdge int) complex128
IntegratePolygon approximates the integral of f along the closed polygonal contour through the given vertices (the last vertex is joined back to the first), applying IntegrateSegment with nPerEdge points on each edge. It returns 0 for fewer than two vertices.
func IntegrateSegment ¶
func IntegrateSegment(f Function, a, b complex128, n int) complex128
IntegrateSegment approximates the integral of f along the straight line segment from a to b using the composite Simpson rule with n subintervals (n is rounded up to the next even number). It panics if n <= 0.
func InverseCayleyTransform ¶
func InverseCayleyTransform(w complex128) complex128
InverseCayleyTransform returns i*(1+w)/(1-w), the inverse of the Cayley transform, mapping the unit disk back to the upper half-plane.
func JoukowskiMap ¶
func JoukowskiMap(z complex128) complex128
JoukowskiMap returns the Joukowski map (z + 1/z)/2, which maps circles about the origin to confocal ellipses and is used in classical airfoil theory. It returns a complex infinity at z = 0.
func LaurentCoefficient ¶
func LaurentCoefficient(f Function, center complex128, k int, radius float64, n int) complex128
LaurentCoefficient returns the k-th Laurent coefficient c_k of f expanded about center, computed from the contour integral c_k = 1/(2*pi*i) * integral of f(z)/(z-center)^(k+1) around the circle of the given radius with n sample points. The index k may be negative; c_{-1} is the residue. The circle must lie in an annulus of analyticity of f.
func LaurentCoefficients ¶
func LaurentCoefficients(f Function, center complex128, lo, hi int, radius float64, n int) []complex128
LaurentCoefficients returns the Laurent coefficients c_k of f about center for k running from lo to hi inclusive, as a slice indexed so that result[k-lo] is c_k. It returns nil when hi < lo.
func Log ¶
func Log(z complex128) complex128
Log returns the principal branch of the natural logarithm of z, with imaginary part (the argument) in (-pi, pi].
func LogBranch ¶
func LogBranch(z complex128, k int) complex128
LogBranch returns the value of the natural logarithm of z on branch k, that is Log(z) + 2*pi*i*k. Branch 0 is the principal branch.
func LogGamma ¶
func LogGamma(z complex128) complex128
LogGamma returns the principal branch of the logarithm of the gamma function at z. For Re(z) >= 0.5 it uses the Lanczos series directly, avoiding the overflow that Gamma would suffer for large arguments; elsewhere it falls back to Log(Gamma(z)).
func NthRoots ¶
func NthRoots(z complex128, n int) []complex128
NthRoots returns all n distinct n-th roots of z, ordered by increasing argument starting from the principal root. It returns nil for n <= 0.
func Polar ¶
func Polar(r, theta float64) complex128
Polar constructs a complex number from a modulus r and an argument theta, i.e. r*(cos(theta) + i*sin(theta)).
func Pow ¶
func Pow(z, w complex128) complex128
Pow returns z raised to the power w using the principal branch, exp(w*Log(z)). Pow(0, 0) is defined to be 1.
func PowerSeriesEval ¶
func PowerSeriesEval(coeffs []complex128, center, z complex128) complex128
PowerSeriesEval evaluates the power series with the given coefficients about center at the point z, returning sum_j coeffs[j] * (z-center)^j via Horner's method.
func Rect ¶
func Rect(re, im float64) complex128
Rect constructs a complex number from its real and imaginary parts.
func Residue ¶
func Residue(f Function, z0 complex128, radius float64, n int) complex128
Residue approximates the residue of f at the isolated singularity z0 by integrating f around a small circle of the given radius and dividing by 2*pi*i. The radius must enclose no singularity other than z0.
func ResidueOrderM ¶
func ResidueOrderM(f Function, z0 complex128, m int, radius float64, n int) complex128
ResidueOrderM returns the residue of f at a pole z0 of order m using the derivative formula Res = lim_{z->z0} 1/(m-1)! d^{m-1}/dz^{m-1} [(z-z0)^m f(z)]. The (m-1)-th derivative is obtained from a Cauchy integral around a circle of the given radius, so f must be analytic on and inside that circle except at z0. It panics if m < 1.
func ResidueSimplePole ¶
func ResidueSimplePole(f Function, z0 complex128, eps float64) complex128
ResidueSimplePole returns the residue of f at a simple pole z0, computed as the limit of (z-z0)f(z) as z approaches z0 via a small symmetric average of radius eps around z0.
func RisingFactorial ¶
func RisingFactorial(z complex128, n int) complex128
RisingFactorial returns the Pochhammer symbol (z)_n = z(z+1)...(z+n-1), computed as Gamma(z+n)/Gamma(z). It returns 1 for n == 0.
func Sign ¶
func Sign(z complex128) complex128
Sign returns z/|z|, the unit complex number with the same argument as z, or 0 when z is 0.
func Sqrt ¶
func Sqrt(z complex128) complex128
Sqrt returns the principal square root of z, the branch whose result lies in the right half-plane (or on the non-negative imaginary axis).
func TaylorCoefficient ¶
func TaylorCoefficient(f Function, center complex128, k int, radius float64, n int) complex128
TaylorCoefficient returns the k-th Taylor coefficient of an analytic function f about center, a_k = f^(k)(center)/k!, computed from the same contour integral as LaurentCoefficient. It panics if k < 0.
func TaylorCoefficients ¶
func TaylorCoefficients(f Function, center complex128, count int, radius float64, n int) []complex128
TaylorCoefficients returns the first count Taylor coefficients (orders 0 through count-1) of an analytic function f about center. It returns nil for count <= 0.
func WindingNumber ¶
func WindingNumber(gamma func(float64) complex128, z0 complex128, n int) int
WindingNumber returns the winding number (index) of the closed curve gamma about the point z0, computed by accumulating the change in the argument of gamma(t)-z0 over t in [0, 1] with n samples and dividing by 2*pi. The result is rounded to the nearest integer. z0 must not lie on the curve.
func Zeta ¶
func Zeta(s complex128) complex128
Zeta returns the Riemann zeta function at s via the Dirichlet eta function and analytic continuation, eta(s) = (1 - 2^(1-s)) zeta(s). It is valid across the complex plane except at the pole s = 1, and is accurate to about 1e-12 for moderate |Im(s)|.
Types ¶
type Function ¶
type Function func(complex128) complex128
Function is a complex-valued function of a single complex variable. It is the common argument type for the numerical routines in this package.
type Mobius ¶
type Mobius struct {
A, B, C, D complex128
}
Mobius represents a Mobius (linear fractional) transformation z -> (A*z + B) / (C*z + D). Such maps are the conformal automorphisms of the extended complex plane (the Riemann sphere).
func IdentityMobius ¶
func IdentityMobius() Mobius
IdentityMobius returns the identity transformation z -> z.
func MobiusFromPoints ¶
func MobiusFromPoints(z1, z2, z3, w1, w2, w3 complex128) Mobius
MobiusFromPoints returns the unique Mobius transformation that sends the three distinct points z1, z2, z3 to w1, w2, w3 respectively. It is built by composing the standard map taking z1, z2, z3 to 0, 1, infinity with the inverse of the analogous map for the w points.
func NewMobius ¶
func NewMobius(a, b, c, d complex128) Mobius
NewMobius constructs the Mobius transformation with the given coefficients.
func RotationMap ¶
RotationMap returns the rotation z -> e^{i*theta} * z about the origin.
func ScalingMap ¶
func ScalingMap(a complex128) Mobius
ScalingMap returns the Mobius map z -> a*z. For |a| = 1 this is a pure rotation and RotationMap is a convenient alias.
func TranslationMap ¶
func TranslationMap(b complex128) Mobius
TranslationMap returns the Mobius map z -> z + b.
func (Mobius) Apply ¶
func (m Mobius) Apply(z complex128) complex128
Apply evaluates the transformation at z. When the denominator vanishes it returns a complex infinity, matching the point at infinity on the sphere.
func (Mobius) Compose ¶
Compose returns the transformation m(other(z)), the composition of m after other. Its coefficient matrix is the product of the two coefficient matrices.
func (Mobius) Determinant ¶
func (m Mobius) Determinant() complex128
Determinant returns A*D - B*C. A Mobius map is invertible exactly when this is non-zero.
func (Mobius) FixedPoints ¶
func (m Mobius) FixedPoints() []complex128
FixedPoints returns the fixed points of the transformation, the solutions of C*z^2 + (D-A)*z - B = 0. For a non-identity map this is one or two points; when C == 0 the point at infinity is a fixed point and only the finite ones are returned. The identity map (and any map fixing every point) returns nil.