Mathematics

Mathematics

Mathematical Operators

Base.:-Method.
-(x)

Unary minus operator.

source
Base.:+Function.
+(x, y...)

Addition operator. x+y+z+... calls this function with all arguments, i.e. +(x, y, z, ...).

source
Base.:-Method.
-(x, y)

Subtraction operator.

source
Base.:*Method.
*(x, y...)

Multiplication operator. x*y*z*... calls this function with all arguments, i.e. *(x, y, z, ...).

source
Base.:/Function.
/(x, y)

Right division operator: multiplication of x by the inverse of y on the right. Gives floating-point results for integer arguments.

source
Base.:\Method.
\(x, y)

Left division operator: multiplication of y by the inverse of x on the left. Gives floating-point results for integer arguments.

julia> 3 \ 6
2.0

julia> inv(3) * 6
2.0

julia> A = [1 2; 3 4]; x = [5, 6];

julia> A \ x
2-element Array{Float64,1}:
 -4.0
  4.5

julia> inv(A) * x
2-element Array{Float64,1}:
 -4.0
  4.5
source
Base.:^Method.
^(x, y)

Exponentiation operator. If x is a matrix, computes matrix exponentiation.

If y is an Int literal (e.g. 2 in x^2 or -3 in x^-3), the Julia code x^y is transformed by the compiler to Base.literal_pow(^, x, Val{y}), to enable compile-time specialization on the value of the exponent. (As a default fallback we have Base.literal_pow(^, x, Val{y}) = ^(x,y), where usually ^ == Base.^ unless ^ has been defined in the calling namespace.)

julia> 3^5
243

