Remove prototype demo evaluation block

This commit is contained in:
andrew committed 2026-11-17 10:08:36 -05:00
1 parent af318a7d32
commit fc8335c380
1 file changed
-96
-96
View File
@@ -3086,100 +3086,4 @@ theorem intervalCard_headD_getLastD_eq_capSum {M : List (WithTop Key)}
simp only [List.headD_cons] at hih
rw [hih, capSum]
/-! ## A computable demonstration
A concrete transaction over a small key space. Each read is run against the
shared witness `db`, its constraints are collected, and the candidate minimal
ranges are read off by hulling supports. -/
/-- The small keys `[0]`, `[1]`, `[2]`. -/
def demoKey (n : Byte) : Key := [n]
/-- A shared witness database with keys `[0]`, `[1]`, `[2]`. -/
def demoDB : DB where
keys := [demoKey 0, demoKey 1, demoKey 2]
sorted := by decide
/-- A complete read from `[0]` to `⊤` at offset one: returns every stored key. -/
def demoRead : RangeRead where
begin := ⟨(demoKey 0 : WithTop Key), 1⟩
end_ := ⟨⊤, 1⟩
limit := none
reverse := false
/-- A second read, from just past `[0]` to `⊤`: returns `[1]`, `[2]`. -/
def demoRead2 : RangeRead where
begin := ⟨(keyAfter (demoKey 0) : WithTop Key), 1⟩
end_ := ⟨⊤, 1⟩
limit := none
reverse := false
/-- A human-readable endpoint: `⊥` for the empty key, `⊤` for the sentinel, and
the byte values of a genuine key otherwise. -/
def showEnd : WithTop Key → String
| none => "⊤"
| some [] => "⊥"
| some k => "[" ++ String.intercalate "," (k.map (fun b => toString b.val)) ++ "]"
/-- A human-readable conflict range. -/
def showRange (cr : ConflictRange) : String × String :=
(showEnd cr.begin, showEnd cr.end_)
/-- A human-readable constraint. -/
def showCon (c : Constraint) : String :=
s!"ρ{showEnd c.hi} − ρ{showEnd c.lo} ≤ {c.bound}"
/-- The collected system of the first read against the shared witness. -/
def demoSys : ConstraintSystem :=
constraintsOf demoRead (RangeRead.completeKeys demoDB demoRead)
/-- The collected system of the second read against the same witness. -/
def demoSys2 : ConstraintSystem :=
constraintsOf demoRead2 (RangeRead.completeKeys demoDB demoRead2)
-- The two reads' reported keys.
#eval RangeRead.completeKeys demoDB demoRead
#eval RangeRead.completeKeys demoDB demoRead2
-- The constraints collected for the first read.
#eval demoSys.map showCon
-- The read-off range of the first read (hull of supports).
#eval (hullSupports demoSys).map showRange
-- The read-off range of the second read.
#eval (hullSupports demoSys2).map showRange
-- The whole transaction: one range covering all reads' supports.
#eval (transactionRanges [demoSys, demoSys2]).map showRange
-- Finite-capacity constraint and the sorted telescoping identity.
-- `[[0], [1])` is infinite (infinitely many keys between `[0]` and `[1]`), so it
-- contributes no finite cap; the successor chain `[0] < [0,0] < [0,0,0]` has
-- adjacent gaps of one key each.
#eval intervalCard ((demoKey 0 : Key) : WithTop Key) ((demoKey 1 : Key) : WithTop Key)
#eval capSum ([(demoKey 0 : Key), keyAfter (demoKey 0), keyAfter (keyAfter (demoKey 0))] :
List (WithTop Key))
#eval intervalCard ((demoKey 0 : Key) : WithTop Key)
(((keyAfter (keyAfter (demoKey 0))) : Key) : WithTop Key)
-- The short-gap branch selector: `[0]` to `⊤` is infinite (long gap, `false`);
-- `[0]` to `[1]` is infinite too; a one-key successor gap with `g = 2` is short.
#eval shortGap 2 ((demoKey 0 : Key) : WithTop Key) (⊤ : WithTop Key)
#eval shortGap 2 ((demoKey 0 : Key) : WithTop Key)
(((keyAfter (demoKey 0)) : Key) : WithTop Key)
-- An empty read: the two alternatives read off `resolve`, for the read with
-- `begin = ⟨[0], 2⟩`, `end = ⟨[1], 1⟩`: `ρ([1]) − ρ([0]) ≤ 1` or `ρ(⊤) − ρ([0]) ≤ 1`.
def demoEmptyRead : RangeRead where
begin := ⟨(demoKey 0 : WithTop Key), 2⟩
end_ := ⟨(demoKey 1 : WithTop Key), 1⟩
limit := none
reverse := false
#eval (emptyConstraints demoEmptyRead).map (fun S => S.map showCon)
-- The general collector. For the complete first read the collected DNF has two
-- alternatives (one per empty boundary read disjunct), each carrying the bracket
-- and middle systems; for the truncated branch it is the single bracket+middle
-- alternative.
#eval (collectOf demoRead (RangeRead.completeKeys demoDB demoRead) false).map
(fun S => S.map showCon)
#eval (collectOf demoRead (RangeRead.completeKeys demoDB demoRead) true).map
(fun S => S.map showCon)
-- The ascending reported keys the collector is stated on, recovered from a result.
#eval ascendingKeys demoRead { keys := RangeRead.completeKeys demoDB demoRead, more := false }
end FormalConflictRange