Programs that read each other's code
On October 21, Jacob Tsimerman gave a talk at SLMath called Mathematical AI Safety: What is it, why do it, how is it looking?. He is the scientific director of MAISI, the institute whose research directions I wrote about in the last post. Near the end he described one direction he finds promising. Two programs play a prisoner's dilemma, and each one can read the other's source code before it moves. Each program also has a budget of computation, and the question is what happens when programs with different budgets meet.
The programs in his example come from a paper by Andrew Critch, Michael Dennis and Stuart Russell, Cooperative and uncooperative institution designs. One of them, CUPOD(k), cooperates unless it finds a proof of at most k characters that its opponent will defect against it. Its mirror image, DUPOC(k), defects unless it finds a proof of at most k characters that its opponent will cooperate. These programs decide by proving things about each other, so I wanted to see how much of this I could check in Lean.
The paper leaves several bounded matchups as open problems. I'll start with an idealized version, where an agent asks what is provable at all instead of running a search with a budget. Barasz, Christiano, Fallenstein, Herreshoff, LaVictoire and Yudkowsky worked out how to compute the outcomes of such agents with the logic of provability. In this post I build that computation in Lean, prove the outcomes of the classic matchups at every world, and then add the idealized versions of the talk's two agents.
I also asked Thinking Machines' Inkling to propose agents of its own, using Lean's checked outcomes as training feedback. The proposed policies didn't beat FairBot, but one passed its original population and failed when the opponents changed. I'll come back to that experiment after the classic matchups, then finish with a smaller, executable bounded-search prototype.
The prisoner's dilemma with source code
In a prisoner's dilemma each player chooses to cooperate (C) or defect (D). Mutual cooperation is better for both than mutual defection, but whatever the other player does, defecting pays a little more. Two players who reason only about payoffs therefore defect, and both end up worse off than they could have been.
Reading the opponent's source code changes this. The simplest program that uses it is CliqueBot, which cooperates exactly when its opponent's code is identical to its own. Two copies of CliqueBot cooperate, and nobody can exploit CliqueBot, because a defecting program is never an identical copy. But CliqueBot also defects against a program that does exactly what it does and differs by a single space. I'd want cooperation that survives that.
The fix is to cooperate based on what the opponent will do, rather than on what its code looks like. The trouble is that what the opponent will do may depend on what I do, so a program that simulates its opponent can run forever. Reasoning with proofs avoids that recursion, although a proof search with no budget can still run forever when there is no proof to find.
FairBot and Löb's theorem
FairBot cooperates with its opponent when it can prove that the opponent cooperates with it. For these classic agents, "prove" means prove in Peano arithmetic, assumed sound. Against DefectBot, which always defects, there is no such proof, so FairBot defects. Against CooperateBot, which always cooperates, the proof is immediate, so FairBot cooperates. Against itself, FairBot cooperates if it can prove that FairBot cooperates with FairBot. At first both mutual cooperation and mutual defection look possible.
Löb's theorem settles it. It says that if arithmetic proves "if \(P\) is provable, then \(P\)", then arithmetic proves \(P\). Take \(P\) to be "FairBot cooperates with FairBot". FairBot's own definition says that a proof of \(P\) makes \(P\) true, so arithmetic proves \(P\), and both copies cooperate. Barasz and his coauthors prove this as their Theorem 3.1, after an argument by Vladimir Slepnev.
To compute outcomes like this, they write each agent as a formula of provability logic, where \(\Box\varphi\) reads "it is provable that \(\varphi\)". FairBot against an opponent \(b\) is \(\Box\,[b \text{ cooperates with FairBot}]\). Every mention of the opponent's behavior sits under a box, though an agent can combine its provability tests with the usual connectives, negation included. These formulas have a semantics that a computer can evaluate, and that is what I build next.
Evaluating provability on a chain of worlds
The semantics uses a chain of worlds \(0, 1, 2, \dots\), where world \(n\) sees exactly the worlds below it. A box holds at world \(n\) when its contents hold at every world below \(n\). At world \(0\) there is nothing below, so every box holds there, \(\Box\bot\) included: world \(0\) is a world where everything is provable. It is a device of the semantics, not a model of arithmetic, and the worlds are not rounds of play or proof budgets. What carries over to arithmetic is the value a formula settles on at high worlds, and the last section says when.
/-- Formulas of provability logic over atoms of type `α`. -/
inductive Form (α : Type) where
| atom : α → Form α
| top : Form α
| bot : Form α
| not : Form α → Form α
| and : Form α → Form α → Form α
| or : Form α → Form α → Form α
| imp : Form α → Form α → Form α
| box : Form α → Form α
deriving DecidableEq, Repr
/-- Truth of `φ` at world `n` of the chain, where `□ψ` holds at `n` when `ψ` holds at every
world below `n`. -/
def eval (V : ℕ → α → Bool) : ℕ → Form α → Bool
| n, atom a => V n a
| _, top => true
| _, bot => false
| n, not φ => !eval V n φ
| n, and φ ψ => eval V n φ && eval V n ψ
| n, or φ ψ => eval V n φ || eval V n ψ
| n, imp φ ψ => !eval V n φ || eval V n ψ
| n, box φ => (List.range n).all fun m => eval V m φFull source
On this chain, Löb's theorem becomes a statement I can prove directly: \(\Box(\Box\varphi \to \varphi) \to \Box\varphi\) holds at every world, for every formula and every valuation of its atoms. The proof is an induction down the chain. The same argument works on any frame whose "sees" relation is transitive and well founded, and transitivity matters. On three worlds where 2 sees 1 and 1 sees 0, but 2 does not see 0, Löb's axiom fails.
/-- Löb's axiom `□(□φ → φ) → □φ` holds at every world of the chain, for every valuation. -/
theorem loeb (V : ℕ → α → Bool) (n : ℕ) (φ : Form α) :
eval V n (imp (box (imp (box φ) φ)) (box φ)) = true Read the proof
by
rw [eval_imp, eval_box, eval_box]
intro h m hm
induction m using Nat.strongRecOn with
| _ m ih =>
have step := (eval_imp V m (box φ) φ).1 (h m hm)
exact step ((eval_box V m φ).2 fun k hk => ih k hk (by omega))/-- Löb's axiom holds on every transitive, well-founded frame. -/
theorem loeb_of_wellFounded {W : Type} (R : W → W → Prop) (trans : ∀ u v w, R u v → R v w → R u w)
(wf : WellFounded R) (V : W → α → Prop) (w : W) (φ : Form α) :
holdsOn R V w (imp (box (imp (box φ) φ)) (box φ)) := by
intro h v hv
induction v using wf.induction with
| _ v ih => exact h v hv fun u hu => ih u hu (trans u v w hu hv)/-- Without transitivity Löb's axiom can fail: world `2` sees `1`, `1` sees `0`, but `2` does not
see `0`, and the atom is false at `0` and `1`. -/
theorem loeb_needs_transitivity :
¬ holdsOn (fun v w : Fin 3 => w.val = v.val + 1) (fun w (_ : Unit) => w.val = 2) 2
(imp (box (imp (box (atom ())) (atom ()))) (box (atom ()))) Read the proof
by
intro h
have step : ∀ v : Fin 3, (2 : Fin 3).val = v.val + 1 →
(∀ u : Fin 3, v.val = u.val + 1 → u.val = 2) → v.val = 2 := by
intro v hv hbox
have hv' : v.val = 1 := by
have h2 : (2 : Fin 3).val = 2 := rfl
omega
have hv1 : v = 1 := Fin.ext hv'
subst hv1
exact absurd (hbox 0 rfl) (by decide)
have h1 : (1 : Fin 3).val = 2 := h step 1 rfl
exact absurd h1 (by decide)Full source
Agents and their outcome table
I write each agent as a schema over two kinds of atoms: "my opponent cooperates with me", and
"my opponent cooperates with agent \(c\)" for some fixed agent \(c\). The same schema is used against
every opponent. An agent therefore cannot look at who it is playing, only at what it can prove
about how the opponent plays. That excludes CliqueBot, which is the point. Every atom sits
under a box, so an agent's decision at world \(n\) only reads worlds below \(n\).
That lets me compute the whole table of outcomes world by world: play n a b says whether \(a\)
cooperates with \(b\) at world \(n\).
/-- What an agent's formula can mention: whether its opponent cooperates with the agent itself,
or with the fixed agent `c`. -/
inductive Target (Agent : Type) where
| me
| agent (c : Agent)
deriving DecidableEq, Repr
/-- A population of modal agents. -/
structure Universe where
/-- The agents. -/
Agent : Type
/-- Each agent's formula, the same against every opponent. -/
schema : Agent → Form (Target Agent)
/-- Every atom in an agent's schema occurs under a box. -/
modalized : ∀ a, (schema a).modalized = true
/-- `a`'s formula against `b`, over the atoms "`x` cooperates with `y`". -/
def rule (a b : U.Agent) : Form (U.Agent × U.Agent) :=
(U.schema a).map fun
| .me => (b, a)
| .agent c => (b, c)
/-- `play n a b`: whether `a` cooperates with `b` at world `n`. -/
def play (n : ℕ) (a b : U.Agent) : Bool :=
eval (fun m p => if _ : m < n then play m p.1 p.2 else false) n (U.rule a b)
termination_by nFull source
The recursion isn't just one way to fill in the table. The table satisfies every agent's defining equation at every world, and any other valuation that does so is equal to it, so the agents' definitions leave no choices on the chain.
/-- The table satisfies every agent's defining equation at every world. -/
theorem play_eq (n : ℕ) (a b : U.Agent) :
U.play n a b = eval (fun m p => U.play m p.1 p.2) n (U.rule a b) := by
rw [play]
exact eval_congr_of_modalized (fun m hm p => by simp [hm]) (U.rule_modalized a b)/-- Any valuation that satisfies the agents' equations at every world is the table. -/
theorem play_unique (V : ℕ → U.Agent → U.Agent → Bool)
(hV : ∀ n a b, V n a b = eval (fun m p => V m p.1 p.2) n (U.rule a b)) :
∀ n a b, V n a b = U.play n a b Read the proof
by
intro n
induction n using Nat.strongRecOn with
| _ n ih =>
intro a b
rw [hV, U.play_eq]
exact eval_congr_of_modalized (fun m hm p => ih m hm p.1 p.2) (U.rule_modalized a b)Full source
Each matchup also settles. If the contents of a box first fail at world \(m\), the box is false at world \(m + 1\) and stays false, and if they never fail, the box is true everywhere. A modalized formula is built from finitely many boxes, so it settles too, under any valuation. Applied to the table, every matchup gets its own cutoff, after which it never changes, and so it has exactly one eventual outcome.
/-- Under any valuation, a boxed formula changes value at most once, from true to false: either
its body holds at every world, or a world where it fails falsifies the box above it. -/
theorem box_stabilizes (V : ℕ → α → Bool) (φ : Form α) :
∃ K, ∀ n ≥ K, eval V n (box φ) = eval V K (box φ) Read the proof
by
by_cases h : ∀ m, eval V m φ = true
· refine ⟨0, fun n _ => ?_⟩
rw [(eval_box V n φ).2 fun m _ => h m, (eval_box V 0 φ).2 fun m _ => h m]
· obtain ⟨m, hm⟩ := Classical.not_forall.1 h
have low : ∀ k > m, eval V k (box φ) = false := fun k hk =>
Bool.eq_false_iff.2 fun hb => hm ((eval_box V k φ).1 hb m hk)
exact ⟨m + 1, fun n hn => by rw [low n (by omega), low (m + 1) (by omega)]⟩/-- Under any valuation, a modalized formula is eventually constant along the chain. -/
theorem stabilizes_of_modalized (V : ℕ → α → Bool) {φ : Form α} (hφ : modalized φ = true) :
∃ K, ∀ n ≥ K, eval V n φ = eval V K φ Read the proof
by
have pair : ∀ {φ ψ : Form α} (f : Bool → Bool → Bool),
(∃ K, ∀ n ≥ K, eval V n φ = eval V K φ) → (∃ K, ∀ n ≥ K, eval V n ψ = eval V K ψ) →
∃ K, ∀ n ≥ K, f (eval V n φ) (eval V n ψ) = f (eval V K φ) (eval V K ψ) := by
rintro φ ψ f ⟨K₁, h₁⟩ ⟨K₂, h₂⟩
refine ⟨max K₁ K₂, fun n hn => ?_⟩
rw [h₁ n (by omega), h₂ n (by omega), h₁ (max K₁ K₂) (by omega), h₂ (max K₁ K₂) (by omega)]
induction φ with
| atom a => simp [modalized] at hφ
| top | bot => exact ⟨0, fun _ _ => rfl⟩
| not φ ih =>
simp only [modalized] at hφ
obtain ⟨K, hK⟩ := ih hφ
exact ⟨K, fun n hn => by simp [eval, hK n hn]⟩
| and φ ψ ihφ ihψ =>
simp only [modalized, Bool.and_eq_true] at hφ
exact pair (· && ·) (ihφ hφ.1) (ihψ hφ.2)
| or φ ψ ihφ ihψ =>
simp only [modalized, Bool.and_eq_true] at hφ
exact pair (· || ·) (ihφ hφ.1) (ihψ hφ.2)
| imp φ ψ ihφ ihψ =>
simp only [modalized, Bool.and_eq_true] at hφ
exact pair (fun x y => !x || y) (ihφ hφ.1) (ihψ hφ.2)
| box φ => exact box_stabilizes V φFull source
/-- Every matchup settles: from some world on, its entry in the table no longer changes. -/
theorem play_stabilizes (a b : U.Agent) : ∃ K, ∀ n ≥ K, U.play n a b = U.play K a b := by
obtain ⟨K, hK⟩ := stabilizes_of_modalized (fun m p => U.play m p.1 p.2) (U.rule_modalized a b)
exact ⟨K, fun n hn => by rw [U.play_eq, U.play_eq K, hK n hn]⟩
/-- Every matchup has an eventual outcome. -/
theorem cooperates_or_defects (a b : U.Agent) : U.Cooperates a b ∨ U.Defects a b := by
obtain ⟨K, hK⟩ := U.play_stabilizes a b
cases h : U.play K a b
· exact Or.inr ⟨K, fun n hn => (hK n hn).trans h⟩
· exact Or.inl ⟨K, fun n hn => (hK n hn).trans h⟩Full source
The table of outcomes
Here are the agents. CooperateBot and DefectBot ignore the opponent. FairBot is the formula
above. twin is FairBot written differently, \(\Box(\text{me} \lor \bot)\). PrudentBot adds a
second requirement, and cupod is the idealized CUPOD. I come back to both below.
/-- The agents of the article. -/
inductive Bot where
| cooperate
| defect
| fair
| twin
| prudent
| cupod
deriving DecidableEq, Repr
/-- Each agent's formula, the same against every opponent. -/
def schema : Bot → Form (Target Bot)
| cooperate => top
| defect => bot
| fair => box (atom .me)
| twin => box (or (atom .me) bot)
| prudent => and (box (atom .me)) (box (imp (not (box bot)) (not (atom (.agent defect)))))
| cupod => not (box (not (atom .me)))
/-- The population of the article's agents. -/
abbrev bots : Universe where
Agent := Bot
schema := Bot.schema
modalized a := by cases a <;> rflFull source
Lean can print the moves. Each line is one matchup, and its four letters are the first agent's moves at worlds \(0\), \(1\), \(2\) and \(3\).
import ProgramEquilibrium.Bots
namespace ProgramTable
open ProgramEquilibrium
-- Whether the first agent cooperates with the second, at worlds 0, 1, 2 and 3.
def moves (a b : Bot) : String :=
String.join ((List.range 4).map fun n => if bots.play n a b then "C" else "D")
#eval moves .fair .fair
#eval moves .fair .defect
#eval moves .prudent .cooperate
#eval moves .prudent .fair
#eval moves .fair .cupod
#eval moves .cupod .fair
#eval moves .cupod .cupod
end ProgramTable
Lean output
"CCCC"
"CDDD"
"CCDD"
"CCCC"
"CDDD"
"DCCC"
"DDDD"At world \(0\), FairBot, its twin and PrudentBot cooperate with everyone, even DefectBot, because every box holds there. CUPOD, whose formula negates a box, defects against everyone at world \(0\). From world \(1\) on, FairBot defects against DefectBot. PrudentBot cooperates with CooperateBot at worlds \(0\) and \(1\) and defects from world \(2\) on. After that none of these sequences changes.
I don't have to trust the printout for small worlds only. Each matchup here is proved at every world.
/-- FairBot cooperates with FairBot at every world: Löb's theorem in the table. -/
theorem fair_fair (n : ℕ) : bots.play n fair fair = true := by
induction n using Nat.strongRecOn with
| _ n ih => exact (fair_play n fair).2 ih/-- FairBot and its twin cooperate with each other at every world, though their formulas
differ. -/
theorem fair_twin (n : ℕ) : bots.play n fair twin = true ∧ bots.play n twin fair = true := by
induction n using Nat.strongRecOn with
| _ n ih =>
exact ⟨(fair_play n twin).2 fun m hm => (ih m hm).2,
(twin_play n fair).2 fun m hm => (ih m hm).1⟩/-- FairBot cooperates with DefectBot only at world `0`. -/
theorem fair_defect (n : ℕ) : bots.play n fair defect = true ↔ n = 0 Read the proof
by
rw [fair_play]
constructor
· intro h
by_contra hn
have := h 0 (Nat.pos_of_ne_zero hn)
simp [defect_play] at this
· rintro rfl m hm
omegaFull source
FairBot's safety property holds against every agent in any population, not just the agents in my table. If an agent defects against FairBot at some world, FairBot defects against it at every higher world, so nobody exploits FairBot in the limit. The exact condition goes further: FairBot eventually cooperates with \(b\) exactly when \(b\) cooperates with FairBot at every world.
theorem fair_defects_above (hf : U.schema f = box (atom .me)) {b : U.Agent} {m : ℕ}
(hm : U.play m b f = false) : ∀ n > m, U.play n f b = false Read the proof
by
intro n hn
rw [U.play_eq, fair_rule hf]
apply Bool.eq_false_iff.2
intro h
have := (eval_box _ n _).1 h m hn
simp [eval, hm] at thistheorem fair_unexploitable (hf : U.schema f = box (atom .me)) {b : U.Agent}
(h : U.Defects b f) : U.Defects f b := by
obtain ⟨K, hK⟩ := h
exact ⟨K + 1, fun n hn => fair_defects_above hf (hK K (Nat.le_refl K)) n (by omega)⟩theorem fair_cooperates_iff (hf : U.schema f = box (atom .me)) (b : U.Agent) :
U.Cooperates f b ↔ ∀ m, U.play m b f = true Read the proof
by
constructor
· rintro ⟨K, hK⟩ m
have h := hK (max K (m + 1)) (by omega)
rw [U.play_eq, fair_rule hf] at h
exact (eval_box _ _ _).1 h m (by omega)
· intro h
refine ⟨0, fun n _ => ?_⟩
rw [U.play_eq, fair_rule hf]
exact (eval_box _ _ _).2 fun m _ => h mFull source
Cooperation without identical code
FairBot and twin have different formulas. CliqueBot would refuse to cooperate across that
difference, but FairBot and its twin cooperate with each other at every world, for the same
reason FairBot cooperates with itself. Each one's cooperation is provable from the other's, and
Löb's theorem turns that into a proof that both cooperate. This is the robustness I was after:
the agents only need to prove things about each other's behavior, not recognize each other's
text.
PrudentBot and CooperateBot
FairBot has one weakness. It cooperates with CooperateBot, which would also cooperate with anyone, so FairBot leaves something on the table. PrudentBot fixes this. Besides a proof that its opponent cooperates with it, it wants a proof that its opponent defects against DefectBot, assuming arithmetic is consistent: \(\Box\,\text{me} \land \Box(\lnot\Box\bot \to \lnot[\text{opponent cooperates with DefectBot}])\).
CooperateBot fails the second test, so PrudentBot defects against it from world \(2\) on. The assumption \(\lnot\Box\bot\) explains the delay. It is false at world \(0\), so the second test first bites at world \(1\), and a box first looks at world \(1\) from world \(2\). FairBot and PrudentBot pass each other's tests, so they cooperate with each other at every world, and PrudentBot cooperates with itself.
/-- PrudentBot cooperates with CooperateBot only at worlds `0` and `1`. -/
theorem prudent_cooperate (n : ℕ) : bots.play n prudent cooperate = true ↔ n ≤ 1 Read the proof
by
rw [prudent_play]
constructor
· rintro ⟨-, h⟩
by_contra hn
have := h 1 (by omega) Nat.one_ne_zero
simp [cooperate_play] at this
· intro hn
exact ⟨fun m _ => cooperate_play m prudent, fun m hm h0 => by omega⟩/-- PrudentBot and FairBot cooperate with each other at every world. -/
theorem prudent_fair (n : ℕ) : bots.play n prudent fair = true ∧ bots.play n fair prudent = true := by
induction n using Nat.strongRecOn with
| _ n ih =>
refine ⟨(prudent_play n fair).2 ⟨fun m hm => (ih m hm).2, fun m _ hm => ?_⟩,
(fair_play n prudent).2 fun m hm => (ih m hm).1⟩
exact Bool.eq_false_iff.2 fun h => hm ((fair_defect m).1 h)/-- PrudentBot cooperates with PrudentBot at every world. -/
theorem prudent_prudent (n : ℕ) : bots.play n prudent prudent = true := by
induction n using Nat.strongRecOn with
| _ n ih =>
refine (prudent_play n prudent).2 ⟨ih, fun m _ hm => ?_⟩
exact Bool.eq_false_iff.2 fun h => hm ((prudent_defect m).1 h)Full source
The talk's agents, idealized
Back to the talk. If I replace DUPOC(k)'s bounded search by ordinary provability, "defect unless it is provable that you cooperate" is FairBot. The same change to CUPOD(k) gives \(\lnot\Box\lnot\,\text{me}\): cooperate unless it is provable that the opponent defects. I add that agent to the table.
theorem cupod_play (n : ℕ) (b : Bot) :
bots.play n cupod b = true ↔ ∃ m < n, bots.play m b cupod = true := by
rw [Universe.play_eq]
change eval (fun m p => bots.play m p.1 p.2) n (not (box (not (atom (b, cupod))))) = true ↔ _
rw [eval_not, Bool.eq_false_iff, ne_eq, eval_box]
simp only [eval_not, not_forall, Bool.not_eq_false]
exact exists_congr fun m => ⟨fun ⟨h, e⟩ => ⟨h, e⟩, fun ⟨h, e⟩ => ⟨h, e⟩⟩/-- CUPOD defects against CUPOD at every world, as CUPOD(k) does for large `k`
(Critch, Dennis and Russell, Theorem 3.4). -/
theorem cupod_cupod (n : ℕ) : bots.play n cupod cupod = false Read the proof
by
induction n using Nat.strongRecOn with
| _ n ih =>
apply Bool.eq_false_iff.2
intro h
obtain ⟨m, hm, hc⟩ := (cupod_play n cupod).1 h
simp [ih m hm] at hc/-- Against CUPOD, FairBot cooperates only at world `0`, and CUPOD cooperates from world `1` on.
Critch, Dennis and Russell conjecture the same outcome, (D, C), for DUPOC(k) against CUPOD(k)
(their Open Problem 3). -/
theorem fair_cupod (n : ℕ) :
(bots.play n fair cupod = true ↔ n = 0) ∧ (bots.play n cupod fair = true ↔ 1 ≤ n) Read the proof
by
induction n using Nat.strongRecOn with
| _ n ih =>
constructor
· rw [fair_play]
constructor
· intro h
by_contra hn
have := (ih 0 (Nat.pos_of_ne_zero hn)).2.1 (h 0 (Nat.pos_of_ne_zero hn))
omega
· rintro rfl m hm
omega
· rw [cupod_play]
constructor
· rintro ⟨m, hm, -⟩
omega
· intro hn
exact ⟨0, by omega, (ih 0 (by omega)).1.2 rfl⟩Full source
Critch, Dennis and Russell prove that, under their assumptions on the proof system, for every sufficiently large \(k\) two copies of CUPOD(k) defect against each other (their Theorem 3.4) and two copies of DUPOC(k) cooperate (Theorem 3.7). The idealized agents do the same at every world. CUPOD against CUPOD is a fixed point of \(p \leftrightarrow \lnot\Box\lnot p\), and Löb's theorem makes \(\lnot p\) provable. Both results surprise people: the paper notes that most computer science graduate students, asked about two DUPOCs, guess that they defect.
The mixed pairing is their Open Problem 3: does DUPOC(k) against CUPOD(k) end in (D, C) for every sufficiently large \(k\), with DUPOC defecting and CUPOD cooperating? They conjecture that it does. For the idealized agents it does. FairBot cooperates with CUPOD only at world \(0\), and CUPOD cooperates with FairBot from world \(1\) on. That doesn't settle their question, though. Their search ranges over proofs of at most \(k\) characters, which bounds the length of a proof rather than the running time, and whether proofs of the right lengths exist is exactly what is open. Whether a bounded PrudentBot exists at all is their Open Problem 9.
The table also has no proof-length parameter, so it cannot reproduce what Tsimerman was after, agents with different budgets meeting each other.
/-- The eventual outcome of every matchup the article discusses. -/
theorem outcomes :
bots.Cooperates fair fair ∧ bots.Cooperates fair twin ∧ bots.Cooperates twin fair ∧
bots.Cooperates fair cooperate ∧ bots.Defects fair defect ∧
bots.Cooperates prudent prudent ∧ bots.Cooperates prudent fair ∧
bots.Cooperates fair prudent ∧ bots.Defects prudent defect ∧
bots.Defects prudent cooperate ∧ bots.Defects cupod cupod ∧ bots.Defects fair cupod ∧
bots.Cooperates cupod fair Read the proof
by
refine ⟨⟨0, fun n _ => fair_fair n⟩, ⟨0, fun n _ => (fair_twin n).1⟩,
⟨0, fun n _ => (fair_twin n).2⟩, ⟨0, fun n _ => fair_cooperate n⟩, ⟨1, fun n hn => ?_⟩,
⟨0, fun n _ => prudent_prudent n⟩, ⟨0, fun n _ => (prudent_fair n).1⟩,
⟨0, fun n _ => (prudent_fair n).2⟩, ⟨1, fun n hn => ?_⟩, ⟨2, fun n hn => ?_⟩,
⟨0, fun n _ => cupod_cupod n⟩, ⟨1, fun n hn => ?_⟩, ⟨1, fun n hn => (fair_cupod n).2.2 hn⟩⟩
· exact Bool.eq_false_iff.2 fun h => by have := (fair_defect n).1 h; omega
· exact Bool.eq_false_iff.2 fun h => by have := (prudent_defect n).1 h; omega
· exact Bool.eq_false_iff.2 fun h => by have := (prudent_cooperate n).1 h; omega
· exact Bool.eq_false_iff.2 fun h => by have := (fair_cupod n).1.1 h; omegaFull source
Cooperation is also collusion
Tsimerman ended on a point about all of this. Cooperation sounds good, but cooperation between agents is the same thing as collusion, and with many agents in the wild we might not want them to cooperate too much. He suggested we might want gatekeeping, and he presented this line of work as one promising direction among several.
Nothing here addresses that question directly. The cooperation in my table assumes that each agent can read the other's code, and it says nothing about how cheaply real systems could coordinate, or how to stop them. FairBot and its twin have different formulas and still reach mutual cooperation by reasoning about each other's behavior.
Asking Inkling to write the policies
Could a model find a better policy if it could try formulas and receive checked feedback? I connected Inkling to the evaluator above. The model returns a small constructor tree: boxes, Boolean connectives and the allowed references to other agents. It does not return Lean code for us to execute. A host program searches for a stopping certificate, and a fixed Lean program checks it before the proposed policy can enter the game. In the training studies, each proposal is conditioned on the current population, with the opponents' schemas visible.
There is a subtlety in that stopping test. Seeing the same outcome table at two consecutive worlds isn't enough: a box buried inside a formula might still change later. The certificate checks agreement of every nested box between a world and its successor, as well as the claimed outcome table. I prove that this complete box state keeps agreeing, so the table never changes again.
/-- A valid certificate binds the supplied table to the permanent table of this population. -/
def check (world : ℕ) (claimed : List (List Bool)) : Bool :=
stoppedCheck U agents world && (claimed == table U agents world)
theorem check_stable (complete : ∀ a, a ∈ agents) {world : ℕ}
{claimed : List (List Bool)} (h : check U agents world claimed = true)
{later : ℕ} (hlater : world ≤ later) (a b : U.Agent) :
U.play later a b = U.play world a b :=
U.play_eq_of_stopped
(stoppedCheck_sound U agents complete (Bool.and_eq_true_iff.mp h).1) hlater a bFull source
A valid certificate needn't describe a policy we'd want. DefectBot has perfectly definite
outcomes! Admission additionally requires no unilateral cooperation against a defector,
self-cooperation, and mutual cooperation with at least one other member of the population.
accepted_safe connects that executable criterion to eventual non-exploitation. Its
quantifier ranges over the supplied population; it doesn't include every possible
opponent.
/-- Certificate validity and desirability are different checks: an always-defecting candidate
can submit a valid certificate but does not pass this policy criterion. -/
def accepted [DecidableEq U.Agent] (world : ℕ) (claimed : List (List Bool))
(candidate : U.Agent) : Bool :=
check U agents world claimed && safeCheck U agents world candidate &&
U.play world candidate candidate && externalCooperation U agents world candidate/-- Accepted candidates cannot be exploited by any member of the supplied population in the
eventual chain outcomes. This does not quantify over agents absent from that population. -/
theorem accepted_safe [DecidableEq U.Agent] (complete : ∀ a, a ∈ agents)
{world : ℕ} {claimed : List (List Bool)} {candidate : U.Agent}
(h : accepted U agents world claimed candidate = true) (b : U.Agent)
(hc : U.Cooperates candidate b) : U.Cooperates b candidate Read the proof
by
have parts := Bool.and_eq_true_iff.mp h
have parts' := Bool.and_eq_true_iff.mp parts.1
have parts'' := Bool.and_eq_true_iff.mp parts'.1
have hs := stoppedCheck_sound U agents complete (Bool.and_eq_true_iff.mp parts''.1).1
obtain ⟨k, hk⟩ := hc
have forward : U.play world candidate b = true :=
(U.play_eq_of_stopped hs (Nat.le_max_left world k) candidate b).symm.trans
(hk _ (Nat.le_max_right world k))
have backward := (List.all_eq_true.mp parts''.2) b (complete b)
have hb : U.play world b candidate = true := by simpa [forward] using backward
exact ⟨world, fun n hn => (U.play_eq_of_stopped hs hn b candidate).trans hb⟩Full source
I compared two ways of proposing policies. In the unrestricted arm, Inkling writes the whole formula. In the shielded arm, it writes an extra condition \(g\), and the host constructs \(\Box\,\text{me} \land g\). That prefix already has a non-exploitation theorem, for any extra condition and any opponent in a compatible modal universe. Training can change how useful the policy is, but it isn't responsible for this guarantee.
/-- Guarded cooperation and eventual counterparty defection cannot occur together. -/
theorem guarded_not_exploited (hf : U.schema f = and (box (atom .me)) guard) :
¬ (U.Cooperates f b ∧ U.Defects b f) := by
rintro ⟨hcoop, hdefect⟩
exact U.not_cooperates_and_defects f b ⟨hcoop, guarded_unexploitable hf hdefect⟩Full source
What changed with training?
The two completed studies used 2,048 proposals altogether, half for training and half for before-and-after evaluation. There were 126 actual optimizer updates. Each row below pools two runs, with 128 evaluation attempts before training and 128 afterward.
Cooperation is the fraction of external opponents with whom an admitted proposal mutually cooperates. An invalid or rejected attempt scores zero. Admission is reported separately so we can see whether a model produces useful policies more often, rather than only inspect its successful attempts.
| Study | Policy class | Admission, before → after | Cooperation, before → after |
|---|---|---|---|
| First, with protocol amendments | Unrestricted | 43.75% → 50.00% | 13.73% → 17.59% |
| First, with protocol amendments | Shielded | 76.56% → 68.75% | 27.06% → 24.30% |
| Fresh replication | Unrestricted | 35.94% → 47.66% | 13.67% → 18.02% |
| Fresh replication | Shielded | 74.22% → 71.09% | 26.07% → 25.29% |
The unrestricted arm improved modestly in the replication. Its cooperation change was +4.35 percentage points, with a case-resampled 95% interval of [+0.61, +8.20]. It produced acceptable policies more often; cooperation among admitted proposals stayed roughly flat. Neither shielded comparison showed a clear learning gain. These intervals describe these runs and populations, not a general result about training: both studies reuse the same 32 test populations and two training halves.
FairBot scored 36.27% on those populations, above every trained arm. No admitted final proposal beat FairBot on its original population. The unrestricted arms also proposed 39 and 46 exploitable policies in their final evaluations. Those were rejected and never deployed. The shielded arms proposed none, as their fixed wrapper theorem predicts. I wouldn't call that learned alignment.
A certificate that doesn't transfer
One unrestricted proposal from the first study passed its original population. Written in the experiment's notation, it was
I kept that policy unchanged and tried it in eight reserved populations. Two of them exposed it: the policy cooperates with an opponent that defects against it. Lean checked the new outcome tables and rejected admission in both cases. The original theorem was still right: it concerned a particular population, and these were different populations. This is why testing more opponents and proving an arbitrary-opponent theorem are different tasks. The guarded class has the latter theorem; an unrestricted policy doesn't acquire it by passing a finite test.
Counting repeated proposals with their original attempt weights, 510 of 512 unrestricted transfers passed in the first study, and all 488 passed in the replication. The failure did not recur in the second study. Both guarded cohorts passed all their transfers. The offline replay includes the exact three certificates for the original success and the two failures, as well as the full evaluated set.
Giving reciprocity more room
FairBot demands reciprocity at every earlier world, including the early worlds that don't model sound arithmetic. I tried a larger family that only demands it above a finite cutoff:
On the chain, \(\Box^k\bot\) holds exactly below world \(k\). This policy therefore ignores reciprocity below \(k\), while still eventually defecting against any eventual defector. The theorem holds for any finite \(k\) and extra condition \(g\), in finite or infinite compatible populations. It doesn't promise non-exploitation at every early world, and \(k\) is still a modal index, not a number of game rounds or a proof-search budget.
/-- The delayed guard prevents eventual exploitation in any compatible universe. -/
theorem delayed_guard_not_exploited
(hf : U.schema f = and (box (imp (not (cutoff k)) (atom .me))) guard) :
¬ (U.Cooperates f b ∧ U.Defects b f) := by
rintro ⟨hcoop, hdefect⟩
exact U.not_cooperates_and_defects f b
⟨hcoop, delayed_guard_unexploitable hf hdefect⟩Full source
This is related to the paper's WaitFairBot family, whose formula also includes an outer \(\lnot\Box^k\bot\) conjunct. I included those policies among the handwritten controls; the delayed-cooperation idea isn't a new mechanism discovered by Inkling.
For the follow-up, I looked for one fixed policy to use across populations. Base Inkling and one saved trained adapter each proposed 24 policies over six feedback rounds. They saw the same pooled development feedback. There were no further weight updates. Forty-one of the 48 responses passed syntax validation. Selection used 16 new development populations, with ties retaining a handwritten control, before evaluating 48 held-out populations. The combinations were new, but the opponent catalog was the same.
| Policy | Development cooperation | Held-out cooperation |
|---|---|---|
| FairBot | 42.75% | 45.71% |
| Selected handwritten control | 46.76% | 45.21% |
| Best base-model proposal | 46.76% | 45.21% |
| Best trained-model proposal | 46.76% | 45.21% |
The primary selection retained the control for both sources. I also checked the actual best model proposals separately. Their constructor trees differ, but the base model duplicated a conjunct and the trained model added a tautology. Lean proves both equivalent to the supplied one-world control for every valuation, not just on these test populations.
/-- Literal translation of the selected JSON constructor tree. -/
def control {Agent : Type} : Form (Target Agent) :=
and (box (imp (not (box bot)) (atom .me))) top
/-- Literal constructor tree proposed by the base sampler. -/
def baseProposal {Agent : Type} : Form (Target Agent) :=
and (box (imp (not (box bot)) (atom .me))) control
/-- Literal constructor tree proposed by the trained sampler. -/
def trainedProposal {Agent : Type} : Form (Target Agent) :=
and (box (imp (not (box bot)) (atom .me)))
(or (box (atom .me)) (not (box (atom .me))))
/-- The base sampler duplicated an existing conjunct rather than changing the rule. -/
theorem eval_base_eq_control {Agent : Type} (V : ℕ → Target Agent → Bool) (n : ℕ) :
eval V n baseProposal = eval V n control := by
simp [baseProposal, control, eval]
/-- The trained sampler's added guard is a Boolean tautology. -/
theorem eval_trained_eq_control {Agent : Type} (V : ℕ → Target Agent → Bool) (n : ℕ) :
eval V n trainedProposal = eval V n control := by
simp [trainedProposal, control, eval]Full source
So the development improvement didn't carry over: the selected policy was 0.50 percentage points below FairBot on held-out cases, with interval [−3.58, +2.52]. This didn't find a new strategy or establish an advantage from training. It did leave us with an experiment where we can inspect the proposed programs, reject the ones that fail the criterion, and prove why some apparently different answers are the same policy.
The experiment notes and replay commands give the training settings, protocol amendments, selection rules and exclusions. The export contains programs and certificates, without credentials, private checkpoints or raw API traces.
What Lean checks here
Lean checks these properties of the chain semantics:
- Löb's axiom at every world of the chain, and on every transitive, well-founded frame, together with the counterexample that shows transitivity is needed.
- The outcome table: it satisfies every agent's defining equation at every world, it is the only valuation that does, and every matchup settles to one eventual outcome.
- The matchups in this post at every world, and FairBot's safety property against every agent in any population that contains it.
- The stopping certificate and admission criterion for an exact finite population, the strict and delayed guard theorems for arbitrary compatible populations, and the semantic equalities of the selected Inkling proposals.
The general theorems are kernel-checked. Individual experimental certificates run the proved Boolean checker through Lean's runtime; they don't each produce a new kernel proof object. Those runs also trust the compiler and runtime. None of these statements verifies Inkling's neural weights or establishes real-world alignment.
The step from the chain to arithmetic is cited, not proved, and it needs more than my definitions. Barasz and his coauthors consider agents given by arithmetic formulas whose defining equations Peano arithmetic proves, ordered by rank so that an agent only refers to simpler ones. The classic bots above fit that: PrudentBot refers to DefectBot, and the others refer to no fixed agent. I haven't established that rank condition for the generated populations; their results here remain about the chain. For the ranked agents, Theorem 4.7 gives each matchup a representative formula without atoms, using the arithmetic soundness of provability logic and its fixed point theorem (their Theorems 4.1 to 4.3, after Lindström). Because the chain validates provability logic, those representatives satisfy the agents' equations there, so by uniqueness their values are my table. For the matchups here they come out as \(\top\), \(\bot\), \(\Box\bot\), \(\Box^2\bot\) or \(\lnot\Box\bot\): PrudentBot against CooperateBot is \(\Box^2\bot\), and the two sides of FairBot against CUPOD are \(\Box\bot\) and \(\lnot\Box\bot\). If arithmetic is sound, \(\Box\bot\) and \(\Box^2\bot\) are false, which is exactly their value at high worlds. I haven't formalized this arithmetic step or Peano arithmetic's proof predicate.
A bounded self-play prototype
The modal index isn't a proof-search budget. I wanted a small example where we could change an actual budget, run the agents, and inspect the evidence behind a move. A small interpreter does that with two cooperation-certificate rules. The first recognizes a program that always cooperates. The second recognizes two searchers, checks their program descriptions and budgets, and verifies that each can afford the reciprocal certificate its own search will look for. It doesn't call either agent while checking the certificate. Both searches contain that certificate, so their actual executions return cooperation. Lean proves this argument from the interpreter's definitions; there is no assumed reflection axiom.
Each agent tries at most two candidates. The budget counts the UTF-8 bytes in a certificate, including the names and punctuation. A searcher cooperates only if it finds an affordable, valid certificate that its opponent cooperates with it. Here is the same program with three different budgets:
import ProgramEquilibrium.Bounded
namespace BoundedSelfPlay
open ProgramEquilibrium.Bounded
-- Every name resolves to a searcher with this budget; no agent tests for an identical name.
def programs (budget : Nat) : String → Program :=
fun _ => .search budget false
-- These are actual terminating moves, not values at modal worlds.
#eval ([15, 16, 64] : List Nat).map fun budget =>
(budget, run (programs budget) "self" "self")
-- The successful search returns the certificate it used. Its literal text occupies 16 bytes.
#eval (findCertificate (programs 16) 16 false "self" "self").map fun p =>
(p.encode, p.bytes)
end BoundedSelfPlay
Lean output
[(15, false), (16, true), (64, true)]
some ("R(\"self\",\"self\")", 16)At 15 bytes it defects against itself. At 16 bytes it finds R("self","self"), a 16-byte
certificate, and cooperates. It still cooperates at 64. The general theorem gives the exact
threshold for every name and budget, and works for either search order. Another theorem says
the searcher cannot cooperate unilaterally against any registered opponent, including an
arbitrary total Lean function. A function can genuinely cooperate without either rule proving
it, so this search is incomplete.
/-- Every accepted certificate describes an actual move of the terminating program.
The reciprocal case unfolds both searches: each contains the affordable certificate whose
validity the checker has already established from the program descriptions. -/
theorem Certificate.check_sound (program : String → Program) (p : Certificate)
(h : p.check program = true) : run program p.subject p.opponent = true Read the proof
by
cases p with
| constant a b =>
cases ha : program a <;> simp [Certificate.check, run, Certificate.subject, ha] at h ⊢
| reciprocal a b =>
cases ha : program a <;> cases hb : program b <;>
simp only [Certificate.check, reciprocalCheck, ha, hb, Bool.false_eq_true] at h
rename_i ka oa kb ob
have limits : (Certificate.reciprocal b a).bytes ≤ ka ∧
(Certificate.reciprocal a b).bytes ≤ kb := of_decide_eq_true h
simp only [Certificate.subject, Certificate.opponent, run, ha]
apply (findCertificate_success program ka oa b a).2
refine Or.inr ⟨limits.1, ?_⟩
simp [Certificate.check, reciprocalCheck, ha, hb, limits.1, limits.2]/-- A successful search never exceeds its declared certificate budget. -/
theorem findCertificate_bytes {program : String → Program} {k : Nat} {order : Bool}
{a b : String} {p : Certificate} (h : findCertificate program k order a b = some p) :
p.bytes ≤ k := by
have hp := List.find?_some h
exact of_decide_eq_true (Bool.and_eq_true_iff.mp hp).1/-- Against any registered opponent, including arbitrary total code, a searcher never
cooperates unilaterally. No eventual-world or population cutoff is involved. -/
theorem search_not_exploited {program : String → Program} {a b : String}
{k : Nat} {order : Bool} (ha : program a = .search k order)
(h : run program a b = true) : run program b a = true := by
simp only [run, ha] at h
rcases (findCertificate_success program k order b a).1 h with h | h
· exact Certificate.check_sound program (.constant b a) h.2
· exact Certificate.check_sound program (.reciprocal b a) h.2/-- The exact self-play threshold, for every name, budget, search order and fixed registry.
This is a theorem about the two certificate rules above, not a bounded Löb theorem for PA. -/
theorem self_cooperates_iff {program : String → Program} {a : String}
{k : Nat} {order : Bool} (ha : program a = .search k order) :
run program a a = true ↔ (Certificate.reciprocal a a).bytes ≤ k := by
simp [run, ha, findCertificate_success, Certificate.check, reciprocalCheck]Full source
To run self-play, the two search orders and the failure cases together:
lake exe play_bounded_agents 16
This prototype doesn't solve Open Problem 4. Its certificates refer to two specialized rules that Lean proves sound, rather than arbitrary arithmetic proofs. Their byte counts don't include expanded Lean proof terms. Names resolve through a fixed program registry; they aren't source-code fingerprints. The two different search orders cooperate, but this doesn't establish cooperation between arbitrary implementations of DUPOC.
To go beyond those two rules, we need a proof language with checked lengths and Critch, Dennis and Russell's parametric bounded Löb theorem, Lemma 3.6. Under its proof-system and growth assumptions, a uniform proof of
leads to a proof of \(\forall k > k_2,\ p(k)\) for some \(k_2\). Here the bound counts characters in proofs, not worlds in a modal model. In the next post I prove the theorem from explicit proof-system properties, build a checker satisfying them, and run two copies of DUPOC that find a proof and cooperate. That system is built for these agents; an instance inside arithmetic remains a further step :)
Cite this article
Robert Joseph George. Programs that read each other's code. TorchLean Verified Examples, 2026.
@misc{george2026program,
author = {Robert Joseph George},
title = {{Programs that read each other's code}},
year = {2026},
howpublished = {TorchLean Verified Examples},
url = {https://robertboy18.github.io/TorchLean-Verified-Examples/week-07-program-equilibrium/}
}
Download BibTeX