Skip to content

Learn: from atoms to definitions

Start with numbers, then use the same idea with words, lists and grids. Each example is already evaluated; edit the expression (or, from lesson 2 onward, the rules) and press Run to try your own.

1. Atoms: the operations you choose

Atoms are starting operations. Here are the integer world's atoms; you can add your own in the Playground.

a + bAddAdd two integers.
a - bSubtractSubtract b from a.
a * bMultiplyMultiply two integers.

More atoms

a / bDivideRound toward zero; zero divisor gives NaN.
a % bRemainderRemainder after division; zero divisor gives NaN.
- aNegateChange the sign.
a @ReverseReverse decimal digits; keep the sign.
# aTriangleSum 1 through a; negate for negative a.
a $Bit countCount 1 bits in the absolute value.
& aDigit sumSum decimal digits; keep the sign.
a ⁺SuccessorAdd one.
a ⁻PredecessorSubtract one.
a «DoubleMultiply by two.
a »HalfHalve, rounding toward zero.
a °Parity0 if even, 1 if odd.
defined aDefined?1 for an integer, 0 for NaN.

No rule is needed yet: atoms are evaluated directly. In (3 + 4) * 2, first add, then multiply; the trace shows two compute steps. Next, we give this calculation a name.

Try it: What is 4 * 3? Try more →

2. Substitute the inputs

a ◆ b = { (a + b) * 2 } names the calculation from lesson 1: ◆ takes two inputs, adds them, then doubles the sum. In 3 ◆ 4, one unfold step replaces both a and b with 3 and 4; then two compute steps evaluate + and *.

Try it: Predict 5 ◆ 1 before opening the answer. Try more →

3. One operator can call another

a ♣ b = { (a ◆ b) - a } uses ◆ from the previous card. First unfold ♣, then unfold ◆; the highlighted part shows what changes at each step.

Try it: What is 5 ♣ 2? Try more →

4. Choose a branch

a ▲ b = { a - b, if a >= b; b - a, else } gives the distance between two numbers. >= means greater than or equal to; the first branch handles equality too. Here 3 ▲ 3 uses that branch and gives zero.

Try it: At a = b = 4, which branch runs, and what is the answer? Try more →

5. Repeat, with a stopping point

a ★ b = { 0, if b <= 0; (a ★ (b - 1)) + a, else } adds a once for each count in b. <= means less than or equal to: when b reaches zero, the rule returns 0 instead of calling itself again. The example 2 ★ 3 adds two three times; the exercise tries 3 ★ 4. An arithmetic result beyond the configured value bound gives NaN, meaning no valid number.

Try it: Predict 3 ★ 4 by adding three four times. Try more →

6. Read the shape of a rule

a ◆ b is binary: it has two inputs. ◇ a is unary prefix (symbol before input), a ♠ is unary postfix (symbol after input), and ⊙(a, b, c) is the call form for three inputs. The three examples below show these shapes in order. In a branched rule like lesson 4's, a semicolon separates branches; Opulse tries them in order and uses else if earlier conditions fail.

Try it: What is ⊙(3, 5, 4)? Try more →

7. Same structure, new material

The string and list rules both join two inputs, then drop the first item. ⊕ joins strings and ⇥ drops the first character; ⊞ joins lists and ⌄ drops the first element. The first two examples use binary a ◆ b. The grid example uses a different, unary a ◆ rule: ↻ rotates clockwise by 90°, so applying it twice turns a grid halfway around.

Try it: After seeing "sun" ◆ "day", predict [1, 2] ◆ [3, 4]. Try more → · Explore Worlds →

8. Where to go next

The Challenge has six angles: compute a result, invert an input, decide a claim, describe a rule, induce a pattern, and create a solution. The rule below, a ◈ b = { a, if a >= b; b, else }, chooses the larger input; try editing it to choose the smaller one. Use the Playground to write a whole world of your own.

Try it: Predict 7 ◈ 4. Try more →