openAI-math-dataset / lean /OAI /Computability /MaxCut /Encoding /TableKeysAddressGame.lean
roseking's picture
Add lean source and binary files (part 61)
ea76aac verified
Raw History Blame Contribute Delete
20.6 kB
import Mathlib
import OAI.Computability.MaxCut.Encoding.ActualAdviceUpper
import OAI.Computability.MaxCut.Games.CanonicalAddress
namespace OAI
/-!
Direct addresses for the v2 single-orbit matrix game. There is one canonical
body address space, with no side bit and no extra right-endpoint offset.
Unused addresses are isolated. Runtime construction uses canonical words and
radix arithmetic, not deduplication or inverse vertex enumeration.
-/
namespace MaxCutGames.Decoder.TableKeysAddressGame
open MaxCutGames.Reduction
open ActualSource Foundations.Target
open Integration.VertexEmbedding
abbrev vertexCount (S : Source) (k s d : Nat) : Nat :=
CanonicalAddress.capacity S.«variables» S.occurrences k s d
def vertexAddress (S : Source) (k s d : Nat) (v : TableKeysGame.Vertex S k s d) :
Fin (vertexCount S k s d) := CanonicalAddress.bodyAddress v.val
theorem vertexAddress_injective (S : Source) (k s d : Nat) :
Function.Injective (vertexAddress S k s d) := by
intro v w h
apply Subtype.ext
exact CanonicalAddress.bodyAddress_injective h
/-- Both endpoints use this same routine and this same address block. -/
def queryAddress (S : Source) (k s d : Nat) (q : TableKeysGame.Query S k s d) :
Fin (vertexCount S k s d) :=
CanonicalAddress.bodyAddress (ActualOrbit.body (TableKeysGame.canonical S k s d) q)
@[simp] theorem vertexAddress_query (S : Source) (k s d : Nat)
(q : TableKeysGame.Query S k s d) :
vertexAddress S k s d (TableKeysGame.vertex S k s d q) =
queryAddress S k s d q := rfl
/-- This inverse is a proof adapter only; the output constructor never calls it. -/
def explicitToAddress (S : Source) (k s d : Nat) :
Fin (TableKeysGame.explicitVertexCount S k s d) → Fin (vertexCount S k s d) :=
fun i => vertexAddress S k s d ((TableKeysGame.explicitVertexEncoding S k s d).symm i)
theorem explicitToAddress_injective (S : Source) (k s d : Nat) :
Function.Injective (explicitToAddress S k s d) :=
(vertexAddress_injective S k s d).comp
(TableKeysGame.explicitVertexEncoding S k s d).symm.injective
@[simp] theorem explicitToAddress_apply (S : Source) (k s d : Nat)
(v : TableKeysGame.Vertex S k s d) :
explicitToAddress S k s d (TableKeysGame.explicitVertexEncoding S k s d v) =
vertexAddress S k s d v := by
simp only [explicitToAddress, Equiv.symm_apply_apply]
noncomputable def semanticToAddress (S : Source) (k s d : Nat) :
Fin (TableKeysGame.vertexCount S k s d) → Fin (vertexCount S k s d) :=
fun i => vertexAddress S k s d ((TableKeysGame.vertexEncoding S k s d).symm i)
theorem semanticToAddress_injective (S : Source) (k s d : Nat) :
Function.Injective (semanticToAddress S k s d) :=
(vertexAddress_injective S k s d).comp
(TableKeysGame.vertexEncoding S k s d).symm.injective
@[simp] theorem semanticToAddress_apply (S : Source) (k s d : Nat)
(v : TableKeysGame.Vertex S k s d) :
semanticToAddress S k s d (TableKeysGame.vertexEncoding S k s d v) =
vertexAddress S k s d v := by
simp only [semanticToAddress, Equiv.symm_apply_apply]
def addressEdge (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(ω : TableKeysGame.Outcome S k g) : Constraint (vertexCount S k s d) (2^s) where
source := queryAddress S k s d (TableKeysGame.leftQuery S k g ω)
target := queryAddress S k s d (TableKeysGame.rightQuery S k g ω)
permutation := Encoding.translationTable
(TableKeysGame.offset S k s d (TableKeysGame.leftQuery S k g ω))
(TableKeysGame.offset S k s d (TableKeysGame.rightQuery S k g ω))
theorem addressEdge_eq_embed (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (ω : TableKeysGame.Outcome S k g) :
addressEdge S k g ω = embedConstraint (explicitToAddress S k s d)
(TableKeysGame.explicitEdge S k g ω) := by
simp only [addressEdge, embedConstraint, TableKeysGame.explicitEdge,
explicitToAddress_apply, vertexAddress_query]
theorem addressEdge_eq_semantic_embed (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (ω : TableKeysGame.Outcome S k g) :
addressEdge S k g ω = embedConstraint (semanticToAddress S k s d)
(TableKeysGame.edge S k g ω) := by
simp only [addressEdge, embedConstraint, TableKeysGame.edge,
semanticToAddress_apply, vertexAddress_query]
/-- The correcting function is not evaluated when producing an edge list. -/
def outputInstance (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(en : NoiseEnumeration g) : Instance (2^s) where
vertices := vertexCount S k s d
constraints := (ActualGame.explicitOutcomes S k g en).map (addressEdge S k g)
nonempty h := by
have hempty := List.map_eq_nil_iff.mp h
apply (TableKeysGame.outputInstanceWithEnumeration S k g en).nonempty
change (ActualGame.explicitOutcomes S k g en).map (TableKeysGame.explicitEdge S k g) = []
rw [hempty]
rfl
/-- Every occurrence, its order, and its full permutation table are retained. -/
theorem outputInstance_eq_embed (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g) :
outputInstance S k g en =
embedInstance (TableKeysGame.outputInstanceWithEnumeration S k g en)
(explicitToAddress S k s d) (explicitToAddress_injective S k s d) := by
unfold outputInstance embedInstance TableKeysGame.outputInstanceWithEnumeration
congr 1
simp only [List.map_map, Function.comp_def, ← addressEdge_eq_embed]
@[simp] theorem outputInstance_length (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g) :
(outputInstance S k g en).constraints.length =
Explicit.edgeCount S.occurrences k (s+d) en.indices.length := by
simp only [outputInstance, List.length_map, ActualGame.explicitOutcomes,
ActualEnumeration.length_indexedOutcomes]
theorem outputInstance_count (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g)
(labeling : Fin (vertexCount S k s d) → Fin (2^s)) :
countSatisfied labeling (outputInstance S k g en).constraints =
countSatisfied (labeling ∘ explicitToAddress S k s d)
(TableKeysGame.outputInstanceWithEnumeration S k g en).constraints := by
simpa only [outputInstance, TableKeysGame.outputInstanceWithEnumeration, List.map_map,
Function.comp_def, ← addressEdge_eq_embed] using
count_map (explicitToAddress S k s d)
((ActualGame.explicitOutcomes S k g en).map (TableKeysGame.explicitEdge S k g)) labeling
theorem completeAt_outputInstance_iff_explicit (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
CompleteAt error (outputInstance S k g en) ↔
CompleteAt error (TableKeysGame.outputInstanceWithEnumeration S k g en) := by
rw [outputInstance_eq_embed]
exact completeAt_embed_iff error _ _ _ (by positivity)
theorem soundAt_outputInstance_iff_explicit (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
SoundAt error (outputInstance S k g en) ↔
SoundAt error (TableKeysGame.outputInstanceWithEnumeration S k g en) := by
rw [outputInstance_eq_embed]
exact soundAt_embed_iff error _ _ _ (by positivity)
theorem completeAt_outputInstance_iff (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
CompleteAt error (outputInstance S k g en) ↔
CompleteAt error (TableKeysGame.outputInstance S k g) :=
(completeAt_outputInstance_iff_explicit error S k g en).trans
(TableKeysGame.completeAt_outputInstanceWithEnumeration_iff error S k g en)
theorem soundAt_outputInstance_iff (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
SoundAt error (outputInstance S k g en) ↔
SoundAt error (TableKeysGame.outputInstance S k g) :=
(soundAt_outputInstance_iff_explicit error S k g en).trans
(TableKeysGame.soundAt_outputInstanceWithEnumeration_iff error S k g en)
theorem outputInstance_translations (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g) :
Integration.TranslationTarget.IsTranslationInstance (Encoding.alphabetEquiv s).symm
(outputInstance S k g en) := by
intro constraint hconstraint
obtain ⟨ω, _, rfl⟩ := List.mem_map.mp hconstraint
refine ⟨TableKeysGame.offset S k s d (TableKeysGame.leftQuery S k g ω) +
TableKeysGame.offset S k s d (TableKeysGame.rightQuery S k g ω), ?_⟩
intro label
have h := Encoding.translationTable_images
(TableKeysGame.offset S k s d (TableKeysGame.leftQuery S k g ω))
(TableKeysGame.offset S k s d (TableKeysGame.rightQuery S k g ω))
((Encoding.alphabetEquiv s).symm label)
simpa only [addressEdge, Encoding.alphabetEquiv_apply_symm_apply,
Encoding.alphabetEquiv_symm_apply_apply, add_assoc] using
congrArg (Encoding.alphabetEquiv s).symm h
/-- Fixed finite noise data suffice for executable output. -/
def tableOutput (S : Source) (k : Nat) {s d : Nat} (T : Integration.NoiseTables.Table s d) :
Instance (2^s) :=
outputInstance S k (Integration.TableReduction.tableSkeleton T)
(Integration.TableReduction.tableEnumeration T Prod.fst (fun _ _ => rfl))
/-- The nonlinear correctness witness is erased from the output program. -/
theorem tableOutput_eq_with_witness (S : Source) (k : Nat) {s d : Nat}
(T : Integration.NoiseTables.Table s d) (f : Ambient s d → Alphabet s)
(hf : ∀ x c, f (x + (c, 0)) = f x + c) :
tableOutput S k T = outputInstance S k (T.gadget f hf)
(Integration.TableReduction.tableEnumeration T f hf) := by
rfl
theorem completeAt_tableOutput_iff (error : RationalError) (S : Source) (k : Nat)
{s d : Nat} (T : Integration.NoiseTables.Table s d)
(f : Ambient s d → Alphabet s) (hf : ∀ x c, f (x + (c, 0)) = f x + c) :
CompleteAt error (tableOutput S k T) ↔
CompleteAt error (TableKeysGame.outputInstance S k (T.gadget f hf)) := by
rw [tableOutput_eq_with_witness S k T f hf]
exact completeAt_outputInstance_iff error S k _ _
theorem soundAt_tableOutput_iff (error : RationalError) (S : Source) (k : Nat)
{s d : Nat} (T : Integration.NoiseTables.Table s d)
(f : Ambient s d → Alphabet s) (hf : ∀ x c, f (x + (c, 0)) = f x + c) :
SoundAt error (tableOutput S k T) ↔
SoundAt error (TableKeysGame.outputInstance S k (T.gadget f hf)) := by
rw [tableOutput_eq_with_witness S k T f hf]
exact soundAt_outputInstance_iff error S k _ _
theorem tableOutput_translations (S : Source) (k : Nat) {s d : Nat}
(T : Integration.NoiseTables.Table s d) :
Integration.TranslationTarget.IsTranslationInstance (Encoding.alphabetEquiv s).symm
(tableOutput S k T) := outputInstance_translations S k _ _
/-- Exact polynomial capacity, without the legacy two-side factor. -/
theorem vertexCount_eq_polynomial (S : Source) (k s d : Nat) :
vertexCount S k s d = (CanonicalAddress.capacityPolynomial k s d).eval
(S.«variables» + S.occurrences) := by
rw [CanonicalAddress.capacityPolynomial_eval]
end MaxCutGames.Decoder.TableKeysAddressGame
/-! Transport the matrix-test bound to the actual direct-address edge list.
Every address labeling restricts to a semantic orbit labeling, with exactly
the same satisfied fraction and the same occurrence multiplicities. -/
namespace MaxCutGames.Decoder.MatrixGap
open MaxCutGames.Integration.BinaryLinear
open MaxCutGames.Reduction MaxCutGames.Foundations.Target
open MaxCutGames.Integration
open ActualSource
noncomputable section
theorem address_rate_eq_semantic_acceptance (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g)
(labeling : Fin (TableKeysAddressGame.vertexCount S k s d) → Fin (2 ^ s)) :
GapSemantics.satisfactionRate (TableKeysAddressGame.outputInstance S k g en) labeling =
TableKeysGame.acceptanceProbability S k g
((labeling ∘ TableKeysAddressGame.explicitToAddress S k s d) ∘
TableKeysGame.semanticToExplicitVertices S k s d) := by
calc
_ = GapSemantics.satisfactionRate
(TableKeysGame.outputInstanceWithEnumeration S k g en)
(labeling ∘ TableKeysAddressGame.explicitToAddress S k s d) := by
unfold GapSemantics.satisfactionRate
exact congrArg₂ (fun a b : Nat => (a : ℚ) / b)
(TableKeysAddressGame.outputInstance_count S k g en labeling)
(by simp only [TableKeysAddressGame.outputInstance,
TableKeysGame.outputInstanceWithEnumeration, List.length_map])
_ = GapSemantics.satisfactionRate (TableKeysGame.outputInstance S k g)
((labeling ∘ TableKeysAddressGame.explicitToAddress S k s d) ∘
TableKeysGame.semanticToExplicitVertices S k s d) :=
InstanceEquivalences.satisfactionRate_eq_of_rename_perm
(TableKeysGame.outputInstance S k g)
(TableKeysGame.outputInstanceWithEnumeration S k g en)
(TableKeysGame.semanticToExplicitVertices S k s d)
(TableKeysGame.explicitConstraints_perm_renamed S k g en) _
_ = _ := (TableKeysGame.acceptanceProbability_eq_count S k g _).symm
/-- Soundness is measured on the generated direct-address instance. Unused
addresses and reindexing introduce no additional labeling advantage. -/
theorem address_value_le_of_semantic_acceptance (S : Source) (k : Nat) {s d : Nat}
(T : NoiseTables.Table s d) (f : Ambient s d → Alphabet s)
(hf : ∀ x c, f (x + (c, 0)) = f x + c)
(h : ∀ labeling : Fin (TableKeysGame.vertexCount S k s d) → Fin (2 ^ s),
TableKeysGame.acceptanceProbability S k (T.gadget f hf) labeling ≤ (99 : ℚ) / 100) :
InstanceValue.value (TableKeysAddressGame.tableOutput S k T) ≤ (99 : ℝ) / 100 := by
rw [TableKeysAddressGame.tableOutput_eq_with_witness S k T f hf]
apply (InstanceValue.forall_rate_le_iff _ (by positivity) _).mp
intro labeling
change (Fin (TableKeysAddressGame.vertexCount S k s d) → Fin (2 ^ s)) at labeling
have hrate : GapSemantics.satisfactionRate
(TableKeysAddressGame.outputInstance S k (T.gadget f hf)
(TableReduction.tableEnumeration T f hf)) labeling ≤ (99 : ℚ) / 100 := by
rw [address_rate_eq_semantic_acceptance S k (T.gadget f hf)
(TableReduction.tableEnumeration T f hf) labeling]
exact h _
have hreal := (Rat.cast_le (K := ℝ)
(p := GapSemantics.satisfactionRate
(TableKeysAddressGame.outputInstance S k (T.gadget f hf)
(TableReduction.tableEnumeration T f hf)) labeling)
(q := (99 : ℚ) / 100)).2 hrate
simpa [GapSemantics.satisfactionRate] using hreal
end
end MaxCutGames.Decoder.MatrixGap
/-!
Completeness on the actual single-orbit address output. An honest semantic
labeling is extended over unused addresses, with its satisfied fraction
unchanged. The two rational error bounds need no packaged error parameter.
-/
namespace MaxCutGames.Decoder.MatrixGap
open MaxCutGames.Integration.BinaryLinear
open MaxCutGames.Reduction MaxCutGames.Foundations.Target
open MaxCutGames.Integration
open ActualSource
noncomputable section
/-- Every semantic labeling extends to a labeling of the padded address space.
The generated edge list retains its exact acceptance fraction. -/
theorem semantic_acceptance_le_address_value (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g)
(labeling : Fin (TableKeysGame.vertexCount S k s d) → Fin (2 ^ s)) :
(TableKeysGame.acceptanceProbability S k g labeling : ℝ) ≤
InstanceValue.value (TableKeysAddressGame.outputInstance S k g en) := by
let e := TableKeysGame.semanticToExplicitVertices S k s d
let addressLabel := VertexEmbedding.extendLabeling
(TableKeysAddressGame.explicitToAddress S k s d) (labeling ∘ e.symm)
(⟨0, by positivity⟩ : Fin (2 ^ s))
have hrestrict : addressLabel ∘ TableKeysAddressGame.explicitToAddress S k s d =
labeling ∘ e.symm :=
VertexEmbedding.extendLabeling_comp _
(TableKeysAddressGame.explicitToAddress_injective S k s d) _ _
have hpullback : (addressLabel ∘ TableKeysAddressGame.explicitToAddress S k s d) ∘
TableKeysGame.semanticToExplicitVertices S k s d = labeling := by
rw [hrestrict]
funext v
exact congrArg labeling (e.symm_apply_apply v)
have hrate := address_rate_eq_semantic_acceptance S k g en addressLabel
rw [hpullback] at hrate
have hvalue := InstanceValue.satisfactionRate_le_value
(TableKeysAddressGame.outputInstance S k g en) addressLabel
rw [hrate] at hvalue
exact hvalue
/-- The exact near-assignment loss and fair-bit factor one half, measured on
the generated address instance and then cast to its real optimum value. -/
theorem address_value_ge_of_near_assignment (S : Source) (k : Nat) {s d : Nat}
(T : NoiseTables.Table s d) (f : Ambient s d → Alphabet s)
(hf : ∀ x c, f (x + (c, 0)) = f x + c)
(assignment : Fin S.«variables» → Bool) (ξ p : ℚ)
(hfailure : S.failure assignment ≤ ξ)
(hstable : (T.gadget f hf).stabilityError ≤ p) :
(1 : ℝ) - ((k : ℝ) * (ξ : ℝ) + (p : ℝ) / 2) ≤
InstanceValue.value (TableKeysAddressGame.tableOutput S k T) := by
let g := T.gadget f hf
have hrat := TableKeysCompleteness.honest_acceptance_of_bounds S k g assignment
ξ p ((k : ℚ) * ξ + p / 2) hfailure hstable (le_refl _)
have hreal : (1 : ℝ) - ((k : ℝ) * (ξ : ℝ) + (p : ℝ) / 2) ≤
(TableKeysGame.acceptanceProbability S k g
(TableKeysCompleteness.honestLabeling S k g assignment) : ℝ) := by
have h := (Rat.cast_le (K := ℝ)).2 hrat
simpa only [Rat.cast_sub, Rat.cast_one, Rat.cast_add, Rat.cast_mul,
Rat.cast_natCast, Rat.cast_div, Rat.cast_ofNat] using h
rw [TableKeysAddressGame.tableOutput_eq_with_witness S k T f hf]
exact hreal.trans (semantic_acceptance_le_address_value S k g
(TableReduction.tableEnumeration T f hf)
(TableKeysCompleteness.honestLabeling S k g assignment))
end
end MaxCutGames.Decoder.MatrixGap
namespace MaxCutGames.Decoder.MatrixGap
open MaxCutGames.Integration.BinaryLinear
open MaxCutGames.Reduction MaxCutGames.Foundations.Target
open MaxCutGames.Foundations.Games
open MaxCutGames.Integration
open ActualSource
noncomputable section
attribute [local instance] Classical.propDecidable
/-- Fixed matrix-test parameters, before the separate bipartite subdivision
and repetition. Existence is proved by the v2 spectral/decoding argument. -/
structure Parameters (p : ℚ) where
k : Nat
s : Nat
d : Nat
k_pos : 1 ≤ k
s_pos : 1 ≤ s
T : NoiseTables.Table s d
f : Ambient s d → Alphabet s
equivariant : ∀ x c, f (x + (c, 0)) = f x + c
stability : (T.gadget f equivariant).stabilityError ≤ p
sound : ∀ S : Source, S.DistinctNames →
Clean.IncidenceGap.parityValue (ActualAdviceUpper.sourceIncidence S)
(FiniteDistribution.uniform (Fin S.occurrences)) ≤ (4 : ℝ) / 5 →
InstanceValue.value (TableKeysAddressGame.tableOutput S k T) ≤ (99 : ℝ) / 100
/-- The rate of any semantic vertex labeling is realized on the direct
address output. Isolated unused addresses receive an arbitrary valid label. -/
theorem semantic_rate_le_address_value (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g)
(labeling : Fin (TableKeysGame.vertexCount S k s d) → Fin (2 ^ s)) :
(GapSemantics.satisfactionRate (TableKeysGame.outputInstance S k g) labeling : ℝ) ≤
InstanceValue.value (TableKeysAddressGame.outputInstance S k g en) := by
have h := semantic_acceptance_le_address_value S k g en labeling
rw [TableKeysGame.acceptanceProbability_eq_count] at h
exact h
namespace Parameters
variable {p : ℚ}
/-- The actual output constructor depends only on finite tables, not on the
correcting map or its equivariance proof. -/
def output (P : Parameters p) (S : Source) : Instance (2 ^ P.s) :=
TableKeysAddressGame.tableOutput S P.k P.T
theorem completeness (P : Parameters p) (S : Source)
(assignment : Fin S.«variables» → Bool) (ξ : ℚ)
(hfailure : S.failure assignment ≤ ξ) :
(1 : ℝ) - ((P.k : ℝ) * (ξ : ℝ) + (p : ℝ) / 2) ≤
InstanceValue.value (TableKeysAddressGame.tableOutput S P.k P.T) :=
address_value_ge_of_near_assignment S P.k P.T P.f P.equivariant assignment
ξ p hfailure P.stability
theorem output_translations (P : Parameters p) (S : Source) :
TranslationTarget.IsTranslationInstance (Encoding.alphabetEquiv P.s).symm
(P.output S) :=
TableKeysAddressGame.tableOutput_translations S P.k P.T
end Parameters
end
end MaxCutGames.Decoder.MatrixGap
end OAI