Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedFill.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 4.49 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedFill.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedFill.lean
-
curl -L -o CountedFill.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Counting/CountedFill.lean
4.49 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.CountedReplay | |
| namespace OAI | |
| /-! # Cost-carrying bounded tie-buffer construction and lookahead -/ | |
| namespace LowSpaceSubsetSum.CountedFill | |
| universe u v | |
| variable {Ξ± : Type u} {Ο : Type v} | |
| def fillAcc (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) : β β Ο β Array Ξ± β β β TieBuffer.Result Ξ± Ο Γ β | |
| | 0, s, buf, q => (β¨buf, s, qβ©, 1) | |
| | fuel + 1, s, buf, q => | |
| let fetched := read s | |
| match fetched.1 with | |
| | none => (β¨buf, s, q + 1β©, fetched.2 + 5) | |
| | some (x, s') => | |
| let found := key x | |
| if found.1 = K then | |
| let rest := fillAcc read key cells K fuel s' (buf.push x) (q + 1) | |
| (rest.1, fetched.2 + found.2 + cells x + 8 + rest.2) | |
| else (β¨buf, s, q + 1β©, fetched.2 + found.2 + 6) | |
| theorem fillAcc_value (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) (fuel : β) (s : Ο) (buf : Array Ξ±) (q : β) : | |
| (fillAcc read key cells K fuel s buf q).1 = | |
| TieBuffer.fillAcc (fun s => (read s).1) (fun x => (key x).1) K fuel s buf q := by | |
| induction fuel generalizing s buf q with | |
| | zero => rfl | |
| | succ fuel ih => | |
| cases hr : (read s).1 with | |
| | none => simp only [fillAcc, TieBuffer.fillAcc, hr] | |
| | some z => | |
| rcases z with β¨x, s'β© | |
| simp only [fillAcc, TieBuffer.fillAcc, hr] | |
| split | |
| Β· exact ih _ _ _ | |
| Β· rfl | |
| theorem fillAcc_work (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) (R L S : β) | |
| (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ L) (hs : β x, cells x β€ S) | |
| (fuel : β) (s : Ο) (buf : Array Ξ±) (q : β) : | |
| (fillAcc read key cells K fuel s buf q).2 + (R + L + S + 8) * q β€ | |
| (R + L + S + 8) * (fillAcc read key cells K fuel s buf q).1.queries + 1 := by | |
| induction fuel generalizing s buf q with | |
| | zero => simp only [fillAcc]; omega | |
| | succ fuel ih => | |
| have hread := hr s | |
| cases hv : (read s).1 with | |
| | none => simp only [fillAcc, hv, Nat.mul_add, Nat.mul_one]; omega | |
| | some z => | |
| rcases z with β¨x, s'β© | |
| have hkey := hk x | |
| have hcell := hs x | |
| simp only [fillAcc, hv] | |
| split | |
| Β· have hrest := ih s' (buf.push x) (q + 1) | |
| simp only [Nat.mul_add, Nat.mul_one] at hrest | |
| dsimp only | |
| omega | |
| Β· simp only [Nat.mul_add, Nat.mul_one]; omega | |
| def fill (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) (B : β) (s : Ο) : TieBuffer.Result Ξ± Ο Γ β := | |
| fillAcc read key cells K B s #[] 0 | |
| theorem fill_value (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) (B : β) (s : Ο) : | |
| (fill read key cells K B s).1 = | |
| TieBuffer.fill (fun s => (read s).1) (fun x => (key x).1) K B s := | |
| fillAcc_value _ _ _ _ _ _ _ _ | |
| theorem fill_work (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) | |
| (cells : Ξ± β β) (K : β€) (R L S : β) | |
| (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ L) (hs : β x, cells x β€ S) | |
| (B : β) (s : Ο) : | |
| (fill read key cells K B s).2 β€ | |
| (R + L + S + 8) * (fill read key cells K B s).1.queries + 1 := by | |
| simpa only [fill, Nat.mul_zero, Nat.add_zero] using | |
| fillAcc_work read key cells K R L S hr hk hs B s #[] 0 | |
| def hasKey (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) (s : Ο) : Bool Γ β := | |
| let fetched := read s | |
| match fetched.1 with | |
| | none => (false, fetched.2 + 3) | |
| | some (x, _) => | |
| let found := key x | |
| (decide (found.1 = K), fetched.2 + found.2 + 4) | |
| theorem hasKey_value (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) (s : Ο) : | |
| (hasKey read key K s).1 = TieBuffer.hasKey (fun s => (read s).1) (fun x => (key x).1) K s := by | |
| cases hv : (read s).1 <;> simp [hasKey, TieBuffer.hasKey, hv] | |
| theorem hasKey_work (read : Ο β Option (Ξ± Γ Ο) Γ β) (key : Ξ± β β€ Γ β) (K : β€) | |
| (R L : β) (hr : β s, (read s).2 β€ R) (hk : β x, (key x).2 β€ L) (s : Ο) : | |
| (hasKey read key K s).2 β€ R + L + 4 := by | |
| have hread := hr s | |
| cases hv : (read s).1 with | |
| | none => simp only [hasKey, hv]; omega | |
| | some z => | |
| rcases z with β¨x, s'β© | |
| have hkey := hk x | |
| simp only [hasKey, hv] | |
| omega | |
| end LowSpaceSubsetSum.CountedFill | |
| end OAI | |