Skip to content
The Lumenary
K–2Ages 5–8 30 min

Doing and undoing

Flip a card, turn an arrow, walk three steps — then put everything back. Which actions can be undone, which cannot, and why doing nothing counts too.

Formally verified · 17 LeanComputationally tested · 1 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review

Your guides: Chloe, Margaret, Gideon

MotivationH

The do-it, undo-it game

Rosa and her little brother Mateo, in Oaxaca in Mexico, are playing a game. Rosa does something. Then Mateo has to undo it — to put everything back exactly as it was.

  • Rosa opens the window. Mateo closes it. Back as it was!
  • Rosa puts on Grandpa's hat. Mateo takes it off her head.
  • Rosa takes 3 big steps forward. Mateo says, "Now take 3 big steps back!"
  • Rosa turns over a card, so the picture is hidden. Mateo turns it over again.

Then Grandma cracks an egg into the pan for breakfast. "Undo that!" laughs Rosa. Mateo looks at the egg. He thinks hard. Can anybody put a cracked egg back together?

IntuitionH

Actions change things

An action is something you do that changes something: open a door, add a block to a tower, turn an arrow, walk forward. Every action has an effect: the door was closed, and now it is open.

Some actions can be undone. To undo an action, you do a second action that puts everything back the way it was before.

ActionHow to undo it
open the doorclose the door
put on a hattake off the hat
put one more block on the towertake one block off
take 3 steps forwardtake 3 steps back
turn a card overturn it over again
crack an egg??? nobody can!
Explore

Do it, then undo it

Blocks. Here are 5 dots. Tap Add one three times. Now undo what you did. How many times do you need to tap Take one away?

Add, then take away

Start with 5. Add 3 dots, then undo it. Are you back to 5?

How many dots?

5

5 more make ten.

Time. The clock shows 8 o'clock. Press + to move it on half an hour. Which button undoes that?

Forward and back

Move the clock forward half an hour, then undo it.

1234567891011120510152025303540455055

Hour hand (short) · Minute hand (long)

12-hour clock

8:00 a.m.

24-hour clock

08:00

8 o'clock · a.m. means between midnight and noon.

Drag either hand, or use the buttons. When a hand has focus, the arrow keys move it.

Turning. Pick the triangle, switch on Rotational symmetry and press Turn. The gold dot shows where one corner went. Now, without a "turn back" button, how can you get the gold dot back where it started? Keep turning! How many more turns does it take? Try the square and the hexagon too.

Turn, and turn again

Press Turn once. How many more turns bring the gold dot home?

Equilateral triangleTriangle

Rotational symmetry
Order 3

All three sides are equal and all three angles are 60°.

DefinitionsH

Big ideas

Definition— action

An action changes an object or a situation. (Sometimes it leaves it the same — keep reading!)

Definition— undo

An action undoes another action if doing the other action first, and then this one, puts everything back exactly as it was. For example, "close the door" undoes "open the door": open it, then close it, and the door is back as it was.

Definition— doing nothing

Doing nothing is an action too: the action that leaves every thing exactly as it was.

Doing nothing is a funny action, but a very useful one. Doing nothing and then flipping a card is just the same as flipping the card. And doing an action and then undoing it has the same effect as doing nothing at all!

Worked examplesH

Let's try some together

Example— Flip it again

A card is face down. Flip it: now it is face up. To undo the flip, flip it again: face down, just as before. For a card, the same action undoes itself.

Example— Walking is different

Take 3 steps forward. Does doing it again undo it? No! After 3 more steps forward you are 6 steps from where you started. To undo 3 steps forward you need a different action: 3 steps back.

Example— Turning an arrow

An arrow on a card points up. A quarter turn (the way clock hands go) makes it point right.

uprightdownleft
Quarter turns of an arrow card: up, right, down, left. One more quarter turn brings it back to up.

How can we undo one quarter turn?

  • Turn it a quarter turn back (the other way): right becomes up again.
  • Or keep going: three more quarter turns the same way: right → down → left → up. Four quarter turns make a full turn, and a full turn is like doing nothing!

But one more quarter turn the same way does not undo it: the arrow would point down.

ExplanationH

Why some actions cannot be undone

Some actions cannot be undone, however hard we try: cracking an egg, mixing two paints, cutting paper into pieces, squashing a sandcastle. Why not?

