Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedOuterCells.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.33 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedOuterCells.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedOuterCells.lean
-
curl -L -o BudgetedOuterCells.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedOuterCells.lean
8.33 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Search.BudgetedOuterLoop | |
| namespace OAI | |
| /-! # Live cells of a tail replay with a prepaid inner callback | |
| The callback may exhaust its remaining allowance. Its scratch trace is added | |
| to the retained reader, current record and user state before the next tail | |
| iteration, and failure drops all local continuations. | |
| -/ | |
| namespace LowSpaceSubsetSum.BudgetedOuterCells | |
| universe u v w | |
| variable {Ξ± : Type u} {Ο : Type v} {Ο : Type w} | |
| def loop (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) : | |
| β β Ο β Ο β β β β β β β β β β β | |
| (Option (TieReplay.Result Ο Ο Γ β) Γ β) Γ β | |
| | fuel, s, a, q, r, budget, work, peak => | |
| let live := max peak (stateCells s + userCells a + 16) | |
| if charge β€ budget then | |
| let left := budget - charge | |
| match fuel with | |
| | 0 => ((some (β¨s, a, q, r, false, falseβ©, left), work + 1), live) | |
| | fuel + 1 => | |
| let fetched := read s | |
| let live := max live (stateCells s + userCells a + fetched.2 + 16) | |
| match fetched.1.1 with | |
| | none => ((some (β¨s, a, q + 1, r, true, falseβ©, left), work + (fetched.1.2 + 5)), live) | |
| | some (x, s') => | |
| let found := key x | |
| let live := max live | |
| (stateCells s + stateCells s' + userCells a + recordCells x + found.2 + 20) | |
| if found.1.1 = K then | |
| let out := report x a left | |
| let live := max live (stateCells s + stateCells s' + userCells a + | |
| recordCells x + out.2 + 24) | |
| match out.1.1 with | |
| | none => ((none, work + (fetched.1.2 + found.1.2 + out.1.2 + 8)), live) | |
| | some ((next, halt), remaining) => | |
| let live := max live (stateCells s + stateCells s' + userCells a + | |
| userCells next + recordCells x + 24) | |
| if halt then | |
| ((some (β¨s', next, q + 1, r + 1, false, trueβ©, remaining), | |
| work + (fetched.1.2 + found.1.2 + out.1.2 + 8)), live) | |
| else loop charge read key K report stateCells userCells recordCells fuel s' next | |
| (q + 1) (r + 1) remaining (work + (fetched.1.2 + found.1.2 + out.1.2 + 8)) live | |
| else ((some (β¨s, a, q + 1, r, true, falseβ©, left), | |
| work + (fetched.1.2 + found.1.2 + 6)), live) | |
| else ((none, work + 1), live) | |
| theorem loop_value (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget work peak : β) : | |
| (loop charge read key K report stateCells userCells recordCells fuel s a q r budget work peak).1 = | |
| BudgetedOuterLoop.loop charge (fun s => (read s).1) (fun x => (key x).1) K | |
| (fun x a b => (report x a b).1) fuel s a q r budget work := by | |
| induction fuel generalizing s a q r budget work peak with | |
| | zero => rw [loop, BudgetedOuterLoop.loop]; split <;> rfl | |
| | succ fuel ih => | |
| rw [loop, BudgetedOuterLoop.loop] | |
| split | |
| Β· dsimp only | |
| cases hr : (read s).1.1 with | |
| | none => rfl | |
| | some p => | |
| rcases p with β¨x, s'β© | |
| dsimp only | |
| split | |
| Β· cases hp : (report x a (budget - charge)).1.1 with | |
| | none => rfl | |
| | some p => | |
| rcases p with β¨β¨next, haltβ©, remainingβ© | |
| dsimp only | |
| split | |
| Β· rfl | |
| Β· exact ih _ _ _ _ _ _ _ | |
| Β· rfl | |
| Β· rfl | |
| theorem loop_cells (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) | |
| (S U X R L H : β) (hs : β s, stateCells s β€ S) (hu : β a, userCells a β€ U) | |
| (hx : β x, recordCells x β€ X) (hr : β s, (read s).2 β€ R) | |
| (hk : β x, (key x).2 β€ L) (hp : β x a b, (report x a b).2 β€ H) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget work peak : β) : | |
| (loop charge read key K report stateCells userCells recordCells fuel s a q r budget work peak).2 β€ | |
| max peak (2 * S + 2 * U + X + R + L + H + 64) := by | |
| induction fuel generalizing s a q r budget work peak with | |
| | zero => | |
| have hs' := hs s | |
| have hu' := hu a | |
| rw [loop] | |
| split <;> dsimp only <;> exact max_le_max le_rfl (by omega) | |
| | succ fuel ih => | |
| have hs' := hs s | |
| have hu' := hu a | |
| have hr' := hr s | |
| rw [loop] | |
| split | |
| Β· dsimp only | |
| cases he : (read s).1.1 with | |
| | none => dsimp only; omega | |
| | some p => | |
| rcases p with β¨x, s'β© | |
| have hs'' := hs s' | |
| have hx' := hx x | |
| have hk' := hk x | |
| dsimp only | |
| split | |
| Β· have hp' := hp x a (budget - charge) | |
| cases ho : (report x a (budget - charge)).1.1 with | |
| | none => dsimp only; omega | |
| | some p => | |
| rcases p with β¨β¨next, haltβ©, remainingβ© | |
| have hu'' := hu next | |
| dsimp only | |
| split | |
| Β· dsimp only; omega | |
| Β· have hi := ih s' next (q + 1) (r + 1) remaining | |
| (work + ((read s).1.2 + (key x).1.2 + (report x a (budget - charge)).1.2 + 8)) | |
| (max (max (max (max (max peak (stateCells s + userCells a + 16)) | |
| (stateCells s + userCells a + (read s).2 + 16)) | |
| (stateCells s + stateCells s' + userCells a + recordCells x + (key x).2 + 20)) | |
| (stateCells s + stateCells s' + userCells a + recordCells x + | |
| (report x a (budget - charge)).2 + 24)) | |
| (stateCells s + stateCells s' + userCells a + userCells next + recordCells x + 24)) | |
| exact hi.trans (by omega) | |
| Β· dsimp only; omega | |
| Β· dsimp only | |
| exact max_le_max le_rfl (by omega) | |
| def run (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget : β) := | |
| loop charge read key K report stateCells userCells recordCells fuel s a q r budget 0 0 | |
| theorem run_value (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget : β) : | |
| (run charge read key K report stateCells userCells recordCells fuel s a q r budget).1 = | |
| BudgetedOuterReplay.execute charge (fun s => (read s).1) (fun x => (key x).1) K | |
| (fun x a b => (report x a b).1) fuel s a q r budget := by | |
| rw [run, loop_value, BudgetedOuterLoop.loop_eq] | |
| simp only [Nat.zero_add] | |
| theorem run_cells (charge : β) (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) | |
| (key : Ξ± β (β€ Γ β) Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β (Option ((Ο Γ Bool) Γ β) Γ β) Γ β) | |
| (stateCells : Ο β β) (userCells : Ο β β) (recordCells : Ξ± β β) | |
| (S U X R L H : β) (hs : β s, stateCells s β€ S) (hu : β a, userCells a β€ U) | |
| (hx : β x, recordCells x β€ X) (hr : β s, (read s).2 β€ R) | |
| (hk : β x, (key x).2 β€ L) (hp : β x a b, (report x a b).2 β€ H) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget : β) : | |
| (run charge read key K report stateCells userCells recordCells fuel s a q r budget).2 β€ | |
| 2 * S + 2 * U + X + R + L + H + 64 := by | |
| simpa only [run, Nat.zero_max] using | |
| loop_cells charge read key K report stateCells userCells recordCells S U X R L H | |
| hs hu hx hr hk hp fuel s a q r budget 0 0 | |
| end LowSpaceSubsetSum.BudgetedOuterCells | |
| end OAI | |