Built-in functions

Every transcendental the language offers, in one place.

This worksheet exists for the golden-file suite more than for the reader. The claim the whole design rests on is that transcendentals come from a libm compiled into the artifact rather than the host's, so that two machines agree to the last bit. Nothing else under examples/ calls one, so without this file the native-versus-WASM comparison in phase 7 would pass without testing the thing it exists to test.

x=0.7
n=3.25

Trigonometric. Arguments are dimensionless; rad, ° and % all qualify.

s=sin⁡(x)=sin⁡(0.7)=0.644218
c=cos⁡(x)=cos⁡(0.7)=0.764842
t=tan⁡(x)=tan⁡(0.7)=0.842288
half=sin⁡(30⁢°)=0.5

Inverses, including the two-argument form.

arcsine=asin⁡(0.5)=0.523599
arccosine=acos⁡(0.5)=1.0472
arctangent=atan⁡(1)=0.785398
quadrant=atan2⁡(1,2)=0.463648

Hyperbolic.

sh=sinh⁡(x)=sinh⁡(0.7)=0.758584
ch=cosh⁡(x)=cosh⁡(0.7)=1.25517
th=tanh⁡(x)=tanh⁡(0.7)=0.604368

Exponential and logarithmic.

ex=exp⁡(x)=exp⁡(0.7)=2.01375
l=ln⁡(n)=ln⁡(3.25)=1.17865
l10=log10⁡(n)=log10⁡(3.25)=0.511883
l2=log2⁡(n)=log2⁡(3.25)=1.70044

Numeric. sqrt halves the dimension, so it is exercised on a real area.

area=16⁢m2
side=area=16⁢m2=4⁢m
a=|−n|=|−3.25|=3.25
r=round⁡(n)=round⁡(3.25)=3
f=floor⁡(n)=floor⁡(3.25)=3
ce=ceil⁡(n)=ceil⁡(3.25)=4

The reciprocal three, written as reciprocals so they cannot drift from the three they come from.

cotangent=cot⁡(x)=cot⁡(0.7)=1.18724
secant=sec⁡(x)=sec⁡(0.7)=1.30746
cosecant=csc⁡(x)=csc⁡(0.7)=1.55227

The inverse hyperbolics.

ash=asinh⁡(x)=asinh⁡(0.7)=0.652667
ach=acosh⁡(1+n)=acosh⁡(1+3.25)=2.12593
ath=atanh⁡(0.5)=0.549306

A logarithm always states its base; log10, log2 and ln are the shorthands.

base7=log⁡(n,7)=log⁡(3.25,7)=0.605709

Numeric, on quantities. mod keeps the sign of its dividend and nthroot divides the dimension, which is what rational dimension exponents are for.

remainder=mod⁡(7⁢m,2⁢m)=1⁢m
diagonal=hypot⁡(3⁢m,4⁢m)=5⁢m
cubeside=nthroot⁡(8⁢m3,3)=2⁢m
oddroot=nthroot⁡(−32,5)=-2

Collections. product multiplies dimensions where sum requires them to agree; the rest need one dimension across the collection.

sizes=[5193]⁢mm
volume=product⁡([2⁢m3⁢m4⁢m])=24⁢m3
average=mean⁡(sizes)=mean⁡([0.005 m, 0.001 m, 0.009 m, 0.003 m])=0.0045⁢m
middle=median⁡(sizes)=median⁡([0.005 m, 0.001 m, 0.009 m, 0.003 m])=0.004⁢m
ordered=sort⁡(sizes)=sort⁡([0.005 m, 0.001 m, 0.009 m, 0.003 m])=[0.001 m, 0.003 m, 0.005 m, 0.009 m]
backwards=reverse⁡(sizes)=reverse⁡([0.005 m, 0.001 m, 0.009 m, 0.003 m])=[0.003 m, 0.009 m, 0.001 m, 0.005 m]

Matrices.

K=[2−10−12−10−12]
tr=trace⁡(K)=trace⁡([[2, -1, 0], [-1, 2, -1], [0, -1, 2]])=6
corner=submatrix⁡(K,2,3,1,2)=submatrix⁡([[2, -1, 0], [-1, 2, -1], [0, -1, 2]],2,3,1,2)=[[-1, 2], [0, -1]]

The identity that would catch a mismatched pair.

pythagoras=sin⁡(x)2+cos⁡(x)2=sin⁡(0.7)2+cos⁡(0.7)2=1