18The manuscript's logarithmic chunk-size choice supplies enough labels.
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 hb23The equivalent
Nat.log2formulation of the chunk-size bound.
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)28A chunk of
bBoolean coordinates. Empty chunks are allowed by the API.
abbrev Chunk (b : ℕ) := Fin b → Bool 31Splitting a nonempty chunk into its first bit and remaining bits.
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⟩
rfl42A computable encoding of a Boolean chunk by exactly
2^blabels.
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]))50The allowed labels for a
b-bit chunk insideFin p.
def ValidLabel (b p : ℕ) := {x : Fin p // x.val < 2 ^ b} instance (b p : ℕ) : Fintype (ValidLabel b p) := body · 1 line
inferInstanceAs (Fintype {x : Fin p // x.val < 2 ^ b})56Including the initial segment of length
2^binto a larger label space.
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 _ := rfl64Encoding and decoding a chunk using precisely the valid labels.
def validLabelEquiv {b p : ℕ} (h : 2 ^ b ≤ p) : Chunk b ≃ ValidLabel b p := body · 1 line
(chunkEquiv b).trans (finValidLabelEquiv h)
68The chunk encoding into the complete label space, including invalid labels.
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)73Decoding is defined on valid labels.
def decode {b p : ℕ} (h : 2 ^ b ≤ p) (x : ValidLabel b p) : Chunk b := body · 1 line
(validLabelEquiv h).symm x
@[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
@[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
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
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⟩)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 _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 _109All chunk-label assignments accepted by the unary validity tests.
def PackedAssignment {J : Type*} (b : J → ℕ) (p : ℕ) := body · 1 line
{x : J → Fin p // ∀ j, (x j).val < 2 ^ b j}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})117Coordinatewise chunk encoding, with validity built into the codomain.
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@[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 @[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 131An index for each original bit, recording both its chunk and position.
abbrev BitIndex {J : Type*} (b : J → ℕ) := Σ j, Fin (b j) 134Regrouping Boolean coordinates requires no assignments to be discarded.
def regroupEquiv {J : Type*} (b : J → ℕ) :
(BitIndex b → Bool) ≃ (∀ j, Chunk (b j)) := body · 1 line
Equiv.piCurry fun _ _ => Bool139Encoding a flat Boolean assignment into accepted chunk labels.
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)
145A concrete partition of the original variable indices transports packing to the original assignment type.
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)151The satisfying assignments for any predicate correspond under encoding.
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)157Exact finite model-count preservation, not just satisfiability preservation.
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)166The exact model-count theorem also applies to any partition of original Boolean variable indices into chunks.
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)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 _ _ _186The finite label equivalence preserves the usual representatives in
ZMod.
@[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 => rfl193Valid representatives inside
ZMod p. For primep, these are field labels.
def ValidZModLabel (b p : ℕ) := {x : ZMod p // x.val < 2 ^ b} 196The same explicit encoding in the residue ring, hence in the prime field.
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)202Encoding a Boolean chunk as a residue-ring element.
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)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⟩)Outline
- theorem
capacity_of_le_log18 - theorem
capacity_of_le_log223 - abbrev
Chunk28 - def
splitChunk31 - def
chunkEquiv42 - def
ValidLabel50 - instance
52 - def
finValidLabelEquiv56 - def
validLabelEquiv64 - def
chunkEmbedding68 - def
decode73 - theorem
decode_encode76 - theorem
encode_decode80 - theorem
chunkEmbedding_valid84 - theorem
mem_range_chunkEmbedding88 - theorem
card_chunk97 - theorem
card_validLabel102 - def
PackedAssignment109 - instance
112 - def
packingEquiv117 - theorem
packingEquiv_apply122 - theorem
packingEquiv_symm_apply126 - abbrev
BitIndex131 - def
regroupEquiv134 - def
flatPackingEquiv139 - def
assignmentPackingEquiv145 - def
satisfyingEquiv151 - theorem
count_preserved157 - theorem
assignment_count_preserved166 - theorem
card_packedAssignment175 - theorem
finEquiv_val186 - def
ValidZModLabel193 - def
validZModEquiv196 - def
chunkZModEmbedding202 - theorem
mem_range_chunkZModEmbedding207
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.