File size: 17,445 Bytes
ea76aac | 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | import Mathlib
import OAI.Computability.MaxCut.Encoding.TableKeysGame
import OAI.Computability.MaxCut.Games.ActualCompleteness
namespace OAI
/-!
Completeness of the v2 single-orbit matrix game. The generic finite-average
calculation is shared with the proved actual completeness calculation. Its
reuse is justified below by pointwise equality of restored answers under
diagonal labels; the output vertices themselves are never doubled.
No gadget existence, dispersion hypothesis, inverse theorem, or legacy
soundness theorem is a premise. The bound includes the exact fair-bit factor
`1 / 2`, and is a statement about the actual finite edge occurrence list.
-/
namespace MaxCutGames.Decoder.TableKeysCompleteness
open MaxCutGames.Integration.BinaryLinear MaxCutGames.Reduction
open ActualSource Foundations.Target
open TableKeysGame
open scoped BigOperators
noncomputable section
/-- Use a single label function on both auxiliary sides, solely to share the
already proved finite-average calculation. This does not change the v2 game. -/
def diagonalLabeling (S : Source) (k s d : Nat)
(labeling : Fin (vertexCount S k s d) → Fin (2^s)) :
Fin (ActualGame.vertexCount S k s d) → Fin (2^s) :=
ActualGame.labelingOf S k s d (fun _ => vertexLabel S k s d labeling)
theorem diagonal_unfolded (S : Source) (k s d : Nat)
(labeling : Fin (vertexCount S k s d) → Fin (2^s))
(side : Bool) (q : Query S k s d) :
ActualGame.unfolded S k s d (diagonalLabeling S k s d labeling) side q =
unfolded S k s d labeling q := by
simp only [diagonalLabeling, ActualGame.unfolded,
ActualGame.sideLabel_labelingOf, unfolded, canonical]
/-- Pointwise-identical matrix tests have exactly the same acceptance average. -/
theorem acceptanceProbability_eq_diagonal (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (labeling : Fin (vertexCount S k s d) → Fin (2^s)) :
acceptanceProbability S k g labeling =
ActualGame.acceptanceProbability S k g (diagonalLabeling S k s d labeling) := by
rw [acceptanceProbability_eq_test, ActualGame.acceptanceProbability_eq_test]
simp only [diagonal_unfolded, leftQuery, rightQuery]
def honestLabeling (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(A : Fin S.«variables» → Bool) : Fin (vertexCount S k s d) → Fin (2^s) :=
labelingOf S k s d (ActualCompleteness.honestVertexLabel S k g A)
theorem diagonal_honestLabeling (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) :
diagonalLabeling S k s d (honestLabeling S k g A) =
ActualCompleteness.honestLabeling S k g A := by
simp only [diagonalLabeling, honestLabeling, vertexLabel_labelingOf,
ActualCompleteness.honestLabeling]
/-- The removed affine intercept is recovered by gadget equivariance. -/
theorem honest_unfolded (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) (q : Query S k s d) :
unfolded S k s d (honestLabeling S k g A) q =
g.f (ActualCompleteness.evaluate (ActualGame.names S) (fun n => ofBit (A n))
(canonical S k s d q)) := by
rw [← diagonal_unfolded S k s d _ false q, diagonal_honestLabeling]
exact ActualCompleteness.honest_unfolded S k g A false q
/-- On a satisfied tuple, every sampled table evaluates the same homogeneous
answer with first coordinate one. -/
theorem honest_unfolded_valid (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) (q : Query S k s d)
(hgood : ∀ j, S.satisfied A (q.1 j) = true) :
unfolded S k s d (honestLabeling S k g A) q =
g.f (q.2 (ActualCompleteness.sourcePoint S k A q.1)) := by
rw [← diagonal_unfolded S k s d _ false q, diagonal_honestLabeling]
exact ActualCompleteness.honest_unfolded_valid S k g A false q hgood
theorem honest_acceptance_bound (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) :
1 - (k : ℚ) * S.failure A - g.stabilityError / 2 ≤
acceptanceProbability S k g (honestLabeling S k g A) := by
rw [acceptanceProbability_eq_diagonal, diagonal_honestLabeling]
exact ActualCompleteness.honest_acceptance_bound S k g A
theorem honest_acceptance_of_bounds (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) (ξ p ε : ℚ)
(hsource : S.failure A ≤ ξ) (hstable : g.stabilityError ≤ p)
(hbudget : (k : ℚ) * ξ + p / 2 ≤ ε) :
1 - ε ≤ acceptanceProbability S k g (honestLabeling S k g A) := by
have hm := mul_le_mul_of_nonneg_left hsource (show (0 : ℚ) ≤ k by positivity)
have hactual := honest_acceptance_bound S k g A
linarith
/-- Completeness is measured on the generated single-orbit edge occurrences. -/
theorem honest_satisfied_fraction_bound (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) :
1 - (k : ℚ) * S.failure A - g.stabilityError / 2 ≤
(countSatisfied (honestLabeling S k g A)
(outputInstance S k g).constraints : ℚ) /
(outputInstance S k g).constraints.length := by
rw [← acceptanceProbability_eq_count]
exact honest_acceptance_bound S k g A
theorem completeAt (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (A : Fin S.«variables» → Bool) (error : RationalError)
(hbudget : (k : ℚ) * S.failure A + g.stabilityError / 2 ≤
Integration.GapSemantics.errorValue error) :
CompleteAt error (outputInstance S k g) := by
apply (Integration.GapSemantics.completeAt_iff error _).2
refine ⟨honestLabeling S k g A, ?_⟩
change 1 - Integration.GapSemantics.errorValue error ≤
(countSatisfied (honestLabeling S k g A)
(outputInstance S k g).constraints : ℚ) /
(outputInstance S k g).constraints.length
have h := honest_satisfied_fraction_bound S k g A
linarith
theorem completeAt_withEnumeration (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g)
(A : Fin S.«variables» → Bool) (error : RationalError)
(hbudget : (k : ℚ) * S.failure A + g.stabilityError / 2 ≤
Integration.GapSemantics.errorValue error) :
CompleteAt error (outputInstanceWithEnumeration S k g en) := by
apply (completeAt_outputInstanceWithEnumeration_iff error S k g en).2
exact completeAt S k g A error hbudget
end
end MaxCutGames.Decoder.TableKeysCompleteness
/-! Internal serialization of canonical orbit bodies. Each record occupies nine
natural-number words, so record boundaries are independent of the tag. The
outer complement coordinate occupies one leading word. These are injectivity,
deduplication, and output-size statements, not machine running-time claims. -/
namespace MaxCutGames.Reduction.CanonicalEncoding
open Integration.BinaryLinear
open Foundations.Complexity
abbrev Ambient (s d : Nat) := Integration.BinaryLinear.Vector s × Integration.BinaryLinear.Vector d
abbrev Record (n m s d : Nat) := ActualCanonical.Record (Fin n) (Fin m) (Ambient s d)
abbrev Body (n m k s d : Nat) := Integration.BinaryLinear.Vector d × (Fin k → Record n m s d)
def vectorWord {s : Nat} (v : Integration.BinaryLinear.Vector s) : Nat :=
(Encoding.alphabetEquiv s v).val
theorem vectorWord_lt {s : Nat} (v : Integration.BinaryLinear.Vector s) :
vectorWord v < 2^s := (Encoding.alphabetEquiv s v).isLt
theorem vectorWord_injective {s : Nat} :
Function.Injective (vectorWord (s := s)) := by
intro x y h
apply (Encoding.alphabetEquiv s).injective
exact Fin.ext h
@[simp] theorem vectorWord_eq_iff {s : Nat} (x y : Integration.BinaryLinear.Vector s) :
vectorWord x = vectorWord y ↔ x = y := vectorWord_injective.eq_iff
/-- Words: tag, name, occurrence, followed by three split coefficient pairs.
Padding is zero. A single record uses only the first coefficient pair. -/
def recordWords {n m s d : Nat} : Record n m s d → List Nat
| .blank => [0, 0, 0, 0, 0, 0, 0, 0, 0]
| .single name coefficient =>
[1, name.val, 0, vectorWord coefficient.1, vectorWord coefficient.2, 0, 0, 0, 0]
| .full occurrence coefficients =>
[2, 0, occurrence.val,
vectorWord (coefficients 0).1, vectorWord (coefficients 0).2,
vectorWord (coefficients 1).1, vectorWord (coefficients 1).2,
vectorWord (coefficients 2).1, vectorWord (coefficients 2).2]
@[simp] theorem recordWords_length {n m s d : Nat} (r : Record n m s d) :
(recordWords r).length = 9 := by
cases r <;> rfl
theorem recordWords_injective {n m s d : Nat} :
Function.Injective (recordWords (n := n) (m := m) (s := s) (d := d)) := by
intro r t h
cases r with
| blank => cases t <;> simp_all [recordWords]
| single name coefficient =>
cases t with
| blank => simp [recordWords] at h
| single name' coefficient' =>
simp [recordWords] at h
rcases h with ⟨hn, hc, hd⟩
have hp : coefficient = coefficient' := Prod.ext hc hd
have hn' : name = name' := Fin.ext hn
cases hn'
cases hp
rfl
| full occurrence coefficients => simp [recordWords] at h
| full occurrence coefficients =>
cases t with
| blank => simp [recordWords] at h
| single name coefficient => simp [recordWords] at h
| full occurrence' coefficients' =>
simp [recordWords] at h
rcases h with ⟨hi, h0c, h0d, h1c, h1d, h2c, h2d⟩
have hp : coefficients = coefficients' := by
funext i
fin_cases i
· exact Prod.ext h0c h0d
· exact Prod.ext h1c h1d
· exact Prod.ext h2c h2d
have hi' : occurrence = occurrence' := Fin.ext hi
cases hi'
cases hp
rfl
def recordsWords {n m s d : Nat} (rs : List (Record n m s d)) : List Nat :=
rs.flatMap recordWords
@[simp] theorem recordsWords_nil {n m s d : Nat} :
recordsWords ([] : List (Record n m s d)) = [] := rfl
@[simp] theorem recordsWords_cons {n m s d : Nat} (r : Record n m s d)
(rs : List (Record n m s d)) :
recordsWords (r :: rs) = recordWords r ++ recordsWords rs := rfl
@[simp] theorem recordsWords_length {n m s d : Nat} (rs : List (Record n m s d)) :
(recordsWords rs).length = 9 * rs.length := by
induction rs with
| nil => rfl
| cons r rs ih => simp [ih, Nat.mul_add, Nat.add_comm]
theorem recordsWords_take_head {n m s d : Nat} (r : Record n m s d)
(rs : List (Record n m s d)) :
(recordsWords (r :: rs)).take 9 = recordWords r := by
change (recordWords r ++ recordsWords rs).take 9 = recordWords r
simpa only [recordWords_length] using
(List.take_append_length (l₁ := recordWords r) (l₂ := recordsWords rs))
theorem recordsWords_injective {n m s d : Nat} :
Function.Injective (recordsWords (n := n) (m := m) (s := s) (d := d)) := by
intro rs
induction rs with
| nil =>
intro ts h
cases ts with
| nil => rfl
| cons t ts =>
have hl := congrArg List.length h
simp only [recordsWords_length, List.length_nil, List.length_cons] at hl
omega
| cons r rs ih =>
intro ts h
cases ts with
| nil =>
have hl := congrArg List.length h
simp only [recordsWords_length, List.length_nil, List.length_cons] at hl
omega
| cons t ts =>
have hh := congrArg (List.take 9) h
simp only [recordsWords_take_head] at hh
have hr := recordWords_injective hh
subst t
apply congrArg (List.cons r)
apply ih
exact List.append_cancel_left (by simpa only [recordsWords_cons] using h)
def bodyWords {n m k s d : Nat} (body : Body n m k s d) : List Nat :=
vectorWord body.1 :: recordsWords (List.ofFn body.2)
@[simp] theorem bodyWords_length {n m k s d : Nat} (body : Body n m k s d) :
(bodyWords body).length = 1 + 9*k := by
simp [bodyWords, Nat.add_comm]
theorem bodyWords_injective {n m k s d : Nat} :
Function.Injective (bodyWords (n := n) (m := m) (k := k) (s := s) (d := d)) := by
intro x y h
have hh := List.cons.inj h
apply Prod.ext
· exact vectorWord_injective hh.1
· exact List.ofFn_injective (recordsWords_injective hh.2)
@[simp] theorem bodyWords_eq_iff {n m k s d : Nat} (x y : Body n m k s d) :
bodyWords x = bodyWords y ↔ x = y := bodyWords_injective.eq_iff
def wordBound (n m s d : Nat) : Nat := n + m + 2^s + 2^d + 3
theorem recordWords_bounded {n m s d : Nat} (r : Record n m s d)
(w : Nat) (hw : w ∈ recordWords r) : w ≤ wordBound n m s d := by
unfold wordBound
cases r with
| blank =>
simp [recordWords] at hw
subst w
exact Nat.zero_le _
| single name coefficient =>
have hn := name.isLt
have hc := vectorWord_lt coefficient.1
have hd := vectorWord_lt coefficient.2
simp only [recordWords, List.mem_cons, List.not_mem_nil, or_false] at hw
rcases hw with h | h | h | h | h | h | h | h | h <;> omega
| full occurrence coefficients =>
have hi := occurrence.isLt
have h0c := vectorWord_lt (coefficients 0).1
have h0d := vectorWord_lt (coefficients 0).2
have h1c := vectorWord_lt (coefficients 1).1
have h1d := vectorWord_lt (coefficients 1).2
have h2c := vectorWord_lt (coefficients 2).1
have h2d := vectorWord_lt (coefficients 2).2
simp only [recordWords, List.mem_cons, List.not_mem_nil, or_false] at hw
rcases hw with h | h | h | h | h | h | h | h | h <;> omega
theorem bodyWords_bounded {n m k s d : Nat} (body : Body n m k s d)
(w : Nat) (hw : w ∈ bodyWords body) : w ≤ wordBound n m s d := by
rcases List.mem_cons.mp hw with h | h
· subst w
have hv := vectorWord_lt body.1
have hs : 0 < (2 : Nat)^s := pow_pos (by decide) _
unfold wordBound
omega
· obtain ⟨r, _, hr⟩ := List.mem_flatMap.mp h
exact recordWords_bounded r w hr
def bodyBits {n m k s d : Nat} (body : Body n m k s d) : List Bool :=
encodeWords (bodyWords body)
theorem bodyBits_injective {n m k s d : Nat} :
Function.Injective (bodyBits (n := n) (m := m) (k := k) (s := s) (d := d)) := by
intro x y h
exact bodyWords_injective (encodeWords_injective h)
@[simp] theorem bodyBits_eq_iff {n m k s d : Nat} (x y : Body n m k s d) :
bodyBits x = bodyBits y ↔ x = y := bodyBits_injective.eq_iff
theorem bodyBits_length_le {n m k s d : Nat} (body : Body n m k s d) :
(bodyBits body).length ≤ (1 + 9*k) * (n + m + 2^s + 2^d + 4) := by
simpa only [bodyBits, bodyWords_length, wordBound, Nat.add_assoc] using
encodeWords_length_le (bodyWords body) (wordBound n m s d) (bodyWords_bounded body)
/-- Serializing before deduplication preserves the exact retained vertex order. -/
theorem imageVertices_bodyWords {Q : Type*} {n m k s d : Nat}
[DecidableEq (Body n m k s d)] (queries : List Q) (body : Q → Body n m k s d) :
Encoding.imageVertices queries (fun q => bodyWords (body q)) =
(Encoding.imageVertices queries body).map bodyWords := by
unfold Encoding.imageVertices
simpa only [List.map_map, Function.comp_def] using
List.dedup_map_of_injective bodyWords_injective (queries.map body)
theorem imageVertices_bodyBits {Q : Type*} {n m k s d : Nat}
[DecidableEq (Body n m k s d)] (queries : List Q) (body : Q → Body n m k s d) :
Encoding.imageVertices queries (fun q => bodyBits (body q)) =
(Encoding.imageVertices queries body).map bodyBits := by
unfold Encoding.imageVertices
simpa only [List.map_map, Function.comp_def] using
List.dedup_map_of_injective bodyBits_injective (queries.map body)
theorem idxOf_map_injective {A B : Type*} [DecidableEq A] [DecidableEq B]
(f : A → B) (hf : Function.Injective f) (x : A) (xs : List A) :
(xs.map f).idxOf (f x) = xs.idxOf x := by
induction xs with
| nil => rfl
| cons y ys ih =>
by_cases h : y = x
· subst y
simp
· have h' : f y ≠ f x := fun hxy => h (hf hxy)
simp [h, h', ih]
/-- Injective serialization leaves the actual numeric vertex index unchanged,
not just the vertex set or its cardinality. -/
theorem imageIndex_map_val {Q A B : Type*} [DecidableEq A] [DecidableEq B]
(queries : List Q) (body : Q → A) (f : A → B) (hf : Function.Injective f)
(q : Q) (hq : q ∈ queries) :
(Encoding.imageIndex queries (fun q => f (body q)) q hq).val =
(Encoding.imageIndex queries body q hq).val := by
change ((queries.map (fun q => f (body q))).dedup).idxOf (f (body q)) =
((queries.map body).dedup).idxOf (body q)
have hmap : (queries.map (fun q => f (body q))).dedup =
(queries.map body).dedup.map f := by
simpa only [List.map_map, Function.comp_def] using
List.dedup_map_of_injective hf (queries.map body)
rw [hmap]
exact idxOf_map_injective f hf (body q) (queries.map body).dedup
theorem imageIndex_bodyWords_val {Q : Type*} {n m k s d : Nat}
[DecidableEq (Body n m k s d)] (queries : List Q) (body : Q → Body n m k s d)
(q : Q) (hq : q ∈ queries) :
(Encoding.imageIndex queries (fun q => bodyWords (body q)) q hq).val =
(Encoding.imageIndex queries body q hq).val :=
imageIndex_map_val queries body bodyWords bodyWords_injective q hq
theorem imageIndex_bodyBits_val {Q : Type*} {n m k s d : Nat}
[DecidableEq (Body n m k s d)] (queries : List Q) (body : Q → Body n m k s d)
(q : Q) (hq : q ∈ queries) :
(Encoding.imageIndex queries (fun q => bodyBits (body q)) q hq).val =
(Encoding.imageIndex queries body q hq).val :=
imageIndex_map_val queries body bodyBits bodyBits_injective q hq
end MaxCutGames.Reduction.CanonicalEncoding
end OAI
|