File size: 5,105 Bytes
5d5048e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | import OAI.Combinatorics.LowSpaceSubsetSum.Storage.PermutationDigitsExecution
import OAI.Combinatorics.LowSpaceSubsetSum.Compression.CompressionSamplerExecution
namespace OAI
/-! # Executing compression sampling into stored input arrays
Only accepted range digits are materialized. The prime draw is skipped when
the permutation sampler exhausts its allowance. Ideal backup values occur
only in the refinement proof, never as a runtime choice.
-/
noncomputable section
namespace LowSpaceSubsetSum.CompressionSampleArrays
variable {n : ℕ}
def prime (hn : 168000000 ≤ n) :=
SamplerExecution.prime (show 4 ≤ compressionPrimeExponent n by
unfold compressionPrimeExponent; omega) n
def run (D : CompressionData n) (hn : 168000000 ≤ n) (s : (D.sampler hn).Seed) :
Option (Vector (Fin n) n × CompressionSetup.PrimeSpace n) × ℕ :=
let digits := PermutationDigitsExecution.run n n s.1
match digits.value with
| none => (none, digits.reads + digits.tests + 1)
| some d =>
let v := PermutationArray.build n d
let q := (prime hn).run s.2
(q.value.map (fun q => (v.1, q)),
digits.reads + digits.tests + v.2 + q.reads + q.tests + 3)
theorem value (D : CompressionData n) (hn : 168000000 ≤ n) (s : (D.sampler hn).Seed)
(v : Vector (Fin n) n) (q : CompressionSetup.PrimeSpace n)
(h : (run D hn s).1 = some (v, q)) :
∃ e, (D.sampler hn).bounded s = some ⟨e, q⟩ ∧ ∀ i : Fin n, v[i.val] = e i := by
rcases s with ⟨first, second⟩
simp only [run] at h
cases hd : (PermutationDigitsExecution.run n n first).value with
| none => simp only [hd, reduceCtorEq] at h
| some d =>
simp only [hd] at h
obtain ⟨q', hq, heq⟩ := Option.map_eq_some_iff.mp h
cases heq
refine ⟨PermutationArray.semantic n d, ?_, PermutationArray.build_value n d⟩
have hp := PermutationDigitsExecution.value n n first
rw [hd] at hp
have hp' : (permutationCoupling n n).bounded first =
some (PermutationArray.semantic n d) := by
rw [← (SamplerExecution.permutation n n).value_eq]
exact hp.symm
have hi := (SamplerExecution.permutation n n).ideal_eq_of_some first
(PermutationArray.semantic n d) hp.symm
have hq' := (prime hn).value_eq second
rw [hq] at hq'
simp only [CompressionData.sampler, SamplerCoupling.bind, hp', reduceCtorEq, ↓reduceIte]
rw [← hq', hi]
rfl
theorem complete (D : CompressionData n) (hn : 168000000 ≤ n) (s : (D.sampler hn).Seed)
(e : Equiv.Perm (Fin n)) (q : CompressionSetup.PrimeSpace n)
(h : (D.sampler hn).bounded s = some ⟨e, q⟩) :
∃ v, (run D hn s).1 = some (v, q) ∧ ∀ i : Fin n, v[i.val] = e i := by
rcases s with ⟨first, second⟩
have hp := PermutationDigitsExecution.value n n first
cases hd : (PermutationDigitsExecution.run n n first).value with
| none =>
rw [hd] at hp
have hp' : (permutationCoupling n n).bounded first = none := by
rw [← (SamplerExecution.permutation n n).value_eq]
exact hp.symm
simp only [CompressionData.sampler, SamplerCoupling.bind, hp', ↓reduceIte,
reduceCtorEq] at h
| some d =>
rw [hd] at hp
have hp' : (permutationCoupling n n).bounded first =
some (PermutationArray.semantic n d) := by
rw [← (SamplerExecution.permutation n n).value_eq]
exact hp.symm
have hi := (SamplerExecution.permutation n n).ideal_eq_of_some first
(PermutationArray.semantic n d) hp.symm
simp only [CompressionData.sampler, SamplerCoupling.bind, hp', reduceCtorEq,
↓reduceIte] at h
obtain ⟨q', hq, heq⟩ := Option.map_eq_some_iff.mp h
have he : PermutationArray.semantic n d = e := by
exact hi.symm.trans (congrArg Sigma.fst heq)
have heq' : q' = q := by
exact congrArg (fun h : CompressionSetup.TrialHistory n => h.2) heq
subst q'
refine ⟨(PermutationArray.build n d).1, ?_, ?_⟩
· have hq' := (prime hn).value_eq second
rw [hq] at hq'
simp only [run, hd, hq', Option.map_some]
· rw [← he]
exact PermutationArray.build_value n d
theorem work (D : CompressionData n) (hn : 168000000 ≤ n) (s : (D.sampler hn).Seed) :
(run D hn s).2 ≤ (n + 1) * n ^ 3 + SamplerExecution.primeTestBudget n +
10 * (n + 1) ^ 2 + 3 := by
have hd := PermutationDigitsExecution.counts n n s.1
have hq := SamplerExecution.prime_bounded
(show 4 ≤ compressionPrimeExponent n by unfold compressionPrimeExponent; omega) n s.2
have he : (compressionPrimeExponent n + 1) / 2 ≤ (n + 1) / 2 := by
unfold compressionPrimeExponent; omega
have ht : n ^ 3 * 2 ^ ((compressionPrimeExponent n + 1) / 2) ≤
n ^ 3 * 2 ^ ((n + 1) / 2) :=
Nat.mul_le_mul_left (n ^ 3) (Nat.pow_le_pow_right (by decide) he)
simp only [run]
split
· dsimp only
nlinarith only [hd.1, hd.2]
next d _ =>
have hv := PermutationArray.build_work n d
change _ + _ + _ + _ + _ + 3 ≤ _
unfold prime SamplerExecution.primeTestBudget
nlinarith only [hd.1, hd.2, hq.1, hq.2, ht, hv]
end LowSpaceSubsetSum.CompressionSampleArrays
end
end OAI
|