Here is a big clue. Kenji's class has a little whiteboard. One day it has a picture of a cat on it. Another day it has a picture of a dog. Each day, after school, the teacher wipes it clean.

catdogblankwipewipe?
Wiping turns the cat board and the dog board into the same blank board. Looking at the blank board, nobody can tell which picture to bring back.

Could some action undo the wiping? It would have to look at the blank board and bring back the picture. But which picture — the cat or the dog? Both boards turned into the very same blank board. Nothing about the blank board tells you which one it was.

So here is the rule: if an action turns two different things into the same thing, it can never be undone. The egg is like that, too: a whole egg and an egg that is already cracked both end up cracked. Orange paint could have come from red and yellow, or straight from a tin of orange.

Note

Taking a block off a tower is a sneaky one. Taking a block off a tower of 1 leaves an empty spot. Trying to take a block from an empty spot also leaves an empty spot! Two different starts, one end — so "take a block away" cannot always be undone, even though "add a block" can.

Formal mathematicsF

Gideon's yes-or-no game

Gideon reads a statement. Is it true or false?

  1. "Flipping a card is undone by flipping it again." — True.
  2. "Every action is undone by doing it again." — False! Walking 3 steps forward twice takes you 6 steps away. One counterexample is enough.
  3. "A quarter turn can be undone by three more quarter turns." — True. Four quarter turns make a full turn.
  4. "Every action can be undone." — False. Wiping the board cannot be undone.
  5. "Doing nothing, and then flipping the card, is the same as just flipping the card." — True.
For grown-ups · the same game in Lean, a proof checker

In Lean an action on a world of things is a function from the world to itself, and "uu undoes aa" says that doing aa and then uu gives back every thing.

ActionLean 4Formally verified
/-- An action on a world of things of type `α`: for each thing, what it becomes. -/
abbrev Action (α : Type) : Type := α → α
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
doNothingLean 4Formally verified
/-- The action of **doing nothing**: every thing stays exactly as it was. -/
def doNothing {α : Type} : Action α := fun x => x
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
andThenLean 4Formally verified
/-- Do `a`, and then do `b`. -/
def andThen {α : Type} (a b : Action α) : Action α := fun x => b (a x)
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
UndoesLean 4Formally verified
/-- `u` **undoes** `a` when doing `a` and then `u` puts every thing back as it was. -/
def Undoes {α : Type} (u a : Action α) : Prop := ∀ x, u (a x) = x
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
doNothing_andThenLean 4Proved here from basic factsFormally verified
/-- Doing nothing and then doing `a` has the same effect as just doing `a`. -/
theorem doNothing_andThen {α : Type} (a : Action α) : andThen doNothing a = a := rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor

The card, and the arrow:

flipLean 4Formally verified
/-- Flip the card over. -/
def flip : Action Card
  | .faceUp => .faceDown
  | .faceDown => .faceUp
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
flip_undoes_flipLean 4Proved here from basic factsFormally verified
/-- Flipping a card is undone by flipping it again. Check both cases. -/
theorem flip_undoes_flip : Undoes flip flip := by
  intro c
  cases c <;> rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
quarterTurnLean 4Formally verified
/-- Turn the arrow a quarter turn clockwise (the way clock hands go). -/
def quarterTurn : Action Arrow
  | .up => .right
  | .right => .down
  | .down => .left
  | .left => .up
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
quarterBack_undoes_quarterTurnLean 4Proved here from basic factsFormally verified
/-- A quarter turn is undone by a quarter turn back. -/
theorem quarterBack_undoes_quarterTurn : Undoes quarterBack quarterTurn := by
  intro a
  cases a <;> rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
three_more_turns_undoLean 4Proved here from basic factsFormally verified
/-- A quarter turn is *also* undone by three more quarter turns the same way. -/
theorem three_more_turns_undo :
    Undoes (fun a => quarterTurn (quarterTurn (quarterTurn a))) quarterTurn := by
  intro a
  cases a <;> rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
quarterTurn_not_undone_by_itselfLean 4Proved here from basic factsFormally verified
/-- A quarter turn is **not** undone by doing it again: an arrow pointing up ends up pointing
down. One counterexample is enough. -/
theorem quarterTurn_not_undone_by_itself : ¬ Undoes quarterTurn quarterTurn := by
  intro h
  have hup : quarterTurn (quarterTurn Arrow.up) = Arrow.up := h Arrow.up
  -- But two quarter turns take `up` to `down`, and `down ≠ up`.
  exact absurd hup (by decide)
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor

