Skip to content

Arithmetic

The operators are +, -, *, /, ^, mod, and the postfix ! (factorial). ^ is right-associative, so 2 ^ 3 ^ 2 is 2 ^ 9.

2 + 3 * 4
(2 + 3) * 4
2 ^ 3 ^ 2
10 - 2 - 3
7 mod 3
5!

Negation binds as tightly as ^, so -2^2 is -4, the mathematical reading. Write (-2)^2 for 4.

-2^2
(-2)^2

Several operators have word forms that read naturally in a note:

WordsSame as
plus, add+
minus, subtract-
times, multiplied by, by, of, ×*
per, divided by, over/
squared, cubed^ 2, ^ 3
3 of 7
60 per 5
12 times 4
4 m by 3 m
12 divided by 4
5 squared

Comparisons give true or false. Comparisons do not chain: write 1 < x and x < 5, not 1 < x < 5.

3 < 5
5 == 5.0
2 != 3
3 < 5 and 2 > 1
not (3 < 5)
true or false

and, or, and not can also be written &&, ||, and !.

if … then … else … is an expression. Both branches must be the same kind of thing, and else is required.

temperature = 31
if temperature > 30 then "hot" else "fine"

Text goes in single or double quotes. + joins strings.

"hello" + " " + 'world'