diff --git a/LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean b/LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean index ed46cdfc2c..445f3c9c81 100644 --- a/LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean +++ b/LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean @@ -216,10 +216,27 @@ theorem varOfDirIdx_eq_none_iff (d : DirIdx) : varOfDirIdx d = none ↔ d = idDi classical fin_cases d <;> decide +-- Check the orbit condition once for the table entry at each directed index. +private theorem varOfDirIdx_pointsToOrbit : + ∀ d : DirIdx, + ((varOfDirIdx d).all fun i => decide (d = varOrbit i ∨ d = invDir (varOrbit i))) = true := by + decide +kernel + +-- Both representatives of each variable must map back to that variable. +private theorem varOfDirIdx_orbitEntries : + ∀ i : Var, varOfDirIdx (varOrbit i) = some i ∧ varOfDirIdx (invDir (varOrbit i)) = some i := by + decide +kernel + theorem varOfDirIdx_eq_some_iff (d : DirIdx) (i : Var) : varOfDirIdx d = some i ↔ d = varOrbit i ∨ d = invDir (varOrbit i) := by - classical - fin_cases d <;> fin_cases i <;> decide + constructor + · intro h + have check := varOfDirIdx_pointsToOrbit d + rw [h] at check + exact of_decide_eq_true check + · rintro (rfl | rfl) + · exact (varOfDirIdx_orbitEntries i).1 + · exact (varOfDirIdx_orbitEntries i).2 theorem varOfDirIdx_spec (d : DirIdx) (hd : d ≠ idDirIdx) : ∃ i : Var, varOfDirIdx d = some i ∧ (d = varOrbit i ∨ d = invDir (varOrbit i)) := by diff --git a/LeanPool/TwoColoringOneRound/LowerBound/N1000000IntersectionCounting.lean b/LeanPool/TwoColoringOneRound/LowerBound/N1000000IntersectionCounting.lean index aa6b571208..6e28e85848 100644 --- a/LeanPool/TwoColoringOneRound/LowerBound/N1000000IntersectionCounting.lean +++ b/LeanPool/TwoColoringOneRound/LowerBound/N1000000IntersectionCounting.lean @@ -324,7 +324,12 @@ private lemma availFor_ge_three {k : DirIdx} (u : BaseOrbit k) (x : AvailFor u) private theorem rowMatch_maskAt_inj (d : DirIdx) {i₁ i₂ j : Fin 3} : rowMatch (maskAt d) i₁ = some j → rowMatch (maskAt d) i₂ = some j → i₁ = i₂ := by intro h1 h2 - fin_cases d <;> fin_cases i₁ <;> fin_cases i₂ <;> fin_cases j <;> cases h1 <;> cases h2 <;> rfl + have columnMatch (i : Fin 3) (h : rowMatch (maskAt d) i = some j) : + colMatch (maskAt d) j = some i := by + apply of_decide_eq_true + rw [← maskAt_testBit_eq_decide_colMatch, maskAt_testBit_eq_decide_rowMatch, h] + exact decide_eq_true rfl + exact Option.some.inj ((columnMatch i₁ h1).symm.trans (columnMatch i₂ h2)) /-- Imported auxiliary declaration for the 2-coloring one-round formalization. -/ noncomputable def encodeInter {k : DirIdx} (u : BaseOrbit k) (a d : DirIdx) (w : Inter u a d) : diff --git a/LeanPool/TwoColoringOneRound/LowerBound/N1000000WeakDuality.lean b/LeanPool/TwoColoringOneRound/LowerBound/N1000000WeakDuality.lean index bf09b02bea..5fc6e2a7b8 100644 --- a/LeanPool/TwoColoringOneRound/LowerBound/N1000000WeakDuality.lean +++ b/LeanPool/TwoColoringOneRound/LowerBound/N1000000WeakDuality.lean @@ -127,8 +127,9 @@ private theorem frobInner_toMat3Scaled (A B : Array (Array Int)) : = ((innerNum A B : Q) / ((D : Q) * (D : Q))) := by classical -- Expand `trace (A * Bᵀ)`; for `3×3` this is the entrywise Frobenius sum. - simp [frobInner, innerNum, toMat3Scaled, matGet, Matrix.trace, Matrix.diag, Matrix.mul_apply, - Matrix.transpose, div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm, Finset.mul_sum] + simp only [frobInner, Matrix.trace, Matrix.diag, Matrix.mul_apply, Matrix.transpose_apply, + toMat3Scaled, innerNum, matGet, Int.cast_sum, Int.cast_mul, div_mul_div_comm] + simp only [div_eq_mul_inv, Finset.sum_mul] private def muCoeff (i : Var) : Q := ∑ k : Mu, (muVal k) * (aCoeff k i) @@ -151,8 +152,23 @@ private theorem muCoeff_eq_num (i : Var) : mul_comm, Finset.mul_sum] +private theorem sum_array_entries {α : Type} (entries : Array α) (f : α → Int) : + (∑ i : Fin entries.size, f entries[i.1]) = + entries.foldl (fun acc entry => acc + f entry) 0 := by + rw [← List.sum_ofFn] + change (List.ofFn (f ∘ (fun i : Fin entries.size => entries[i.1]))).sum = _ + rw [← List.map_ofFn, ← Array.toList_ofFn, Array.ofFn_getElem, + List.sum_eq_foldl, List.foldl_map, Array.foldl_toList] + private theorem muCoeffNumD_eq_linNumD (i : Var) : muCoeffNumD i = linNumD i.1 := by - fin_cases i <;> decide + unfold muCoeffNumD linNumD + rw [← sum_array_entries] + apply Finset.sum_congr rfl + intro k _ + delta muNumD aCoeffInt aVec + simp only [Array.getD_eq_getD_getElem?, + Array.getElem?_eq_getElem k.isLt, Option.getD_some] + exact mul_comm _ _ private theorem muCoeff_eq_lin (i : Var) : muCoeff i = (linNumD i.1 : Q) / (D : Q) := by @@ -226,7 +242,14 @@ private theorem muSum_eq_num : private def muSumD_fold : Int := muSupport.foldl (fun acc t => acc + t.2.2) 0 -private theorem muSumNumD_eq_muSumD_fold : muSumNumD = muSumD_fold := by decide +private theorem muSumNumD_eq_muSumD_fold : muSumNumD = muSumD_fold := by + unfold muSumNumD muSumD_fold + rw [← sum_array_entries] + apply Finset.sum_congr rfl + intro k _ + delta muNumD + simp only [Array.getD_eq_getD_getElem?, Array.getElem?_eq_getElem k.isLt, + Option.getD_some] private theorem dualObjective_eq_expression : dualObjective = -muSum - zSum0 := by @@ -249,9 +272,11 @@ private theorem dualObjective_eq_expression : private theorem stationarity (i : Var) : (if i.1 = edgeVar then (1 : Q) else 0) + muCoeff i - zCoeff i = 0 := by classical - -- Integer stationarity is checked coordinatewise; convert and rewrite the coefficients. + -- Read the coordinate from the integer stationarity certificate. have hInt : stationarityLHSD2 i.1 = -(c i.1) * ((D : Int) * (D : Int)) := by - fin_cases i <;> decide + have certificate := stationarityOK_true + unfold stationarityOK at certificate + exact of_decide_eq_true (List.all_eq_true.mp certificate i.1 (List.mem_range.mpr i.isLt)) have hDne : (D : Q) ≠ 0 := by exact_mod_cast (show (D : Nat) ≠ 0 by decide) have hD2ne : ((D : Q) * (D : Q)) ≠ 0 := by simp [hDne] have hQ :