Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionTrialLedger.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionTrialLedger.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionTrialLedger.lean
-
curl -L -o CompressionTrialLedger.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionTrialLedger.lean
11.3 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Compression.CompressionQueryBounds | |
| namespace OAI | |
| /-! # A complete compression-join ledger and its live data structures | |
| The counters retain the actual compact-test and overflow branches. The | |
| storage bound describes the arrays, current cursors, replay snapshots, tie | |
| buffer and bounded trie. | |
| -/ | |
| noncomputable section | |
| namespace LowSpaceSubsetSum | |
| open scoped BigOperators | |
| structure CompressionLedger where | |
| queries : β | |
| reports : β | |
| copies : β | |
| controls : β | |
| namespace CompressionData | |
| variable {n : β} (D : CompressionData n) | |
| /-- No right-hand work is counted after dictionary overflow. The control | |
| count includes even the unused fuel suffix of the original `run` loop. -/ | |
| def residueLedger (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) : CompressionLedger := | |
| if D.compactTests e then | |
| let lf := D.streamLength e 0 + D.streamLength e 1 + 1 | |
| let left := D.leftJoin B e q z lf | |
| if left.user.overflow then | |
| β¨left.queries, left.reports, left.copies, lfβ© | |
| else | |
| let rf := D.streamLength e 2 + D.streamLength e 3 + 1 | |
| let right := D.rightJoin B e q z left.user.tree rf | |
| β¨left.queries + right.queries, left.reports + right.reports, | |
| left.copies + right.copies, lf + rfβ© | |
| else β¨0, 0, 0, 0β© | |
| def trialLedger (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) : | |
| CompressionLedger := | |
| β¨β z, (D.residueLedger B e q z).queries, | |
| β z, (D.residueLedger B e q z).reports, | |
| β z, (D.residueLedger B e q z).copies, | |
| β z, (D.residueLedger B e q z).controlsβ© | |
| theorem residueLedger_queries (B : β) (e : Equiv.Perm (Fin n)) | |
| (q : CompressionSetup.PrimeSpace n) (z : Fin q.val) : | |
| (D.residueLedger B e q z).queries = D.residueQueries B e q z := by | |
| simp only [residueLedger, residueQueries] | |
| split | |
| Β· split <;> rfl | |
| Β· rfl | |
| theorem residueLedger_bounds (B : β) (e : Equiv.Perm (Fin n)) | |
| (q : CompressionSetup.PrimeSpace n) (z : Fin q.val) : | |
| (D.residueLedger B e q z).reports β€ D.leftPotential e q z + D.rightPotential e q z β§ | |
| B * (D.residueLedger B e q z).copies β€ 2 * (D.leftPotential e q z + D.rightPotential e q z) β§ | |
| (D.residueLedger B e q z).controls β€ (β i : Fin 4, D.streamLength e i) + 2 := by | |
| have hl := D.leftJoin_bounds B e q z (D.streamLength e 0 + D.streamLength e 1 + 1) | |
| have hr := D.rightJoin_bounds B e q z | |
| (D.leftJoin B e q z (D.streamLength e 0 + D.streamLength e 1 + 1)).user.tree | |
| (D.streamLength e 2 + D.streamLength e 3 + 1) | |
| simp only [residueLedger] | |
| split | |
| Β· split <;> dsimp only | |
| Β· simp only [Fin.sum_univ_four] | |
| omega | |
| Β· simp only [Nat.mul_add, Fin.sum_univ_four] | |
| omega | |
| Β· simp | |
| theorem trialLedger_reports_copies (B : β) (e : Equiv.Perm (Fin n)) | |
| (q : CompressionSetup.PrimeSpace n) : | |
| (D.trialLedger B e q).reports β€ | |
| D.streamLength e 0 * D.streamLength e 1 + D.streamLength e 2 * D.streamLength e 3 β§ | |
| B * (D.trialLedger B e q).copies β€ | |
| 2 * (D.streamLength e 0 * D.streamLength e 1 + D.streamLength e 2 * D.streamLength e 3) β§ | |
| (D.trialLedger B e q).controls β€ q.val * (β i : Fin 4, D.streamLength e i) + 2 * q.val := by | |
| have hr := Finset.sum_le_sum (fun z (_ : z β (Finset.univ : Finset (Fin q.val))) => | |
| (D.residueLedger_bounds B e q z).1) | |
| have hc := Finset.sum_le_sum (fun z (_ : z β (Finset.univ : Finset (Fin q.val))) => | |
| (D.residueLedger_bounds B e q z).2.1) | |
| have ht := Finset.sum_le_sum (fun z (_ : z β (Finset.univ : Finset (Fin q.val))) => | |
| (D.residueLedger_bounds B e q z).2.2) | |
| simp only [Finset.sum_add_distrib, D.sum_leftPotential, D.sum_rightPotential] at hr | |
| simp_rw [Nat.mul_add] at hc | |
| rw [β Finset.mul_sum, Finset.sum_add_distrib, β Finset.mul_sum, β Finset.mul_sum, | |
| D.sum_leftPotential, D.sum_rightPotential] at hc | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] at ht | |
| exact β¨hr, by simpa only [trialLedger, Nat.mul_add] using hc, | |
| by simpa only [trialLedger, Nat.mul_add, Nat.add_mul, Nat.mul_comm] using htβ© | |
| /-- A compact bound for all measured join activity in one compression | |
| trial. Copy work is measured in units of a full `B`-word snapshot. -/ | |
| theorem trialLedger_half_exponential (B : β) (e : Equiv.Perm (Fin n)) | |
| (q : CompressionSetup.PrimeSpace n) (hn : 2000 β€ n) : | |
| ((D.trialLedger B e q).queries : β) β€ 30 * (2 : β) ^ ((n : β) / 2) β§ | |
| ((D.trialLedger B e q).reports : β) β€ 2 * (2 : β) ^ ((n : β) / 2) β§ | |
| (B * (D.trialLedger B e q).copies : β) β€ 4 * (2 : β) ^ ((n : β) / 2) β§ | |
| ((D.trialLedger B e q).controls : β) β€ 6 * (2 : β) ^ ((n : β) / 2) := by | |
| have hquery := D.queries_half_exponential B e q hn | |
| have heq : (D.trialLedger B e q).queries = β z, D.residueQueries B e q z := by | |
| simp only [trialLedger, D.residueLedger_queries] | |
| rw [heq] | |
| refine β¨by simpa only [Nat.cast_sum] using hquery, ?_β© | |
| by_cases he : D.compactTests e = true | |
| Β· have h := D.trialLedger_reports_copies B e q | |
| have hp := D.matching_product_bound e he hn | |
| have hs : ((q.val * β i : Fin 4, D.streamLength e i : β) : β) β€ | |
| 4 * (2 : β) ^ ((n : β) / 2) := by | |
| rw [Finset.mul_sum, Nat.cast_sum] | |
| apply (Finset.sum_le_sum (fun i _ => D.prime_regeneration_bound e he hn q i)).trans_eq | |
| simp | |
| have hq : (q.val : β) β€ (2 : β) ^ ((n : β) / 2) := by | |
| have hz : 1 β€ D.streamLength e 0 := by | |
| have hnonempty (i : Fin 7) : 0 < (compactWeightList D.weights (D.block e i)).length := by | |
| rw [compactWeightList_length] | |
| exact Nat.zero_lt_of_lt (Finset.card_pos.mpr β¨0, zero_mem_distinctSums _ _β©) | |
| have h0 := hnonempty 4 | |
| have h1 := hnonempty 5 | |
| change 1 β€ (compactWeightList D.weights (D.block e 4)).length * | |
| (compactWeightList D.weights (D.block e 5)).length | |
| nlinarith | |
| exact (Nat.cast_le.mpr (Nat.le_mul_of_pos_right _ (by omega))).trans | |
| (D.prime_regeneration_bound e he hn q 0) | |
| have hr : ((D.trialLedger B e q).reports : β) β€ | |
| (D.streamLength e 0 * D.streamLength e 1 : β) + | |
| (D.streamLength e 2 * D.streamLength e 3 : β) := by exact_mod_cast h.1 | |
| have hc : ((B * (D.trialLedger B e q).copies : β) : β) β€ | |
| 2 * ((D.streamLength e 0 * D.streamLength e 1 : β) + | |
| (D.streamLength e 2 * D.streamLength e 3 : β)) := by exact_mod_cast h.2.1 | |
| have ht : ((D.trialLedger B e q).controls : β) β€ | |
| (q.val * β i : Fin 4, D.streamLength e i : β) + 2 * (q.val : β) := by | |
| exact_mod_cast h.2.2 | |
| exact β¨by linarith [hp.1, hp.2], by linarith [hp.1, hp.2], by linarithβ© | |
| Β· have hf : D.compactTests e = false := Bool.eq_false_iff.mpr he | |
| simp only [trialLedger, residueLedger, hf, Bool.false_eq_true, βreduceIte, | |
| Finset.sum_const_zero, Nat.mul_zero, Nat.cast_zero] | |
| exact β¨by positivity, by positivity, by positivityβ© | |
| /-- Only the mutable tournament and its cached cursors are copied. The | |
| immutable stored arrays are shared by every replay snapshot. -/ | |
| def snapshotCells (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (i : Fin 4) (mode : FilteredStream.Mode) (s : D.GroupState e q i mode) : β := | |
| 10 * (Tournament.nodes s.tree + 1) | |
| theorem snapshotCells_le_buffer (e : Equiv.Perm (Fin n)) (he : D.compactTests e = true) | |
| (hn : 2000 β€ n) (q : CompressionSetup.PrimeSpace n) (i : Fin 4) | |
| (mode : FilteredStream.Mode) (s : D.GroupState e q i mode) : | |
| D.snapshotCells e q i mode s β€ 2 ^ (19 * n / 100) := by | |
| have ha := compression_cap_rate (by omega : 40 β€ n) | |
| have hfloor : 19 * n < 100 * (19 * n / 100 + 1) := by omega | |
| have hfloorR : (19 : β) * n < 100 * ((19 * n / 100 : β) + 1 : β) := by | |
| exact_mod_cast hfloor | |
| have hnR : (2000 : β) β€ n := by exact_mod_cast hn | |
| have hexp : compressionCapExponent n + 7 β€ 19 * n / 100 := by | |
| have hR : (compressionCapExponent n : β) + 7 β€ (19 * n / 100 : β) := by linarith | |
| exact_mod_cast hR | |
| have ht := Tournament.padded_nodes_le (D.storedFirst e i).toArray.size s.tree | |
| simp only [List.size_toArray] at ht | |
| have hl := D.storedFirst_length_bound e he i | |
| have hpos : 1 β€ 2 ^ compressionCapExponent n := Nat.one_le_pow _ _ (by decide) | |
| calc | |
| D.snapshotCells e q i mode s β€ 80 * 2 ^ compressionCapExponent n := by | |
| unfold snapshotCells | |
| omega | |
| _ β€ 2 ^ (compressionCapExponent n + 7) := by | |
| rw [pow_add] | |
| norm_num | |
| omega | |
| _ β€ _ := Nat.pow_le_pow_right (by decide) hexp | |
| /-- A conservative simultaneous footprint, including the preliminary | |
| single-block enumeration and three copies of every group state. -/ | |
| def storageCells (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (fuel : β) (mode : Fin 4 β FilteredStream.Mode) | |
| (states : β i, D.GroupState e q i (mode i)) : β := | |
| 2 ^ compressionHalfSize n + 7 * 2 ^ compressionCapExponent n + | |
| 3 * (β i, D.groupFootprint e q i (mode i) (states i)) + 10 * (B + 1) + | |
| 3 * BinaryTrie.nodes (D.leftJoin B e q z fuel).user.tree | |
| theorem storageCells_bound (B : β) (hB : B β€ compressionDictionaryCapacity n) | |
| (e : Equiv.Perm (Fin n)) (he : D.compactTests e = true) (hn : 2000 β€ n) | |
| (q : CompressionSetup.PrimeSpace n) (z : Fin q.val) (fuel : β) | |
| (mode : Fin 4 β FilteredStream.Mode) (states : β i, D.GroupState e q i (mode i)) : | |
| D.storageCells B e q z fuel mode states β€ | |
| (800 + 3 * (WeightEncoding.weightWidth D.input + 1)) * (compressionDictionaryCapacity n + 1) := by | |
| have hs : (β i, D.groupFootprint e q i (mode i) (states i)) β€ | |
| 40 * (6 * compressionDictionaryCapacity n + 4) := by | |
| apply (Finset.sum_le_sum (fun i _ => D.groupFootprint_bound e he hn q i (mode i) (states i))).trans_eq | |
| simp | |
| ring | |
| have ht := D.leftJoin_nodes B e q z fuel | |
| have hnR : (2000 : β) β€ n := by exact_mod_cast hn | |
| have hlow : (2 : β) ^ ((3 / 25 : β) * n) β€ compressionDictionaryCapacity n := by | |
| apply (Real.rpow_le_rpow_of_exponent_le (by norm_num) | |
| (show (3 / 25 : β) * n β€ (199 / 1000 : β) * n - 1 by linarith)).trans | |
| exact compression_capacity_lower n | |
| have hhalf : 2 ^ compressionHalfSize n β€ compressionDictionaryCapacity n := by | |
| have hb := (mixerSize_bounds n).2 | |
| have hhalfR : (compressionHalfSize n : β) β€ (3 / 25 : β) * n := by | |
| have heq : mixerSize n = 2 * compressionHalfSize n := by | |
| rw [compressionHalfSize_eq] | |
| unfold mixerSize | |
| omega | |
| rw [heq, Nat.cast_mul, Nat.cast_ofNat] at hb | |
| linarith | |
| have hpow := Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : β) β€ 2) hhalfR | |
| rw [Real.rpow_natCast] at hpow | |
| exact_mod_cast hpow.trans hlow | |
| have hcap : 2 ^ compressionCapExponent n β€ compressionDictionaryCapacity n := by | |
| have ha := compression_cap_rate (by omega : 40 β€ n) | |
| have hrate : (compressionCapExponent n : β) β€ (3 / 25 : β) * n := by linarith | |
| have hpow := Real.rpow_le_rpow_of_exponent_le (by norm_num : (1 : β) β€ 2) hrate | |
| rw [Real.rpow_natCast] at hpow | |
| exact_mod_cast hpow.trans hlow | |
| unfold storageCells | |
| nlinarith only [hs, ht, hhalf, hcap, hB] | |
| end CompressionData | |
| end LowSpaceSubsetSum | |
| end | |
| end OAI | |