julia> A = [1 2; 3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

julia> A^3
2×2 Array{Int64,2}:
 37   54
 81  118
source
Base.fmaFunction.
fma(x, y, z)

Computes x*y+z without rounding the intermediate result x*y. On some systems this is significantly more expensive than x*y+z. fma is used to improve accuracy in certain algorithms. See muladd.

source
Base.muladdFunction.
muladd(x, y, z)

Combined multiply-add, computes x*y+z in an efficient manner. This may on some systems be equivalent to x*y+z, or to fma(x,y,z). muladd is used to improve performance. See fma.

Example

julia> muladd(3, 2, 1)
7

julia> 3 * 2 + 1
7
source
Base.divFunction.
div(x, y)
÷(x, y)

The quotient from Euclidean division. Computes x/y, truncated to an integer.

julia> 9 ÷ 4
2

julia> -5 ÷ 3
-1
source
Base.fldFunction.
fld(x, y)

Largest integer less than or equal to x/y.

julia> fld(7.3,5.5)
1.0
source
Base.cldFunction.
cld(x, y)

Smallest integer larger than or equal to x/y.

julia> cld(5.5,2.2)
3.0
source
Base.modFunction.
mod(x, y)
rem(x, y, RoundDown)

The reduction of x modulo y, or equivalently, the remainder of x after floored division by y, i.e.

x - y*fld(x,y)

if computed without intermediate rounding.

The result will have the same sign as y, and magnitude less than abs(y) (with some exceptions, see note below).

Note

When used with floating point values, the exact result may not be representable by the type, and so rounding error may occur. In particular, if the exact result is very close to y, then it may be rounded to y.

julia> mod(8, 3)
2

julia> mod(9, 3)
0

julia> mod(8.9, 3)
2.9000000000000004

julia> mod(eps(), 3)
2.220446049250313e-16

julia> mod(-eps(), 3)
3.0
source
rem(x::Integer, T::Type{<:Integer}) -> T
mod(x::Integer, T::Type{<:Integer}) -> T
%(x::Integer, T::Type{<:Integer}) -> T

Find y::T such that xy (mod n), where n is the number of integers representable in T, and y is an integer in [typemin(T),typemax(T)]. If T can represent any integer (e.g. T == BigInt), then this operation corresponds to a conversion to T.

julia> 129 % Int8
-127
source
Base.remFunction.
rem(x, y)
%(x, y)

Remainder from Euclidean division, returning a value of the same sign as x, and smaller in magnitude than y. This value is always exact.

julia> x = 15; y = 4;

julia> x % y
3

julia> x == div(x, y) * y + rem(x, y)
true
source
Base.Math.rem2piFunction.
rem2pi(x, r::RoundingMode)

Compute the remainder of x after integer division by , with the quotient rounded according to the rounding mode r. In other words, the quantity

x - 2π*round(x/(2π),r)

without any intermediate rounding. This internally uses a high precision approximation of 2π, and so will give a more accurate result than rem(x,2π,r)

  • if r == RoundNearest, then the result is in the interval $[-π, π]$. This will generally be the most accurate result.

  • if r == RoundToZero, then the result is in the interval $[0, 2π]$ if x is positive,. or $[-2π, 0]$ otherwise.

  • if r == RoundDown, then the result is in the interval $[0, 2π]$.

  • if r == RoundUp, then the result is in the interval $[-2π, 0]$.

Example

julia> rem2pi(7pi/4, RoundNearest)
-0.7853981633974485

julia> rem2pi(7pi/4, RoundDown)
5.497787143782138
source
Base.Math.mod2piFunction.
mod2pi(x)

Modulus after division by , returning in the range $[0,2π)$.

This function computes a floating point representation of the modulus after division by numerically exact , and is therefore not exactly the same as mod(x,2π), which would compute the modulus of x relative to division by the floating-point number .

Example

julia> mod2pi(9*pi/4)
0.7853981633974481
source
Base.divremFunction.
divrem(x, y)

The quotient and remainder from Euclidean division. Equivalent to (div(x,y), rem(x,y)) or (x÷y, x%y).

julia> divrem(3,7)
(0, 3)

julia> divrem(7,3)
(2, 1)
source
Base.fldmodFunction.
fldmod(x, y)

The floored quotient and modulus after division. Equivalent to (fld(x,y), mod(x,y)).

source
Base.fld1Function.
fld1(x, y)

Flooring division, returning a value consistent with mod1(x,y)

See also: mod1.

julia> x = 15; y = 4;

julia> fld1(x, y)
4

julia> x == fld(x, y) * y + mod(x, y)
true

julia> x == (fld1(x, y) - 1) * y + mod1(x, y)
true
source
Base.mod1Function.
mod1(x, y)

Modulus after flooring division, returning a value r such that mod(r, y) == mod(x, y) in the range $(0, y]$ for positive y and in the range $[y,0)$ for negative y.

julia> mod1(4, 2)
2

julia> mod1(4, 3)
1
source
Base.fldmod1Function.
fldmod1(x, y)

Return (fld1(x,y), mod1(x,y)).

See also: fld1, mod1.

source
Base.://Function.
//(num, den)

Divide two integers or rational numbers, giving a Rational result.

julia> 3 // 5
3//5

julia> (3 // 5) // (2 // 1)
3//10
source
Base.rationalizeFunction.
rationalize([T<:Integer=Int,] x; tol::Real=eps(x))

Approximate floating point number x as a Rational number with components of the given integer type. The result will differ from x by no more than tol. If T is not provided, it defaults to Int.

julia> rationalize(5.6)
28//5

julia> a = rationalize(BigInt, 10.3)
103//10

julia> typeof(numerator(a))
BigInt
source
Base.numeratorFunction.
numerator(x)

Numerator of the rational representation of x.

julia> numerator(2//3)
2

julia> numerator(4)
4
source
Base.denominatorFunction.
denominator(x)

Denominator of the rational representation of x.

julia> denominator(2//3)
3

julia> denominator(4)
1
source
Base.:<<Function.
<<(x, n)

Left bit shift operator, x << n. For n >= 0, the result is x shifted left by n bits, filling with 0s. This is equivalent to x * 2^n. For n < 0, this is equivalent to x >> -n.

julia> Int8(3) << 2
12

julia> bits(Int8(3))
"00000011"

julia> bits(Int8(12))
"00001100"

See also >>, >>>.

source
<<(B::BitVector, n) -> BitVector

Left bit shift operator, B << n. For n >= 0, the result is B with elements shifted n positions backwards, filling with false values. If n < 0, elements are shifted forwards. Equivalent to B >> -n.

Examples

julia> B = BitVector([true, false, true, false, false])
5-element BitArray{1}:
  true
 false
  true
 false
 false

julia> B << 1
5-element BitArray{1}:
 false
  true
 false
 false
 false

julia> B << -1
5-element BitArray{1}:
 false
  true
 false
  true
 false
source
Base.:>>Function.
>>(x, n)

Right bit shift operator, x >> n. For n >= 0, the result is x shifted right by n bits, where n >= 0, filling with 0s if x >= 0, 1s if x < 0, preserving the sign of x. This is equivalent to fld(x, 2^n). For n < 0, this is equivalent to x << -n.

julia> Int8(13) >> 2
3

julia> bits(Int8(13))
"00001101"

julia> bits(Int8(3))
"00000011"

julia> Int8(-14) >> 2
-4

julia> bits(Int8(-14))
"11110010"

julia> bits(Int8(-4))
"11111100"

See also >>>, <<.

source
>>(B::BitVector, n) -> BitVector

Right bit shift operator, B >> n. For n >= 0, the result is B with elements shifted n positions forward, filling with false values. If n < 0, elements are shifted backwards. Equivalent to B << -n.

Example

julia> B = BitVector([true, false, true, false, false])
5-element BitArray{1}:
  true
 false
  true
 false
 false

julia> B >> 1
5-element BitArray{1}:
 false
  true
 false
  true
 false

julia> B >> -1
5-element BitArray{1}:
 false
  true
 false
 false
 false
source
Base.:>>>Function.
>>>(x, n)

Unsigned right bit shift operator, x >>> n. For n >= 0, the result is x shifted right by n bits, where n >= 0, filling with 0s. For n < 0, this is equivalent to x << -n.

For Unsigned integer types, this is equivalent to >>. For Signed integer types, this is equivalent to signed(unsigned(x) >> n).

julia> Int8(-14) >>> 2
60

julia> bits(Int8(-14))
"11110010"

julia> bits(Int8(60))
"00111100"

BigInts are treated as if having infinite size, so no filling is required and this is equivalent to >>.

See also >>, <<.

source
>>>(B::BitVector, n) -> BitVector

Unsigned right bitshift operator, B >>> n. Equivalent to B >> n. See >> for details and examples.

source
Base.colonFunction.
colon(start, [step], stop)

Called by : syntax for constructing ranges.

julia> colon(1, 2, 5)
1:2:5
source
:(start, [step], stop)

Range operator. a:b constructs a range from a to b with a step size of 1, and a:s:b is similar but uses a step size of s. These syntaxes call the function colon. The colon is also used in indexing to select whole dimensions.

source
Base.rangeFunction.
range(start, [step], length)

Construct a range by length, given a starting value and optional step (defaults to 1).

source
Base.OneToType.
Base.OneTo(n)

Define an AbstractUnitRange that behaves like 1:n, with the added distinction that the lower limit is guaranteed (by the type system) to be 1.

source
StepRangeLen{T,R,S}(ref::R, step::S, len, [offset=1])

A range r where r[i] produces values of type T, parametrized by a reference value, a step, and the length. By default ref is the starting value r[1], but alternatively you can supply it as the value of r[offset] for some other index 1 <= offset <= len. In conjunction with TwicePrecision this can be used to implement ranges that are free of roundoff error.

source
Base.:==Function.
==(x, y)

Generic equality operator, giving a single Bool result. Falls back to ===. Should be implemented for all types with a notion of equality, based on the abstract value that an instance represents. For example, all numeric types are compared by numeric value, ignoring type. Strings are compared as sequences of characters, ignoring encoding.

Follows IEEE semantics for floating-point numbers.

Collections should generally implement == by calling == recursively on all contents.

New numeric types should implement this function for two arguments of the new type, and handle comparison to other types via promotion rules where possible.

source
Base.:!=Function.
!=(x, y)
≠(x,y)

Not-equals comparison operator. Always gives the opposite answer as ==. New types should generally not implement this, and rely on the fallback definition !=(x,y) = !(x==y) instead.

julia> 3 != 2
true

julia> "foo" ≠ "foo"
false
source
Base.:!==Function.
!==(x, y)
≢(x,y)

Equivalent to !(x === y).

julia> a = [1, 2]; b = [1, 2];

julia> a ≢ b
true

julia> a ≢ a
false
source
Base.:<Function.
<(x, y)

Less-than comparison operator. New numeric types should implement this function for two arguments of the new type. Because of the behavior of floating-point NaN values, < implements a partial order. Types with a canonical partial order should implement <, and types with a canonical total order should implement isless.

julia> 'a' < 'b'
true

julia> "abc" < "abd"
true

julia> 5 < 3
false
source
Base.:<=Function.
<=(x, y)
≤(x,y)

Less-than-or-equals comparison operator.

julia> 'a' <= 'b'
true

julia> 7 ≤ 7 ≤ 9
true

julia> "abc" ≤ "abc"
true

julia> 5 <= 3
false
source
Base.:>Function.
>(x, y)

Greater-than comparison operator. Generally, new types should implement < instead of this function, and rely on the fallback definition >(x, y) = y < x.

julia> 'a' > 'b'
false

julia> 7 > 3 > 1
true

julia> "abc" > "abd"
false

julia> 5 > 3
true
source
Base.:>=Function.
>=(x, y)
≥(x,y)

Greater-than-or-equals comparison operator.

julia> 'a' >= 'b'
false

julia> 7 ≥ 7 ≥ 3
true

julia> "abc" ≥ "abc"
true

julia> 5 >= 3
true
source
Base.cmpFunction.
cmp(x,y)

Return -1, 0, or 1 depending on whether x is less than, equal to, or greater than y, respectively. Uses the total order implemented by isless. For floating-point numbers, uses < but throws an error for unordered arguments.

julia> cmp(1, 2)
-1

julia> cmp(2, 1)
1

julia> cmp(2+im, 3-im)
ERROR: MethodError: no method matching isless(::Complex{Int64}, ::Complex{Int64})
[...]
source
Base.:~Function.
~(x)

Bitwise not.

Examples

julia> ~4
-5

julia> ~10
-11

julia> ~true
false
source
Base.:&Function.
&(x, y)

Bitwise and.

Examples

julia> 4 & 10
0

julia> 4 & 12
4
source
Base.:|Function.
|(x, y)

Bitwise or.

Examples

julia> 4 | 10
14

julia> 4 | 1
5
source
Base.xorFunction.
xor(x, y)
⊻(x, y)

Bitwise exclusive or of x and y. The infix operation a ⊻ b is a synonym for xor(a,b), and can be typed by tab-completing \xor or \veebar in the Julia REPL.

julia> [true; true; false] .⊻ [true; false; false]
3-element BitArray{1}:
 false
  true
 false
source
Base.:!Function.
!(x)

Boolean not.

julia> !true
false

julia> !false
true

julia> .![true false true]
1×3 BitArray{2}:
 false  true  false
source
!f::Function

Predicate function negation: when the argument of ! is a function, it returns a function which computes the boolean negation of f. Example:

julia> str = "∀ ε > 0, ∃ δ > 0: |x-y| < δ ⇒ |f(x)-f(y)| < ε"
"∀ ε > 0, ∃ δ > 0: |x-y| < δ ⇒ |f(x)-f(y)| < ε"

julia> filter(isalpha, str)
"εδxyδfxfyε"

julia> filter(!isalpha, str)
"∀  > 0, ∃  > 0: |-| <  ⇒ |()-()| < "
source
&&Keyword.
x && y

Short-circuiting boolean AND.

source
||Keyword.
x || y

Short-circuiting boolean OR.

source

Mathematical Functions

Base.isapproxFunction.
isapprox(x, y; rtol::Real=sqrt(eps), atol::Real=0, nans::Bool=false, norm::Function)

Inexact equality comparison: true if norm(x-y) <= atol + rtol*max(norm(x), norm(y)). The default atol is zero and the default rtol depends on the types of x and y. The keyword argument nans determines whether or not NaN values are considered equal (defaults to false).

For real or complex floating-point values, rtol defaults to sqrt(eps(typeof(real(x-y)))). This corresponds to requiring equality of about half of the significand digits. For other types, rtol defaults to zero.

x and y may also be arrays of numbers, in which case norm defaults to vecnorm but may be changed by passing a norm::Function keyword argument. (For numbers, norm is the same thing as abs.) When x and y are arrays, if norm(x-y) is not finite (i.e. ±Inf or NaN), the comparison falls back to checking whether all elements of x and y are approximately equal component-wise.

The binary operator is equivalent to isapprox with the default arguments, and x ≉ y is equivalent to !isapprox(x,y).

julia> 0.1 ≈ (0.1 - 1e-10)
true

julia> isapprox(10, 11; atol = 2)
true

julia> isapprox([10.0^9, 1.0], [10.0^9, 2.0])
true
source
Base.sinFunction.
sin(x)

Compute sine of x, where x is in radians.

source
Base.cosFunction.
cos(x)

Compute cosine of x, where x is in radians.

source
Base.tanFunction.
tan(x)

Compute tangent of x, where x is in radians.

source
Base.Math.sindFunction.
sind(x)

Compute sine of x, where x is in degrees.

source
Base.Math.cosdFunction.
cosd(x)

Compute cosine of x, where x is in degrees.

source
Base.Math.tandFunction.
tand(x)

Compute tangent of x, where x is in degrees.

source
Base.Math.sinpiFunction.
sinpi(x)

Compute $\sin(\pi x)$ more accurately than sin(pi*x), especially for large x.

source
Base.Math.cospiFunction.
cospi(x)

Compute $\cos(\pi x)$ more accurately than cos(pi*x), especially for large x.

source
Base.sinhFunction.
sinh(x)

Compute hyperbolic sine of x.

source
Base.coshFunction.
cosh(x)

Compute hyperbolic cosine of x.

source
Base.tanhFunction.
tanh(x)

Compute hyperbolic tangent of x.

source
Base.asinFunction.
asin(x)

Compute the inverse sine of x, where the output is in radians.

source
Base.acosFunction.
acos(x)

Compute the inverse cosine of x, where the output is in radians

source
Base.atanFunction.
atan(x)

Compute the inverse tangent of x, where the output is in radians.

source
Base.Math.atan2Function.
atan2(y, x)

Compute the inverse tangent of y/x, using the signs of both x and y to determine the quadrant of the return value.

source
Base.Math.asindFunction.
asind(x)

Compute the inverse sine of x, where the output is in degrees.

source
Base.Math.acosdFunction.
acosd(x)

Compute the inverse cosine of x, where the output is in degrees.

source
Base.Math.atandFunction.
atand(x)

Compute the inverse tangent of x, where the output is in degrees.

source
Base.Math.secFunction.
sec(x)

Compute the secant of x, where x is in radians.

source
Base.Math.cscFunction.
csc(x)

Compute the cosecant of x, where x is in radians.

source
Base.Math.cotFunction.
cot(x)

Compute the cotangent of x, where x is in radians.

source
Base.Math.secdFunction.
secd(x)

Compute the secant of x, where x is in degrees.

source
Base.Math.cscdFunction.
cscd(x)

Compute the cosecant of x, where x is in degrees.

source
Base.Math.cotdFunction.
cotd(x)

Compute the cotangent of x, where x is in degrees.

source
Base.Math.asecFunction.
asec(x)

Compute the inverse secant of x, where the output is in radians.

source
Base.Math.acscFunction.
acsc(x)

Compute the inverse cosecant of x, where the output is in radians.

source
Base.Math.acotFunction.
acot(x)

Compute the inverse cotangent of x, where the output is in radians.

source
Base.Math.asecdFunction.
asecd(x)

Compute the inverse secant of x, where the output is in degrees.

source
Base.Math.acscdFunction.
acscd(x)

Compute the inverse cosecant of x, where the output is in degrees.

source
Base.Math.acotdFunction.
acotd(x)

Compute the inverse cotangent of x, where the output is in degrees.

source
Base.Math.sechFunction.
sech(x)

Compute the hyperbolic secant of x

source
Base.Math.cschFunction.
csch(x)

Compute the hyperbolic cosecant of x.

source
Base.Math.cothFunction.
coth(x)

Compute the hyperbolic cotangent of x.

source
Base.asinhFunction.
asinh(x)

Compute the inverse hyperbolic sine of x.

source
Base.acoshFunction.
acosh(x)

Compute the inverse hyperbolic cosine of x.

source
Base.atanhFunction.
atanh(x)

Compute the inverse hyperbolic tangent of x.

source
Base.Math.asechFunction.
asech(x)

Compute the inverse hyperbolic secant of x.

source
Base.Math.acschFunction.
acsch(x)

Compute the inverse hyperbolic cosecant of x.

source
Base.Math.acothFunction.
acoth(x)

Compute the inverse hyperbolic cotangent of x.

source
Base.Math.sincFunction.
sinc(x)

Compute $\sin(\pi x) / (\pi x)$ if $x \neq 0$, and $1$ if $x = 0$.

source
Base.Math.coscFunction.
cosc(x)

Compute $\cos(\pi x) / x - \sin(\pi x) / (\pi x^2)$ if $x \neq 0$, and $0$ if $x = 0$. This is the derivative of sinc(x).

source
Base.Math.deg2radFunction.
deg2rad(x)

Convert x from degrees to radians.

julia> deg2rad(90)
1.5707963267948966
source
Base.Math.rad2degFunction.
rad2deg(x)

Convert x from radians to degrees.

julia> rad2deg(pi)
180.0
source
Base.Math.hypotFunction.
hypot(x, y)

Compute the hypotenuse $\sqrt{x^2+y^2}$ avoiding overflow and underflow.

Examples

julia> a = 10^10;

julia> hypot(a, a)
1.4142135623730951e10

julia> √(a^2 + a^2) # a^2 overflows
ERROR: DomainError:
sqrt will only return a complex result if called with a complex argument. Try sqrt(complex(x)).
Stacktrace:
 [1] sqrt(::Int64) at ./math.jl:434
source
hypot(x...)

Compute the hypotenuse $\sqrt{\sum x_i^2}$ avoiding overflow and underflow.

source
Base.logMethod.
log(x)

Compute the natural logarithm of x. Throws DomainError for negative Real arguments. Use complex negative arguments to obtain complex results.

There is an experimental variant in the Base.Math.JuliaLibm module, which is typically faster and more accurate.

source
Base.logMethod.
log(b,x)

Compute the base b logarithm of x. Throws DomainError for negative Real arguments.

julia> log(4,8)
1.5

julia> log(4,2)
0.5
Note

If b is a power of 2 or 10, log2 or log10 should be used, as these will typically be faster and more accurate. For example,

julia> log(100,1000000)
2.9999999999999996

julia> log10(1000000)/2
3.0
source
Base.log2Function.
log2(x)

Compute the logarithm of x to base 2. Throws DomainError for negative Real arguments.

Example

julia> log2(4)
2.0

julia> log2(10)
3.321928094887362
source
Base.log10Function.
log10(x)

Compute the logarithm of x to base 10. Throws DomainError for negative Real arguments.

Example

julia> log10(100)
2.0

julia> log10(2)
0.3010299956639812
source
Base.log1pFunction.
log1p(x)

Accurate natural logarithm of 1+x. Throws DomainError for Real arguments less than -1.

There is an experimental variant in the Base.Math.JuliaLibm module, which is typically faster and more accurate.

Examples

julia> log1p(-0.5)
-0.6931471805599453

julia> log1p(0)
0.0
source
Base.Math.frexpFunction.
frexp(val)

Return (x,exp) such that x has a magnitude in the interval $[1/2, 1)$ or 0, and val is equal to $x \times 2^{exp}$.

source
Base.expFunction.
exp(x)

Compute the natural base exponential of x, in other words $e^x$.

source
Base.exp2Function.
exp2(x)

Compute $2^x$.

julia> exp2(5)
32.0
source
Base.exp10Function.
exp10(x)

Compute $10^x$.

Examples

julia> exp10(2)
100.0

julia> exp10(0.2)
1.5848931924611136
source
Base.Math.ldexpFunction.
ldexp(x, n)

Compute $x \times 2^n$.

Example

julia> ldexp(5., 2)
20.0
source
Base.Math.modfFunction.
modf(x)

Return a tuple (fpart,ipart) of the fractional and integral parts of a number. Both parts have the same sign as the argument.

Example

julia> modf(3.5)
(0.5, 3.0)
source
Base.expm1Function.
expm1(x)

Accurately compute $e^x-1$.

source
Base.roundMethod.
round([T,] x, [digits, [base]], [r::RoundingMode])

Rounds x to an integer value according to the provided RoundingMode, returning a value of the same type as x. When not specifying a rounding mode the global mode will be used (see rounding), which by default is round to the nearest integer (RoundNearest mode), with ties (fractional values of 0.5) being rounded to the nearest even integer.

julia> round(1.7)
2.0

julia> round(1.5)
2.0

julia> round(2.5)
2.0

The optional RoundingMode argument will change how the number gets rounded.

round(T, x, [r::RoundingMode]) converts the result to type T, throwing an InexactError if the value is not representable.

round(x, digits) rounds to the specified number of digits after the decimal place (or before if negative). round(x, digits, base) rounds using a base other than 10.

julia> round(pi, 2)
3.14

julia> round(pi, 3, 2)
3.125
Note

Rounding to specified digits in bases other than 2 can be inexact when operating on binary floating point numbers. For example, the Float64 value represented by 1.15 is actually less than 1.15, yet will be rounded to 1.2.

julia> x = 1.15
1.15

julia> @sprintf "%.20f" x
"1.14999999999999991118"

julia> x < 115//100
true

julia> round(x, 1)
1.2
source
RoundingMode

A type used for controlling the rounding mode of floating point operations (via rounding/setrounding functions), or as optional arguments for rounding to the nearest integer (via the round function).

Currently supported rounding modes are:

source
RoundNearest

The default rounding mode. Rounds to the nearest integer, with ties (fractional values of 0.5) being rounded to the nearest even integer.

source
RoundNearestTiesAway

Rounds to nearest integer, with ties rounded away from zero (C/C++ round behaviour).

source
RoundNearestTiesUp

Rounds to nearest integer, with ties rounded toward positive infinity (Java/JavaScript round behaviour).

source
RoundToZero

round using this rounding mode is an alias for trunc.

source
Base.Rounding.RoundUpConstant.
RoundUp

round using this rounding mode is an alias for ceil.

source
RoundDown

round using this rounding mode is an alias for floor.

source
Base.roundMethod.
round(z, RoundingModeReal, RoundingModeImaginary)

Returns the nearest integral value of the same type as the complex-valued z to z, breaking ties using the specified RoundingModes. The first RoundingMode is used for rounding the real components while the second is used for rounding the imaginary components.

source
Base.ceilFunction.
ceil([T,] x, [digits, [base]])

ceil(x) returns the nearest integral value of the same type as x that is greater than or equal to x.

ceil(T, x) converts the result to type T, throwing an InexactError if the value is not representable.

digits and base work as for round.

source
Base.floorFunction.
floor([T,] x, [digits, [base]])

floor(x) returns the nearest integral value of the same type as x that is less than or equal to x.

floor(T, x) converts the result to type T, throwing an InexactError if the value is not representable.

digits and base work as for round.

source
Base.truncFunction.
trunc([T,] x, [digits, [base]])

trunc(x) returns the nearest integral value of the same type as x whose absolute value is less than or equal to x.

trunc(T, x) converts the result to type T, throwing an InexactError if the value is not representable.

digits and base work as for round.

source
Base.unsafe_truncFunction.
unsafe_trunc(T, x)

unsafe_trunc(T, x) returns the nearest integral value of type T whose absolute value is less than or equal to x. If the value is not representable by T, an arbitrary value will be returned.

source
Base.signifFunction.
signif(x, digits, [base])

Rounds (in the sense of round) x so that there are digits significant digits, under a base base representation, default 10. E.g., signif(123.456, 2) is 120.0, and signif(357.913, 4, 2) is 352.0.

source
Base.minFunction.
min(x, y, ...)

Return the minimum of the arguments. See also the minimum function to take the minimum element from a collection.

julia> min(2, 5, 1)
1
source
Base.maxFunction.
max(x, y, ...)

Return the maximum of the arguments. See also the maximum function to take the maximum element from a collection.

julia> max(2, 5, 1)
5
source
Base.minmaxFunction.
minmax(x, y)

Return (min(x,y), max(x,y)). See also: extrema that returns (minimum(x), maximum(x)).

julia> minmax('c','b')
('b', 'c')
source
Base.Math.clampFunction.
clamp(x, lo, hi)

Return x if lo <= x <= hi. If x < lo, return lo. If x > hi, return hi. Arguments are promoted to a common type.

julia> clamp.([pi, 1.0, big(10.)], 2., 9.)
3-element Array{BigFloat,1}:
 3.141592653589793238462643383279502884197169399375105820974944592307816406286198
 2.000000000000000000000000000000000000000000000000000000000000000000000000000000
 9.000000000000000000000000000000000000000000000000000000000000000000000000000000
source
Base.Math.clamp!Function.
clamp!(array::AbstractArray, lo, hi)

Restrict values in array to the specified range, in-place. See also clamp.

source
Base.absFunction.
abs(x)

The absolute value of x.

When abs is applied to signed integers, overflow may occur, resulting in the return of a negative value. This overflow occurs only when abs is applied to the minimum representable value of a signed integer. That is, when x == typemin(typeof(x)), abs(x) == x < 0, not -x as might be expected.

julia> abs(-3)
3

julia> abs(1 + im)
1.4142135623730951

julia> abs(typemin(Int64))
-9223372036854775808
source
Base.checked_abs(x)

Calculates abs(x), checking for overflow errors where applicable. For example, standard two's complement signed integers (e.g. Int) cannot represent abs(typemin(Int)), thus leading to an overflow.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_neg(x)

Calculates -x, checking for overflow errors where applicable. For example, standard two's complement signed integers (e.g. Int) cannot represent -typemin(Int), thus leading to an overflow.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_add(x, y)

Calculates x+y, checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_sub(x, y)

Calculates x-y, checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_mul(x, y)

Calculates x*y, checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_div(x, y)

Calculates div(x,y), checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_rem(x, y)

Calculates x%y, checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_fld(x, y)

Calculates fld(x,y), checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_mod(x, y)

Calculates mod(x,y), checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.checked_cld(x, y)

Calculates cld(x,y), checking for overflow errors where applicable.

The overflow protection may impose a perceptible performance penalty.

source
Base.add_with_overflow(x, y) -> (r, f)

Calculates r = x+y, with the flag f indicating whether overflow has occurred.

source
Base.sub_with_overflow(x, y) -> (r, f)

Calculates r = x-y, with the flag f indicating whether overflow has occurred.

source
Base.mul_with_overflow(x, y) -> (r, f)

Calculates r = x*y, with the flag f indicating whether overflow has occurred.

source
Base.abs2Function.
abs2(x)

Squared absolute value of x.

julia> abs2(-3)
9
source
Base.copysignFunction.
copysign(x, y) -> z

Return z which has the magnitude of x and the same sign as y.

Examples

julia> copysign(1, -2)
-1

julia> copysign(-1, 2)
1
source
Base.signFunction.
sign(x)

Return zero if x==0 and $x/|x|$ otherwise (i.e., ±1 for real x).

source
Base.signbitFunction.
signbit(x)

Returns true if the value of the sign of x is negative, otherwise false.

Examples

julia> signbit(-4)
true

julia> signbit(5)
false

julia> signbit(5.5)
false

julia> signbit(-4.1)
true
source
Base.flipsignFunction.
flipsign(x, y)

Return x with its sign flipped if y is negative. For example abs(x) = flipsign(x,x).

julia> flipsign(5, 3)
5

julia> flipsign(5, -3)
-5
source
Base.sqrtFunction.
sqrt(x)

Return $\sqrt{x}$. Throws DomainError for negative Real arguments. Use complex negative arguments instead. The prefix operator is equivalent to sqrt.

source
Base.isqrtFunction.
isqrt(n::Integer)

Integer square root: the largest integer m such that m*m <= n.

julia> isqrt(5)
2
source
Base.Math.cbrtFunction.
cbrt(x::Real)

Return the cube root of x, i.e. $x^{1/3}$. Negative values are accepted (returning the negative real root when $x < 0$).

The prefix operator is equivalent to cbrt.

julia> cbrt(big(27))
3.000000000000000000000000000000000000000000000000000000000000000000000000000000
source
Base.realMethod.
real(z)

Return the real part of the complex number z.

julia> real(1 + 3im)
1
source
Base.imagFunction.
imag(z)

Return the imaginary part of the complex number z.

julia> imag(1 + 3im)
3
source
Base.reimFunction.
reim(z)

Return both the real and imaginary parts of the complex number z.

julia> reim(1 + 3im)
(1, 3)
source
Base.conjFunction.
conj(v::RowVector)

Returns a ConjArray lazy view of the input, where each element is conjugated.

Example

julia> v = [1+im, 1-im].'
1×2 RowVector{Complex{Int64},Array{Complex{Int64},1}}:
 1+1im  1-1im

julia> conj(v)
1×2 RowVector{Complex{Int64},ConjArray{Complex{Int64},1,Array{Complex{Int64},1}}}:
 1-1im  1+1im
source
conj(z)

Compute the complex conjugate of a complex number z.

julia> conj(1 + 3im)
1 - 3im
source
Base.angleFunction.
angle(z)

Compute the phase angle in radians of a complex number z.

source
Base.cisFunction.
cis(z)

Return $\exp(iz)$.

source
Base.binomialFunction.
binomial(n, k)

Number of ways to choose k out of n items.

Example

julia> binomial(5, 3)
10

julia> factorial(5) ÷ (factorial(5-3) * factorial(3))
10
source
Base.factorialFunction.
factorial(n)

Factorial of n. If n is an Integer, the factorial is computed as an integer (promoted to at least 64 bits). Note that this may overflow if n is not small, but you can use factorial(big(n)) to compute the result exactly in arbitrary precision. If n is not an Integer, factorial(n) is equivalent to gamma(n+1).

julia> factorial(6)
720

julia> factorial(21)
ERROR: OverflowError()
[...]

julia> factorial(21.0)
5.109094217170944e19

julia> factorial(big(21))
51090942171709440000
source
Base.gcdFunction.
gcd(x,y)

Greatest common (positive) divisor (or zero if x and y are both zero).

Examples

julia> gcd(6,9)
3

julia> gcd(6,-9)
3
source
Base.lcmFunction.
lcm(x,y)

Least common (non-negative) multiple.

Examples

julia> lcm(2,3)
6

julia> lcm(-2,3)
6
source
Base.gcdxFunction.
gcdx(x,y)

Computes the greatest common (positive) divisor of x and y and their Bézout coefficients, i.e. the integer coefficients u and v that satisfy $ux+vy = d = gcd(x,y)$. $gcdx(x,y)$ returns $(d,u,v)$.

Examples

julia> gcdx(12, 42)
(6, -3, 1)

julia> gcdx(240, 46)
(2, -9, 47)
Note

Bézout coefficients are not uniquely defined. gcdx returns the minimal Bézout coefficients that are computed by the extended Euclidean algorithm. (Ref: D. Knuth, TAoCP, 2/e, p. 325, Algorithm X.) For signed integers, these coefficients u and v are minimal in the sense that $|u| < |y/d|$ and $|v| < |x/d|$. Furthermore, the signs of u and v are chosen so that d is positive. For unsigned integers, the coefficients u and v might be near their typemax, and the identity then holds only via the unsigned integers' modulo arithmetic.

source
Base.ispow2Function.
ispow2(n::Integer) -> Bool

Test whether n is a power of two.

Examples

julia> ispow2(4)
true

julia> ispow2(5)
false
source
Base.nextpow2Function.
nextpow2(n::Integer)

The smallest power of two not less than n. Returns 0 for n==0, and returns -nextpow2(-n) for negative arguments.

Examples

julia> nextpow2(16)
16

julia> nextpow2(17)
32
source
Base.prevpow2Function.
prevpow2(n::Integer)

The largest power of two not greater than n. Returns 0 for n==0, and returns -prevpow2(-n) for negative arguments.

Examples

julia> prevpow2(5)
4

julia> prevpow2(0)
0
source
Base.nextpowFunction.
nextpow(a, x)

The smallest a^n not less than x, where n is a non-negative integer. a must be greater than 1, and x must be greater than 0.

Examples

julia> nextpow(2, 7)
8

julia> nextpow(2, 9)
16

julia> nextpow(5, 20)
25

julia> nextpow(4, 16)
16

See also prevpow.

source
Base.prevpowFunction.
prevpow(a, x)

The largest a^n not greater than x, where n is a non-negative integer. a must be greater than 1, and x must not be less than 1.

Examples

julia> prevpow(2, 7)
4

julia> prevpow(2, 9)
8

julia> prevpow(5, 20)
5

julia> prevpow(4, 16)
16

See also nextpow.

source
Base.nextprodFunction.
nextprod([k_1, k_2,...], n)

Next integer greater than or equal to n that can be written as $\prod k_i^{p_i}$ for integers $p_1$, $p_2$, etc.

Example

julia> nextprod([2, 3], 105)
108

julia> 2^2 * 3^3
108
source
Base.invmodFunction.
invmod(x,m)

Take the inverse of x modulo m: y such that $x y = 1 \pmod m$, with $div(x,y) = 0$. This is undefined for $m = 0$, or if $gcd(x,m) \neq 1$.

Examples

julia> invmod(2,5)
3

julia> invmod(2,3)
2

julia> invmod(5,6)
5
source
Base.powermodFunction.
powermod(x::Integer, p::Integer, m)

Compute $x^p \pmod m$.

Examples

julia> powermod(2, 6, 5)
4

julia> mod(2^6, 5)
4

julia> powermod(5, 2, 20)
5

julia> powermod(5, 2, 19)
6

julia> powermod(5, 3, 19)
11
source
Base.Math.gammaFunction.
gamma(x)

Compute the gamma function of x.

source
Base.Math.lgammaFunction.
lgamma(x)

Compute the logarithm of the absolute value of gamma for Real x, while for Complex x compute the principal branch cut of the logarithm of gamma(x) (defined for negative real(x) by analytic continuation from positive real(x)).

source
Base.Math.lfactFunction.
lfact(x)

Compute the logarithmic factorial of a nonnegative integer x. Equivalent to lgamma of x + 1, but lgamma extends this function to non-integer x.

source
Base.Math.betaFunction.
beta(x, y)

Euler integral of the first kind $\operatorname{B}(x,y) = \Gamma(x)\Gamma(y)/\Gamma(x+y)$.

source
Base.Math.lbetaFunction.
lbeta(x, y)

Natural logarithm of the absolute value of the beta function $\log(|\operatorname{B}(x,y)|)$.

source
Base.ndigitsFunction.
ndigits(n::Integer, b::Integer=10)

Compute the number of digits in integer n written in base b. The base b must not be in [-1, 0, 1].

Examples

julia> ndigits(12345)
5

julia> ndigits(1022, 16)
3

julia> base(16, 1022)
"3fe"
source
Base.widemulFunction.
widemul(x, y)

Multiply x and y, giving the result as a larger type.

julia> widemul(Float32(3.), 4.)
1.200000000000000000000000000000000000000000000000000000000000000000000000000000e+01
source
@evalpoly(z, c...)

Evaluate the polynomial $\sum_k c[k] z^{k-1}$ for the coefficients c[1], c[2], ...; that is, the coefficients are given in ascending order by power of z. This macro expands to efficient inline code that uses either Horner's method or, for complex z, a more efficient Goertzel-like algorithm.

julia> @evalpoly(3, 1, 0, 1)
10

julia> @evalpoly(2, 1, 0, 1)
5

julia> @evalpoly(2, 1, 1, 1)
7
source

Statistics

Base.meanFunction.
mean(f::Function, v)

Apply the function f to each element of v and take the mean.

julia> mean(√, [1, 2, 3])
1.3820881233139908

julia> mean([√1, √2, √3])
1.3820881233139908
source
mean(v[, region])

Compute the mean of whole array v, or optionally along the dimensions in region.

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.mean!Function.
mean!(r, v)

Compute the mean of v over the singleton dimensions of r, and write results to r.

source
Base.stdFunction.
std(v[, region]; corrected::Bool=true, mean=nothing)

Compute the sample standard deviation of a vector or array v, optionally along dimensions in region. The algorithm returns an estimator of the generative distribution's standard deviation under the assumption that each entry of v is an IID drawn from that generative distribution. This computation is equivalent to calculating sqrt(sum((v - mean(v)).^2) / (length(v) - 1)). A pre-computed mean may be provided. If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = length(x).

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.stdmFunction.
stdm(v, m::Number; corrected::Bool=true)

Compute the sample standard deviation of a vector v with known mean m. If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = length(x).

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.varFunction.
var(v[, region]; corrected::Bool=true, mean=nothing)

Compute the sample variance of a vector or array v, optionally along dimensions in region. The algorithm will return an estimator of the generative distribution's variance under the assumption that each entry of v is an IID drawn from that generative distribution. This computation is equivalent to calculating sum(abs2, v - mean(v)) / (length(v) - 1). If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = length(x). The mean mean over the region may be provided.

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.varmFunction.
varm(v, m[, region]; corrected::Bool=true)

Compute the sample variance of a collection v with known mean(s) m, optionally over region. m may contain means for each dimension of v. If corrected is true, then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = length(x).

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.middleFunction.
middle(x)

Compute the middle of a scalar value, which is equivalent to x itself, but of the type of middle(x, x) for consistency.

source
middle(x, y)

Compute the middle of two reals x and y, which is equivalent in both value and type to computing their mean ((x + y) / 2).

source
middle(range)

Compute the middle of a range, which consists of computing the mean of its extrema. Since a range is sorted, the mean is performed with the first and last element.

julia> middle(1:10)
5.5
source
middle(a)

Compute the middle of an array a, which consists of finding its extrema and then computing their mean.

julia> a = [1,2,3.6,10.9]
4-element Array{Float64,1}:
  1.0
  2.0
  3.6
 10.9

julia> middle(a)
5.95
source
Base.medianFunction.
median(v[, region])

Compute the median of an entire array v, or, optionally, along the dimensions in region. For an even number of elements no exact median element exists, so the result is equivalent to calculating mean of two median elements.

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended.

source
Base.median!Function.
median!(v)

Like median, but may overwrite the input vector.

source
Base.quantileFunction.
quantile(v, p; sorted=false)

Compute the quantile(s) of a vector v at a specified probability or vector p. The keyword argument sorted indicates whether v can be assumed to be sorted.

The p should be on the interval [0,1], and v should not have any NaN values.

Quantiles are computed via linear interpolation between the points ((k-1)/(n-1), v[k]), for k = 1:n where n = length(v). This corresponds to Definition 7 of Hyndman and Fan (1996), and is the same as the R default.

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended. quantile will throw an ArgumentError in the presence of NaN values in the data array.

  • Hyndman, R.J and Fan, Y. (1996) "Sample Quantiles in Statistical Packages", The American Statistician, Vol. 50, No. 4, pp. 361-365

source
Base.quantile!Function.
quantile!([q, ] v, p; sorted=false)

Compute the quantile(s) of a vector v at the probabilities p, with optional output into array q (if not provided, a new output array is created). The keyword argument sorted indicates whether v can be assumed to be sorted; if false (the default), then the elements of v may be partially sorted.

The elements of p should be on the interval [0,1], and v should not have any NaN values.

Quantiles are computed via linear interpolation between the points ((k-1)/(n-1), v[k]), for k = 1:n where n = length(v). This corresponds to Definition 7 of Hyndman and Fan (1996), and is the same as the R default.

Note

Julia does not ignore NaN values in the computation. For applications requiring the handling of missing data, the DataArrays.jl package is recommended. quantile! will throw an ArgumentError in the presence of NaN values in the data array.

  • Hyndman, R.J and Fan, Y. (1996) "Sample Quantiles in Statistical Packages", The American Statistician, Vol. 50, No. 4, pp. 361-365

source
Base.covFunction.
cov(x[, corrected=true])

Compute the variance of the vector x. If corrected is true (the default) then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = length(x).

source
cov(X[, vardim=1, corrected=true])

Compute the covariance matrix of the matrix X along the dimension vardim. If corrected is true (the default) then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = size(X, vardim).

source
cov(x, y[, corrected=true])

Compute the covariance between the vectors x and y. If corrected is true (the default), computes $\frac{1}{n-1}\sum_{i=1}^n (x_i-\bar x) (y_i-\bar y)^*$ where $*$ denotes the complex conjugate and n = length(x) = length(y). If corrected is false, computes $rac{1}{n}sum_{i=1}^n (x_i-\bar x) (y_i-\bar y)^*$.

source
cov(X, Y[, vardim=1, corrected=true])

Compute the covariance between the vectors or matrices X and Y along the dimension vardim. If corrected is true (the default) then the sum is scaled with n-1, whereas the sum is scaled with n if corrected is false where n = size(X, vardim) = size(Y, vardim).

source
Base.corFunction.
cor(x)

Return the number one.

source
cor(X[, vardim=1])

Compute the Pearson correlation matrix of the matrix X along the dimension vardim.

source
cor(x, y)

Compute the Pearson correlation between the vectors x and y.

source
cor(X, Y[, vardim=1])

Compute the Pearson correlation between the vectors or matrices X and Y along the dimension vardim.

source

Signal Processing

Fast Fourier transform (FFT) functions in Julia are implemented by calling functions from FFTW.

Base.DFT.fftFunction.
fft(A [, dims])

Performs a multidimensional FFT of the array A. The optional dims argument specifies an iterable subset of dimensions (e.g. an integer, range, tuple, or array) to transform along. Most efficient if the size of A along the transformed dimensions is a product of small primes; see nextprod(). See also plan_fft() for even greater efficiency.

A one-dimensional FFT computes the one-dimensional discrete Fourier transform (DFT) as defined by

\[\operatorname{DFT}(A)[k] = \sum_{n=1}^{\operatorname{length}(A)} \exp\left(-i\frac{2\pi (n-1)(k-1)}{\operatorname{length}(A)} \right) A[n].\]

A multidimensional FFT simply performs this operation along each transformed dimension of A.

Note
  • Julia starts FFTW up with 1 thread by default. Higher performance is usually possible by increasing number of threads. Use FFTW.set_num_threads(Sys.CPU_CORES) to use as many threads as cores on your system.

  • This performs a multidimensional FFT by default. FFT libraries in other languages such as Python and Octave perform a one-dimensional FFT along the first non-singleton dimension of the array. This is worth noting while performing comparisons. For more details, refer to the Noteworthy Differences from other Languages section of the manual.

source
Base.DFT.fft!Function.
fft!(A [, dims])

Same as fft, but operates in-place on A, which must be an array of complex floating-point numbers.

source
Base.DFT.ifftFunction.
ifft(A [, dims])

Multidimensional inverse FFT.

A one-dimensional inverse FFT computes

\[\operatorname{IDFT}(A)[k] = \frac{1}{\operatorname{length}(A)} \sum_{n=1}^{\operatorname{length}(A)} \exp\left(+i\frac{2\pi (n-1)(k-1)} {\operatorname{length}(A)} \right) A[n].\]

A multidimensional inverse FFT simply performs this operation along each transformed dimension of A.

source
Base.DFT.ifft!Function.
ifft!(A [, dims])

Same as ifft, but operates in-place on A.

source
Base.DFT.bfftFunction.
bfft(A [, dims])

Similar to ifft, but computes an unnormalized inverse (backward) transform, which must be divided by the product of the sizes of the transformed dimensions in order to obtain the inverse. (This is slightly more efficient than ifft because it omits a scaling step, which in some applications can be combined with other computational steps elsewhere.)

\[\operatorname{BDFT}(A)[k] = \operatorname{length}(A) \operatorname{IDFT}(A)[k]\]
source
Base.DFT.bfft!Function.
bfft!(A [, dims])

Same as bfft, but operates in-place on A.

source
Base.DFT.plan_fftFunction.
plan_fft(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Pre-plan an optimized FFT along given dimensions (dims) of arrays matching the shape and type of A. (The first two arguments have the same meaning as for fft.) Returns an object P which represents the linear operator computed by the FFT, and which contains all of the information needed to compute fft(A, dims) quickly.

To apply P to an array A, use P * A; in general, the syntax for applying plans is much like that of matrices. (A plan can only be applied to arrays of the same size as the A for which the plan was created.) You can also apply a plan with a preallocated output array  by calling A_mul_B!(Â, plan, A). (For A_mul_B!, however, the input array A must be a complex floating-point array like the output Â.) You can compute the inverse-transform plan by inv(P) and apply the inverse plan with P \  (the inverse plan is cached and reused for subsequent calls to inv or \), and apply the inverse plan to a pre-allocated output array A with A_ldiv_B!(A, P, Â).

The flags argument is a bitwise-or of FFTW planner flags, defaulting to FFTW.ESTIMATE. e.g. passing FFTW.MEASURE or FFTW.PATIENT will instead spend several seconds (or more) benchmarking different possible FFT algorithms and picking the fastest one; see the FFTW manual for more information on planner flags. The optional timelimit argument specifies a rough upper bound on the allowed planning time, in seconds. Passing FFTW.MEASURE or FFTW.PATIENT may cause the input array A to be overwritten with zeros during plan creation.

plan_fft! is the same as plan_fft but creates a plan that operates in-place on its argument (which must be an array of complex floating-point numbers). plan_ifft and so on are similar but produce plans that perform the equivalent of the inverse transforms ifft and so on.

source
Base.DFT.plan_ifftFunction.
plan_ifft(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Same as plan_fft, but produces a plan that performs inverse transforms ifft.

source
Base.DFT.plan_bfftFunction.
plan_bfft(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Same as plan_fft, but produces a plan that performs an unnormalized backwards transform bfft.

source
Base.DFT.plan_fft!Function.
plan_fft!(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Same as plan_fft, but operates in-place on A.

source
Base.DFT.plan_ifft!Function.
plan_ifft!(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Same as plan_ifft, but operates in-place on A.

source
Base.DFT.plan_bfft!Function.
plan_bfft!(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Same as plan_bfft, but operates in-place on A.

source
Base.DFT.rfftFunction.
rfft(A [, dims])

Multidimensional FFT of a real array A, exploiting the fact that the transform has conjugate symmetry in order to save roughly half the computational time and storage costs compared with fft. If A has size (n_1, ..., n_d), the result has size (div(n_1,2)+1, ..., n_d).

The optional dims argument specifies an iterable subset of one or more dimensions of A to transform, similar to fft. Instead of (roughly) halving the first dimension of A in the result, the dims[1] dimension is (roughly) halved in the same way.

source
Base.DFT.irfftFunction.
irfft(A, d [, dims])

Inverse of rfft: for a complex array A, gives the corresponding real array whose FFT yields A in the first half. As for rfft, dims is an optional subset of dimensions to transform, defaulting to 1:ndims(A).

d is the length of the transformed real array along the dims[1] dimension, which must satisfy div(d,2)+1 == size(A,dims[1]). (This parameter cannot be inferred from size(A) since both 2*size(A,dims[1])-2 as well as 2*size(A,dims[1])-1 are valid sizes for the transformed real array.)

source
Base.DFT.brfftFunction.
brfft(A, d [, dims])

Similar to irfft but computes an unnormalized inverse transform (similar to bfft), which must be divided by the product of the sizes of the transformed dimensions (of the real output array) in order to obtain the inverse transform.

source
Base.DFT.plan_rfftFunction.
plan_rfft(A [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Pre-plan an optimized real-input FFT, similar to plan_fft except for rfft instead of fft. The first two arguments, and the size of the transformed result, are the same as for rfft.

source
Base.DFT.plan_brfftFunction.
plan_brfft(A, d [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Pre-plan an optimized real-input unnormalized transform, similar to plan_rfft except for brfft instead of rfft. The first two arguments and the size of the transformed result, are the same as for brfft.

source
Base.DFT.plan_irfftFunction.
plan_irfft(A, d [, dims]; flags=FFTW.ESTIMATE;  timelimit=Inf)

Pre-plan an optimized inverse real-input FFT, similar to plan_rfft except for irfft and brfft, respectively. The first three arguments have the same meaning as for irfft.

source
Base.DFT.FFTW.dctFunction.
dct(A [, dims])

Performs a multidimensional type-II discrete cosine transform (DCT) of the array A, using the unitary normalization of the DCT. The optional dims argument specifies an iterable subset of dimensions (e.g. an integer, range, tuple, or array) to transform along. Most efficient if the size of A along the transformed dimensions is a product of small primes; see nextprod. See also plan_dct for even greater efficiency.

source
Base.DFT.FFTW.dct!Function.
dct!(A [, dims])

Same as dct!, except that it operates in-place on A, which must be an array of real or complex floating-point values.

source
Base.DFT.FFTW.idctFunction.
idct(A [, dims])

Computes the multidimensional inverse discrete cosine transform (DCT) of the array A (technically, a type-III DCT with the unitary normalization). The optional dims argument specifies an iterable subset of dimensions (e.g. an integer, range, tuple, or array) to transform along. Most efficient if the size of A along the transformed dimensions is a product of small primes; see nextprod. See also plan_idct for even greater efficiency.

source
Base.DFT.FFTW.idct!Function.
idct!(A [, dims])

Same as idct!, but operates in-place on A.

source
plan_dct(A [, dims [, flags [, timelimit]]])

Pre-plan an optimized discrete cosine transform (DCT), similar to plan_fft except producing a function that computes dct. The first two arguments have the same meaning as for dct.

source
plan_dct!(A [, dims [, flags [, timelimit]]])

Same as plan_dct, but operates in-place on A.

source
plan_idct(A [, dims [, flags [, timelimit]]])

Pre-plan an optimized inverse discrete cosine transform (DCT), similar to plan_fft except producing a function that computes idct. The first two arguments have the same meaning as for idct.

source
plan_idct!(A [, dims [, flags [, timelimit]]])

Same as plan_idct, but operates in-place on A.

source
Base.DFT.fftshiftMethod.
fftshift(x)

Swap the first and second halves of each dimension of x.

source
Base.DFT.fftshiftMethod.
fftshift(x,dim)

Swap the first and second halves of the given dimension or iterable of dimensions of array x.

source
Base.DFT.ifftshiftFunction.
ifftshift(x, [dim])

Undoes the effect of fftshift.

source
Base.DSP.filtFunction.
filt(b, a, x, [si])

Apply filter described by vectors a and b to vector x, with an optional initial filter state vector si (defaults to zeros).

source
Base.DSP.filt!Function.
filt!(out, b, a, x, [si])

Same as filt but writes the result into the out argument, which may alias the input x to modify it in-place.

source
Base.DSP.deconvFunction.
deconv(b,a) -> c

Construct vector c such that b = conv(a,c) + r. Equivalent to polynomial division.

source
Base.DSP.convFunction.
conv(u,v)

Convolution of two vectors. Uses FFT algorithm.

source
Base.DSP.conv2Function.
conv2(u,v,A)

2-D convolution of the matrix A with the 2-D separable kernel generated by the vectors u and v. Uses 2-D FFT algorithm.

source
conv2(B,A)

2-D convolution of the matrix B with the matrix A. Uses 2-D FFT algorithm.

source
Base.DSP.xcorrFunction.
xcorr(u,v)

Compute the cross-correlation of two vectors.

source

The following functions are defined within the Base.FFTW module.

Base.DFT.FFTW.r2rFunction.
r2r(A, kind [, dims])

Performs a multidimensional real-input/real-output (r2r) transform of type kind of the array A, as defined in the FFTW manual. kind specifies either a discrete cosine transform of various types (FFTW.REDFT00, FFTW.REDFT01, FFTW.REDFT10, or FFTW.REDFT11), a discrete sine transform of various types (FFTW.RODFT00, FFTW.RODFT01, FFTW.RODFT10, or FFTW.RODFT11), a real-input DFT with halfcomplex-format output (FFTW.R2HC and its inverse FFTW.HC2R), or a discrete Hartley transform (FFTW.DHT). The kind argument may be an array or tuple in order to specify different transform types along the different dimensions of A; kind[end] is used for any unspecified dimensions. See the FFTW manual for precise definitions of these transform types, at http://www.fftw.org/doc.

The optional dims argument specifies an iterable subset of dimensions (e.g. an integer, range, tuple, or array) to transform along. kind[i] is then the transform type for dims[i], with kind[end] being used for i > length(kind).

See also plan_r2r to pre-plan optimized r2r transforms.

source
Base.DFT.FFTW.r2r!Function.
r2r!(A, kind [, dims])

Same as r2r, but operates in-place on A, which must be an array of real or complex floating-point numbers.

source
plan_r2r(A, kind [, dims [, flags [, timelimit]]])

Pre-plan an optimized r2r transform, similar to plan_fft except that the transforms (and the first three arguments) correspond to r2r and r2r!, respectively.

source
plan_r2r!(A, kind [, dims [, flags [, timelimit]]])

Similar to plan_fft, but corresponds to r2r!.

source