Download data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionQueryBounds.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionQueryBounds.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionQueryBounds.lean
-
curl -L -o CompressionQueryBounds.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/LowSpaceSubsetSum/Compression/CompressionQueryBounds.lean
11.9 kB
| import OAI.Combinatorics.LowSpaceSubsetSum.Compression.CompressionWorkBounds | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Counting.ResidueMatchAccounting | |
| import OAI.Combinatorics.LowSpaceSubsetSum.Streams.DictionaryPrefixes | |
| namespace OAI | |
| /-! # Actual compression join queries across the deterministic residue loop -/ | |
| noncomputable section | |
| namespace LowSpaceSubsetSum | |
| open scoped BigOperators | |
| namespace MatchPotential | |
| theorem count_perm {Ξ± Ξ² : Type*} (kβ : Ξ± β β€) (kβ : Ξ² β β€) | |
| {xs xs' : List Ξ±} {ys ys' : List Ξ²} (hx : xs.Perm xs') (hy : ys.Perm ys') : | |
| count kβ kβ xs ys = count kβ kβ xs' ys' := by | |
| rw [count_eq_filter_product_length, count_eq_filter_product_length] | |
| exact ((hx.product hy).filter _).length_eq | |
| end MatchPotential | |
| namespace CompressionData | |
| variable {n : β} (D : CompressionData n) | |
| theorem groupOutput_perm (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (i : Fin 4) (mode : FilteredStream.Mode) : | |
| (D.groupOutput e q i mode (D.groupStart e q i mode)).Perm (D.groupList e i) := by | |
| have hp := (FilteredStream.sorted_output_perm | |
| (D.storedFirst e i).toArray (D.storedSecond e i).toArray id id 1 q.val 0 | |
| (by exact_mod_cast (primeRange_prime q.property).pos) mode).map | |
| (fun p : β€ Γ β€ => p.1 + p.2) | |
| simpa only [groupOutput, groupStart, storedRightArray, groupList, pairSumList, id_eq, | |
| Int.emod_one, decide_true, List.filter_true, List.toList_toArray, SProd.sprod] using hp | |
| def leftJoin (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (fuel : β) := | |
| StreamJoin.run (D.groupRead e q 0 .direct) (fun x => x % (q.val : β€)) | |
| (D.groupRead e q 1 (.complementary z.val)) (fun y => ((z.val : β€) - y) % q.val) | |
| (BinaryTrie.callback (compressionDictionaryCapacity n) | |
| (fun x y => WeightEncoding.weightKey D.input (x + y))) | |
| B (D.streamLength e 0) (D.streamLength e 1) fuel | |
| (D.groupStart e q 0 .direct) (D.groupStart e q 1 (.complementary z.val)) | |
| β¨.empty, false, 0β© | |
| def rightJoin (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (tree : BinaryTrie.Tree) (fuel : β) := | |
| let target := (D.input.target : β€) - z.val | |
| StreamJoin.run (D.groupRead e q 2 .direct) (fun x => x % (q.val : β€)) | |
| (D.groupRead e q 3 (.complementary target)) (fun y => (target - y) % q.val) | |
| (StreamWitness.remember (fun x y => BinaryTrie.contains tree | |
| (WeightEncoding.weightKey D.input ((D.input.target : β€) - (x + y))))) | |
| B (D.streamLength e 2) (D.streamLength e 3) fuel | |
| (D.groupStart e q 2 .direct) (D.groupStart e q 3 (.complementary target)) false | |
| theorem leftJoin_user (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) : | |
| (D.leftJoin B e q z (D.streamLength e 0 + D.streamLength e 1 + 1)).user = | |
| D.actualLeftDictionary B e q z := rfl | |
| theorem rightJoin_user (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (tree : BinaryTrie.Tree) : | |
| (D.rightJoin B e q z tree (D.streamLength e 2 + D.streamLength e 3 + 1)).user = | |
| D.actualRightHit B e q z tree := rfl | |
| def leftPotential (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) (z : Fin q.val) : β := | |
| MatchPotential.count (fun x => x % (q.val : β€)) (fun y => ((z.val : β€) - y) % q.val) | |
| (D.groupList e 0) (D.groupList e 1) | |
| def rightPotential (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) (z : Fin q.val) : β := | |
| MatchPotential.count (fun x => x % (q.val : β€)) | |
| (fun y => ((D.input.target : β€) - z.val - y) % q.val) | |
| (D.groupList e 2) (D.groupList e 3) | |
| theorem leftJoin_bounds (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (fuel : β) : | |
| (D.leftJoin B e q z fuel).queries β€ | |
| 6 * (D.streamLength e 0 + D.streamLength e 1) + D.leftPotential e q z + 2 β§ | |
| (D.leftJoin B e q z fuel).reports β€ D.leftPotential e q z β§ | |
| B * (D.leftJoin B e q z fuel).copies β€ 2 * D.leftPotential e q z := by | |
| have h := StreamJoin.run_bounds | |
| (D.groupRead e q 0 .direct) (fun x => x % (q.val : β€)) | |
| (D.groupRead e q 1 (.complementary z.val)) (fun y => ((z.val : β€) - y) % q.val) | |
| (BinaryTrie.callback (compressionDictionaryCapacity n) | |
| (fun x y => WeightEncoding.weightKey D.input (x + y))) (fun _ _ _ => rfl) | |
| (D.groupOutput e q 0 .direct) (D.groupRead_law e q 0 .direct) | |
| (D.groupOutput e q 1 (.complementary z.val)) (D.groupRead_law e q 1 (.complementary z.val)) | |
| B (D.streamLength e 0) (D.streamLength e 1) fuel | |
| (D.groupStart e q 0 .direct) (D.groupStart e q 1 (.complementary z.val)) β¨.empty, false, 0β© | |
| (D.groupOutput_sorted e q 0 .direct) (D.groupOutput_sorted e q 1 (.complementary z.val)) | |
| (by rw [D.initial_output_length]) (by rw [D.initial_output_length]) | |
| have hp := MatchPotential.count_perm | |
| (fun x => x % (q.val : β€)) (fun y => ((z.val : β€) - y) % q.val) | |
| (D.groupOutput_perm e q 0 .direct) (D.groupOutput_perm e q 1 (.complementary z.val)) | |
| simpa only [leftJoin, leftPotential, D.initial_output_length, hp] using h | |
| theorem rightJoin_bounds (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (tree : BinaryTrie.Tree) (fuel : β) : | |
| (D.rightJoin B e q z tree fuel).queries β€ | |
| 6 * (D.streamLength e 2 + D.streamLength e 3) + D.rightPotential e q z + 2 β§ | |
| (D.rightJoin B e q z tree fuel).reports β€ D.rightPotential e q z β§ | |
| B * (D.rightJoin B e q z tree fuel).copies β€ 2 * D.rightPotential e q z := by | |
| let target := (D.input.target : β€) - z.val | |
| have h := StreamJoin.run_bounds | |
| (D.groupRead e q 2 .direct) (fun x => x % (q.val : β€)) | |
| (D.groupRead e q 3 (.complementary target)) (fun y => (target - y) % q.val) | |
| (StreamWitness.remember (fun x y => BinaryTrie.contains tree | |
| (WeightEncoding.weightKey D.input ((D.input.target : β€) - (x + y))))) (fun _ _ _ => rfl) | |
| (D.groupOutput e q 2 .direct) (D.groupRead_law e q 2 .direct) | |
| (D.groupOutput e q 3 (.complementary target)) (D.groupRead_law e q 3 (.complementary target)) | |
| B (D.streamLength e 2) (D.streamLength e 3) fuel | |
| (D.groupStart e q 2 .direct) (D.groupStart e q 3 (.complementary target)) false | |
| (D.groupOutput_sorted e q 2 .direct) (D.groupOutput_sorted e q 3 (.complementary target)) | |
| (by rw [D.initial_output_length]) (by rw [D.initial_output_length]) | |
| have hp := MatchPotential.count_perm | |
| (fun x => x % (q.val : β€)) (fun y => (target - y) % q.val) | |
| (D.groupOutput_perm e q 2 .direct) (D.groupOutput_perm e q 3 (.complementary target)) | |
| simpa only [rightJoin, rightPotential, target, D.initial_output_length, hp] using h | |
| theorem sum_leftPotential (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) : | |
| (β z, D.leftPotential e q z) = D.streamLength e 0 * D.streamLength e 1 := by | |
| have h := ResidueMatchAccounting.sum_potential (primeRange_prime q.property).pos | |
| id id (D.groupList e 0) (D.groupList e 1) | |
| simpa only [leftPotential, groupList, pairSumList_length, streamLength, id_eq] using h | |
| theorem sum_rightPotential (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) : | |
| (β z, D.rightPotential e q z) = D.streamLength e 2 * D.streamLength e 3 := by | |
| have h := ResidueMatchAccounting.sum_complementary_potential (primeRange_prime q.property).pos | |
| (D.input.target : β€) id id (D.groupList e 2) (D.groupList e 3) | |
| simpa only [rightPotential, groupList, pairSumList_length, streamLength, id_eq] using h | |
| /-- The query counter of the actually enabled two joins. The right join is | |
| skipped on overflow, and all joins are skipped when a compact-list test fails. -/ | |
| def residueQueries (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) : β := | |
| if D.compactTests e then | |
| let left := D.leftJoin B e q z (D.streamLength e 0 + D.streamLength e 1 + 1) | |
| left.queries + if left.user.overflow then 0 else | |
| (D.rightJoin B e q z left.user.tree (D.streamLength e 2 + D.streamLength e 3 + 1)).queries | |
| else 0 | |
| theorem residueQueries_le (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) : | |
| D.residueQueries B e q z β€ 6 * (β i : Fin 4, D.streamLength e i) + | |
| D.leftPotential e q z + D.rightPotential e q z + 4 := by | |
| have hl := (D.leftJoin_bounds B e q z (D.streamLength e 0 + D.streamLength e 1 + 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)).1 | |
| simp only [residueQueries] | |
| split | |
| Β· split <;> simp only [Fin.sum_univ_four] <;> omega | |
| Β· omega | |
| theorem sum_residueQueries_le (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) : | |
| (β z, D.residueQueries B e q z) β€ | |
| 6 * (q.val * β i : Fin 4, D.streamLength e i) + | |
| D.streamLength e 0 * D.streamLength e 1 + | |
| D.streamLength e 2 * D.streamLength e 3 + 4 * q.val := by | |
| apply (Finset.sum_le_sum (fun z _ => D.residueQueries_le B e q z)).trans_eq | |
| rw [Finset.sum_add_distrib, Finset.sum_add_distrib, Finset.sum_add_distrib, | |
| D.sum_leftPotential, D.sum_rightPotential] | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] | |
| ring | |
| theorem queries_half_exponential (B : β) (e : Equiv.Perm (Fin n)) | |
| (q : CompressionSetup.PrimeSpace n) (hn : 2000 β€ n) : | |
| ((β z, D.residueQueries B e q z) : β) β€ 30 * (2 : β) ^ ((n : β) / 2) := by | |
| by_cases he : D.compactTests e = true | |
| Β· 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 hp := D.matching_product_bound e he hn | |
| have hq : (q.val : β) β€ (2 : β) ^ ((n : β) / 2) := by | |
| have hq' : q.val β€ 2 ^ compressionPrimeExponent n := | |
| Nat.le_of_mem_primesLE (Finset.mem_filter.mp q.property).1 | |
| apply (Nat.cast_le.mpr hq').trans | |
| rw [Nat.cast_pow, Nat.cast_ofNat, β Real.rpow_natCast] | |
| apply Real.rpow_le_rpow_of_exponent_le (by norm_num) | |
| have hfloor : 1000 * compressionPrimeExponent n β€ 249 * n := by | |
| unfold compressionPrimeExponent | |
| omega | |
| have hR : (1000 : β) * compressionPrimeExponent n β€ 249 * n := by exact_mod_cast hfloor | |
| linarith | |
| have hledger : ((β z, D.residueQueries B e q z) : β) β€ | |
| 6 * (q.val * β i : Fin 4, D.streamLength e i : β) + | |
| (D.streamLength e 0 * D.streamLength e 1 : β) + | |
| (D.streamLength e 2 * D.streamLength e 3 : β) + 4 * (q.val : β) := by | |
| exact_mod_cast D.sum_residueQueries_le B e q | |
| linarith [hp.1, hp.2] | |
| Β· have hf : D.compactTests e = false := Bool.eq_false_iff.mpr he | |
| simp only [residueQueries, hf, Bool.false_eq_true, βreduceIte, Finset.sum_const_zero, Nat.cast_zero] | |
| positivity | |
| /-- Capacity is respected even at arbitrary stopped control prefixes. -/ | |
| theorem leftJoin_nodes (B : β) (e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n) | |
| (z : Fin q.val) (fuel : β) : | |
| BinaryTrie.nodes (D.leftJoin B e q z fuel).user.tree β€ | |
| (WeightEncoding.weightWidth D.input + 1) * (compressionDictionaryCapacity n + 1) := by | |
| exact DictionaryPrefixes.stopped_nodes | |
| (D.groupRead e q 0 .direct) (fun x => x % (q.val : β€)) | |
| (D.groupRead e q 1 (.complementary z.val)) (fun y => ((z.val : β€) - y) % q.val) | |
| (fun x y => WeightEncoding.weightKey D.input (x + y)) | |
| (fun x y => WeightEncoding.weightKey_length D.input (x + y)) | |
| B (D.streamLength e 0) (D.streamLength e 1) fuel | |
| (D.groupStart e q 0 .direct) (D.groupStart e q 1 (.complementary z.val)) | |
| end CompressionData | |
| end LowSpaceSubsetSum | |
| end | |
| end OAI | |