Download data/lean/OAI/Computability/MaxCut/Encoding/AdviceFibers.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Encoding/AdviceFibers.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MaxCut/Encoding/AdviceFibers.lean
-
curl -L -o AdviceFibers.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Encoding/AdviceFibers.lean
12.2 kB
| import Mathlib | |
| import OAI.Computability.MaxCut.Encoding.Encoding | |
| namespace OAI | |
| /-! | |
| # Exact visible row advice and private matrix coordinates | |
| Every nonempty fiber of `M β¦ A β M` is an affine copy of | |
| `Hom(E, ker A)`, whether or not `A` is surjective. Choosing one base matrix | |
| for each attainable row gives a product decomposition of the complete matrix | |
| space. Uniform sampling therefore makes visible row advice and the hidden | |
| kernel-valued matrix independent. | |
| -/ | |
| noncomputable section | |
| open scoped BigOperators | |
| open MaxCutGames.Integration.BinaryLinear | |
| namespace MaxCutGames.Decoder.AdviceFibers | |
| variable {E K R : Type*} | |
| [AddCommGroup E] [Module F2 E] | |
| [AddCommGroup K] [Module F2 K] | |
| [AddCommGroup R] [Module F2 R] | |
| /-- Actual matrices with the specified observed row advice. -/ | |
| abbrev RowFiber (A : K ββ[F2] R) (S : E ββ[F2] R) := | |
| {M : E ββ[F2] K // A.comp M = S} | |
| /-- Hidden coordinates relative to one base matrix in the same row fiber. -/ | |
| def kernelDifference (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) (M : RowFiber A S) : | |
| E ββ[F2] A.ker := | |
| (M.val - Mβ).codRestrict A.ker (by | |
| intro x | |
| change A (M.val x - Mβ x) = 0 | |
| rw [map_sub] | |
| have hM := LinearMap.congr_fun M.property x | |
| have hbase := LinearMap.congr_fun hβ x | |
| change A (M.val x) = S x at hM | |
| change A (Mβ x) = S x at hbase | |
| rw [hM, hbase, sub_self]) | |
| @[simp] theorem kernelDifference_apply (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) (M : RowFiber A S) (x : E) : | |
| (kernelDifference A S Mβ hβ M x : K) = M.val x - Mβ x := rfl | |
| /-- Reassemble an actual matrix from its fixed visible base and private part. -/ | |
| def assemble (A : K ββ[F2] R) (Mβ : E ββ[F2] K) | |
| (N : E ββ[F2] A.ker) : E ββ[F2] K := | |
| Mβ + A.ker.subtype.comp N | |
| @[simp] theorem assemble_apply (A : K ββ[F2] R) (Mβ : E ββ[F2] K) | |
| (N : E ββ[F2] A.ker) (x : E) : | |
| assemble A Mβ N x = Mβ x + (N x : K) := rfl | |
| /-- Observed advice is completely unchanged by the private coordinates. -/ | |
| theorem observed_assemble (A : K ββ[F2] R) (Mβ : E ββ[F2] K) | |
| (N : E ββ[F2] A.ker) : A.comp (assemble A Mβ N) = A.comp Mβ := by | |
| ext x | |
| have hN : A (N x : K) = 0 := (N x).property | |
| simp only [LinearMap.comp_apply, assemble_apply, map_add, hN, add_zero] | |
| /-- The exact row-fiber bijection; no rank or surjectivity premise is needed. -/ | |
| def rowFiberEquiv (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) : | |
| (E ββ[F2] A.ker) β RowFiber A S where | |
| toFun N := β¨assemble A Mβ N, (observed_assemble A Mβ N).trans hββ© | |
| invFun := kernelDifference A S Mβ hβ | |
| left_inv N := by | |
| apply LinearMap.ext | |
| intro x | |
| apply Subtype.ext | |
| change Mβ x + (N x : K) - Mβ x = (N x : K) | |
| exact add_sub_cancel_left _ _ | |
| right_inv M := by | |
| apply Subtype.ext | |
| ext x | |
| change Mβ x + (M.val x - Mβ x) = M.val x | |
| simpa only [β add_sub_assoc] using add_sub_cancel_left (Mβ x) (M.val x) | |
| @[simp] theorem rowFiberEquiv_coe (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) (N : E ββ[F2] A.ker) : | |
| (rowFiberEquiv A S Mβ hβ N).val = assemble A Mβ N := rfl | |
| @[simp] theorem rowFiberEquiv_symm (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) (M : RowFiber A S) : | |
| (rowFiberEquiv A S Mβ hβ).symm M = kernelDifference A S Mβ hβ M := rfl | |
| /-- Affine target intercepts are retained in the private coordinates. -/ | |
| theorem assemble_affine_target (A : K ββ[F2] R) (Mβ : E ββ[F2] K) | |
| (N : E ββ[F2] A.ker) (z : E) (u : K) : | |
| assemble A Mβ N z + u = (N z : K) + (Mβ z + u) := by | |
| rw [assemble_apply] | |
| ac_rfl | |
| section UniformFiber | |
| variable (A : K ββ[F2] R) (S : E ββ[F2] R) | |
| [Fintype (E ββ[F2] K)] [Fintype (E ββ[F2] A.ker)] | |
| omit [Fintype (E ββ[F2] K)] in | |
| theorem rowFiber_card (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) : | |
| Nat.card (RowFiber A S) = Fintype.card (E ββ[F2] A.ker) := by | |
| rw [Nat.card_congr (rowFiberEquiv A S Mβ hβ).symm, Nat.card_eq_fintype_card] | |
| omit [Fintype (E ββ[F2] K)] in | |
| /-- Uniform private matrices push forward to uniform matrices in the fiber. -/ | |
| theorem rowFiber_expect (Mβ : E ββ[F2] K) (hβ : A.comp Mβ = S) | |
| [Fintype (RowFiber A S)] (f : (E ββ[F2] K) β β) : | |
| (πΌ M : RowFiber A S, f M.val) = | |
| πΌ N : E ββ[F2] A.ker, f (assemble A Mβ N) := by | |
| exact (Fintype.expect_equiv (rowFiberEquiv A S Mβ hβ) | |
| (fun N => f (assemble A Mβ N)) (fun M => f M.val) (fun _ => rfl)).symm | |
| end UniformFiber | |
| /-- Only attainable rows are observation values. -/ | |
| abbrev ObservedRow (A : K ββ[F2] R) := | |
| {S : E ββ[F2] R // β M : E ββ[F2] K, A.comp M = S} | |
| def observe (A : K ββ[F2] R) (M : E ββ[F2] K) : ObservedRow (E := E) A := | |
| β¨A.comp M, M, rflβ© | |
| /-- A canonical base depends only on observed advice, never on the hidden matrix. -/ | |
| def observedBase (A : K ββ[F2] R) (S : ObservedRow (E := E) A) : E ββ[F2] K := | |
| Classical.choose S.property | |
| theorem observedBase_property (A : K ββ[F2] R) (S : ObservedRow (E := E) A) : | |
| A.comp (observedBase A S) = S.val := Classical.choose_spec S.property | |
| def hiddenCoordinate (A : K ββ[F2] R) (M : E ββ[F2] K) : | |
| E ββ[F2] A.ker := | |
| (rowFiberEquiv A (observe A M).val (observedBase A (observe A M)) | |
| (observedBase_property A (observe A M))).symm β¨M, rflβ© | |
| theorem observe_assemble_base (A : K ββ[F2] R) (S : ObservedRow (E := E) A) | |
| (N : E ββ[F2] A.ker) : observe A (assemble A (observedBase A S) N) = S := by | |
| apply Subtype.ext | |
| exact (observed_assemble A (observedBase A S) N).trans (observedBase_property A S) | |
| /-- Full matrix space is a product of attainable visible rows and private | |
| kernel-valued maps. A section of `A` is not required. -/ | |
| def observationEquiv (A : K ββ[F2] R) : | |
| (E ββ[F2] K) β ObservedRow (E := E) A Γ (E ββ[F2] A.ker) where | |
| toFun M := (observe A M, hiddenCoordinate A M) | |
| invFun p := assemble A (observedBase A p.1) p.2 | |
| left_inv M := by | |
| exact congrArg Subtype.val | |
| ((rowFiberEquiv A (observe A M).val (observedBase A (observe A M)) | |
| (observedBase_property A (observe A M))).apply_symm_apply β¨M, rflβ©) | |
| right_inv p := by | |
| apply Prod.ext | |
| Β· exact observe_assemble_base A p.1 p.2 | |
| Β· apply LinearMap.ext | |
| intro x | |
| apply Subtype.ext | |
| change assemble A (observedBase A p.1) p.2 x - | |
| observedBase A (observe A (assemble A (observedBase A p.1) p.2)) x = | |
| (p.2 x : K) | |
| rw [observe_assemble_base, assemble_apply] | |
| exact add_sub_cancel_left _ _ | |
| @[simp] theorem observationEquiv_apply (A : K ββ[F2] R) (M : E ββ[F2] K) : | |
| observationEquiv A M = (observe A M, hiddenCoordinate A M) := rfl | |
| variable (A : K ββ[F2] R) | |
| [Fintype (E ββ[F2] K)] [Fintype (E ββ[F2] A.ker)] [Fintype (ObservedRow (E := E) A)] | |
| /-- The joint law is exactly the uniform product law. -/ | |
| theorem observation_expect (f : ObservedRow (E := E) A β (E ββ[F2] A.ker) β β) : | |
| (πΌ M : E ββ[F2] K, f (observe A M) (hiddenCoordinate A M)) = | |
| πΌ S : ObservedRow (E := E) A, πΌ N : E ββ[F2] A.ker, f S N := by | |
| rw [Fintype.expect_equiv (observationEquiv A) | |
| (fun M => f (observe A M) (hiddenCoordinate A M)) | |
| (fun p => f p.1 p.2) (fun _ => rfl)] | |
| rw [β Finset.univ_product_univ, Finset.expect_product] | |
| /-- Exact factorization of every product of visible and private observables. -/ | |
| theorem observed_hidden_independent (f : ObservedRow (E := E) A β β) | |
| (g : (E ββ[F2] A.ker) β β) : | |
| (πΌ M : E ββ[F2] K, f (observe A M) * g (hiddenCoordinate A M)) = | |
| (πΌ S : ObservedRow (E := E) A, f S) * (πΌ N : E ββ[F2] A.ker, g N) := by | |
| rw [observation_expect A (fun S N => f S * g N)] | |
| simp_rw [β Finset.mul_expect] | |
| exact (Finset.expect_mul _ _ _).symm | |
| end MaxCutGames.Decoder.AdviceFibers | |
| end | |
| /-! The finite set of realizable orbit records. Vertices are the image of the | |
| actual canonical-data map, so equal retained data from different questions | |
| become one vertex. The two sides remain distinct. -/ | |
| namespace MaxCutGames.Reduction.ActualOrbit | |
| open MaxCutGames.Integration.BinaryLinear | |
| universe u v | |
| variable {Q : Type u} {T : Type v} {s d : Nat} | |
| abbrev Ambient (s d : Nat) := Vector s Γ Vector d | |
| def body (can : Q β Ambient s d Γ T) (q : Q) : Vector d Γ T := | |
| ((can q).1.2, (can q).2) | |
| def offset (can : Q β Ambient s d Γ T) (q : Q) : Vector s := (can q).1.1 | |
| /-- Only realized bodies are vertices; no extra formal records are added. -/ | |
| def Vertex (can : Q β Ambient s d Γ T) := {o : Vector d Γ T // β q, body can q = o} | |
| def vertex (can : Q β Ambient s d Γ T) (q : Q) : Vertex can := | |
| β¨body can q, q, rflβ© | |
| theorem vertex_surjective (can : Q β Ambient s d Γ T) : | |
| Function.Surjective (vertex can) := by | |
| rintro β¨o, q, hqβ© | |
| exact β¨q, Subtype.ext hqβ© | |
| noncomputable instance vertexFintype [Fintype Q] (can : Q β Ambient s d Γ T) : | |
| Fintype (Vertex can) := by | |
| classical | |
| exact Fintype.ofSurjective (vertex can) (vertex_surjective can) | |
| instance vertexNonempty [Nonempty Q] (can : Q β Ambient s d Γ T) : | |
| Nonempty (Vertex can) := Nonempty.map (vertex can) inferInstance | |
| theorem vertex_eq_iff (can : Q β Ambient s d Γ T) (q r : Q) : | |
| vertex can q = vertex can r β body can q = body can r := by | |
| constructor | |
| Β· exact congrArg Subtype.val | |
| Β· intro h | |
| exact Subtype.ext h | |
| /-- `false` is the left copy and `true` is the right copy. -/ | |
| abbrev TwoSidedVertex (can : Q β Ambient s d Γ T) := Bool Γ Vertex can | |
| noncomputable def vertexEquiv [Fintype Q] (can : Q β Ambient s d Γ T) : | |
| TwoSidedVertex can β Fin (Fintype.card (TwoSidedVertex can)) := | |
| Fintype.equivFin _ | |
| /-- Executable vertex numbering from an exhaustive list, preserving the same | |
| realizable-body subtype used in the semantic statements. -/ | |
| def explicitVertexEquiv [DecidableEq (Vector d Γ T)] | |
| (can : Q β Ambient s d Γ T) (queries : List Q) (full : β q, q β queries) : | |
| Vertex can β Fin (Encoding.imageVertices queries (body can)).length := | |
| let e : Vertex can β Encoding.ImageVertex queries (body can) := | |
| { toFun v := β¨v.val, (Encoding.imageVertices_range queries (body can) full v.val).mpr | |
| v.propertyβ© | |
| invFun v := β¨v.val, (Encoding.imageVertices_range queries (body can) full v.val).mp | |
| v.propertyβ© | |
| left_inv _ := rfl | |
| right_inv _ := rfl } | |
| e.trans (Encoding.imageEquiv queries (body can)) | |
| def unfold (can : Q β Ambient s d Γ T) (label : Vertex can β Vector s) (q : Q) : | |
| Vector s := label (vertex can q) + offset can q | |
| theorem add_self_vector (c : Vector s) : c + c = 0 := by | |
| funext i | |
| exact CharTwo.add_self_eq_zero (c i) | |
| theorem add_cancel_vector (a b : Vector s) : (a + b) + b = a := by | |
| rw [add_assoc, add_self_vector, add_zero] | |
| /-- The precise orientation used by the generated edge. -/ | |
| theorem constraint_iff_unfolded (can : Q β Ambient s d Γ T) | |
| (labelL labelR : Vertex can β Vector s) (q r : Q) : | |
| (labelL (vertex can q) + offset can q) + offset can r = labelR (vertex can r) β | |
| unfold can labelL q = unfold can labelR r := by | |
| constructor | |
| Β· intro h | |
| have h' := congrArg (fun c => c + offset can r) h | |
| simpa only [add_cancel_vector, unfold] using h' | |
| Β· intro h | |
| have h' := congrArg (fun c => c + offset can r) h | |
| simpa only [add_cancel_vector, unfold] using h' | |
| /-- A common full canonical record has one common unfolded value on each side. -/ | |
| theorem unfold_eq_of_canonical_eq (can : Q β Ambient s d Γ T) | |
| (label : Vertex can β Vector s) (q r : Q) (h : can q = can r) : | |
| unfold can label q = unfold can label r := by | |
| have hv : vertex can q = vertex can r := by | |
| apply (vertex_eq_iff can q r).2 | |
| exact congrArg (fun z : Ambient s d Γ T => (z.1.2, z.2)) h | |
| simp only [unfold, hv, offset, h] | |
| end MaxCutGames.Reduction.ActualOrbit | |
| end OAI | |