Builtin Functions

Constants

iImaginary unit: i² = -1
pi, πSmallest positive zero of sin(x).
eEuler's number
eulergammaEuler-Mascheroni constant
°π/180, so 360° = 360 * ° = 2π
NANUndefined value. f(NAN) = NAN.
const Physical constants. Use either const(name) or const_name with any of these (names are case-insensitive):
NameValueUnitDescription
Avogadro6.022…e23mol⁻¹particles per mole
c0, c2.997…e8m s⁻¹speed of light
G6.673…e-11kg⁻¹ m³ s⁻²gravitation constant
h6.626…e-34J sPlanck's constant
ℏ, hbar1.054…e-34J sconst_h / 2π
µ01.256…N A⁻²magnetic constant
eps08.854…e-12F m⁻¹electric constant
alpha7.297…e-3fine-structure constant
e1.602…e-19A selementary charge
lP1.616…e-35mPlanck length
mP2.176…e-8kgPlanck mass
tP5.391…e-44sPlanck time
qP1.875…e-18A sPlanck charge
TP1.416…e32KPlanck temperature

Operators and precedence

Operators
ordered by
precedence
MeaningAssociativityExamples
( ), [ ], { }Grouping (see below)-
|•|Absolute value-|z| = abs(z)
•! •²…•⁹Postfix operators (factorial, powers)-x^3! = x^(3!) = x^6
Function call-sinx² = sin(x²), also sin(x)² = sin(x²), but (sinx)² = (sin(x))²
-• ~•Prefix operators (Negation, complex conjugation)--x² = -(x²)
Implicit Multiplicationleftab^cd = (ab)^(cd), abc = (ab)c, sinxy = (sinx)*y, xx² = x^3, not x^4
^ **Exponentiationrighta^b^c = a^(b^c)
* / %Multiplication, Division, Modulus (only defined for real numbers: a % b = a-b*floor(a/b). The result is always between 0 and b)lefta/b/c = (a/b)/c = a/(bc), a*b^c*d = a*(b^c)*d
+ -Addition, Subtractionlefta-b-c = (a-b)-c = a-(b+c)
and, or, xorBinary AND, OR, XOR (see bit function)left-(a and b) = -a or -b, a xor b = -a xor -b
< >Comparison - only defined for real numbers: a > b := 1 if a > b, else 0-(a < b) * (b < c) is a < b < c
Sets can be plotted like this:
sin xx - sin yy > 0.
Whitespace (grouping)-see below

Functions