Walking along a path, with positions as whole numbers (negative numbers are behind the start):

back_undoes_forwardLean 4Applies a library theoremFormally verified
/-- "Take 3 steps forward" is undone by "take 3 steps back" — for any number of steps.
This applies core Lean's `Int.add_sub_cancel`. -/
theorem back_undoes_forward (n : Int) : Undoes (back n) (forward n) :=
  fun x => Int.add_sub_cancel x n
Axioms used: propextformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
forward_not_undone_by_itselfLean 4Proved here from basic factsFormally verified
/-- Walking forward again does **not** undo walking forward (unless the number of steps is
`0`): starting from `0`, two walks of `n` steps end at `n + n`, not at `0`. -/
theorem forward_not_undone_by_itself (n : Int) (hn : n ≠ 0) :
    ¬ Undoes (forward n) (forward n) := by
  intro h
  have h0 : 0 + n + n = 0 := h 0
  omega
Axioms used: propext, Quot.soundformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor

And the main idea of the lesson, proved for every world and every action: an action that sends two different things to the same result cannot be undone. The proof is the whiteboard argument: an undo would send the one result back to both things, so the two things would be equal.

cannot_undo_of_same_resultLean 4Proved here from basic factsFormally verified
/-- **Why some actions cannot be undone.** If an action sends two *different* things `x`
and `y` to the *same* result, then no action can undo it: an undo would have to take that one
result back to `x` and also back to `y`.
`x = u (a x) = u (a y) = y`, which contradicts `x ≠ y`. -/
theorem cannot_undo_of_same_result {α : Type} (a : Action α) {x y : α} (hxy : x ≠ y)
    (h : a x = a y) : ¬ ∃ u, Undoes u a := by
  intro ⟨u, hu⟩
  apply hxy
  calc x = u (a x) := (hu x).symm
    _ = u (a y) := by rw [h]
    _ = y := hu y
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
wipe_cannot_be_undoneLean 4Proved here from basic factsFormally verified
/-- Wiping the board cannot be undone: the cat board and the dog board both become blank,
so no action can know which picture to bring back. -/
theorem wipe_cannot_be_undone : ¬ ∃ u, Undoes u wipe :=
  cannot_undo_of_same_result wipe (x := .cat) (y := .dog) (by decide) rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
crack_cannot_be_undoneLean 4Proved here from basic factsFormally verified
/-- Cracking an egg cannot be undone, even in our tiny model: a whole egg and a cracked egg
both end up cracked. -/
theorem crack_cannot_be_undone : ¬ ∃ u, Undoes u crack :=
  cannot_undo_of_same_result crack (x := .whole) (y := .cracked) (by decide) rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor
takeBlock_cannot_be_undoneLean 4Proved here from basic factsFormally verified
/-- But "take a block away" cannot be undone in general: a tower of 1 block and an empty
spot both end up with 0 blocks, so nothing can tell whether to put a block back. -/
theorem takeBlock_cannot_be_undone : ¬ ∃ u, Undoes u takeBlock :=
  cannot_undo_of_same_result takeBlock (x := 1) (y := 0) (by decide) rfl
Axioms used: No axiomsformal/Lumenary/ActionsAndUndoing.leanTry it in the Lean web editor

What is not formalised here: the converse. In a finite world, an action that never sends two things to the same result can always be undone (it is a shuffle, and shuffling back undoes it). Margaret's program checks this for every action on worlds of up to 4 things; a proof for every finite world is part of the theory of permutations (Mathlib: Finite.injective_iff_bijective). And of course Lean does not know that real eggs cannot be uncracked — that is physics. Our egg is a two-state model.

ComputationC

Margaret tries every action

Margaret found that only 6 of the 27 actions can be undone: the ones that just shuffle the counters around, never turning two counters into the same one. And only 4 of those 6 are undone by doing them again. The other 2 move every counter one place round in a circle, and they are undone by going round the other way.

For grown-ups · Margaret's program

