import Mathlib.LinearAlgebra.Pi import Mathlib.LinearAlgebra.Span.Basic namespace OAI namespace PerfectCompleteness.FactoredFunctions variable {π•œ Ξ© Z I J : Type*} [Field π•œ] def factoringSpace (other : Ξ© β†’ Z) : Submodule π•œ (Ξ© β†’ π•œ) where carrier := {f | βˆ€ x y, other x = other y β†’ f x = f y} zero_mem' := by intro x y _; rfl add_mem' := by intro f g hf hg x y h change f x + g x = f y + g y rw [hf x y h, hg x y h] smul_mem' := by intro c f hf x y h change c β€’ f x = c β€’ f y rw [hf x y h] @[simp] theorem mem_factoringSpace (other : Ξ© β†’ Z) (f : Ξ© β†’ π•œ) : f ∈ factoringSpace other ↔ βˆ€ x y, other x = other y β†’ f x = f y := Iff.rfl theorem mem_factoringSpace_iff_exists_factor (other : Ξ© β†’ Z) (f : Ξ© β†’ π•œ) : f ∈ factoringSpace other ↔ βˆƒ g : Z β†’ π•œ, βˆ€ x, f x = g (other x) := by classical constructor Β· intro hf let g : Z β†’ π•œ := fun z => if h : βˆƒ x, other x = z then f (Classical.choose h) else 0 refine ⟨g, ?_⟩ intro x have hx : βˆƒ y, other y = other x := ⟨x, rfl⟩ change f x = if h : βˆƒ y, other y = other x then f (Classical.choose h) else 0 rw [dite_eq_left hx] exact hf x _ (Classical.choose_spec hx).symm Β· rintro ⟨g, hg⟩ x y h rw [hg x, hg y, h] theorem const_mem_factoringSpace (other : Ξ© β†’ Z) (c : π•œ) : (fun _ : Ξ© => c) ∈ factoringSpace other := by intro x y _ rfl theorem one_mem_factoringSpace (other : Ξ© β†’ Z) : (1 : Ξ© β†’ π•œ) ∈ factoringSpace other := const_mem_factoringSpace other 1 theorem mul_mem_factoringSpace (other : Ξ© β†’ Z) {f g : Ξ© β†’ π•œ} (hf : f ∈ factoringSpace other) (hg : g ∈ factoringSpace other) : f * g ∈ factoringSpace other := by intro x y h change f x * g x = f y * g y rw [hf x y h, hg x y h] theorem coordinate_mem_factoringSpace (lower : Ξ© β†’ I β†’ J β†’ π•œ) (i : I) (t : J) : (fun x => lower x i t) ∈ factoringSpace lower := by intro x y h exact congrFun (congrFun h i) t def quadraticSpan (lower : Ξ© β†’ I β†’ J β†’ π•œ) : Submodule π•œ (Ξ© β†’ π•œ) := Submodule.span π•œ {f | f = 1 ∨ βˆƒ (i : I) (t u : J), f = fun x => lower x i t * lower x i u} theorem one_mem_quadraticSpan (lower : Ξ© β†’ I β†’ J β†’ π•œ) : (1 : Ξ© β†’ π•œ) ∈ quadraticSpan lower := Submodule.subset_span (Or.inl rfl) theorem product_mem_quadraticSpan (lower : Ξ© β†’ I β†’ J β†’ π•œ) (i : I) (t u : J) : (fun x => lower x i t * lower x i u) ∈ quadraticSpan lower := Submodule.subset_span (Or.inr ⟨i, t, u, rfl⟩) theorem quadraticSpan_le_factoringSpace (lower : Ξ© β†’ I β†’ J β†’ π•œ) : quadraticSpan lower ≀ factoringSpace lower := by apply Submodule.span_le.mpr intro f hf rcases hf with rfl | ⟨i, t, u, rfl⟩ Β· exact one_mem_factoringSpace lower Β· exact mul_mem_factoringSpace lower (coordinate_mem_factoringSpace lower i t) (coordinate_mem_factoringSpace lower i u) noncomputable section def realizer (other : Ξ© β†’ Z) (z : Set.range other) : Ξ© := Classical.choose z.property theorem realizer_spec (other : Ξ© β†’ Z) (z : Set.range other) : other (realizer other z) = z.val := Classical.choose_spec z.property def evaluation {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (_hB : B ≀ factoringSpace other) (z : Set.range other) : B β†’β‚—[π•œ] π•œ := (LinearMap.proj (realizer other z)).comp B.subtype @[simp] theorem evaluation_apply {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (hB : B ≀ factoringSpace other) (z : Set.range other) (b : B) : evaluation hB z b = b.val (realizer other z) := rfl theorem evaluation_apply_of_eq {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (hB : B ≀ factoringSpace other) (z : Set.range other) (x : Ξ©) (hx : other x = z.val) (b : B) : evaluation hB z b = b.val x := hB b.property (realizer other z) x ((realizer_spec other z).trans hx.symm) theorem evaluation_eq_pointEvaluation {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (hB : B ≀ factoringSpace other) (z : Set.range other) (x : Ξ©) (hx : other x = z.val) : evaluation hB z = (LinearMap.proj x).comp B.subtype := by apply LinearMap.ext intro b exact evaluation_apply_of_eq hB z x hx b @[simp] theorem evaluation_at_image {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (hB : B ≀ factoringSpace other) (x : Ξ©) (b : B) : evaluation hB ⟨other x, ⟨x, rfl⟩⟩ b = b.val x := evaluation_apply_of_eq hB _ x rfl b theorem evaluation_one {other : Ξ© β†’ Z} {B : Submodule π•œ (Ξ© β†’ π•œ)} (hB : B ≀ factoringSpace other) (z : Set.range other) (h1 : (1 : Ξ© β†’ π•œ) ∈ B) : evaluation hB z ⟨1, h1⟩ = 1 := rfl end end PerfectCompleteness.FactoredFunctions namespace PerfectCompleteness.FactoredFunctionsDependent open PerfectCompleteness.FactoredFunctions variable {π•œ Ξ© I : Type*} [Field π•œ] {J : I β†’ Type*} theorem coordinate_mem_factoringSpace (lower : Ξ© β†’ (i : I) β†’ J i β†’ π•œ) (i : I) (t : J i) : (fun x => lower x i t) ∈ factoringSpace lower := by intro x y h exact congrFun (congrFun h i) t def dependentQuadraticSpan (lower : Ξ© β†’ (i : I) β†’ J i β†’ π•œ) : Submodule π•œ (Ξ© β†’ π•œ) := Submodule.span π•œ {f | f = 1 ∨ βˆƒ (i : I) (t u : J i), f = fun x => lower x i t * lower x i u} theorem one_mem_dependentQuadraticSpan (lower : Ξ© β†’ (i : I) β†’ J i β†’ π•œ) : (1 : Ξ© β†’ π•œ) ∈ dependentQuadraticSpan lower := Submodule.subset_span (Or.inl rfl) theorem product_mem_dependentQuadraticSpan (lower : Ξ© β†’ (i : I) β†’ J i β†’ π•œ) (i : I) (t u : J i) : (fun x => lower x i t * lower x i u) ∈ dependentQuadraticSpan lower := Submodule.subset_span (Or.inr ⟨i, t, u, rfl⟩) theorem dependentQuadraticSpan_le_factoringSpace (lower : Ξ© β†’ (i : I) β†’ J i β†’ π•œ) : dependentQuadraticSpan lower ≀ factoringSpace lower := by apply Submodule.span_le.mpr intro f hf rcases hf with rfl | ⟨i, t, u, rfl⟩ Β· exact one_mem_factoringSpace lower Β· exact mul_mem_factoringSpace lower (coordinate_mem_factoringSpace lower i t) (coordinate_mem_factoringSpace lower i u) end PerfectCompleteness.FactoredFunctionsDependent end OAI