cfahlgren1's picture
download
raw
9.51 kB

The manuscript's logarithmic chunk-size choice supplies enough labels.

18
theorem capacity_of_le_log {b p : ℕ} (hp : p ≠ 0) (hb : b ≤ Nat.log 2 p) :
    2 ^ b ≤ p :=
proof · 1 line
  Nat.pow_le_of_le_log hp hb

The equivalent Nat.log2 formulation of the chunk-size bound.

23
theorem capacity_of_le_log2 {b p : ℕ} (hp : p ≠ 0) (hb : b ≤ Nat.log2 p) :
    2 ^ b ≤ p :=
proof · 1 line
  capacity_of_le_log hp (by simpa only [Nat.log2_eq_log_two] using hb)

A chunk of b Boolean coordinates. Empty chunks are allowed by the API.

28
abbrev Chunk (b : ℕ) := Fin b → Bool

Splitting a nonempty chunk into its first bit and remaining bits.

31
def splitChunk (b : ℕ) : Chunk (b + 1) ≃ Bool × Chunk b where
body · 8 lines
  toFun x := (x 0, fun i => x i.succ)
  invFun x := Fin.cases x.1 x.2
  left_inv x := by
    funext i
    refine Fin.cases ?_ (fun j => ?_) i <;> rfl
  right_inv x := by
    rcases x with ⟨head, tail⟩
    rfl

A computable encoding of a Boolean chunk by exactly 2^b labels.

42
def chunkEquiv : (b : ℕ) → Chunk b ≃ Fin (2 ^ b)
body · 5 lines
  | 0 => by simpa only [pow_zero] using Equiv.ofUnique (Chunk 0) (Fin 1)
  | b + 1 =>
      (splitChunk b).trans <|
        (Equiv.prodCongr finTwoEquiv.symm (chunkEquiv b)).trans <|
          finProdFinEquiv.trans (finCongr (by simp [pow_succ, Nat.mul_comm]))

The allowed labels for a b-bit chunk inside Fin p.

