Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedReplay.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.48 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedReplay.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedReplay.lean
-
curl -L -o CountedReplay.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedReplay.lean
4.48 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Streams.BufferReplay | |
| namespace OAI | |
| /-! # Cost-carrying tie-suffix replay | |
| Every performed reader, key and callback evaluation contributes its own | |
| counter. The result is exactly the bounded replay. The work bound | |
| uses its actual stopped query/report counts, rather than the supplied fuel. | |
| -/ | |
| namespace LowSpaceSubsetSum.CountedReplay | |
| universe u v w | |
| variable {Ξ± : Type u} {Ο : Type v} {Ο : Type w} | |
| def runAcc (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) : | |
| β β Ο β Ο β β β β β TieReplay.Result Ο Ο Γ β | |
| | 0, s, a, q, r => (β¨s, a, q, r, false, falseβ©, 1) | |
| | fuel + 1, s, a, q, r => | |
| let fetched := read s | |
| match fetched.1 with | |
| | none => (β¨s, a, q + 1, r, true, falseβ©, fetched.2 + 5) | |
| | some (x, s') => | |
| let found := key x | |
| if found.1 = K then | |
| let emitted := report x a | |
| if emitted.1.2 then | |
| (β¨s', emitted.1.1, q + 1, r + 1, false, trueβ©, | |
| fetched.2 + found.2 + emitted.2 + 8) | |
| else | |
| let rest := runAcc read key K report fuel s' emitted.1.1 (q + 1) (r + 1) | |
| (rest.1, fetched.2 + found.2 + emitted.2 + 8 + rest.2) | |
| else (β¨s, a, q + 1, r, true, falseβ©, fetched.2 + found.2 + 6) | |
| theorem runAcc_value (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) (fuel : β) (s : Ο) (a : Ο) (q r : β) : | |
| (runAcc read key K report fuel s a q r).1 = | |
| TieReplay.runAcc (fun s => (read s).1) (fun x => (key x).1) K | |
| (fun x a => (report x a).1) fuel s a q r := by | |
| induction fuel generalizing s a q r with | |
| | zero => rfl | |
| | succ fuel ih => | |
| cases hr : (read s).1 with | |
| | none => simp only [runAcc, TieReplay.runAcc, hr] | |
| | some z => | |
| rcases z with β¨x, s'β© | |
| simp only [runAcc, TieReplay.runAcc, hr] | |
| split | |
| Β· split | |
| Β· rfl | |
| Β· exact ih _ _ _ _ | |
| Β· rfl | |
| theorem runAcc_work (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) (R L C : β) | |
| (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ L) | |
| (hc : β x a, (report x a).2 β€ C) | |
| (fuel : β) (s : Ο) (a : Ο) (q r : β) : | |
| (runAcc read key K report fuel s a q r).2 + (R + L + 8) * q + C * r β€ | |
| (R + L + 8) * (runAcc read key K report fuel s a q r).1.queries + | |
| C * (runAcc read key K report fuel s a q r).1.reports + 1 := by | |
| induction fuel generalizing s a q r with | |
| | zero => simp only [runAcc]; omega | |
| | succ fuel ih => | |
| have hread := hr s | |
| cases hv : (read s).1 with | |
| | none => | |
| simp only [runAcc, hv, Nat.mul_add, Nat.mul_one] | |
| omega | |
| | some z => | |
| rcases z with β¨x, s'β© | |
| have hkey := hk x | |
| simp only [runAcc, hv] | |
| split | |
| Β· have hcallback := hc x a | |
| split | |
| Β· simp only [Nat.mul_add, Nat.mul_one]; omega | |
| Β· have hrest := ih s' (report x a).1.1 (q + 1) (r + 1) | |
| simp only [Nat.mul_add, Nat.mul_one] at hrest | |
| dsimp only | |
| omega | |
| Β· simp only [Nat.mul_add, Nat.mul_one]; omega | |
| def run (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) (fuel : β) (s : Ο) (a : Ο) : | |
| TieReplay.Result Ο Ο Γ β := runAcc read key K report fuel s a 0 0 | |
| theorem run_value (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) (fuel : β) (s : Ο) (a : Ο) : | |
| (run read key K report fuel s a).1 = | |
| TieReplay.run (fun s => (read s).1) (fun x => (key x).1) K | |
| (fun x a => (report x a).1) fuel s a := runAcc_value _ _ _ _ _ _ _ _ _ | |
| theorem run_work (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (report : Ξ± β Ο β (Ο Γ Bool) Γ β) (R L C : β) | |
| (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ L) | |
| (hc : β x a, (report x a).2 β€ C) (fuel : β) (s : Ο) (a : Ο) : | |
| (run read key K report fuel s a).2 β€ | |
| (R + L + 8) * (run read key K report fuel s a).1.queries + | |
| C * (run read key K report fuel s a).1.reports + 1 := by | |
| simpa only [run, Nat.mul_zero, Nat.add_zero] using | |
| runAcc_work read key K report R L C hr hk hc fuel s a 0 0 | |
| end LowSpaceSubsetSum.CountedReplay | |
| end OAI | |