roseking's picture
Add lean source and binary files (part 63)
760f90e verified
Raw History Blame Contribute Delete
12 kB
import OAI.Computability.UniqueGames.Reduction.ActualGame
namespace OAI
section
namespace UniqueGamesTheorem.Decoder.TableKeysGame
open UniqueGamesTheorem.Integration.BinaryLinear UniqueGamesTheorem.Reduction
open ActualSource Foundations.Target
open scoped BigOperators
abbrev Question (S : Source) (k : Nat) := ActualGame.Question S k
abbrev Map (k s d : Nat) := ActualGame.Map k s d
abbrev Dual (k : Nat) := ActualGame.Dual k
abbrev Query (S : Source) (k s d : Nat) := ActualGame.Query S k s d
abbrev canonical (S : Source) (k s d : Nat) := ActualGame.canonical S k s d
/-- One realized key orbit, with no prover-side copy. -/
abbrev Vertex (S : Source) (k s d : Nat) := ActualGame.Vertex S k s d
abbrev vertex (S : Source) (k s d : Nat) := ActualGame.vertex S k s d
abbrev offset (S : Source) (k s d : Nat) := ActualGame.offset S k s d
abbrev shiftQuery (S : Source) (k s d : Nat) := ActualGame.shiftQuery S k s d
noncomputable def vertexCount (S : Source) (k s d : Nat) : Nat :=
Fintype.card (Vertex S k s d)
noncomputable def vertexEncoding (S : Source) (k s d : Nat) :
Vertex S k s d ≃ Fin (vertexCount S k s d) := Fintype.equivFin _
/-- All four sampling choices remain separate occurrence indices. -/
abbrev Outcome (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) :=
Query S k s d × g.NoiseIndex × Dual k
abbrev leftQuery (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) :=
ActualGame.leftQuery S k g
abbrev rightQuery (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) :=
ActualGame.rightQuery S k g
noncomputable def edge (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(ω : Outcome S k g) : Constraint (vertexCount S k s d) (2^s) where
source := vertexEncoding S k s d (vertex S k s d (leftQuery S k g ω))
target := vertexEncoding S k s d (vertex S k s d (rightQuery S k g ω))
permutation := Encoding.translationTable
(offset S k s d (leftQuery S k g ω)) (offset S k s d (rightQuery S k g ω))
noncomputable def outcomes (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) :=
ActualGame.outcomes S k g
noncomputable def outputInstance (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) :
Instance (2^s) where
vertices := vertexCount S k s d
constraints := (outcomes S k g).map (edge S k g)
nonempty := by
intro h
let ω : Outcome S k g := Classical.choice inferInstance
have hm : edge S k g ω ∈ (outcomes S k g).map (edge S k g) :=
List.mem_map.mpr ⟨ω, ActualGame.mem_outcomes S k g ω, rfl⟩
rw [h] at hm
exact List.not_mem_nil hm
@[simp] theorem outputInstance_constraints_length (S : Source) (k : Nat)
{s d : Nat} (g : SplitGadget s d) :
(outputInstance S k g).constraints.length = Fintype.card (Outcome S k g) := by
simp [outputInstance, outcomes]
noncomputable def vertexLabel (S : Source) (k s d : Nat)
(labeling : Fin (vertexCount S k s d) → Fin (2^s)) :
Vertex S k s d → Alphabet s := fun v =>
(Encoding.alphabetEquiv s).symm (labeling (vertexEncoding S k s d v))
noncomputable def labelingOf (S : Source) (k s d : Nat)
(labels : Vertex S k s d → Alphabet s) :
Fin (vertexCount S k s d) → Fin (2^s) := fun i =>
Encoding.alphabetEquiv s (labels ((vertexEncoding S k s d).symm i))
@[simp] theorem vertexLabel_labelingOf (S : Source) (k s d : Nat)
(labels : Vertex S k s d → Alphabet s) :
vertexLabel S k s d (labelingOf S k s d labels) = labels := by
funext v
simp [vertexLabel, labelingOf]
/-- Restore the removed alphabet component of the affine intercept. -/
noncomputable def unfolded (S : Source) (k s d : Nat)
(labeling : Fin (vertexCount S k s d) → Fin (2^s))
(q : Query S k s d) : Alphabet s :=
ActualOrbit.unfold (canonical S k s d) (vertexLabel S k s d labeling) q
theorem unfolded_equivariant (S : Source) (k s d : Nat)
(labeling : Fin (vertexCount S k s d) → Fin (2^s))
(q : Query S k s d) (c : Alphabet s) :
unfolded S k s d labeling (shiftQuery S k s d c q) =
unfolded S k s d labeling q + c := by
change vertexLabel S k s d labeling
(ActualGame.vertex S k s d (ActualGame.shiftQuery S k s d c q)) +
ActualGame.offset S k s d (ActualGame.shiftQuery S k s d c q) = _
rw [ActualGame.vertex_shiftQuery, ActualGame.offset_shiftQuery]
exact (add_assoc _ _ _).symm
theorem edge_satisfied_iff (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(labeling : Fin (vertexCount S k s d) → Fin (2^s)) (ω : Outcome S k g) :
(edge S k g ω).satisfied labeling = true ↔
unfolded S k s d labeling (leftQuery S k g ω) =
unfolded S k s d labeling (rightQuery S k g ω) := by
rw [Constraint.satisfied, decide_eq_true_eq]
have h := Encoding.translationTable_satisfied_iff
(offset S k s d (leftQuery S k g ω)) (offset S k s d (rightQuery S k g ω))
(vertexLabel S k s d labeling (vertex S k s d (leftQuery S k g ω)))
(vertexLabel S k s d labeling (vertex S k s d (rightQuery S k g ω)))
simp only [vertexLabel, Encoding.alphabetEquiv_apply_symm_apply] at h
exact h.trans (ActualOrbit.constraint_iff_unfolded (canonical S k s d)
(vertexLabel S k s d labeling) (vertexLabel S k s d labeling) _ _)
noncomputable def acceptanceProbability (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (labeling : Fin (vertexCount S k s d) → Fin (2^s)) : ℚ :=
𝔼 ω : Outcome S k g, if (edge S k g ω).satisfied labeling then (1 : ℚ) else 0
theorem acceptanceProbability_eq_test (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 =
𝔼 ω : Outcome S k g,
if unfolded S k s d labeling (leftQuery S k g ω) =
unfolded S k s d labeling (rightQuery S k g ω)
then (1 : ℚ) else 0 := by
unfold acceptanceProbability
apply Finset.expect_congr rfl
intro ω _
simp only [edge_satisfied_iff]
private theorem countSatisfied_map {n q : Nat} {I : Type*}
(labeling : Fin n → Fin q) (edges : I → Constraint n q) (xs : List I) :
countSatisfied labeling (xs.map edges) =
(xs.map (fun x => if (edges x).satisfied labeling then 1 else 0)).sum := by
induction xs with
| nil => rfl
| cons x xs ih => simp only [List.map_cons, countSatisfied, List.sum_cons, ih]
theorem countSatisfied_eq_sum (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (labeling : Fin (vertexCount S k s d) → Fin (2^s)) :
countSatisfied labeling (outputInstance S k g).constraints =
∑ ω : Outcome S k g, if (edge S k g ω).satisfied labeling then 1 else 0 := by
change countSatisfied labeling ((outcomes S k g).map (edge S k g)) = _
rw [countSatisfied_map]
exact Finset.sum_map_toList _ _
/-- The test probability is the satisfied fraction of the actual occurrence list. -/
theorem acceptanceProbability_eq_count (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 =
(countSatisfied labeling (outputInstance S k g).constraints : ℚ) /
(outputInstance S k g).constraints.length := by
rw [acceptanceProbability, Fintype.expect_eq_sum_div_card,
outputInstance_constraints_length, countSatisfied_eq_sum]
congr 1
simp
/-- Exhaustive numbering of the same single-orbit vertex type. -/
def explicitVertexCount (S : Source) (k s d : Nat) : Nat :=
(ActualGame.explicitBodies S k s d).length
def explicitVertexEncoding (S : Source) (k s d : Nat) :
Vertex S k s d ≃ Fin (explicitVertexCount S k s d) := by
letI := ActualGame.orbitBodyDecidableEq S k s d
exact ActualOrbit.explicitVertexEquiv (canonical S k s d)
(ActualEnumeration.queries S.occurrences k s d) ActualEnumeration.mem_queries
noncomputable def semanticToExplicitVertices (S : Source) (k s d : Nat) :
Fin (vertexCount S k s d) ≃ Fin (explicitVertexCount S k s d) :=
(vertexEncoding S k s d).symm.trans (explicitVertexEncoding S k s d)
@[simp] theorem semanticToExplicitVertices_apply (S : Source) (k s d : Nat)
(v : Vertex S k s d) :
semanticToExplicitVertices S k s d (vertexEncoding S k s d v) =
explicitVertexEncoding S k s d v := by
simp [semanticToExplicitVertices]
theorem explicitVertexCount_eq (S : Source) (k s d : Nat) :
explicitVertexCount S k s d = vertexCount S k s d := by
simpa using (Fintype.card_congr (semanticToExplicitVertices S k s d)).symm
def explicitEdge (S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d)
(ω : Outcome S k g) : Constraint (explicitVertexCount S k s d) (2^s) where
source := explicitVertexEncoding S k s d (vertex S k s d (leftQuery S k g ω))
target := explicitVertexEncoding S k s d (vertex S k s d (rightQuery S k g ω))
permutation := Encoding.translationTable
(offset S k s d (leftQuery S k g ω)) (offset S k s d (rightQuery S k g ω))
theorem explicitEdge_eq_rename (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (ω : Outcome S k g) :
explicitEdge S k g ω = Integration.InstanceEquivalences.renameConstraint
(semanticToExplicitVertices S k s d) (edge S k g ω) := by
simp only [explicitEdge, Integration.InstanceEquivalences.renameConstraint, edge,
semanticToExplicitVertices_apply]
/-- Executable finite output, still allowing loops and parallel occurrences. -/
def outputInstanceWithEnumeration (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g) : Instance (2^s) where
vertices := explicitVertexCount S k s d
constraints := (ActualGame.explicitOutcomes S k g en).map (explicitEdge S k g)
nonempty := by
intro h
let ω : Outcome S k g := Classical.choice inferInstance
have hm : explicitEdge S k g ω ∈
(ActualGame.explicitOutcomes S k g en).map (explicitEdge S k g) :=
List.mem_map.mpr ⟨ω, ActualGame.mem_explicitOutcomes S k g en ω, rfl⟩
rw [h] at hm
exact List.not_mem_nil hm
@[simp] theorem outputInstanceWithEnumeration_length (S : Source) (k : Nat)
{s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
(outputInstanceWithEnumeration S k g en).constraints.length =
Explicit.edgeCount S.occurrences k (s+d) en.indices.length := by
simp only [outputInstanceWithEnumeration, List.length_map,
ActualGame.explicitOutcomes, ActualEnumeration.length_indexedOutcomes]
theorem explicitConstraints_perm_renamed (S : Source) (k : Nat) {s d : Nat}
(g : SplitGadget s d) (en : NoiseEnumeration g) :
(outputInstanceWithEnumeration S k g en).constraints.Perm
((outputInstance S k g).constraints.map
(Integration.InstanceEquivalences.renameConstraint (semanticToExplicitVertices S k s d))) := by
simpa only [outputInstanceWithEnumeration, outputInstance, List.map_map,
Function.comp_def, ← explicitEdge_eq_rename, outcomes] using
(ActualGame.explicitOutcomes_perm_outcomes S k g en).map (explicitEdge S k g)
theorem completeAt_outputInstanceWithEnumeration_iff (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
CompleteAt error (outputInstanceWithEnumeration S k g en) ↔
CompleteAt error (outputInstance S k g) :=
Integration.InstanceEquivalences.completeAt_iff_of_rename_perm error
(outputInstance S k g) (outputInstanceWithEnumeration S k g en)
(semanticToExplicitVertices S k s d) (explicitConstraints_perm_renamed S k g en)
theorem soundAt_outputInstanceWithEnumeration_iff (error : RationalError)
(S : Source) (k : Nat) {s d : Nat} (g : SplitGadget s d) (en : NoiseEnumeration g) :
SoundAt error (outputInstanceWithEnumeration S k g en) ↔
SoundAt error (outputInstance S k g) :=
Integration.InstanceEquivalences.soundAt_iff_of_rename_perm error
(outputInstance S k g) (outputInstanceWithEnumeration S k g en)
(semanticToExplicitVertices S k s d) (explicitConstraints_perm_renamed S k g en)
end UniqueGamesTheorem.Decoder.TableKeysGame
end
end OAI