Simple & Polynomials
reReal part: re(a+ib) = a
imImaginary part: im(a+ib) = b
absMagnitude/absolute value. Can also be written as |z|.
absqSquared magnitude: absq(z) := abs(z)^2 (but faster).
argArgument function, arg(z) is the angle between the positive real axis and the connection line from 0 to z. In the range [-π,π).
arg(x, y) := arg(x+iy).
sgnSign function: sgn(z) = z / |z| or 0 if z = 0
conjComplex conjugation, same as ~z.
complexcomplex(x,y) = x+iy.
hypothypot(z,w) = sqrt(z²+w²)
sqrsqr(z) = z²
√, sqrtSquare root, branch cut along the negative real axis.
clampclamp(x, a, b) restricts x to [min(a,b), max(a,b)]. clamp(x) = clamp(x,0,1).
clamp(z, a, b) = clamp(re z, re a, re b) + i clamp(im z, im a, im b) for complex z, a, b.
clamp(z) = clamp(z, 0, 1+i) = clamp(re z) + i clamp(im z).
Invariant under permutation: clamp(a,b,c) = clamp(b,c,a) = clamp(c,b,a) = ...
clamp(∞,x,y) = max(x,y), clamp(-∞,x,y) = min(x,y)
clamp(x,x,y) = x, a ≤ b ≤ c ⇒ clamp(a,b,c) = b
detdet(a+ib, c+id) = ad-bc
spsp(a+ib, c+id) = ac+bd
swapswap(a+ib) = b+ia
midaArithmetic mean: mida(z,w) = (z+w)/2
midgGeometric mean: midg(z,w) = √(z*w)
midhHarmonic mean: midh(z,w) = 2zw / (z+w)
Min/Max Variations
min, maxMinimum/Maximum. Only defined for real numbers: min(a,b) := a if a < b, else b
absmin, absmaxReturns the number with the smaller/larger absolute value: absmin(z, w) := z if |z| < |w|, else w
realmin, realmaxReturns the number with the smaller/larger real part
imagmin, imagmaxReturns the number with the smaller/larger imaginary part
Exponential
expe^z (but exp(z) is a little faster and slightly more precise)
ln, logNatural logarithm. Inverse of exp with branch cut along the negative real axis.
log2Binary logarithm: log2(z) = log(z) / log(2)
log10Decadic logarithm: log10(z) = log(z) / log(10)
spowspow(x,y) = |x|^y * sgn(x)
Trigonometric
sin, cosSine and Cosine
tanTangent function: tan(z) = sin(z) / cos(z)
secSecant: sec(z) = 1 / cos(z)
cscCosecant: csc(z) = 1 / sin(z)
cotCotangent: cot(z) = 1 / tan(z) = cos(z) / sin(z)
sinhHyperbolic sine
coshHyperbolic cosine
tanhHyperbolic tangent: tanh(z) = sinh(z) / cosh(z)
sechHyperbolic secant: sech(z) = 1 / cosh(z)
cschHyperbolic cosecant: csch(z) = 1 / sinh(z)
cothHyperbolic cotangent: coth(z) = 1 / tanh(z) = cosh(z) / sinh(z)
arcsin, arccosInverse of sin and cos.
arctanInverse of tan(z)
arcsecInverse of sec(z), arcsec(z) = arccos(1/z)
arccscInverse of csc(z), arccsc(z) = arcsin(1/z)
arccotInverse of cot(z), arccot(z) = arctan(1/z)
arsinh, arcosh, artanh, arsech, arcsch, arcothInverse hyperbolic functions
Gamma
gamma, ΓGamma function
factorialfactorial(z) = z! = gamma(z+1)
betaBeta function: beta(a,b) = Γ(a)Γ(b) / Γ(a+b)
bicoBinomial coefficient: bico(n,k) = n! / k!(n-k)!
digammaLogarithmic derivative of the Gamma function: digamma(z) = (lnΓ)'(z) = Γ'(z) / Γ(z)
trigammaSecond logarithmic derivative of the Gamma function: trigamma(z) = (lnΓ)''(z)
Special Functions
wpWeierstraß' elliptic P-function. Doubly periodic with periods 2 and 2i, i.e. wp(z+2n+2im) = wp(z) for all integer n,m.
J(n,x)Bessel function of the first kind, implemented only for real n and x.
Y(n,x)Bessel function of the second kind, implemented only for real n and x.
I(n,x)Hyperbolic Bessel function of the first kind, implemented only for real n and x.
K(n,x)Hyperbolic Bessel function of the second kind, implemented only for real n and x.
Ai(x)Airy function of the first kind, implemented only for real x.
Bi(x)Airy function of the second kind, implemented only for real x.
Ai'(x)Derivative of Ai, implemented only for real x.
Bi'(x)Derivative of Bi, implemented only for real x.
Ei(x)Exponential integral, implemented only for real x.
En(n,x)Exponential integral, implemented only for real x and integer n ≥ 0.
Probability & Random
normal(z)Probability density function of the normal distribution with µ=0 and σ=1
erfError function
erfcComplementary error function: erfc(z) = 1 - erf(z)
random, rndGenerates uniformly distributed random variates in [-1,1].
riemann_random, rrndGenerates complex numbers that are uniformly distributed on the Riemann sphere.
disk_random, drndGenerates complex numbers that are uniformly distributed on the unit disk {z: |z| < 1}.
normal_random, nrndGenerates normal variates (µ=0, σ=1).
normal_z_random, nzrndGenerates normally distributed complex numbers (i.e. real and imaginary parts are independent and normally distributed). Same as nrnd + i nrnd.
Rounding
roundround(z) rounds the real and imaginary parts of z to the nearest integer.
floorfloor(z) rounds the real and imaginary parts of z down (i.e. towards -∞).
ceilceil(z) rounds the real and imaginary parts of z up (i.e. towards +∞).
Binary
bit(x,k)Return k'th bit of x. Only defined for integer k. bit(-x,k) = 1-bit(x,k) for all x and k (0=+0 with all bits zero). For x ≥ 0: x = sum(bit(x,k) * 2^k). For complex numbers: bit(x+iy, n) = bit(x,n) + i bit(y,n)
ieee_mMantissa of an IEEE 754 double precision floating point number. Includes the leading 1. Properties:
|x| = ieee_m(x) * 2 ^ ieee_e(x)
ieee_m(-x) = ieee_m(x)
ieee_m(2x) = ieee_m(x)
ieee_eExponent of an IEEE 754 double precision floating point number. Bias is already subtracted, so ieee_e(1) = 0, not 1023.
Misc
blendBlends two functions, which can be useful for the image modes ("Image" and "Riemann"). Let s = max(0, min(1, t)), then blend(z,w,t) = s w + (1-s) z, which gives blend(z,w,0) = z and blend(z,w,1) = w. If t is complex, its imaginary part is ignored.
cblendSimilar to blend, but uses s = (1 + cos(pi t))/2, which gives cblend(z,w,2k) = z and cblend(z,w,2k+1) = w. Tends to look better in animation. If t is complex, its imaginary part is ignored.
mixmix(z,w,t) = (1-t)z + tw. Unlike blend and cblend, does not ignore t's imaginary part.
fowlerReturns the Fowler angle of a complex number. Result is in the range [0,8).
juliajulia(z,c) = 1 if z is in the Julia set for c (the numbers for which the iteration z → z²+c stays finite), otherwise closer to 0, depending on how quickly it diverges.
mandelmandel(c) = 1 if c is in the Mandelbrot set (the numbers for which the iteration 0 → z → z²+c stays finite), otherwise closer to 0, depending on how quickly it diverges.

