aien-architecture-mv
Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.
Brought by drakestapleton
aien-architecture-mv / bootstrap / formal-oracles / lean / MutantSeqModels.lean
| 1 | import AienSeq.Corpus |
| 2 | /-! |
| 3 | # Deliberate mutants of the sequence arena (each must break one required rule) |
| 4 | |
| 5 | WRONG on purpose. Each mutant model compiles; the matching claim file must not. |
| 6 | -/ |
| 7 | namespace AienSeq |
| 8 | |
| 9 | /-- MUTANT 1 (free_keeps_generation): free does not bump the generation. -/ |
| 10 | def Arena.releaseM1 (a : Arena) (id : Id) : Arena × Bool := |
| 11 | if a.live id then |
| 12 | ({ a with occ := upd a.occ id.slot false, free := id.slot :: a.free, active := a.active - 1 }, true) |
| 13 | else (a, false) |
| 14 | |
| 15 | /-- MUTANT 2 (get_ignores_generation): resolution ignores the generation. -/ |
| 16 | def Arena.liveM2 (a : Arena) (id : Id) : Bool := |
| 17 | decide (id.slot < a.cap) && a.occ id.slot |
| 18 | |
| 19 | /-- MUTANT 3 (wrap_to_zero): the wrap drops the `.max(1)`, so generation 0 can appear. -/ |
| 20 | def nextGenM3 (g : Nat) : Nat := (g + 1) % two32 |
| 21 | |
| 22 | /-- MUTANT 4 (free_keeps_active): free forgets to decrement the active count. -/ |
| 23 | def Arena.releaseM4 (a : Arena) (id : Id) : Arena × Bool := |
| 24 | if a.live id then |
| 25 | ({ a with occ := upd a.occ id.slot false, gen := upd a.gen id.slot (nextGen (a.gen id.slot)), |
| 26 | free := id.slot :: a.free }, true) |
| 27 | else (a, false) |
| 28 | |
| 29 | /-- MUTANT 5 (fork_without_parent_check): fork allocates even when the parent id is stale. -/ |
| 30 | def Arena.forkM5 (a : Arena) (_parent : Id) : Option (Arena × Id) := a.alloc |
| 31 | |
| 32 | /-- witnesses: each mutant accepts what the real model refuses -/ |
| 33 | theorem m1_reuses_generation : |
| 34 | allocId ((allocArena a2).releaseM1 ⟨0, 1⟩).1 = some ⟨0, 1⟩ := by decide |
| 35 | theorem m2_wrong_gen_resolves : (allocArena a2).liveM2 ⟨0, 7⟩ = true := by decide |
| 36 | theorem m3_zero_generation : nextGenM3 genMax = 0 := by decide |
| 37 | theorem m4_active_stuck : (((allocArena a2).releaseM4 ⟨0, 1⟩).1).active = 1 := by decide |
| 38 | theorem m5_stale_fork_allowed : |
| 39 | (((allocArena a2).release ⟨0, 1⟩).1.forkM5 ⟨0, 1⟩).isSome = true := by decide |
| 40 | theorem real_refuses_stale_fork : |
| 41 | (((allocArena a2).release ⟨0, 1⟩).1.fork ⟨0, 1⟩).isSome = false := by decide |
| 42 | |
| 43 | end AienSeq |