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 / AienSeq / Corpus.lean
| 1 | import AienSeq.Theorems |
| 2 | namespace AienSeq |
| 3 | |
| 4 | /-! Concrete traces. The theorems in `Theorems.lean` hold for every arena; the corpus shows the rules |
| 5 | fire on concrete records, and fixes the Rust numbers (generation starts at 1, wrap skips 0). -/ |
| 6 | |
| 7 | /-- the id handed out by alloc, if any -/ |
| 8 | def allocId (a : Arena) : Option Id := (a.alloc).map (·.2) |
| 9 | /-- the arena after alloc (unchanged when refused) -/ |
| 10 | def allocArena (a : Arena) : Arena := match a.alloc with | some (a', _) => a' | none => a |
| 11 | |
| 12 | def a2 : Arena := Arena.init 2 |
| 13 | |
| 14 | /-! Positive -/ |
| 15 | theorem pos_first_id : allocId a2 = some ⟨0, 1⟩ := by decide |
| 16 | theorem pos_second_id : allocId (allocArena a2) = some ⟨1, 1⟩ := by decide |
| 17 | theorem pos_live_after_alloc : (allocArena a2).live ⟨0, 1⟩ = true := by decide |
| 18 | theorem pos_free_then_reuse_new_gen : |
| 19 | allocId ((allocArena a2).release ⟨0, 1⟩).1 = some ⟨0, 2⟩ := by decide |
| 20 | theorem pos_free_live_true : ((allocArena a2).release ⟨0, 1⟩).2 = true := by decide |
| 21 | theorem pos_fork_live_parent : ((allocArena a2).fork ⟨0, 1⟩).isSome = true := by decide |
| 22 | theorem pos_wrap_skips_zero : nextGen genMax = 1 := by decide |
| 23 | theorem pos_gen_increments : nextGen 1 = 2 := by decide |
| 24 | |
| 25 | /-! Negative: each is refused / not live. -/ |
| 26 | theorem neg_never_allocated : a2.live ⟨0, 1⟩ = false := by decide |
| 27 | theorem neg_stale_after_free : |
| 28 | (((allocArena a2).release ⟨0, 1⟩).1).live ⟨0, 1⟩ = false := by decide |
| 29 | theorem neg_stale_free_refused : |
| 30 | ((((allocArena a2).release ⟨0, 1⟩).1).release ⟨0, 1⟩).2 = false := by decide |
| 31 | theorem neg_wrong_generation : (allocArena a2).live ⟨0, 2⟩ = false := by decide |
| 32 | theorem neg_generation_zero : (allocArena a2).live ⟨0, 0⟩ = false := by decide |
| 33 | theorem neg_slot_out_of_range : (allocArena a2).live ⟨5, 1⟩ = false := by decide |
| 34 | theorem neg_fork_stale_parent : |
| 35 | ((((allocArena a2).release ⟨0, 1⟩).1).fork ⟨0, 1⟩).isSome = false := by decide |
| 36 | theorem neg_capacity_exhausted : |
| 37 | allocId (allocArena (allocArena a2)) = none := by decide |
| 38 | theorem neg_old_id_vs_new_slot_owner : |
| 39 | ((allocArena ((allocArena a2).release ⟨0, 1⟩).1).live ⟨0, 1⟩) = false := by decide |
| 40 | |
| 41 | /-- an arena whose slot 0 generation sits at u32::MAX: free then reuse yields generation 1, not 0 -/ |
| 42 | def aMax : Arena := { Arena.init 1 with gen := fun _ => genMax, occ := fun _ => true, free := [], active := 1 } |
| 43 | theorem pos_wrap_in_arena : allocId (aMax.release ⟨0, genMax⟩).1 = some ⟨0, 1⟩ := by decide |
| 44 | theorem neg_wrapped_id_differs : (aMax.release ⟨0, genMax⟩).1.live ⟨0, genMax⟩ = false := by decide |
| 45 | |
| 46 | /-- Real Rust numbers: 2^32 - 1 = 4294967295 generations per slot before the wrap limitation applies -/ |
| 47 | theorem generation_period : genMax = 4294967295 := rfl |
| 48 | |
| 49 | end AienSeq |