Defining Functions

To create: Use the + button in the Definitions box.

To edit: Click on the definition, which will bring up an editor dialog. At the bottom of the dialog is also a delete button.

Functions can not be recursive or use the plotting variables without declaring them as parameters. For example f = x*y is an error because x and y are unknown when the function is parsed. This must be written as f(x,y) = x*y. Parameters and other functions can be used though.

Names

Names of functions, variables and parameters cannot contain spaces, commas, bars ('|'), control characters, parantheses, brackets, braces, unicode exponents or start with a digit. But other than that, the full unicode range is valid and there is no limit on the length.

Expression Syntax

Basics

Parantheses are optional unless a function has more than one argument (sin(x) and sinx are the same). Multiplication is implicit, so x*y and xy are the same. Whitespace is for grouping, so (x+y)*(z+w) can be written as x+y * z+w and sin(x+y) as sin x+y. Numbers are not localized, the decimal separator is always a dot, never a comma because the comma separates multiple arguments. Writing |z| for abs(z) is ok.

The parser does backtracking, so functions can be overloaded (different functions with the same name for different numbers of arguments). When an expression is split into separate tokens, longer matches are always tried first if there are several possibilities. For example, even if there are parameters a and c, arcsin is never read as a*r*c*sin.

Numbers

Can be decimal like 0.1234 or -12.34e-5, or (probably not too useful here) binary 0b110.001101e1101 (the exponent is binary too), or hexadecimal: 0xA8B.CD53q-7F (since e is already a digit, we use q as exponent marker).

Unicode superscripts are read as power operators. For example x⁻⁴⁺⁵ⁱ is equal to x^(-4+5i).

Parantheses and whitespace

Any block of tokens (without mismatched parantheses) that is surrounded by whitespace (beginning and end of the expression count as whitespace) and can be put inside parantheses without creating syntax errors will be put in parantheses and then whitespace is removed.

For example:
x*y⌴^⌴x*y becomes (x*y)^(x*y),
x+y⌴sin⌴x becomes (x+y)sin(x),
x*⌴x+y⌴*⌴x becomes (x*(x+y))*(x), which is x*(x+y)*x,
x⌴*x+y⌴x becomes ((x)*x+y)(x), which is (x*x+y)*x.

Parantheses work as usual for grouping subexpressions. Brackets and braces can be used as well and they must match: {sin[x]+cos[x]+1} is ok, but {x+y) is a syntax error.

Bars are the usual alternative syntax for the absolute value. When there are ambiguities, the parser will try bars as closing bars first. For example: |x|y|x| is abs(x) y abs(x) and not abs(x absy x).