# Proof compression: tactics and the Robbins problem

A good formal proof is **compressed**. Repeated fragments have been turned into lemmas, bookkeeping into tactics, and
long terms into abbreviations. This chapter shows it on one famous example: the proof that every Robbins algebra is
Boolean, found in 1996 by William McCune's program EQP (see {ref}`w03-robbins`). We take the shortest published
computer proof known to us, turn it into a proof in tactics checked by our kernel from lecture 3, design new tactics
that shorten it, and measure the effect. Then we analyse "heavy" code of other people with the same theorem —
formalizations in Lean, Isabelle and Mizar — and ask what could be compressed in it.

The chapter has five parts:

* {doc}`k1_najkrotszy` — how many steps a proof has; EQP's twelve equations (search m5-50, November 1996) are exactly
  Mann's lemmas 44–54; our kernel checks them as theorems, and the Otter proof without built-in associativity is more
  than three times longer.
* {doc}`k2_taktyki` — four tactics: `ac` (a normal form with a proof), `rw_ac` (matching modulo associativity and
  commutativity), `ac_simp` (simplification to the end) and `auto` (creative expansions from a search); their
  structure, cost and design principles.
* {doc}`k3_caly_dowod` — the whole proof from the Robbins equation to Huntington's equation: lemmas with hypotheses,
  sections with constants as abbreviations of terms, the result checked by the kernel with the assumptions A1, A2, R;
  three sizes of a proof — the script, the proof object and the tree without lemmas.
* {doc}`k4_cudzy_kod` — four formalizations (Lean 4, Lean 3, Isabelle, Mizar) and machine proofs (EQP, Otter) as data:
  sizes, tactic profiles, the bookkeeping of associativity and commutativity, `metis`; what would compress it.
* {doc}`k5_scenariusze` — scenarios in the Boole Lab and in the Tactic Lab: the script and the proof object, a tactic
  with a measure of progress, a tactic that loops, what the kernel sees; exercises and references.

```{admonition} Materials
:class: tip
The code of the chapter exists in two language versions: [kernel/](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/kernel/)
(`ac.py`, `robbins.py`, `robbins_proof.py`) and [jadro/](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/jadro/)
(`ac.py`, `robbins.py`, `robbins_dowod.py`). Other people's code with proofs is fetched by the script
`obce/pobierz.py` (pinned versions, SHA-256 checksums); we do not publish it on the course site. Tactics made of
combinators are composed in the [Boole Lab](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/applets/boole-lab.html)
and in the [Tactic Lab](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/applets/tactic-lab.html).
```

```{rubric} Map of examples
```

| Example | What it shows | Where |
|---|---|---|
| Table I of McCune's paper: 8, 12, 86 steps | the length of a proof depends on what we count | {doc}`k1_najkrotszy` |
| equation 8855 = lemma `mann_51` | Winker's condition 2 after eight EQP steps | {doc}`k1_najkrotszy` |
| 12 EQP equations = `mann_44` … `winker` | Mann's proof is the EQP proof written out as lemmas | {doc}`k1_najkrotszy` |
| Otter: 40 steps instead of 12 | the cost of no built-in associativity and commutativity | {doc}`k1_najkrotszy` |
| the cost of `ac` grows like $k^2$ | bookkeeping that the tactic removes from the script | {doc}`k2_taktyki` |
| `auto` finds `← robbins (-(a + b)) (-a + b)` | search instead of a creative hint | {doc}`k2_taktyki` |
| lemma 36 for $k = 1, 2, 3$ | induction unrolled into a loop | {doc}`k3_caly_dowod` |
| $e$ of 329 symbols and the constant $e$ | abbreviations compress terms | {doc}`k3_caly_dowod` |
| the tree without lemmas: over half a billion nodes | lemmas compress proofs | {doc}`k3_caly_dowod` |
| 33 × `ac_rfl`, 110 × `metis`, 81 Mizar steps with only associativity or commutativity | where the bookkeeping sits in other people's code | {doc}`k4_cudzy_kod` |
| `repeat rw [H1]` loops, `ac` does not | a measure of progress: the number of inversions | {doc}`k5_scenariusze` |
