interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / bootstrap / formal-oracles / lean / AienSeq / Corpus.lean

49 lines · 2731 bytes Raw Blame History
1import AienSeq.Theorems
2namespace AienSeq
3
4/-! Concrete traces. The theorems in `Theorems.lean` hold for every arena; the corpus shows the rules
5fire 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 -/
8def allocId (a : Arena) : Option Id := (a.alloc).map (·.2)
9/-- the arena after alloc (unchanged when refused) -/
10def allocArena (a : Arena) : Arena := match a.alloc with | some (a', _) => a' | none => a
11
12def a2 : Arena := Arena.init 2
13
14/-! Positive -/
15theorem pos_first_id : allocId a2 = some ⟨0, 1⟩ := by decide
16theorem pos_second_id : allocId (allocArena a2) = some ⟨1, 1⟩ := by decide
17theorem pos_live_after_alloc : (allocArena a2).live ⟨0, 1⟩ = true := by decide
18theorem pos_free_then_reuse_new_gen :
19 allocId ((allocArena a2).release ⟨0, 1⟩).1 = some ⟨0, 2⟩ := by decide
20theorem pos_free_live_true : ((allocArena a2).release ⟨0, 1⟩).2 = true := by decide
21theorem pos_fork_live_parent : ((allocArena a2).fork ⟨0, 1⟩).isSome = true := by decide
22theorem pos_wrap_skips_zero : nextGen genMax = 1 := by decide
23theorem pos_gen_increments : nextGen 1 = 2 := by decide
24
25/-! Negative: each is refused / not live. -/
26theorem neg_never_allocated : a2.live ⟨0, 1⟩ = false := by decide
27theorem neg_stale_after_free :
28 (((allocArena a2).release ⟨0, 1⟩).1).live ⟨0, 1⟩ = false := by decide
29theorem neg_stale_free_refused :
30 ((((allocArena a2).release ⟨0, 1⟩).1).release ⟨0, 1⟩).2 = false := by decide
31theorem neg_wrong_generation : (allocArena a2).live ⟨0, 2⟩ = false := by decide
32theorem neg_generation_zero : (allocArena a2).live ⟨0, 0⟩ = false := by decide
33theorem neg_slot_out_of_range : (allocArena a2).live ⟨5, 1⟩ = false := by decide
34theorem neg_fork_stale_parent :
35 ((((allocArena a2).release ⟨0, 1⟩).1).fork ⟨0, 1⟩).isSome = false := by decide
36theorem neg_capacity_exhausted :
37 allocId (allocArena (allocArena a2)) = none := by decide
38theorem 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 -/
42def aMax : Arena := { Arena.init 1 with gen := fun _ => genMax, occ := fun _ => true, free := [], active := 1 }
43theorem pos_wrap_in_arena : allocId (aMax.release ⟨0, genMax⟩).1 = some ⟨0, 1⟩ := by decide
44theorem 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 -/
47theorem generation_period : genMax = 4294967295 := rfl
48
49end AienSeq