import OAI.Algorithms.SubexponentialSAT.LeanCompat namespace OAI.Algorithms /-! # Coset invariance of residue lifts Section 4.3 of the candidate exposition chooses a fixed section of reduction and applies it to the residue of a lifted row evaluation. The coordinate lifts themselves need not preserve addition. This file isolates that fact: only their residues must agree with the specified linear row. -/ namespace SubexponentialSAT.CosetInvariance section Linear variable {R M N : Type*} [Ring R] [AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N] /-- A row which annihilates a submodule is constant on each of its cosets. -/ theorem linear_map_eq_of_sub_mem (L : M →ₗ[R] N) (K : Submodule R M) (hK : K ≤ LinearMap.ker L) {x y : M} (hxy : y - x ∈ K) : L y = L x := by have hzero : L (y - x) = 0 := hK hxy simpa only [map_sub, sub_eq_zero] using hzero theorem linear_map_add_eq_of_mem (L : M →ₗ[R] N) (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (x : M) {r : M} (hr : r ∈ K) : L (x + r) = L x := by have hzero : L r = 0 := hK hr simp only [map_add, hzero, add_zero] /-- Applying any fixed function preserves this exact coset invariance. -/ theorem compose_eq_of_sub_mem {A : Type*} (L : M →ₗ[R] N) (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (s : N → A) {x y : M} (hxy : y - x ∈ K) : s (L y) = s (L x) := congrArg s (linear_map_eq_of_sub_mem L K hK hxy) /-- The common value is genuinely a function on the quotient by the subspace. -/ def onQuotient {A : Type*} (L : M →ₗ[R] N) (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (s : N → A) : (M ⧸ K) → A := fun q => s (K.liftQ L hK q) @[simp] theorem onQuotient_mk {A : Type*} (L : M →ₗ[R] N) (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (s : N → A) (x : M) : onQuotient L K hK s (Submodule.Quotient.mk x) = s (L x) := rfl end Linear section Residue variable {A E : Type*} [CommRing A] [CommRing E] /-- An arbitrary fixed right inverse of a residue homomorphism. No additive or multiplicative property is required of the lift. -/ structure ResidueSection (ρ : A →+* E) where lift : E → A residue_lift : ∀ y, ρ (lift y) = y namespace ResidueSection variable {ρ : A →+* E} (s : ResidueSection ρ) /-- The error between a value and the chosen lift of its residue. -/ def defect (a : A) : A := a - s.lift (ρ a) @[simp] theorem residue_defect (a : A) : ρ (s.defect a) = 0 := by simp only [defect, map_sub, s.residue_lift, sub_self] theorem defect_mem_kernel (a : A) : s.defect a ∈ RingHom.ker ρ := s.residue_defect a /-- If the residue kernel is generated by p, every lift error is p-divisible. -/ theorem defect_dvd (p : A) (hker : RingHom.ker ρ = Ideal.span ({p} : Set A)) (a : A) : p ∣ s.defect a := by rw [← Ideal.mem_span_singleton, ← hker] exact s.defect_mem_kernel a /-- The same interface using the elementwise kernel description. -/ theorem defect_exists_mul (p : A) (hker : ∀ z : A, ρ z = 0 → ∃ q : A, z = p * q) (a : A) : ∃ q : A, s.defect a = p * q := hker _ (s.residue_defect a) /-- The failure of a section to preserve addition is a residue-kernel element. -/ theorem carry_mem_kernel (x y : E) : s.lift (x + y) - s.lift x - s.lift y ∈ RingHom.ker ρ := by change ρ (s.lift (x + y) - s.lift x - s.lift y) = 0 simp only [map_sub, s.residue_lift, add_sub_cancel_left, sub_self] theorem carry_dvd (p : A) (hker : RingHom.ker ρ = Ideal.span ({p} : Set A)) (x y : E) : p ∣ s.lift (x + y) - s.lift x - s.lift y := by rw [← Ideal.mem_span_singleton, ← hker] exact s.carry_mem_kernel x y end ResidueSection variable {R M : Type*} [Ring R] [AddCommGroup M] [Module R M] [Module R E] /-- A lifted evaluation may be nonlinear because of representative carries. Its only requirement is that reduction gives the specified linear row. -/ structure LiftedRow (ρ : A →+* E) (L : M →ₗ[R] E) where value : M → A residue_value : ∀ x, ρ (value x) = L x namespace LiftedRow variable {ρ : A →+* E} {L : M →ₗ[R] E} (row : LiftedRow ρ L) (s : ResidueSection ρ) /-- The beta value in Section 4.3, defined using the lifted evaluation. -/ def beta (x : M) : A := s.lift (ρ (row.value x)) theorem beta_eq_lift_row (x : M) : row.beta s x = s.lift (L x) := by rw [beta, row.residue_value] @[simp] theorem residue_beta (x : M) : ρ (row.beta s x) = L x := by rw [beta, s.residue_lift, row.residue_value] /-- Beta is exactly equal, not just congruent, at two inputs in one coset. -/ theorem beta_invariant (K : Submodule R M) (hK : K ≤ LinearMap.ker L) {x y : M} (hxy : y - x ∈ K) : row.beta s y = row.beta s x := by rw [row.beta_eq_lift_row, row.beta_eq_lift_row] exact compose_eq_of_sub_mem L K hK s.lift hxy theorem beta_add_invariant (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (x : M) {r : M} (hr : r ∈ K) : row.beta s (x + r) = row.beta s x := by rw [row.beta_eq_lift_row, row.beta_eq_lift_row, linear_map_add_eq_of_mem L K hK x hr] theorem beta_factors_through_quotient (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (x : M) : row.beta s x = onQuotient L K hK s.lift (Submodule.Quotient.mk x) := by exact row.beta_eq_lift_row s x /-- The lifted row can change inside a coset, but only by a kernel element. -/ theorem value_sub_mem_kernel (K : Submodule R M) (hK : K ≤ LinearMap.ker L) {x y : M} (hxy : y - x ∈ K) : row.value y - row.value x ∈ RingHom.ker ρ := by change ρ (row.value y - row.value x) = 0 rw [map_sub, row.residue_value, row.residue_value, linear_map_eq_of_sub_mem L K hK hxy, sub_self] theorem value_sub_dvd (K : Submodule R M) (hK : K ≤ LinearMap.ker L) (p : A) (hker : RingHom.ker ρ = Ideal.span ({p} : Set A)) {x y : M} (hxy : y - x ∈ K) : p ∣ row.value y - row.value x := by rw [← Ideal.mem_span_singleton, ← hker] exact row.value_sub_mem_kernel K hK hxy theorem value_sub_beta_mem_kernel (x : M) : row.value x - row.beta s x ∈ RingHom.ker ρ := s.defect_mem_kernel (row.value x) /-- This is the p-divisible coefficient of U after input substitution. -/ theorem value_sub_beta_dvd (p : A) (hker : RingHom.ker ρ = Ideal.span ({p} : Set A)) (x : M) : p ∣ row.value x - row.beta s x := s.defect_dvd p hker (row.value x) end LiftedRow end Residue section FiniteRows variable {R A E ι : Type*} [CommRing R] [CommRing A] [CommRing E] [Algebra R E] [Fintype ι] /-- A finite coefficient row over an extension ring, linear over the base ring. -/ def finiteRow (c : ι → E) : (ι → R) →ₗ[R] E where toFun x := ∑ i, c i * algebraMap R E (x i) map_add' x y := by simp only [Pi.add_apply, map_add, mul_add, Finset.sum_add_distrib] map_smul' r x := by simp only [Pi.smul_apply, smul_eq_mul, map_mul, Algebra.smul_def, Finset.mul_sum] apply Finset.sum_congr rfl intro i _ exact mul_left_comm _ _ _ @[simp] theorem finiteRow_apply (c : ι → E) (x : ι → R) : finiteRow c x = ∑ i, c i * algebraMap R E (x i) := rfl /-- Actual coordinate lifts give the lifted-row interface. No law about sums of representatives is assumed: all representative carries are permitted. -/ def liftedFiniteRow (ρ : A →+* E) (coordinateLift : R → A) (hLift : ∀ r, ρ (coordinateLift r) = algebraMap R E r) (c : ι → A) : LiftedRow (R := R) ρ (finiteRow (R := R) (fun i => ρ (c i))) where value x := ∑ i, c i * coordinateLift (x i) residue_value x := by simp only [map_sum, map_mul, hLift, finiteRow_apply] @[simp] theorem liftedFiniteRow_value (ρ : A →+* E) (coordinateLift : R → A) (hLift : ∀ r, ρ (coordinateLift r) = algebraMap R E r) (c : ι → A) (x : ι → R) : (liftedFiniteRow ρ coordinateLift hLift c).value x = ∑ i, c i * coordinateLift (x i) := rfl end FiniteRows end SubexponentialSAT.CosetInvariance end OAI.Algorithms