File size: 2,938 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 | import OAI.Combinatorics.LowSpaceSubsetSum.Storage.StoredBackgroundBlocks
namespace OAI
/-! # Copying the eight background rows from their shared array
Each read uses the computed prefix-sum offset. Rows are retained once in an
explicit vector, and the returned view indexes that vector.
-/
namespace LowSpaceSubsetSum.BackgroundBlockCells
open scoped BigOperators
variable {n m : ℕ}
def index (counts : Vector ℕ 8) (hc : (∑ i : Fin 8, counts[i.val]) = m)
(i : Fin 8) (k : Fin counts[i.val]) : Fin m :=
⟨(∑ j : Fin i.val, counts[(Fin.castLE i.isLt.le j).val])+k.val, by
have h := (StoredBackgroundBlocks.index counts hc i k).isLt
rwa [StoredBackgroundBlocks.index_value] at h⟩
theorem index_value (counts : Vector ℕ 8) (hc : (∑ i : Fin 8, counts[i.val]) = m)
(i : Fin 8) (k : Fin counts[i.val]) :
index counts hc i k = StoredBackgroundBlocks.index counts hc i k := by
apply Fin.ext
exact (StoredBackgroundBlocks.index_value counts hc i k).symm
def row (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) (i : Fin 8) :
(List (Fin n) × ℕ) × ℕ :=
let out := (List.finRange counts[i.val]).map (fun k => xs[(index counts hc i k).val])
((out, 24*counts[i.val]+16), 6*counts[i.val]+32)
theorem row_value (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) (i : Fin 8) :
(row xs counts hc i).1.1 = StoredBackgroundBlocks.row xs counts hc i := by
simp only [row, StoredBackgroundBlocks.row, List.ofFn_eq_map, index_value]
def run (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) :
(Vector (List (Fin n)) 8 × ℕ) × ℕ :=
let rows := Vector.ofFn (fun i => row xs counts hc i)
((rows.map (fun r => r.1.1), 32*m+200),
(∑ i : Fin 8, rows[i.val].2)+4*m+128)
theorem value (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) :
(run xs counts hc).1 = StoredBackgroundBlocks.run xs counts hc := by
apply Prod.ext
· apply Vector.ext
intro i hi
simp only [run, StoredBackgroundBlocks.run, Vector.getElem_map, Vector.getElem_ofFn, row_value]
· rfl
theorem row_work (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) :
(∑ i : Fin 8, (row xs counts hc i).1.2)+72 ≤ (run xs counts hc).1.2 := by
simp only [row, run, Finset.sum_add_distrib, ← Finset.mul_sum,
Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul, hc]
omega
theorem cells (xs : Vector (Fin n) m) (counts : Vector ℕ 8)
(hc : (∑ i : Fin 8, counts[i.val]) = m) :
(run xs counts hc).2 ≤ 16*m+512 := by
simp only [run, Vector.getElem_ofFn, row, Finset.sum_add_distrib,
← Finset.mul_sum, Finset.sum_const, Finset.card_univ, Fintype.card_fin,
smul_eq_mul, hc]
omega
end LowSpaceSubsetSum.BackgroundBlockCells
end OAI
|