Word-based mathematics
Many built-in functions can also be written as an English phrase, such as half of £37,
greater of £20 and per player or average of 22 min, 25 min and 24 min. This page lists those
phrases, grouped by what they do, with the function each one matches. Reach for it when you want
a calculation to read like the sentence you would say out loud. The phrase and the function do
the same job, so use whichever reads better in your note.
Halves, smaller and larger values
half of £37 gives £18.50double £80 gives £160.00twice 45 min gives 90 minthe difference between £120 and £85 gives £35.00lesser of £250 and 10% of £3,000 gives £250.00greater of £15 and 3% of £1,200 gives £36.00smaller of 5 km and 3 miles gives 4.828032 kmdouble and twice multiply by two, and triple by three. the difference between gives how
far apart two values are, whichever you write first, so it’s never negative. Between two places,
difference between London and Tokyo still gives their time difference.
lesser of and smaller of pick the smaller of two values; greater of and larger of pick the
larger. They are handy for caps and minimums: the lesser of line caps a 10% fee at £250, and
the greater of line charges 3% with a minimum of £15. When the two values use different units,
the answer is given in the first value’s unit.
clamp keeps a value within a range. It works with plain numbers, money, quantities and
durations, and keeps the unit, as long as the value and both limits measure the same thing:
clamp 32 between 10 and 25 gives 25clamp 8 from 10 to 25 gives 10clamp 23 °C between 18 °C and 21 °C gives 21 °Cclamp £120 between £0 and £100 gives £100.00clamp 2.5 kg between 500 g and 2 kg gives 2 kgThe thermostat line holds a setting at 21 °C, and the next caps a refund at £100.
Remainders, factors and primes
remainder of 50 divided by 6 gives 2gcd of 24 and 36 gives 12lcm of 12 and 15 gives 60is 97 prime gives trueis 91 a prime number gives falseremainder of is the same as mod: 50 eggs in boxes of six leave 2 over. gcd is the greatest
common divisor: the largest square tile that fits a 24 cm by 36 cm panel exactly is 12 cm. lcm
is the lowest common multiple, so buses every 12 minutes and every 15 minutes leave together
every 60 minutes.
Primality is exact for whole numbers up to 2^63. Numbers with a decimal part and negative numbers
give false.
Powers, roots and logarithms
10 squared gives 1002 cubed gives 83 raised to 4 gives 812 to the power of 10 gives 1,024square root of 144 gives 12cube root of 1,000 gives 10root 4 of 81 gives 3log base 2 of 1,024 gives 101,024 is 2 to what power gives 10squared and cubed apply to what’s straight before them, as ² and ³ do, so 5 m squared
is the area 5 m² and (5 m) squared is 25 m². root n of x and n root of x take any root. log base b of x and log x base b give the
logarithm to any base, and x is b to what power asks the same question the other way round.
Counting arrangements
10 combination 2 gives 4510 choose 3 gives 1208 permutation 3 gives 336n combination k counts the ways to choose k things from n when order doesn’t matter: ten
people shaking hands with each other make 45 handshakes. n choose k is another way to say it,
so 10 choose 3 is the number of ways to pick three people from ten. n permutation k counts them when order
does matter: eight runners can fill the gold, silver and bronze places in 336 ways. To count
every possible finishing order, use a factorial: 8! is 40,320.
Totals and averages
List the values after the phrase, separated by commas, with and before the last one if you
like:
sum of £12.50, £8.20 and £4.30 gives £25.00average of 22 min, 25 min, 24 min, 41 min and 23 min gives 27 minmedian of 22 min, 25 min, 24 min, 41 min and 23 min gives 24 minmin of £4.20, £3.80, £5.10 gives £3.80max of £4.20, £3.80, £5.10 gives £5.10count of £4.20, £3.80, £5.10 gives 3standard deviation of 20 min, 25 min and 30 min gives 5 mintotal of is the same as sum of, and mean of is the same as average of. The average and
median of the same commute times differ because one slow day (41 minutes) pulls the average up
but barely moves the median. standard deviation of gives the sample standard deviation.
For more on working with lists, including sorting and filtering, see Lists and statistics.
Random values
random number between a and b picks a whole number from a to b, including both ends. The
answer changes each time it is worked out, so these examples show one possible draw:
random number between 1 and 6 gives 4winning ticket = random number between 1 and 250 gives 200random() gives 0.7220223468| Form | Gives |
|---|---|
random number between 1 and 10 |
A whole number from 1 to 10, including both |
random(1, 6), rand(1, 6) |
The same, as a function |
random(), rand() |
A fraction from 0 up to, but not including, 1 |
random(0, 1) |
A fraction between 0 and 1, not a choice of 0 or 1 |
The bounds must be whole numbers without units, and the first must not be larger than the
second. A draw stored in a name, like winning ticket above, stays fixed while you work on the
rest of the note, and is drawn again when the note is loaded or recalculated.
All phrases at a glance
| Phrase | Example | Result | Function form |
|---|---|---|---|
half of x |
half of £37 |
£18.50 |
x / 2 |
double x, twice x, triple x |
double £80 |
£160.00 |
x * 2 |
the difference between a and b |
the difference between £120 and £85 |
£35.00 |
abs(a - b) |
a in b, for two numbers |
1 in 5 as % |
20% |
a / b |
lesser of a and b, smaller of |
lesser of 3 and 5 |
3 |
min(a, b) |
greater of a and b, larger of |
greater of 3 and 5 |
5 |
max(a, b) |
clamp x between a and b, clamp x from a to b |
clamp 32 between 10 and 25 |
25 |
clamp(x, a, b) |
remainder of a divided by b |
remainder of 50 divided by 6 |
2 |
a mod b |
gcd of a and b |
gcd of 24 and 36 |
12 |
gcd(a, b) |
lcm of a and b |
lcm of 12 and 15 |
60 |
lcm(a, b) |
is n prime, is n a prime number |
is 97 prime |
true |
|
a divided by b |
17 divided by 5 |
3.4 |
a / b |
a multiplied by b |
£3.50 multiplied by 4 |
£14.00 |
a * b |
x squared, x cubed |
10 squared |
100 |
x^2, x^3 |
a to the power of b, a raised to b, a exponent b |
2 to the power of 10 |
1,024 |
a^b |
square root of x |
square root of 144 |
12 |
sqrt(x) |
cube root of x |
cube root of 1,000 |
10 |
cbrt(x) |
root n of x, n root of x |
root 4 of 81 |
3 |
(no general function) |
log base b of x, log x base b |
log base 2 of 1,024 |
10 |
logbase(x, b) |
x is b to what power |
1,024 is 2 to what power |
10 |
logbase(x, b) |
n combination k, n choose k |
10 choose 3 |
120 |
combination(n, k) |
n permutation k |
8 permutation 3 |
336 |
permutation(n, k) |
sum of a, b and c, total of |
sum of 1, 2 and 3 |
6 |
sum([a, b, c]), total([a, b, c]) |
mean of, average of |
mean of 24, 31, 28 and 29 |
28 |
average([…]), avg([…]) |
median of, min of, max of, count of |
median of 3, 7, 9, 12, 40 |
9 |
|
standard deviation of |
standard deviation of 20, 25 and 30 |
5 |
stddev([…]), stdev([…]) |
random number between a and b |
random number between 1 and 10 |
a whole number | random(a, b) |
The function reference covers every function form in detail.
Putting it together
Working out fixtures and fees for a small five-a-side league:
# Five-a-side leagueteams = 6matches = teams choose 2 gives 15pitch hire = £54season cost = matches * pitch hire gives £810.00players = 45players / teams rounded down gives 7remainder of players divided by teams gives 3per player = season cost / players gives £18.00fee = greater of £20 and per player gives £20.00If every team plays every other team once, six teams need 15 matches. Forty-five players make
squads of seven with three reserves left over, and greater of sets the fee to the club’s £20
minimum because the pitch hire alone only works out at £18 each.