Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Search/BudgetedOuterLoop.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Search/BudgetedOuterLoop.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Search/BudgetedOuterLoop.lean
-
curl -L -o BudgetedOuterLoop.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Search/BudgetedOuterLoop.lean
3.36 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Search.BudgetedOuterReplay | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Search.BudgetedReplayLoops | |
| namespace OAI | |
| namespace LowSpaceSubsetSum.BudgetedOuterLoop | |
| universe u v w | |
| variable {Ξ± : Type u} {Ο : Type v} {Ο : Type w} | |
| def loop (charge : β) (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β Option ((Ο Γ Bool) Γ β) Γ β) : | |
| β β Ο β Ο β β β β β β β β β Option (TieReplay.Result Ο Ο Γ β) Γ β | |
| | fuel, s, a, q, r, budget, work => | |
| if charge β€ budget then | |
| let left := budget - charge | |
| match fuel with | |
| | 0 => (some (β¨s, a, q, r, false, falseβ©, left), work + 1) | |
| | fuel + 1 => | |
| let fetched := read s | |
| match fetched.1 with | |
| | none => (some (β¨s, a, q + 1, r, true, falseβ©, left), work + (fetched.2 + 5)) | |
| | some (x, s') => | |
| let found := key x | |
| if found.1 = K then | |
| let reported := report x a left | |
| match reported.1 with | |
| | none => (none, work + (fetched.2 + found.2 + reported.2 + 8)) | |
| | some ((next, halt), remaining) => | |
| if halt then | |
| (some (β¨s', next, q + 1, r + 1, false, trueβ©, remaining), | |
| work + (fetched.2 + found.2 + reported.2 + 8)) | |
| else loop charge read key K report fuel s' next (q + 1) (r + 1) remaining | |
| (work + (fetched.2 + found.2 + reported.2 + 8)) | |
| else (some (β¨s, a, q + 1, r, true, falseβ©, left), work + (fetched.2 + found.2 + 6)) | |
| else (none, work + 1) | |
| theorem loop_eq (charge : β) (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β Option ((Ο Γ Bool) Γ β) Γ β) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget work : β) : | |
| loop charge read key K report fuel s a q r budget work = | |
| ((BudgetedOuterReplay.execute charge read key K report fuel s a q r budget).1, | |
| work + (BudgetedOuterReplay.execute charge read key K report fuel s a q r budget).2) := by | |
| induction fuel generalizing s a q r budget work with | |
| | zero => rw [loop, BudgetedOuterReplay.execute]; split <;> rfl | |
| | succ fuel ih => | |
| rw [loop, BudgetedOuterReplay.execute] | |
| split | |
| Β· dsimp only | |
| cases hr : (read s).1 with | |
| | none => dsimp only | |
| | some p => | |
| rcases p with β¨x, s'β© | |
| dsimp only | |
| split | |
| Β· cases hc : (report x a (budget - charge)).1 with | |
| | none => dsimp only | |
| | some p => | |
| rcases p with β¨β¨next, haltβ©, remainingβ© | |
| dsimp only | |
| split | |
| Β· rfl | |
| Β· rw [ih] | |
| simp only [Nat.add_assoc] | |
| Β· rfl | |
| Β· rfl | |
| def execute (charge : β) (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β β β Option ((Ο Γ Bool) Γ β) Γ β) | |
| (fuel : β) (s : Ο) (a : Ο) (q r budget : β) := | |
| loop charge read key K report fuel s a q r budget 0 | |
| @[csimp] theorem execute_eq : @BudgetedOuterReplay.execute.{u, v, w} = @execute.{u, v, w} := by | |
| funext Ξ± Ο Ο charge read key K report fuel s a q r budget | |
| rw [execute, loop_eq] | |
| simp only [Nat.zero_add] | |
| end LowSpaceSubsetSum.BudgetedOuterLoop | |
| end OAI | |