50
def ValidLabel (b p : ℕ) := {x : Fin p // x.val < 2 ^ b}
52
instance (b p : ℕ) : Fintype (ValidLabel b p) :=
body · 1 line
  inferInstanceAs (Fintype {x : Fin p // x.val < 2 ^ b})

Including the initial segment of length 2^b into a larger label space.

56
def finValidLabelEquiv {b p : ℕ} (h : 2 ^ b ≤ p) :
    Fin (2 ^ b) ≃ ValidLabel b p where
body · 4 lines
  toFun x := ⟨⟨x.val, lt_of_lt_of_le x.isLt h⟩, x.isLt⟩
  invFun x := ⟨x.val.val, x.property⟩
  left_inv _ := rfl
  right_inv _ := rfl

Encoding and decoding a chunk using precisely the valid labels.

64
def validLabelEquiv {b p : ℕ} (h : 2 ^ b ≤ p) : Chunk b ≃ ValidLabel b p :=
body · 1 line
  (chunkEquiv b).trans (finValidLabelEquiv h)

The chunk encoding into the complete label space, including invalid labels.

68
def chunkEmbedding {b p : ℕ} (h : 2 ^ b ≤ p) : Chunk b ↪ Fin p where
body · 2 lines
  toFun x := (validLabelEquiv h x).val
  inj' _ _ heq := (validLabelEquiv h).injective (Subtype.ext heq)

Decoding is defined on valid labels.

73
def decode {b p : ℕ} (h : 2 ^ b ≤ p) (x : ValidLabel b p) : Chunk b :=
body · 1 line
  (validLabelEquiv h).symm x
76
@[simp] theorem decode_encode {b p : ℕ} (h : 2 ^ b ≤ p) (x : Chunk b) :
    decode h (validLabelEquiv h x) = x :=
proof · 1 line
  (validLabelEquiv h).symm_apply_apply x
80
@[simp] theorem encode_decode {b p : ℕ} (h : 2 ^ b ≤ p) (x : ValidLabel b p) :
    validLabelEquiv h (decode h x) = x :=
proof · 1 line
  (validLabelEquiv h).apply_symm_apply x
84
theorem chunkEmbedding_valid {b p : ℕ} (h : 2 ^ b ≤ p) (x : Chunk b) :
    (chunkEmbedding h x).val < 2 ^ b :=
proof · 1 line
  (validLabelEquiv h x).property
88
theorem mem_range_chunkEmbedding {b p : ℕ} (h : 2 ^ b ≤ p) (a : Fin p) :
    a ∈ Set.range (chunkEmbedding h) ↔ a.val < 2 ^ b := by
proof · 6 lines
  constructor
  · rintro ⟨x, rfl⟩
    exact chunkEmbedding_valid h x
  · intro ha
    refine ⟨decode h ⟨a, ha⟩, ?_⟩
    exact congrArg Subtype.val (encode_decode h ⟨a, ha⟩)
97
theorem card_chunk (b : ℕ) : Fintype.card (Chunk b) = 2 ^ b := by
proof · 3 lines
  calc
    _ = Fintype.card (Fin (2 ^ b)) := Fintype.card_congr (chunkEquiv b)
    _ = _ := Fintype.card_fin _
102
theorem card_validLabel {b p : ℕ} (h : 2 ^ b ≤ p) :
    Fintype.card (ValidLabel b p) = 2 ^ b := by
proof · 3 lines
  calc
    _ = Fintype.card (Fin (2 ^ b)) := Fintype.card_congr (finValidLabelEquiv h).symm
    _ = _ := Fintype.card_fin _

All chunk-label assignments accepted by the unary validity tests.

109
def PackedAssignment {J : Type*} (b : J → ℕ) (p : ℕ) :=
body · 1 line
  {x : J → Fin p // ∀ j, (x j).val < 2 ^ b j}
112
instance {J : Type*} [Fintype J] [DecidableEq J] (b : J → ℕ) (p : ℕ) :
    Fintype (PackedAssignment b p) :=
body · 1 line
  inferInstanceAs (Fintype {x : J → Fin p // ∀ j, (x j).val < 2 ^ b j})

Coordinatewise chunk encoding, with validity built into the codomain.

117
def packingEquiv {J : Type*} (b : J → ℕ) {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) :
    (∀ j, Chunk (b j)) ≃ PackedAssignment b p :=
body · 2 lines
  (Equiv.piCongrRight fun j => validLabelEquiv (h j)).trans
    Equiv.subtypePiEquivPi.symm
122
@[simp] theorem packingEquiv_apply {J : Type*} (b : J → ℕ) {p : ℕ}
    (h : ∀ j, 2 ^ b j ≤ p) (x : ∀ j, Chunk (b j)) (j : J) :
    (packingEquiv b h x).val j = chunkEmbedding (h j) (x j) := rfl
126
@[simp] theorem packingEquiv_symm_apply {J : Type*} (b : J → ℕ) {p : ℕ}
    (h : ∀ j, 2 ^ b j ≤ p) (x : PackedAssignment b p) (j : J) :
    (packingEquiv b h).symm x j = decode (h j) ⟨x.val j, x.property j⟩ := rfl

An index for each original bit, recording both its chunk and position.

131
abbrev BitIndex {J : Type*} (b : J → ℕ) := Σ j, Fin (b j)

Regrouping Boolean coordinates requires no assignments to be discarded.

134
def regroupEquiv {J : Type*} (b : J → ℕ) :
    (BitIndex b → Bool) ≃ (∀ j, Chunk (b j)) :=
body · 1 line
  Equiv.piCurry fun _ _ => Bool

Encoding a flat Boolean assignment into accepted chunk labels.

139
def flatPackingEquiv {J : Type*} (b : J → ℕ) {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) :
    (BitIndex b → Bool) ≃ PackedAssignment b p :=
body · 1 line
  (regroupEquiv b).trans (packingEquiv b h)

A concrete partition of the original variable indices transports packing to the original assignment type.

145
def assignmentPackingEquiv {V J : Type*} (b : J → ℕ) (indices : V ≃ BitIndex b)
    {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) :
    (V → Bool) ≃ PackedAssignment b p :=
body · 1 line
  (Equiv.arrowCongr indices (Equiv.refl Bool)).trans (flatPackingEquiv b h)

The satisfying assignments for any predicate correspond under encoding.

151
def satisfyingEquiv {J : Type*} (b : J → ℕ) {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p)
    (P : (∀ j, Chunk (b j)) → Prop) :
    {x // P x} ≃ {y : PackedAssignment b p // P ((packingEquiv b h).symm y)} :=
body · 1 line
  (packingEquiv b h).subtypeEquiv (by intro x; simp)

Exact finite model-count preservation, not just satisfiability preservation.

157
theorem count_preserved {J : Type*} [Fintype J] [DecidableEq J] (b : J → ℕ)
    {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) (P : (∀ j, Chunk (b j)) → Prop)
    [DecidablePred P] :
    Fintype.card {x // P x} =
      Fintype.card {y : PackedAssignment b p // P ((packingEquiv b h).symm y)} :=
proof · 1 line
  Fintype.card_congr (satisfyingEquiv b h P)

The exact model-count theorem also applies to any partition of original Boolean variable indices into chunks.

166
theorem assignment_count_preserved {V J : Type*} [Fintype V] [DecidableEq V]
    [Fintype J] [DecidableEq J] (b : J → ℕ) (indices : V ≃ BitIndex b)
    {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) (P : (V → Bool) → Prop) [DecidablePred P] :
    Fintype.card {x // P x} =
      Fintype.card {y : PackedAssignment b p //
        P ((assignmentPackingEquiv b indices h).symm y)} := by
proof · 2 lines
  apply Fintype.card_congr
  exact (assignmentPackingEquiv b indices h).subtypeEquiv (by intro x; simp)
175
theorem card_packedAssignment {J : Type*} [Fintype J] [DecidableEq J]
    (b : J → ℕ) {p : ℕ} (h : ∀ j, 2 ^ b j ≤ p) :
    Fintype.card (PackedAssignment b p) = 2 ^ (∑ j, b j) := by
proof · 6 lines
  calc
    Fintype.card (PackedAssignment b p) = Fintype.card (∀ j, Chunk (b j)) :=
      Fintype.card_congr (packingEquiv b h).symm
    _ = ∏ j, Fintype.card (Chunk (b j)) := Fintype.card_pi
    _ = ∏ j, 2 ^ b j := by simp only [card_chunk]
    _ = 2 ^ (∑ j, b j) := Finset.prod_pow_eq_pow_sum _ _ _

The finite label equivalence preserves the usual representatives in ZMod.

186
@[simp] theorem finEquiv_val {p : ℕ} [NeZero p] (x : Fin p) :
    (ZMod.finEquiv p x).val = x.val := by
proof · 3 lines
  cases p with
  | zero => exact (NeZero.ne (0 : ℕ) rfl).elim
  | succ p => rfl

Valid representatives inside ZMod p. For prime p, these are field labels.

193
def ValidZModLabel (b p : ℕ) := {x : ZMod p // x.val < 2 ^ b}

The same explicit encoding in the residue ring, hence in the prime field.

196
def validZModEquiv {b p : ℕ} [NeZero p] (h : 2 ^ b ≤ p) :
    Chunk b ≃ ValidZModLabel b p :=
body · 2 lines
  (validLabelEquiv h).trans <|
    (ZMod.finEquiv p).toEquiv.subtypeEquiv (by intro x; simp)

Encoding a Boolean chunk as a residue-ring element.

202
def chunkZModEmbedding {b p : ℕ} [NeZero p] (h : 2 ^ b ≤ p) :
    Chunk b ↪ ZMod p where
body · 2 lines
  toFun x := (validZModEquiv h x).val
  inj' _ _ heq := (validZModEquiv h).injective (Subtype.ext heq)
207
theorem mem_range_chunkZModEmbedding {b p : ℕ} [NeZero p] (h : 2 ^ b ≤ p)
    (a : ZMod p) : a ∈ Set.range (chunkZModEmbedding h) ↔ a.val < 2 ^ b := by
proof · 6 lines
  constructor
  · rintro ⟨x, rfl⟩
    exact (validZModEquiv h x).property
  · intro ha
    refine ⟨(validZModEquiv h).symm ⟨a, ha⟩, ?_⟩
    exact congrArg Subtype.val ((validZModEquiv h).apply_symm_apply ⟨a, ha⟩)

Xet Storage Details

Size:
9.51 kB
·
Xet hash:
7e906711803667347be06b349fad5f3ed079cdc7eca55667b83fff005afa8678

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.