Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedStoppedCells.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedStoppedCells.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedStoppedCells.lean
-
curl -L -o BudgetedStoppedCells.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/BudgetedStoppedCells.lean
4.5 kB
Lean 4 Β· 6
declarations fullstatements
| import OAI.Combinatorics.LowSpaceSubsetSum.Search.BudgetedStoppedLoop | |
| namespace OAI | |
| /-! # Constant-retention execution of the stopped join loop | |
| Only the current state survives an iteration. The peak accumulator records | |
| the temporary overlap between the old and returned state; no prior state is | |
| stored in a continuation frame. | |
| -/ | |
| namespace LowSpaceSubsetSum.BudgetedStoppedCells | |
| universe s t w | |
| variable {Οβ : Type s} {Οβ : Type t} {Ο : Type w} | |
| local notation "State" => StreamJoin.State Οβ Οβ Ο | |
| local notation "Result" => StreamJoin.StoppedResult Οβ Οβ Ο | |
| def loop (step : State β β β (Option (State Γ β) Γ β) Γ β) | |
| (cells : State β β) : | |
| β β State β β β β β β β β β (Option (Result Γ β) Γ β) Γ β | |
| | fuel, st, steps, budget, work, peak => | |
| let live := max peak (cells st + 16) | |
| if 4 β€ budget then | |
| match fuel with | |
| | 0 => ((some (β¨st, stepsβ©, budget - 4), work + 1), live) | |
| | fuel + 1 => | |
| if st.done then ((some (β¨st, stepsβ©, budget - 4), work + 1), live) else | |
| let next := step st (budget - 4) | |
| let live := max live (cells st + next.2 + 16) | |
| match next.1.1 with | |
| | none => ((none, work + next.1.2 + 2), live) | |
| | some (state, left) => | |
| loop step cells fuel state (steps + 1) left (work + next.1.2 + 3) | |
| (max live (cells st + cells state + 16)) | |
| else ((none, work + 1), live) | |
| theorem loop_value (step : State β β β (Option (State Γ β) Γ β) Γ β) | |
| (cells : State β β) (fuel : β) (st : State) (steps budget work peak : β) : | |
| (loop step cells fuel st steps budget work peak).1 = | |
| BudgetedStoppedLoop.loop (fun st b => (step st b).1) fuel st steps budget work := by | |
| induction fuel generalizing st steps budget work peak with | |
| | zero => rw [loop, BudgetedStoppedLoop.loop]; split <;> rfl | |
| | succ fuel ih => | |
| rw [loop, BudgetedStoppedLoop.loop] | |
| split | |
| Β· by_cases hd : st.done = true | |
| Β· simp only [hd, βreduceIte] | |
| Β· simp only [hd, Bool.false_eq_true, βreduceIte] | |
| cases hn : (step st (budget - 4)).1.1 with | |
| | none => rfl | |
| | some p => | |
| rcases p with β¨state, leftβ© | |
| exact ih _ _ _ _ _ | |
| Β· rfl | |
| theorem loop_cells (step : State β β β (Option (State Γ β) Γ β) Γ β) | |
| (cells : State β β) (S T : β) | |
| (hs : β st, cells st β€ S) (ht : β st b, (step st b).2 β€ T) | |
| (fuel : β) (st : State) (steps budget work peak : β) : | |
| (loop step cells fuel st steps budget work peak).2 β€ max peak (2 * S + T + 32) := by | |
| induction fuel generalizing st steps budget work peak with | |
| | zero => | |
| have h := hs st | |
| rw [loop] | |
| split <;> dsimp only <;> exact max_le_max le_rfl (by omega) | |
| | succ fuel ih => | |
| have h := hs st | |
| have hk := ht st (budget - 4) | |
| rw [loop] | |
| split | |
| Β· by_cases hd : st.done = true | |
| Β· simp only [hd, βreduceIte] | |
| exact max_le_max le_rfl (by omega) | |
| Β· simp only [hd, Bool.false_eq_true, βreduceIte] | |
| cases hn : (step st (budget - 4)).1.1 with | |
| | none => dsimp only; omega | |
| | some p => | |
| rcases p with β¨state, leftβ© | |
| have ho := hs state | |
| have hi := ih state (steps + 1) left (work + (step st (budget - 4)).1.2 + 3) | |
| (max (max (max peak (cells st + 16)) | |
| (cells st + (step st (budget - 4)).2 + 16)) (cells st + cells state + 16)) | |
| exact hi.trans (by omega) | |
| Β· dsimp only | |
| exact max_le_max le_rfl (by omega) | |
| def run (step : State β β β (Option (State Γ β) Γ β) Γ β) (cells : State β β) | |
| (fuel : β) (st : State) (budget : β) := loop step cells fuel st 0 budget 0 0 | |
| theorem run_value (step : State β β β (Option (State Γ β) Γ β) Γ β) (cells : State β β) | |
| (fuel : β) (st : State) (budget : β) : | |
| (run step cells fuel st budget).1 = BudgetedStoppedLoop.run (fun st b => (step st b).1) fuel st budget := | |
| loop_value _ _ _ _ _ _ _ _ | |
| theorem run_cells (step : State β β β (Option (State Γ β) Γ β) Γ β) | |
| (cells : State β β) (S T : β) | |
| (hs : β st, cells st β€ S) (ht : β st b, (step st b).2 β€ T) | |
| (fuel : β) (st : State) (budget : β) : | |
| (run step cells fuel st budget).2 β€ 2 * S + T + 32 := by | |
| simpa only [run, Nat.zero_max] using loop_cells step cells S T hs ht fuel st 0 budget 0 0 | |
| end LowSpaceSubsetSum.BudgetedStoppedCells | |
| end OAI | |
Outline