Buckets:
cfahlgren1/math / lean /OAI /LinearAlgebra /MatrixMultiplication /AuxiliarySeparation /Convex /RationalCone.lean
| import OAI.LinearAlgebra.MatrixMultiplication.AuxiliarySeparation.Convex.RationalSpan | |
| import OAI.LinearAlgebra.MatrixMultiplication.AuxiliarySeparation.Convex.RationalDenominators | |
| import Mathlib.Analysis.Convex.Caratheodory | |
| import Mathlib.Geometry.Convex.Cone.Pointed | |
| import Mathlib.Tactic | |
| namespace OAI | |
| /-!+# Rational nonnegative certificates | |
| Finite rational linear systems with a nonnegative real solution have a | |
| nonnegative rational solution. Affinely independent convex representations | |
| allow a rational-linear projection to preserve the coefficients exactly. | |
| -/ | |
| namespace MatrixMultiplication.AuxiliarySeparation | |
| /-- Coordinatewise inclusion of rational vectors into real vectors. -/ | |
| def rationalVectorCast {J : Type*} (v : J → ℚ) : J → ℝ := fun j ↦ v j | |
| @[simp] theorem rationalVectorCast_apply {J : Type*} (v : J → ℚ) (j : J) : | |
| rationalVectorCast v j = (v j : ℝ) := rfl | |
| /-- In an affinely independent rational family, the coefficients of a real | |
| convex representation of a rational point are rational. -/ | |
| theorem exists_rat_convex_weights_of_affineIndependent | |
| {I J : Type*} [Fintype I] (v : I → J → ℚ) (b : J → ℚ) | |
| (w : I → ℝ) | |
| (hpos : ∀ i, 0 ≤ w i) (hsum : ∑ i, w i = 1) | |
| (heq : ∑ i, w i • rationalVectorCast (v i) = rationalVectorCast b) | |
| (hind : AffineIndependent ℝ (fun i ↦ rationalVectorCast (v i))) : | |
| ∃ q : I → ℚ, (∀ i, 0 ≤ q i) ∧ ∑ i, q i = 1 ∧ | |
| ∑ i, q i • v i = b := by | |
| classical | |
| obtain ⟨p, hp⟩ := exists_ratLinear_retraction | |
| have hpone : p 1 = 1 := by simpa using hp 1 | |
| let q : I → ℚ := fun i ↦ p (w i) | |
| have hqsum : ∑ i, q i = 1 := by | |
| simpa only [q, map_sum, hpone] using congrArg p hsum | |
| have hqeq : ∑ i, q i • v i = b := by | |
| funext j | |
| have hj := congrFun heq j | |
| simp only [Finset.sum_apply, Pi.smul_apply, rationalVectorCast_apply, | |
| smul_eq_mul] at hj | |
| have hj' := congrArg p hj | |
| simp only [map_sum, hp] at hj' | |
| simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] | |
| convert hj' using 1 | |
| apply Finset.sum_congr rfl | |
| intro i _ | |
| have hm := p.map_smul (v i j) (w i) | |
| simpa only [q, Rat.smul_def, smul_eq_mul, mul_comm] using hm.symm | |
| have hqsumReal : ∑ i, (q i : ℝ) = 1 := by exact_mod_cast hqsum | |
| have hqeqReal : | |
| ∑ i, (q i : ℝ) • rationalVectorCast (v i) = rationalVectorCast b := by | |
| funext j | |
| have hj := congrFun hqeq j | |
| simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul] at hj | |
| simpa only [Finset.sum_apply, Pi.smul_apply, rationalVectorCast_apply, | |
| smul_eq_mul] using (show (∑ i, (q i : ℝ) * (v i j : ℝ)) = (b j : ℝ) by | |
| exact_mod_cast hj) | |
| have hqw : ∀ i, (q i : ℝ) = w i := by | |
| intro i | |
| exact hind.eq_of_sum_eq_sum (s := Finset.univ) | |
| (hqsumReal.trans hsum.symm) (hqeqReal.trans heq.symm) i (Finset.mem_univ i) | |
| refine ⟨q, ?_, hqsum, hqeq⟩ | |
| intro i | |
| exact_mod_cast (hqw i ▸ hpos i : 0 ≤ (q i : ℝ)) | |
| /-- Taking the convex hull of rational vectors in real space does not create | |
| new rational points. -/ | |
| theorem rationalVectorCast_mem_convexHull_descend | |
| {J : Type*} {s : Set (J → ℚ)} {b : J → ℚ} | |
| (h : rationalVectorCast b ∈ convexHull ℝ (rationalVectorCast '' s)) : | |
| b ∈ convexHull ℚ s := by | |
| classical | |
| obtain ⟨I, hI, z, w, hz, hind, hpos, hsum, heq⟩ := | |
| eq_pos_convex_span_of_mem_convexHull h | |
| let : Fintype I := hI | |
| have hv : ∀ i, ∃ v ∈ s, rationalVectorCast v = z i := by | |
| intro i | |
| exact hz (Set.mem_range_self i) | |
| choose v hv hvc using hv | |
| obtain ⟨q, hqpos, hqsum, hqeq⟩ := | |
| exists_rat_convex_weights_of_affineIndependent v b w (fun i ↦ (hpos i).le) | |
| hsum (by simpa only [hvc] using heq) (by simpa only [hvc] using hind) | |
| exact mem_convexHull_of_exists_fintype q v hqpos hqsum hv hqeq | |
| /-- A rational point in the real cone generated by a finite rational family | |
| already lies in the rational cone generated by that family. -/ | |
| theorem mem_rationalCone_of_nonneg_real_solution | |
| {I J : Type*} [Fintype I] (A : I → J → ℚ) (b : J → ℚ) | |
| (x : I → ℝ) (hxpos : ∀ i, 0 ≤ x i) | |
| (hxeq : ∀ j, ∑ i, x i * (A i j : ℝ) = (b j : ℝ)) : | |
| b ∈ PointedCone.hull ℚ (Set.range A) := by | |
| classical | |
| obtain ⟨N, hN⟩ := exists_nat_gt (∑ i, x i) | |
| have hNpos : (0 : ℝ) < N := | |
| (Finset.sum_nonneg fun i _ ↦ hxpos i).trans_lt hN | |
| have hNne : (N : ℝ) ≠ 0 := hNpos.ne' | |
| have hNrat : (N : ℚ) ≠ 0 := by exact_mod_cast hNne | |
| let scaled : J → ℚ := fun j ↦ b j / N | |
| let v : Option I → J → ℚ := fun i ↦ match i with | |
| | none => 0 | |
| | some i => A i | |
| let w : Option I → ℝ := fun i ↦ match i with | |
| | none => 1 - (∑ i, x i) / N | |
| | some i => x i / N | |
| have hwpos : ∀ i, 0 ≤ w i := by | |
| intro i | |
| cases i with | |
| | none => | |
| change 0 ≤ 1 - (∑ i, x i) / N | |
| exact sub_nonneg.mpr ((div_le_one hNpos).2 hN.le) | |
| | some i => exact div_nonneg (hxpos i) hNpos.le | |
| have hwsum : ∑ i, w i = 1 := by | |
| simp only [Fintype.sum_option, w, ← Finset.sum_div] | |
| ring | |
| have hweq : ∑ i, w i • rationalVectorCast (v i) = rationalVectorCast scaled := by | |
| funext j | |
| simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul, | |
| Fintype.sum_option, w, v, rationalVectorCast_apply, Pi.zero_apply, | |
| Rat.cast_zero, mul_zero, zero_add, scaled, Rat.cast_div, Rat.cast_natCast] | |
| simp_rw [div_mul_eq_mul_div] | |
| rw [← Finset.sum_div, hxeq] | |
| let s : Set (J → ℚ) := insert 0 (Set.range A) | |
| have hv : ∀ i, rationalVectorCast (v i) ∈ rationalVectorCast '' s := by | |
| intro i | |
| refine ⟨v i, ?_, rfl⟩ | |
| cases i with | |
| | none => exact Set.mem_insert 0 _ | |
| | some i => exact Set.mem_insert_of_mem 0 (Set.mem_range_self i) | |
| have hcReal : rationalVectorCast scaled ∈ | |
| convexHull ℝ (rationalVectorCast '' s) := | |
| mem_convexHull_of_exists_fintype w (fun i ↦ rationalVectorCast (v i)) | |
| hwpos hwsum hv hweq | |
| have hcRat : scaled ∈ convexHull ℚ s := | |
| rationalVectorCast_mem_convexHull_descend hcReal | |
| have hs : s ⊆ PointedCone.hull ℚ (Set.range A) := by | |
| intro a ha | |
| rcases ha with rfl | ha | |
| · exact Submodule.zero_mem _ | |
| · exact PointedCone.subset_hull ha | |
| have hscaled : scaled ∈ PointedCone.hull ℚ (Set.range A) := | |
| convexHull_min hs (PointedCone.convex _) hcRat | |
| have hscale : (N : ℚ) • scaled = b := by | |
| funext j | |
| simp only [Pi.smul_apply, smul_eq_mul, scaled] | |
| field_simp | |
| rw [← hscale] | |
| exact PointedCone.smul_mem _ (Nat.cast_nonneg N) hscaled | |
| /-- Nonnegative solvability of a finite rational linear system descends from | |
| real coefficients to rational coefficients. The equation index type may be | |
| infinite. -/ | |
| theorem exists_nonneg_rat_solution_of_real | |
| {I J : Type*} [Fintype I] (A : I → J → ℚ) (b : J → ℚ) | |
| (h : ∃ x : I → ℝ, (∀ i, 0 ≤ x i) ∧ | |
| ∀ j, ∑ i, x i * (A i j : ℝ) = (b j : ℝ)) : | |
| ∃ q : I → ℚ, (∀ i, 0 ≤ q i) ∧ ∀ j, ∑ i, q i * A i j = b j := by | |
| obtain ⟨x, hxpos, hxeq⟩ := h | |
| have hb := mem_rationalCone_of_nonneg_real_solution A b x hxpos hxeq | |
| obtain ⟨q, hq⟩ := (Submodule.mem_span_range_iff_exists_fun (Nonneg ℚ)).1 hb | |
| refine ⟨fun i ↦ (q i : ℚ), fun i ↦ (q i).property, ?_⟩ | |
| intro j | |
| have hj := congrFun hq j | |
| simpa only [Finset.sum_apply, Pi.smul_apply, ← Nonneg.coe_smul, smul_eq_mul] using hj | |
| /-- Clearing denominators turns a nonnegative real solution of a rational | |
| system into a positive integer multiple with natural coefficients. -/ | |
| theorem exists_nat_scaled_solution_of_nonneg_real | |
| {I J : Type*} [Fintype I] (A : I → J → ℚ) (b : J → ℚ) | |
| (h : ∃ x : I → ℝ, (∀ i, 0 ≤ x i) ∧ | |
| ∀ j, ∑ i, x i * (A i j : ℝ) = (b j : ℝ)) : | |
| ∃ D : ℕ, 0 < D ∧ ∃ c : I → ℕ, | |
| ∀ j, ∑ i, (c i : ℚ) * A i j = (D : ℚ) * b j := by | |
| obtain ⟨q, hqpos, hqeq⟩ := exists_nonneg_rat_solution_of_real A b h | |
| obtain ⟨D, hDpos, c, hc⟩ := exists_nat_mul_eq_nat q hqpos | |
| refine ⟨D, hDpos, c, fun j ↦ ?_⟩ | |
| calc | |
| ∑ i, (c i : ℚ) * A i j = ∑ i, ((D : ℚ) * q i) * A i j := by simp only [hc] | |
| _ = (D : ℚ) * ∑ i, q i * A i j := by rw [Finset.mul_sum]; simp only [mul_assoc] | |
| _ = (D : ℚ) * b j := by rw [hqeq] | |
| /-- Integer form of finite cone certificate extraction. This is the form used | |
| when the selected additive relations have integral coefficients. -/ | |
| theorem exists_nat_scaled_int_solution_of_nonneg_real | |
| {I J : Type*} [Fintype I] (A : I → J → ℤ) (b : J → ℤ) | |
| (h : ∃ x : I → ℝ, (∀ i, 0 ≤ x i) ∧ | |
| ∀ j, ∑ i, x i * (A i j : ℝ) = (b j : ℝ)) : | |
| ∃ D : ℕ, 0 < D ∧ ∃ c : I → ℕ, | |
| ∀ j, ∑ i, (c i : ℤ) * A i j = (D : ℤ) * b j := by | |
| obtain ⟨x, hxpos, hxeq⟩ := h | |
| obtain ⟨D, hDpos, c, hc⟩ := | |
| exists_nat_scaled_solution_of_nonneg_real | |
| (fun i j ↦ (A i j : ℚ)) (fun j ↦ (b j : ℚ)) | |
| ⟨x, hxpos, by simpa using hxeq⟩ | |
| refine ⟨D, hDpos, c, fun j ↦ ?_⟩ | |
| exact_mod_cast hc j | |
| end MatrixMultiplication.AuxiliarySeparation | |
| end OAI | |
Xet Storage Details
- Size:
- 9.11 kB
- Xet hash:
- 3e5f0cd57ceb06bc175523b284ef645453dd7666abba2b986901af73c70e4dfb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.