Löb's theorem with a budget
Last week I computed the modal agents' outcomes without performing their proof searches. The bounded prototype at the end tried only two kinds of certificate. Jacob Tsimerman's question at the end of his SLMath talk made me want to go further: could we run agents that search a proof language with a genuine length bound?
The agent at the center of that question is DUPOC(k), from Critch, Dennis and Russell. It searches for a proof, of at most k characters, that its opponent will cooperate with it. If it finds one, it cooperates; otherwise it defects. Their Theorem 3.7 says that two copies of DUPOC(k) cooperate once k is large enough, and their Open Problem 4 asks whether anyone can make that happen on a present-day computer, with a proof search that halts. The budget limits accepted proof length, not the time spent searching.
This week I got it to happen, in a proof system built for these agents whose bounded Löb properties are all proved. Two copies of DUPOC(17880), each reading the other's source and searching for a proof about it, find a proof of 3,007 characters, check it, and cooperate. The match takes about two milliseconds on one core. Everything around that run is checked in Lean: the proof system, the search, the theorem that guarantees the proof exists, and what the programs do with it. I also prove mutual defection for DUPOC against DIMCID under explicit proof-system assumptions, and the argument points to a slip in one of the paper's examples.
The theorem behind bounded cooperation
Löb's theorem says that if a theory like Peano arithmetic proves "if \(P\) is provable then \(P\)", it proves \(P\). With a budget, the statement has to track lengths. Write \(\Box_n \varphi\) for "there is a proof of \(\varphi\) with at most \(n\) characters". Andrew Critch's parametric bounded Löb theorem says, in the form the 2022 paper uses: if the theory proves
and the budget \(f(k)\) grows faster than \(\log k\), then for some \(K\) it proves \(\forall k > K,\ p(k)\). For DUPOC, \(p(k)\) is "DUPOC(k) cooperates with itself", and \(f(k) = k\).
Its proof is a careful version of the classic one. You build a sentence \(\psi(k)\) that says "if I have a proof of at most \(g(k)\) characters, then \(p(k)\)". Proving \(\psi\) costs some fixed number of characters, and using that proof inside the theory costs about \(\log k\) more, because writing the number \(k\) in binary takes that long. Everything else fits into the rest of the budget. What surprised me is how little room the argument needs: once \(f(k)\) beats any constant times \(\log k\), the budget always wins in the end.
Critch proves this for any proof system with a short list of properties, and that is how I formalized it first. Each property is a field of a structure, so the theorem holds for every system that has them:
/-- A proof system with formulas in one free variable `k` and a bounded provability operator.
`f` is the meaning of the budget symbol `Bound.f`. -/
structure System (f : ℕ → ℕ) where
/-- Sentences. -/
Sen : Type
/-- Formulas with the free variable `k`. -/
Pred : Type
/-- Pointwise implication. -/
imp : Pred → Pred → Pred
/-- Pointwise equivalence. -/
iff : Pred → Pred → Pred
/-- `box b φ` is `□_{b(k)} φ(k)`. -/
box : Bound → Pred → Pred
/-- `above k₀ φ` is the sentence `∀ k > k₀, φ(k)`. -/
above : ℕ → Pred → Sen
/-- `ProvesIn n σ`: the system proves `σ` with at most `n` characters. -/
ProvesIn : ℕ → Sen → Prop
/-- Modus ponens under the guarded quantifier. -/
mp {a b : ℕ} {φ ψ : Pred} : (∃ n, ProvesIn n (above a (imp φ ψ))) →
(∃ n, ProvesIn n (above b φ)) → ∃ n, ProvesIn n (above (max a b) ψ)
/-- Hypothetical syllogism. -/
trans {a b : ℕ} {φ ψ χ : Pred} : (∃ n, ProvesIn n (above a (imp φ ψ))) →
(∃ n, ProvesIn n (above b (imp ψ χ))) → ∃ n, ProvesIn n (above (max a b) (imp φ χ))
/-- `φ → ψ → χ` and `φ → ψ` give `φ → χ`. -/
contract {a b : ℕ} {φ ψ χ : Pred} : (∃ n, ProvesIn n (above a (imp φ (imp ψ χ)))) →
(∃ n, ProvesIn n (above b (imp φ ψ))) → ∃ n, ProvesIn n (above (max a b) (imp φ χ))
/-- Weakening a consequent under a hypothesis. -/
imp_mono {a : ℕ} {φ ψ χ : Pred} : (∃ n, ProvesIn n (above a (imp ψ χ))) →
∃ n, ProvesIn n (above a (imp (imp φ ψ) (imp φ χ)))
/-- The extra characters for taking the forward half of an equivalence. -/
iffCost : ℕ
/-- The forward half of a proved equivalence, at most `iffCost` characters longer. -/
iff_forward {n a : ℕ} {φ ψ : Pred} : ProvesIn n (above a (iff φ ψ)) →
ProvesIn (n + iffCost) (above a (imp φ ψ))
/-- The backward half of a proved equivalence, with no bound on how much longer it is. -/
iff_backward {n a : ℕ} {φ ψ : Pred} : ProvesIn n (above a (iff φ ψ)) →
∃ m, ProvesIn m (above a (imp ψ φ))
/-- The extra characters for modus ponens inside a box (Critch's `c`). -/
distCost : ℕ
/-- Critch's Property 1, implication distribution. -/
imp_dist (x y : Bound) (φ ψ : Pred) :
∃ n, ProvesIn n (above 0
(imp (box x (imp φ ψ)) (imp (box y φ) (box (x + y + .const distCost) ψ))))
/-- The extra characters for instantiating a universal statement (Critch's `C`). -/
instCost : ℕ
/-- Critch's Property 2, quantifier distribution. -/
quant_dist {N a : ℕ} {φ : Pred} : ProvesIn N (above a φ) →
∃ n, ProvesIn n (above a (box (.const (instCost + 2 * N) + .lg) φ))
/-- The factor by which checking a proof inside the system lengthens it (Critch's `e`). -/
expansion : ℕ
/-- Critch's Property 4, bounded inner necessitation, beyond a guard that may depend on `x`. -/
inner_nec (x : Bound) (φ : Pred) :
∃ a n, ProvesIn n (above a (imp (box x φ) (box (.scale expansion x) (box x φ))))
/-- The system proves `□_x φ → □_y φ` beyond some guard whenever `y` eventually exceeds `x` by
every constant. -/
mono {x y : Bound} (φ : Pred) : (∀ c, ∃ K, ∀ k > K, x.eval f k + c ≤ y.eval f k) →
∃ a n, ProvesIn n (above a (imp (box x φ) (box y φ)))
/-- The parametric diagonal lemma for `□_{g(k)} ψ(k) → p(k)`. -/
diag (g : Bound) (p : Pred) : ∃ ψ n, ProvesIn n (above 0 (iff ψ (imp (box g ψ) p)))Full source
These are the properties a well-designed proof system can be expected to have, though each depends on how proofs are written: combining two proofs with modus ponens costs a constant number of extra characters; a proof of a universal statement gives short proofs of its instances; a theory can check one of its own proofs with a proof only a constant factor longer (the linear case of Critch's theorem, the one the paper uses); and a diagonal lemma lets a formula talk about its own provability. Two of them only need to hold from some \(k\) on, which turned out to matter. With those in hand, the theorem is fully proved, with \(g(k) = \lfloor b(k) / 2(e+1) \rfloor\) for the budget \(b\), where \(e\) is the expansion constant.
/-- **Parametric bounded Löb theorem** (Lemma 3.6 of Critch, Dennis and Russell): if the system
proves `∀ k > k₁, □_{b(k)} p(k) → p(k)` and `b` grows faster than `lg k`, it proves
`∀ k > k₂, p(k)` for some `k₂`. -/
theorem pblt (b : Bound) (grows : GrowsFasterThanLog (b.eval f)) {k₁ : ℕ} {p : S.Pred}
(h : S.Proves (S.above k₁ (S.imp (S.box b p) p))) : ∃ k₂, S.Proves (S.above k₂ p) Read the proof
by
-- The two smaller budgets of Critch's proof.
set D := 2 * (S.expansion + 1) with hD
have hDpos : 0 < D := by omega
set g : Bound := .div b D
set expanded : Bound := .scale S.expansion g
-- ψ(k) ↔ (□_{g(k)} ψ(k) → p(k)), proved with `n` characters.
obtain ⟨ψ, n, hdiag⟩ := S.diag g p
set G := S.imp (S.box g ψ) p
-- Distribute the box over the forward implication `ψ → G`.
set ℓ : Bound := .const (S.instCost + 2 * (n + S.iffCost)) + .lg
have h1 : S.Proves (S.above 0 (S.box ℓ (S.imp ψ G))) := S.quant_dist (S.iff_forward hdiag)
set x₁ : Bound := ℓ + g + .const S.distCost
have h2 : S.Proves (S.above 0 (S.imp (S.box g ψ) (S.box x₁ G))) := by
simpa only [max_self, Proves] using S.mp (S.imp_dist ℓ g ψ G) h1
-- Distribute over the consequent of `G = □_g ψ → p`.
set x₂ : Bound := x₁ + expanded + .const S.distCost
have h3 : S.Proves (S.above 0
(S.imp (S.box g ψ) (S.imp (S.box expanded (S.box g ψ)) (S.box x₂ p)))) := by
simpa only [max_self, Proves] using S.trans h2 (S.imp_dist x₁ expanded (S.box g ψ) p)
-- The budget `x₂(k)` eventually fits in `b(k)`, with room to spare.
have fits : ∀ c, ∃ K, ∀ k > K, x₂.eval f k + c ≤ b.eval f k := by
intro c
obtain ⟨ka, hka⟩ :=
grows.eventually_le_div (S.instCost + 2 * (n + S.iffCost) + 2 * S.distCost + c) 2
(by omega)
refine ⟨ka, fun k hk => ?_⟩
have half := hka k hk
have share : (S.expansion + 1) * (b.eval f k / D) ≤ b.eval f k / 2 := by
rw [Nat.le_div_iff_mul_le (by omega)]
calc (S.expansion + 1) * (b.eval f k / D) * 2 = b.eval f k / D * D := by rw [hD]; ring
_ ≤ b.eval f k := Nat.div_mul_le_self (b.eval f k) D
have split : (S.expansion + 1) * (b.eval f k / D) =
b.eval f k / D + S.expansion * (b.eval f k / D) := by ring
simp only [x₂, x₁, ℓ, expanded, g, Bound.eval]
omega
-- Spend the budget through the hypothesis: (5.4) in Critch's proof.
obtain ⟨ka, hmono⟩ := S.mono p fits
have h4 : S.Proves (S.above (max ka k₁) (S.imp (S.box x₂ p) p)) := S.trans hmono h
have h5 : S.Proves (S.above (max ka k₁)
(S.imp (S.box g ψ) (S.imp (S.box expanded (S.box g ψ)) p))) := by
simpa only [Nat.zero_max, Proves] using S.trans h3 (S.imp_mono h4)
-- Inner necessitation lands exactly on `expanded = e · g`: (5.5), then (5.6).
obtain ⟨a₄, hnec⟩ := S.inner_nec g ψ
set K := max (max ka k₁) a₄
have hK : S.Proves (S.above K (S.imp (S.box g ψ) p)) := S.contract h5 hnec
-- That implication is `ψ(k)` itself.
obtain ⟨N, hN⟩ : S.Proves (S.above K ψ) := by
simpa only [Nat.zero_max, Proves] using S.mp (S.iff_backward hdiag) hK
-- One more distribution, and `instCost + 2N + lg k` eventually fits in `g(k)`: (5.7).
have fits' : ∀ c, ∃ K, ∀ k > K,
(Bound.const (S.instCost + 2 * N) + .lg).eval f k + c ≤ g.eval f k := by
intro c
obtain ⟨kb, hkb⟩ := grows.eventually_le_div (S.instCost + 2 * N + c) D hDpos
refine ⟨kb, fun k hk => ?_⟩
have := hkb k hk
simp only [g, Bound.eval]
omega
obtain ⟨kb, hmono'⟩ := S.mono ψ fits'
have h7 : S.Proves (S.above (max kb K) (S.box g ψ)) := S.mp hmono' (S.quant_dist hN)
exact ⟨max K (max kb K), S.mp hK h7⟩Full source
One quantifier in the hypothesis
Working through the proof in Lean made me read the growth condition very literally. In the 2022 paper it is written as "there is some constant \(c > 0\) with \(f(k) > c \log k\) eventually". The theorem they cite uses it for every constant: the length of the proof built from the diagonal lemma depends on the formula that lemma returns, so it isn't known in advance, and the argument absorbs it by letting the budget beat every multiple of \(\log k\). Critch's original theorem states the condition this way, and so do I. The paper's applications use \(f(k) = k\) or \(\lfloor k/2\rfloor\), which satisfy the stronger condition. The cited theorem covers those applications, but its hypothesis is stronger than the one printed in Lemma 3.6.
/-- `f(k) / lg k` tends to infinity: for every `c`, eventually `c · (lg k + 1) < f(k)`. -/
def GrowsFasterThanLog (f : ℕ → ℕ) : Prop :=
∀ c : ℕ, ∃ K, ∀ k > K, c * (Nat.log 2 k + 1) < f k/-- Any fixed overhead plus `lg k` eventually fits in `f(k) / D`. -/
theorem GrowsFasterThanLog.eventually_le_div {f : ℕ → ℕ} (hf : GrowsFasterThanLog f) (A D : ℕ)
(hD : 0 < D) : ∃ K, ∀ k > K, A + Nat.log 2 k ≤ f k / D Read the proof
by
obtain ⟨K, hK⟩ := hf (D * (A + 1))
refine ⟨K, fun k hk => ?_⟩
have big := hK k hk
rw [Nat.le_div_iff_mul_le hD]
have : (A + Nat.log 2 k) * D ≤ D * (A + 1) * (Nat.log 2 k + 1) := by
have : A + Nat.log 2 k ≤ (A + 1) * (Nat.log 2 k + 1) := by nlinarith
calc (A + Nat.log 2 k) * D ≤ (A + 1) * (Nat.log 2 k + 1) * D := Nat.mul_le_mul_right D this
_ = D * (A + 1) * (Nat.log 2 k + 1) := by ring
omegaFull source
A proof system you can search
A theorem about bounded proofs is only as good as the proof system it talks about, so the next step was to build one and prove that it has every property above. Its formulas talk about agents directly. \(\Box_t\varphi\) says that \(\varphi\) has a proof with at most \(t(k)\) characters, where \(t\) is a bound like \(k\), \(2k\) or \(\lfloor k/6 \rfloor + \log k\). \(\mathrm{coop}(a, b)\) says that the agent with source \(a\) cooperates with the agent with source \(b\). A source is itself a formula, written with two placeholders, the opponent and me, and running an agent means reading its formula with the two real sources filled in. DUPOC's source is \(\Box_k\,\mathrm{coop}(\text{opponent}, \text{me})\).
Proofs are strings over 35 characters, with numbers in binary. A proof of a statement is the statement followed by a certificate, and its length is the number of characters of both. The checker only reads syntax: the axioms of classical logic, modus ponens, the bounds of the quantifier, and one rule for each bounded property, with the side condition that makes it sound. Lean proves that every sentence the checker accepts is true:
/-- **Soundness.** A sentence with a checked certificate is true. -/
theorem sound : ∀ (c : Cert) (σ : Sen), check c σ = true → σ.holds
| .axK, σ, h => by
simp only [check] at h
split at h
· rename_i φ ψ φ' hf
simp only [beq_iff_eq] at h
subst h
exact Sen.holds_of_valid fun n => by rw [hf]; exact fun a _ => a
· simp at h
| .axS, σ, h => by
simp only [check] at h
split at h
· rename_i φ ψ χ φ₁ ψ₁ φ₂ χ₁ hf
simp only [Bool.and_eq_true, beq_iff_eq] at h
obtain ⟨⟨⟨h₁, h₂⟩, h₃⟩, h₄⟩ := h
subst h₁ h₂ h₃ h₄
exact Sen.holds_of_valid fun n => by
rw [hf]; exact fun a b c => a c (b c)
· simp at h
| .axDN, σ, h => by
simp only [check] at h
split at h
· rename_i φ φ' hf
simp only [beq_iff_eq] at h
subst h
exact Sen.holds_of_valid fun n => by
rw [hf]; exact fun a => Classical.byContradiction a
· simp at h
| .iffL c, σ, h => by
simp only [check] at h
split at h
· rename_i φ ψ hf
exact Sen.holds_of_withForm (φ := iff φ ψ) (fun n hv => by rw [hf]; exact hv.1) (sound c _ h)
· simp at h
| .iffR c, σ, h => by
simp only [check] at h
split at h
· rename_i ψ φ hf
exact Sen.holds_of_withForm (φ := iff φ ψ) (fun n hv => by rw [hf]; exact hv.2) (sound c _ h)
· simp at h
| .iffI c d, σ, h => by
simp only [check] at h
split at h
· rename_i φ ψ hf
simp only [Bool.and_eq_true] at h
have h₁ := sound c _ h.1
have h₂ := sound d _ h.2
cases σ with
| all a χ =>
simp only [Sen.form] at hf
subst hf
exact fun k hk => ⟨h₁ k hk, h₂ k hk⟩
| inst n χ =>
simp only [Sen.form] at hf
subst hf
exact ⟨h₁, h₂⟩
· simp at h
| .mp φ c d, σ, h => by
simp only [check, Bool.and_eq_true] at h
exact Sen.holds_mp (sound c _ h.1) (sound d _ h.2)
| .raise a c, σ, h => by
cases σ with
| all b φ =>
simp only [check, Bool.and_eq_true, decide_eq_true_eq] at h
exact fun k hk => sound c _ h.2 k (by omega)
| inst _ _ => simp [check] at h
| .inst a c, σ, h => by
cases σ with
| inst n φ =>
simp only [check, Bool.and_eq_true, decide_eq_true_eq] at h
exact sound c _ h.2 n h.1
| all _ _ => simp [check] at h
| .qd c, σ, h => by
simp only [check] at h
split at h
· rename_i a M φ
simp only [Bool.and_eq_true, decide_eq_true_eq] at h
intro k hk
refine ⟨.inst a c, ?_, ?_⟩
· simp [check, hk, h.2]
· simp only [len_inst, len_all, Cert.size_inst, Bound.eval, Form.within_none, Cost.inst]
at h ⊢
omega
· simp at h
| .nec c, σ, h => by
simp only [check] at h
split at h
· rename_i n t φ
simp only [Bool.and_eq_true, decide_eq_true_eq] at h
exact ⟨c, h.2, h.1⟩
· simp at h
| .dist, σ, h => by
simp only [check] at h
split at h
· rename_i x φ ψ y φ₁ z ψ₁ hf
simp only [Bool.and_eq_true, beq_iff_eq] at h
obtain ⟨⟨h₁, h₂⟩, h₃⟩ := h
subst h₁ h₂ h₃
exact Sen.holds_of_valid fun n => by
rw [hf]
intro hx hy
have := provable_dist hx hy
simp only [holds, Form.within_none, Bound.eval, Nat.add_zero]
exact this
· simp at h
| .four, σ, h => by
simp only [check] at h
split at h
· rename_i a x φ y x₁ φ₁
simp only [Bool.and_eq_true, beq_iff_eq] at h
obtain ⟨⟨⟨h₁, h₂⟩, h₃⟩, h₄⟩ := h
subst h₁ h₂ h₃
intro k hk hx
have := provable_four (Bound.fits_spec h₄ hk) hx
simp only [holds, Form.within_none, Bound.eval, Cost.expansion]
exact this
· rename_i n x φ y x₁ φ₁
simp only [Bool.and_eq_true, beq_iff_eq, decide_eq_true_eq] at h
obtain ⟨⟨⟨h₁, h₂⟩, h₃⟩, h₄⟩ := h
subst h₁ h₂ h₃
intro hx
have := provable_four (Or.inl h₄) hx
simp only [holds, Form.within_none, Bound.eval, Cost.expansion]
exact this
· simp at h
| .mono, σ, h => by
simp only [check] at h
split at h
· rename_i a x φ y φ₁
simp only [Bool.and_eq_true, beq_iff_eq] at h
obtain ⟨h₁, h₂⟩ := h
subst h₁
split at h₂
· rename_i K hK
simp only [decide_eq_true_eq] at h₂
intro k hk hx
exact hx.mono (Bound.le_of_guard hK k (by omega))
· simp at h₂
· rename_i n x φ y φ₁
simp only [Bool.and_eq_true, beq_iff_eq, decide_eq_true_eq] at h
obtain ⟨h₁, h₂⟩ := h
subst h₁
exact fun hx => hx.mono h₂
· simp at h
| .diag, σ, h => by
simp only [check] at h
split at h
· rename_i g p g₁ g₂ p₁ p₂ hf
simp only [Bool.and_eq_true, beq_iff_eq] at h
obtain ⟨⟨⟨h₁, h₂⟩, h₃⟩, h₄⟩ := h
subst h₁ h₂ h₃ h₄
exact Sen.holds_of_valid fun n => by
rw [hf]
exact Iff.rfl
· simp at h
| .prog, σ, h => by
simp only [check] at h
split at h
· rename_i a b φ hf
simp only [Bool.and_eq_true, Bool.not_eq_true', beq_iff_eq] at h
obtain ⟨⟨⟨ha, hb⟩, hg⟩, hφ⟩ := h
subst hφ
exact Sen.holds_of_valid fun n => by
rw [hf]
simp only [holds, ha, hb, Bool.or_self, true_and]
exact (holds_fill hb ha n a hg none).symm
· simp at hFull source
The checker satisfies every field of the structure, with explicit constants, so the bounded Löb theorem applies to it:
/-- The checker as a proof system with Critch's properties. -/
def calculus : System id where
Sen := Sen
Pred := Form
imp := imp
iff := iff
box := box
above := Sen.all
ProvesIn := Provable
mp := by
rintro a b φ ψ ⟨_, c, hc, -⟩ ⟨_, d, hd, -⟩
exact ⟨_, .mp φ (.raise a c) (.raise b d), by
simp [check, Sen.withForm, Sen.form, hc, hd], le_rfl⟩
trans := by
rintro a b φ ψ χ ⟨_, c, hc, -⟩ ⟨_, d, hd, -⟩
exact ⟨_, Cert.trans φ ψ χ (.raise a c) (.raise b d), by
simp [Cert.trans, check, Sen.withForm, Sen.form, hc, hd], le_rfl⟩
contract := by
rintro a b φ ψ χ ⟨_, c, hc, -⟩ ⟨_, d, hd, -⟩
exact ⟨_, Cert.contract φ ψ χ (.raise a c) (.raise b d), by
simp [Cert.contract, check, Sen.withForm, Sen.form, hc, hd], le_rfl⟩
imp_mono := by
rintro a φ ψ χ ⟨_, c, hc, -⟩
exact ⟨_, Cert.impMono φ ψ χ c, by
simp [Cert.impMono, check, Sen.withForm, Sen.form, hc], le_rfl⟩
iffCost := 1
iff_forward := by
rintro n a φ ψ ⟨c, hc, hl⟩
refine ⟨.iffL c, by simp [check, Sen.withForm, Sen.form, hc], ?_⟩
simp only [len_all, Form.size_imp, Form.size_iff, Cert.size_iffL] at hl ⊢
omega
iff_backward := by
rintro n a φ ψ ⟨c, hc, -⟩
exact ⟨_, .iffR c, by simp [check, Sen.withForm, Sen.form, hc], le_rfl⟩
distCost := 0
imp_dist x y φ ψ := ⟨_, .dist, by simp [check, Sen.form], le_rfl⟩
instCost := Cost.inst
quant_dist := by
rintro N a φ ⟨c, hc, hl⟩
refine ⟨_, .qd c, ?_, le_rfl⟩
have : len c (.all a φ) + Cost.inst ≤ Cost.inst + 2 * N := by omega
simp [check, hc, this]
expansion := Cost.expansion
inner_nec x φ := ⟨2 ^ x.size, _, .four, by simp [check, Bound.fits], le_rfl⟩
mono := by
intro x y φ hgap
obtain ⟨K, hK⟩ := Option.isSome_iff_exists.1 (Bound.guard_isSome hgap)
exact ⟨K, _, .mono, by simp [check, hK], le_rfl⟩
diag g p := ⟨diag g p, _, .diag, by simp [check, Sen.form], le_rfl⟩Full source
Building it changed two of the properties. Inner necessitation, \(\Box_x \varphi \to \Box_{2x} \Box_x \varphi\), needs room in the outer budget for the text of \(x\) itself, and a bound can be small in value but long in text, so as I first stated it, it was false. It holds from some \(k\) on: past \(2^{|x|}\), where the binary numeral for \(k\) that every proof contains already pays for the text, or past the point where \(x(k)\) exceeds the length of its own text by two. Monotonicity of the bound needs the checker to decide inequalities like \(\lfloor k/6\rfloor + \log k + 4000 \le k\) for all \(k\) past a point, which it can do whenever the gap between the two sides grows with \(k\), and every inequality the proof uses has such a gap. Both properties now hold from some \(k\) on, and the bounded Löb theorem goes through with the guards carried along.
DUPOC as a program
An agent's search for a proof of a sentence \(\sigma\) with at most \(t\) characters has three stages. First it checks whether \(\sigma\) fails at one of the first six worlds of the chain from last week. Forget the budgets and every rule of the checker is valid at every world, so a sentence that fails at one world has no proof of any length, and the search can answer no right away. Then it builds a few candidate proofs from the two sources and asks the checker about them. Then it checks every certificate with at most \(t - |\sigma|\) characters. Lean proves that the three stages together decide exactly whether a proof of at most \(t\) characters exists, so the first two only make it faster:
/-- Bounded proof search: is there a proof of `σ` with at most `t` characters? -/
def search (t : ℕ) (σ : Sen) : Bool :=
if refuted worldDepth σ.form then false
else if byCandidate t σ then true
else exhaustive t σ/-- **The search is exact**: `search t σ` holds exactly when `σ` has a proof of at most `t`
characters. -/
theorem search_spec {t : ℕ} {σ : Sen} : search t σ = true ↔ Provable t σ Read the proof
by
unfold search
split
· rename_i hr
simp only [Bool.false_eq_true, false_iff]
exact not_provable_of_refuted hr t
· split
· rename_i hh
simp only [true_iff]
obtain ⟨c, -, hc⟩ := List.any_eq_true.1 hh
exact ⟨c, affordable_iff.1 hc⟩
· exact exhaustive_spec/-- **`run` plays exactly what the source says.** -/
theorem run_spec (n : ℕ) (a b : Form) : run n a b = true ↔ holds n (.coop a b) none :=
eval_spec n _ noneFull source
The candidates are the paper's own suggestion. Critch, Dennis and Russell point out that if the search tried the proof of Theorem 3.7 first, both agents would finish at once. Here the agent builds that proof itself: it runs a certificate builder that follows the proof of the bounded Löb theorem step by step on the two sources it is given, and the checker decides whether the result is a proof. The candidate sits in front of the complete search, never instead of it. In a toy checker with two proofs of size zero, a search that only tries a template defects while a valid, affordable proof exists:
import BoundedLob.Theory.Dupoc
namespace BoundedCoverage
open BoundedLob BoundedLob.Example
-- One cooperating program and two proofs of size zero; only `true` checks.
-- Trying only the template `false` defects:
#eval missChecker.decision [false] 0 () ()
-- The template in front of the complete list of proofs of size zero cooperates:
#eval missChecker.decision ([false] ++ [false, true]) 0 () ()
end BoundedCoverage
Lean output
false
trueTwo copies of DUPOC
The proof the two DUPOCs build is a certificate of 2,962 characters for the sentence "for every \(k > 17879\), DUPOC(k) cooperates with DUPOC(k)". At a budget \(k\) it becomes a proof of \(2993 + \lfloor \log_2 k\rfloor\) characters: the certificate, 17 more for instantiating it at the guard, 11 for the formula and 3 for the sentence around it, plus the numeral for \(k\). At \(k = 17880\) the proof has 3,007 characters, and the whole match, both agents reading both sources and building and checking their proofs, takes about two milliseconds. The certificate is only valid past 17879; below that some other affordable proof might exist, and nothing here says what the smallest cooperating budget is.
Lean proves this about the program that runs, threshold included. The kernel builds the certificate and checks it, and from there, for every \(k > 17879\), DUPOC's search accepts it without ever reaching the complete search, and DUPOC cooperates with itself:
/-- The kernel computes the guard and size of `selfProof` and checks it. -/
theorem selfProof_spec : selfProof.guard = selfThreshold ∧ selfProof.cert.size = 2962 ∧
check selfProof.cert (.all selfThreshold (coop dupoc dupoc)) = true := by
decide +kernel/-- **The fast path.** For every `k > 17879`, DUPOC's search against itself is not refuted by the
worlds and accepts the certificate it builds; the complete search over strings is never
reached. -/
theorem dupoc_fast {k : ℕ} (hk : selfThreshold < k) :
refuted worldDepth (coop dupoc dupoc) = false ∧
byCandidate k (.inst k (coop dupoc dupoc)) = true Read the proof
by
have hp : Provable k (.inst k (coop dupoc dupoc)) :=
⟨_, selfProof_check hk, (selfProof_len k).trans_le (selfProof_fits hk)⟩
refine ⟨?_, List.any_eq_true.2 ⟨_, selfProof_mem hk, affordable_iff.2 ⟨selfProof_check hk,
(selfProof_len k).trans_le (selfProof_fits hk)⟩⟩⟩
cases hr : refuted worldDepth (coop dupoc dupoc)
· rfl
· exact absurd hp (not_provable_of_refuted (σ := .inst k (coop dupoc dupoc)) hr k)/-- **Theorem 3.7, with its threshold.** DUPOC cooperates with itself at every `k > 17879`. -/
theorem dupoc_self_of_lt {k : ℕ} (hk : selfThreshold < k) : run k dupoc dupoc = true := by
obtain ⟨h₁, h₂⟩ := dupoc_fast hk
have : run k dupoc dupoc = search k (.inst k (coop dupoc dupoc)) := rfl
rw [this, search]
simp [Sen.form, h₁, h₂]Full source
Here are recorded runs of the program:
import BoundedLob.Agents.Outcomes
namespace BoundedRun
open BoundedLob BoundedLob.Agent
-- `true` is cooperation. Two copies of DUPOC at budget 17880 find their proof and cooperate:
#eval (run 17880 dupoc dupoc, run 17880 dupoc dupoc)
-- At budget 500000, DUPOC against CUPOD, then DIMCID against CooperateBot and against DUPOC:
#eval (run 500000 dupoc cupod, run 500000 cupod dupoc)
#eval (run 500000 dimcid cooperate, run 500000 cooperate dimcid)
#eval (run 500000 dupoc dimcid, run 500000 dimcid dupoc)
-- DUPOC and CIMCIC are written differently and still cooperate:
#eval (run 500000 dupoc cimcic, run 500000 cimcic dupoc)
end BoundedRun
Lean output
(true, true)
(false, true)
(false, true)
(false, false)
(true, true)CUPOD, which cooperates unless it finds a proof that its opponent defects, gets the same treatment: against itself it builds a 4,457-character certificate of its own defection, valid past \(k = 26963\), and defects (their Theorem 3.4). That threshold comes from the run; only the DUPOC threshold has its own theorem.
Programs that are written differently
Open Problem 4 has a second half: how much can the two implementations differ while cooperation still halts? Critch's 2019 paper answers it for \(G\)-fair agents, which provably cooperate as soon as they have a short enough proof that the opponent cooperates, each with its own parameter. I proved the version for agents that share the parameter \(k\), in a form general enough for the programs I wanted to try. Each agent provably cooperates once it has a proof, within its own budget, of something the system proves from mutual cooperation. If some budget \(u(k)\), growing faster than \(\log k\), leaves room under both, meaning \(u(k) + \log k + c\) is eventually below both agents' budgets for every constant \(c\), then the two cooperate for every large \(k\).
/-- **Robust cooperation** in the checker's system. Two guarded sources that read, in the match,
as `□_{t_A} α` and `□_{t_B} β` cooperate at every large `k`, when the checker proves `α` and `β`
from mutual cooperation and some budget `u` growing faster than `lg k` stays below `t_A` and
`t_B` by `lg k` and any constant. -/
theorem fair_cooperate {a b α β : Form} {ta tb u : Bound}
(ha : a.isPlaceholder = false) (hb : b.isPlaceholder = false) (hga : a.guarded = true)
(hgb : b.guarded = true) (hfa : a.fill b a = box ta α) (hfb : b.fill a b = box tb β)
(hα : calculus.Proves (calculus.above 0 (imp (Form.conj (coop a b) (coop b a)) α)))
(hβ : calculus.Proves (calculus.above 0 (imp (Form.conj (coop a b) (coop b a)) β)))
(hu : GrowsFasterThanLog (u.eval id))
(gapA : ∀ c, ∃ K, ∀ k > K, u.eval id k + Nat.log 2 k + c ≤ ta.eval id k)
(gapB : ∀ c, ∃ K, ∀ k > K, u.eval id k + Nat.log 2 k + c ≤ tb.eval id k) :
∃ K, ∀ k > K, run k a b = true ∧ run k b a = true Read the proof
by
set X := coop a b
set Y := coop b a
have fairA := proves_of_check (a := 0) (φ := imp (box ta α) X) (.iffR .prog) (by
simp [X, check, Sen.withForm, Sen.form, ha, hb, hga, hfa])
have fairB := proves_of_check (a := 0) (φ := imp (box tb β) Y) (.iffR .prog) (by
simp [Y, check, Sen.withForm, Sen.form, ha, hb, hgb, hfb])
have hP := proves_of_check _ (check_conjIntro X Y)
obtain ⟨K, hK⟩ := calculus.robust hu gapA gapB hα hβ hP fairA fairB
have hX := calculus.mp (proves_of_check _ (check_conjLeft X Y)) hK
have hY := calculus.mp (proves_of_check _ (check_conjRight X Y)) hK
refine ⟨max 0 K, fun k hk => ⟨(run_spec k a b).2 ?_, (run_spec k b a).2 ?_⟩⟩
· exact calculus_sound hX k hk
· exact calculus_sound hY k hk/-- **Budgets may differ.** For every fixed `p, q ≥ 1` and `r, s`, DUPOC with budget `p·k + r`
and DUPOC with budget `q·k + s` cooperate with each other at every large `k`. -/
theorem dupoc_linear {p q r s : ℕ} (hp : 0 < p) (hq : 0 < q) :
∃ K, ∀ k > K,
run k (dupoc (.add (.scale p .f) (.const r))) (dupoc (.add (.scale q .f) (.const s))) =
true ∧
run k (dupoc (.add (.scale q .f) (.const s))) (dupoc (.add (.scale p .f) (.const r))) =
true :=
fair_cooperate (u := .div .f 2) (ha := rfl) (hb := rfl) (hga := rfl) (hgb := rfl)
(hfa := rfl) (hfb := rfl) (proves_of_check _ (check_conjRight _ _))
(proves_of_check _ (check_conjLeft _ _)) (growsFasterThanLog_id.div 2 (by decide))
(gap_half (le_linear hp)) (gap_half (le_linear hq))Full source
For DUPOCs with linear budgets this means: for every fixed \(p, q \ge 1\) and \(r, s\), DUPOC with budget \(pk + r\) and DUPOC with budget \(qk + s\) cooperate for all large \(k\). DUPOC against CIMCIC, which cooperates if it can prove that its cooperation implies its opponent's, is another instance (their Theorem 5.2). CIMCIC against itself needs no bounded Löb argument at all: in self-play its condition reads "if I cooperate, then I cooperate", which has a proof of under two hundred characters, so two CIMCICs already cooperate at a budget of 400.
The agents build these proofs the same way, with a builder that follows the argument. I played nine agents against each other at \(k = 500{,}000\): CooperateBot, DefectBot, DUPOC, CUPOD, CIMCIC, DIMCID, DUPOC with budget \(2k\), DUPOC with budget \(k + 100\), and a DUPOC whose source is \(\Box_k(\top \to \mathrm{coop}(\text{opponent}, \text{me}))\). All 81 ordered matches were decided by the first two stages of the search, together in 0.7 seconds and none in more than 16 milliseconds (timing only the two runs of each match), and the five agents that look for proofs of cooperation cooperated with each other in every pairing. For the four pairs of DUPOC with a differently written agent, the certificates have 24,000 to 32,000 characters and are valid from budgets between about 268,000 and 362,000 on. Those are budgets at which these particular certificates work, not budgets cooperation needs. The builder also only tries a few ratios between the two budgets, so a lopsided pair like \(128k\) against \(k\) is covered by the theorem but not by the fast path.
DIMCID defects
DIMCID ("defect if my cooperation implies defection") searches for a proof that if it cooperates, its opponent defects, and defects if it finds one. Critch, Dennis and Russell leave the match against DUPOC open (their Open Problem 6). Under the proof-system assumptions below, I get mutual defection. A proof that DIMCID defects is, a few lines later, a proof of DIMCID's condition, since "I cooperate" is then false and anything follows from it. So a short proof of DIMCID's defection makes DIMCID defect, which is exactly the self-fulfilling shape the bounded Löb theorem turns into a proof. DIMCID defects for every large \(k\), and DUPOC, which would need a proof that DIMCID cooperates, finds none, because there is no true one to find. The argument works in any sound system with the properties above that proves the agents' code and the propositional fact \(\neg A \to (A \to B)\):
/-- **Self-fulfilling statements.** If `f` grows faster than `lg k` and the system proves `d → G`
and `□_f G → d` for every positive `k`, it proves `d` beyond some `k₂`. For DIMCID, `d` is its
defection and `G` its guard. -/
theorem self_fulfilling (hf : GrowsFasterThanLog f) {d G : S.Pred}
(exfalso : S.Proves (S.above 0 (S.imp d G)))
(code : S.Proves (S.above 0 (S.imp (S.box .f G) d))) :
∃ k₂, S.Proves (S.above k₂ d) Read the proof
by
-- Half the budget leaves room for the overhead of turning a proof of `d` into one of `G`.
have gap : ∀ c, ∃ K, ∀ k > K,
(Bound.div .f 2).eval f k + Nat.log 2 k + c ≤ Bound.f.eval f k := by
intro c
obtain ⟨K, hK⟩ := hf.eventually_le_div c 2 (by omega)
refine ⟨K, fun k hk => ?_⟩
have := hK k hk
simp only [Bound.eval]
omega
obtain ⟨K, hK⟩ := S.box_imp_of_gap gap exfalso code
exact S.pblt (.div .f 2) (hf.div 2 (by omega)) hK/-- **Open Problem 6.** DUPOC(k) against DIMCID(k) ends in mutual defection for every large `k`.
`S` is a system with Critch's properties and budget symbol `f(k) = k`, in which `defects` says
"DIMCID(k) defects against DUPOC(k)" and `guard` is DIMCID's guard. The hypotheses are what the
setting of Critch, Dennis and Russell provides: `exfalso` (a program has one output), `code`
(DIMCID defects whenever its guard has a proof of at most `k` characters), soundness of `S` for
the sentences `∀ k > k₂, defects(k)`, and DUPOC as an executable search over a sound checker. -/
theorem dupoc_vs_dimcid {G : Game} {P : Checker G} (sound : P.Sound)
{cands : ℕ → G.Source → G.Source → List P.Proof} {dupoc : ℕ → G.Source}
(hd : P.IsDupoc cands dupoc) (dimcid : ℕ → G.Source) (S : System id) (defects guard : S.Pred)
(exfalso : S.Proves (S.above 0 (S.imp defects guard)))
(code : S.Proves (S.above 0 (S.imp (S.box .f guard) defects)))
(true_of : ∀ k₂, S.Proves (S.above k₂ defects) →
∀ k > k₂, G.run (dimcid k) (dupoc k) = false) :
∃ k₂, ∀ k > k₂, G.run (dupoc k) (dimcid k) = false ∧ G.run (dimcid k) (dupoc k) = false Read the proof
by
obtain ⟨k₂, h⟩ := S.self_fulfilling growsFasterThanLog_id exfalso code
refine ⟨k₂, fun k hk => ⟨?_, true_of k₂ h k hk⟩⟩
cases hrun : G.run (dupoc k) (dimcid k)
· rfl
· have := Checker.not_exploited sound hd hrun
rw [true_of k₂ h k hk] at this
exact absurd this Bool.false_ne_trueFull source
The same argument says something about an easier question. Their Example 5.3 asks what DIMCID does against CooperateBot, and the footnote answers that both cooperate. But against CooperateBot DIMCID's condition is just "I defect", so the self-fulfilling argument applies again and DIMCID defects for every large \(k\). I think the footnote is a slip. In this system the theorem holds against every fixed opponent, with a threshold that depends on the opponent, and against DUPOC, DUPOC defects at every budget:
/-- **Open Problem 6.** DUPOC against DIMCID: DUPOC defects at every budget, DIMCID at every
large budget. -/
theorem dupoc_dimcid :
(∀ k, run k dupoc dimcid = false) ∧ ∃ K, ∀ k > K, run k dimcid dupoc = false Read the proof
by
refine ⟨fun k => ?_, dimcid_defects rfl⟩
cases h : run k dupoc dimcid
· rfl
· rw [run_iff_holds_fill rfl rfl rfl] at h
refine absurd h (not_provable_of_world0 ?_)
simp only [Sen.form, Form.within_none]
decide/-- **Correction to Example 5.3(a).** DIMCID defects against CooperateBot at every large budget,
where the paper answers `(C, C)`. -/
theorem dimcid_vs_cooperate :
∃ K, ∀ k > K, run k dimcid cooperate = false ∧ run k cooperate dimcid = true :=
(dimcid_defects rfl).imp fun _ h k hk => ⟨h k hk, rfl⟩Full source
A Lean engine for open-source game theory, written for a master's thesis, covers a lot of this ground with a different proof system, a classical proof search and its own way of counting proof length. It proves the footnote's \((C, C)\) for DIMCID and CooperateBot, and \((C, D)\) for DIMCID and DUPOC, at every budget. Its rule for contradictions needs two closed proofs, so it can't derive \(A \to B\) from \(\neg A\) under a hypothesis, and that step is exactly the one these proofs need.
What this system can decide
Two of the paper's open problems concern matches whose outcome depends on whether bounded searches succeed: DUPOC against CUPOD (their Open Problem 3, conjectured \((D, C)\)) and CUPOD against CIMCIC (Open Problem 5). In this system both are settled at every budget, by the worlds. Each agent's search asks for a sentence that is false at the first world of the chain, so neither finds a proof of any length: DUPOC defects and CUPOD cooperates, and CUPOD cooperates while CIMCIC defects.
/-- **Open Problem 3**, in this system: DUPOC defects and CUPOD cooperates, at every budget. -/
theorem dupoc_cupod (k : ℕ) : run k dupoc cupod = false ∧ run k cupod dupoc = true Read the proof
by
constructor
· cases h : run k dupoc cupod
· rfl
· rw [run_iff_holds_fill rfl rfl rfl] at h
refine absurd h (not_provable_of_world0 ?_)
simp only [Sen.form, Form.within_none]
decide
· rw [run_iff_holds_fill rfl rfl rfl]
exact not_provable_of_world0 (by simp only [Sen.form, Form.within_none]; decide)/-- **Open Problem 5**, in this system: CUPOD cooperates and CIMCIC defects, at every budget. -/
theorem cupod_cimcic (k : ℕ) : run k cupod cimcic = true ∧ run k cimcic cupod = false Read the proof
by
constructor
· rw [run_iff_holds_fill rfl rfl rfl]
exact not_provable_of_world0 (by simp only [Sen.form, Form.within_none]; decide)
· cases h : run k cimcic cupod
· rfl
· rw [run_iff_holds_fill rfl rfl rfl] at h
refine absurd h (not_provable_of_world0 ?_)
simp only [Sen.form, Form.within_none]
decideFull source
This is an answer about this proof system and not about arithmetic, and the reason is worth saying plainly. The checker cannot prove some elementary finite facts about itself. \(\neg \Box_0 \top\), "there is no proof of \(\top\) with zero characters", is true, but it is false at the first world, so the checker has no proof of it. An arithmetic like Peano's proves facts like that by checking, and it could prove that CUPOD's search runs out, if it really does, by simulating it, when the simulation is short enough. So this development doesn't settle the two problems for arithmetic. The thesis engine proves the analogue of Open Problem 3 in its own calculus, by a transposition of C and D that preserves budgets exactly.
What is still open
The proof system here is built for agents. It has the bounded properties as rules rather than deriving them in arithmetic, its diagonal sentences are a primitive, and its programs are the agents of this game rather than arbitrary code. That is enough for the deterministic results discussed here and for real runs, though not for the paper's probabilistic agents. An arithmetic version still needs Gödel numbering, a programming language, proof predicates that count characters, diagonalization, and the derivability properties with explicit lengths, of which bounded inner necessitation is the central one. And a certificate that is valid only past a threshold says nothing about whether shorter proofs exist below it.
Why I care about this
I care about the gap between what a theorem predicts and what a program can finish. With very different budgets, the theorem can guarantee eventual cooperation even when my candidate builder misses the proof. Below the threshold, a different proof might work, but this one tells us nothing. I'd like to repeat this in arithmetic and test agents with less similar implementations. We'll keep adding to this as it goes :)
Cite this article
Robert Joseph George. Löb's theorem with a budget. TorchLean Verified Examples, 2026.
@misc{george2026bounded,
author = {Robert Joseph George},
title = {{Löb's theorem with a budget}},
year = {2026},
howpublished = {TorchLean Verified Examples},
url = {https://robertboy18.github.io/TorchLean-Verified-Examples/week-08-bounded-lob/}
}
Download BibTeX