The program lists every action on worlds of 1, 2, 3 and 4 things, searches every possible undo, and checks the rule from the lesson: an action can be undone exactly when it never sends two things to the same result. Because every case is tried, the counts are certain for these tiny worlds — but a computer search cannot cover every world. The Lean theorem cannot_undo_of_same_result proves one half of the rule for all worlds at once.

Every action in a tiny world: which can be undone?PythonExact computationExhaustive finite checkComputationally tested
"""Every action in a tiny world: which ones can be undone?

A tiny world has a few things in it, say a red, a blue and a green counter in
three boxes. An action says, for each thing, what it becomes. With n things
there are n^n actions. For worlds of 1 to 4 things this program lists every
action, searches all n^n candidates for an action that undoes it, and checks
the lesson's rule: an action can be undone exactly when it never sends two
different things to the same result. It also counts the actions that are
undone by simply doing them again, like flipping a card, and finds how many
quarter turns undo one quarter turn of an arrow.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

from itertools import product
from math import factorial
import textwrap

def all_actions(n):
    """Every action on the things 0..n-1, as a tuple: thing i becomes a[i]."""
    return list(product(range(n), repeat=n))

def then(a, b):
    """Do action a, then action b."""
    return tuple(b[a[i]] for i in range(len(a)))

def do_nothing(n):
    """The action that leaves every thing as it was."""
    return tuple(range(n))

def undoes(u, a):
    """Does u undo a, i.e. does doing a then u put everything back?"""
    return then(a, u) == do_nothing(len(a))

def find_undo(a):
    """Search every action for one that undoes a; return it, or None."""
    for u in all_actions(len(a)):
        if undoes(u, a):
            return u
    return None

def no_two_the_same(a):
    """True when the action never sends two different things to one result."""
    return len(set(a)) == len(a)

def turns_to_undo(turn, start):
    """How many more times must `turn` be done to undo one `turn`?"""
    count, state = 0, turn(start)
    while state != start:
        state = turn(state)
        count += 1
    return count

def describe(a):
    """Write an action as 'thing -> result' pairs, e.g. '0->1, 1->2, 2->0'."""
    return ", ".join(f"{i}->{j}" for i, j in enumerate(a))

ARROWS = ["up", "right", "down", "left"]

def quarter_turn(arrow):
    """Turn an arrow a quarter turn clockwise."""
    return ARROWS[(ARROWS.index(arrow) + 1) % 4]

def main():
    print("Tiny worlds: every action, and every possible undo, checked.")
    print("  things  actions  can be undone  undone by doing it again")
    rule_holds, counts = True, []
    for n in range(1, 5):
        acts = all_actions(n)
        undoable = [a for a in acts if find_undo(a) is not None]
        rule_holds &= all((a in undoable) == no_two_the_same(a) for a in acts)
        self_undo = sum(1 for a in acts if undoes(a, a))
        counts.append(len(undoable))
        print(f"  {n:6d} {len(acts):8d} {len(undoable):14d} {self_undo:25d}")
    print()
    print("Can be undone exactly when no two things end up the same:",
          rule_holds)
    shuffles = [factorial(n) for n in range(1, 5)]
    print("Undoable counts are the numbers of shuffles 1, 1x2, 1x2x3, 1x2x3x4:",
          counts == shuffles)
    print()
    print("Three things, an action that goes round: 0->1, 1->2, 2->0.")
    go_round = (1, 2, 0)
    print(f"  undone by doing it again? {undoes(go_round, go_round)}")
    print(f"  undone by:                {describe(find_undo(go_round))}"
          "  (round the other way)")
    extra = turns_to_undo(quarter_turn, "up")
    print(f"A quarter turn of an arrow is undone by {extra} more quarter turns.")
    print()
    print(textwrap.fill(
        "Epistemic status: exact and exhaustive for worlds of 1 to 4 things "
        "(every action and every candidate undo was tried), so these counts "
        "are certain. It is not a proof for bigger worlds. The lesson proves, "
        "for every world, that an action sending two things to the same "
        "result can never be undone.",
        width=78,
    ))

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Exercises

Your turn

Act them out if you can: walk, turn, flip cards, build towers. You can ask for a hint whenever you like.

1. Doing and undoing

Warm-upHuman

Mateo opens the door. Which action undoes that?

Choose one

2. Doing and undoing

Warm-upHuman

Rosa takes 4 steps forward. Which action undoes it?

Choose one

3. Doing and undoing

CoreHuman

Which of these actions can be undone? Choose all of them.

Choose all that apply

4. Doing and undoing

CoreHuman

Which action is undone by doing exactly the same action again?

Choose one

5. Doing and undoing

CoreHuman

An arrow points up. You turn it a quarter turn, so it points right. How many more quarter turns, the same way, bring it back to pointing up?

6. Doing and undoing

CoreFormal

Gideon's game: true or false? "Doing nothing, and then putting on a hat, has the same effect as just putting on a hat."

Choose one

7. Doing and undoing

CoreFormal

Gideon's game: true or false? "Every action can be undone."

Choose one

8. Doing and undoing

StretchHuman

Why can't wiping the whiteboard be undone?

Choose one

9. Doing and undoing

StretchComputational

Margaret's tiny world: a lamp is on or off. She found exactly 4 actions: do nothing, press the switch (on becomes off, off becomes on), always make it on, and always make it off. How many of these 4 actions can be undone?

Common misconceptionsH

Things that trip people up

Misconception

"Every action can be undone." Many can, but not all. Cracking an egg, wiping a board and mixing paints cannot be undone, because two different starting points end up looking exactly the same.

Misconception

"Doing nothing isn't an action." It is! It is the action that leaves everything as it was. Doing an action and then undoing it has the same effect as doing nothing.

Misconception

"To undo something, just do it again." That works for flipping a card or switching a light on and off. But walking 3 steps forward again takes you further away, and a quarter turn again makes the arrow point the opposite way. Often the undo is a different action.

Misconception

"Undoing part of it is good enough." Undoing means everything goes back exactly as it was. Two steps back do not undo three steps forward.

ViewpointsH

Two ways of looking at doing and undoing

Geometry— The geometer: moves that can be undone

Slides, turns and flips move a shape without changing it, and every one of them can be undone: slide back, turn back, flip again. The moves that leave a shape looking exactly the same are its symmetries. A square has 8 of them: doing nothing, three turns, and four flips. You will meet them in Symmetry: slides, turns and flips.

Algebra— The algebraist: collections of actions

An algebraist looks at a whole collection of actions together: for example, the four turns of the arrow card (do nothing, a quarter turn, a half turn, three quarter turns). Doing one and then another always gives another one in the collection, doing nothing is in it, and every one can be undone. A collection like that is called a group, and it is one of the most important ideas in mathematics: see Groups.

Category-theoretic connectionH

Where doing and undoing lead

Doing one action after another is the next step: One thing after another asks how to undo a whole chain of actions (think about socks and shoes!).

For grown-ups · the grown-up words

Later on, actions become functions, "doing nothing" becomes the identity function, "doing one action after another" becomes composition, and an action that undoes another becomes an inverse. These ideas are the heart of Composition, and in category theory an arrow that can be undone in both orders is called an isomorphism. The theorem cannot_undo_of_same_result is the statement that a function with a left inverse must be injective. Young children need none of this vocabulary: playing "do it, undo it" is the real idea.

History & global context

Undoing in history

  • "Algebra" means "restoring". Around 820 CE, in Baghdad, Muḥammad ibn Mūsā al-Khwārizmī wrote a book about solving problems by two kinds of steps. One was called al-jabr, "restoring": when something has been taken away on one side of a problem, add it back, on both sides, so that nothing is missing. Our word algebra comes from it.
  • Groups. In the 1830s the young French mathematician Évariste Galois studied collections of shuffles that can all be undone, to understand when equations can be solved. Today such collections are called groups.
  • A famous puzzle. In 1974, Ernő Rubik, a teacher of design in Budapest, invented his cube puzzle. Every twist can be undone by twisting back — but undoing a long muddle of twists takes careful thinking about the order.
Further reading

For grown-ups: further reading

  • F. William Lawvere and Stephen H. Schanuel, Conceptual Mathematics: A First Introduction to Categories (1997; 2nd ed. 2009) — maps, identity maps and inverses ("retractions" and "sections") with everyday examples.
  • Eugenia Cheng, How to Bake Pi: An Edible Exploration of the Mathematics of Mathematics (2015) — a popular introduction to the ideas behind category theory.
  • Nathan Carter, Visual Group Theory (2009) — groups as collections of actions, with many pictures.