Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/DistinctCountCells.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 3.99 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/DistinctCountCells.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/DistinctCountCells.lean
-
curl -L -o DistinctCountCells.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Storage/DistinctCountCells.lean
3.99 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Streams.MeasuredDistinctCount | |
| namespace OAI | |
| /-! # Live storage of the tail distinct-key counter | |
| Each iteration drops the previous reader state after obtaining its | |
| successor. The trace retains the previous scalar key, count, remaining | |
| fuel and work counter, but no list of emitted values. | |
| -/ | |
| namespace LowSpaceSubsetSum.DistinctCountCells | |
| variable {Ξ± Ο : Type*} | |
| def loop (cells : Ο β β) (X : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) : | |
| β β Ο β Option β€ β β β β β β β (β Γ β) Γ β | |
| | 0, s, _, count, work, peak => ((count, work+1), max peak (cells s+16)) | |
| | fuel+1, s, previous, count, work, peak => | |
| let out := read s | |
| match out.1.1 with | |
| | none => ((count, work+out.1.2+1), max peak (cells s+out.2+16)) | |
| | some (x, next) => | |
| let k := key x | |
| let fresh := match previous with | none => true | some p => decide (p β k.1.1) | |
| loop cells X read key fuel next (some k.1.1) (count+if fresh then 1 else 0) | |
| (work+out.1.2+k.1.2+3) | |
| (max peak (cells s+cells next+out.2+k.2+X+32)) | |
| theorem loop_value (cells : Ο β β) (X : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) | |
| (fuel : β) (s : Ο) (previous : Option β€) (count work peak : β) : | |
| (loop cells X read key fuel s previous count work peak).1 = | |
| MeasuredDistinctCount.loop (fun s => (read s).1) (fun x => (key x).1) | |
| fuel s previous count work := by | |
| induction fuel generalizing s previous count work peak with | |
| | zero => rfl | |
| | succ fuel ih => | |
| cases h : (read s).1.1 with | |
| | none => simp only [loop, MeasuredDistinctCount.loop, h] | |
| | some out => | |
| rcases out with β¨x, nextβ© | |
| simp only [loop, MeasuredDistinctCount.loop, h, ih] | |
| rfl | |
| theorem loop_cells (cells : Ο β β) (X S R K : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) | |
| (hs : β s, cells s β€ S) (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ K) | |
| (fuel : β) (s : Ο) (previous : Option β€) (count work peak : β) : | |
| (loop cells X read key fuel s previous count work peak).2 β€ | |
| max peak (2*S+R+K+X+32) := by | |
| induction fuel generalizing s previous count work peak with | |
| | zero => | |
| have h := hs s | |
| simp only [loop] | |
| exact max_le_max le_rfl (by omega) | |
| | succ fuel ih => | |
| have hβ := hs s | |
| have hβ := hr s | |
| simp only [loop] | |
| split | |
| Β· dsimp only | |
| exact max_le_max le_rfl (by omega) | |
| next x next _ => | |
| have hβ := hs next | |
| have hβ := hk x | |
| have h := ih next (some (key x).1.1) | |
| (count+if (match previous with | none => true | some p => decide (p β (key x).1.1)) then 1 else 0) | |
| (work+(read s).1.2+(key x).1.2+3) | |
| (max peak (cells s+cells next+(read s).2+(key x).2+X+32)) | |
| exact h.trans (by omega) | |
| def run (cells : Ο β β) (X : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) | |
| (fuel : β) (s : Ο) : (β Γ β) Γ β := | |
| loop cells X read key fuel s none 0 0 0 | |
| theorem run_value (cells : Ο β β) (X : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) | |
| (fuel : β) (s : Ο) : | |
| (run cells X read key fuel s).1 = | |
| MeasuredDistinctCount.run (fun s => (read s).1) (fun x => (key x).1) fuel s := | |
| loop_value cells X read key fuel s none 0 0 0 | |
| theorem run_cells (cells : Ο β β) (X S R K : β) | |
| (read : Ο β (Option (Ξ± Γ Ο) Γ β) Γ β) (key : Ξ± β (β€ Γ β) Γ β) | |
| (hs : β s, cells s β€ S) (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ K) | |
| (fuel : β) (s : Ο) : | |
| (run cells X read key fuel s).2 β€ 2*S+R+K+X+32 := by | |
| simpa only [run, Nat.zero_max] using loop_cells cells X S R K read key hs hr hk fuel s none 0 0 0 | |
| end LowSpaceSubsetSum.DistinctCountCells | |
| end OAI | |