import Math.ApTangentDet2 import Math.CircleEqScaled import Mathlib.Tactic /-! # Explicit scaled circle equation from the determinant circle This file defines explicit coefficients * $A,B,C,D$ for the determinant circle polynomial, as determinants of updated rows of a fixed base matrix. It then proves (without `sorry`) that the determinant circle polynomial equals $$A(x^2+y^2)+Bx+Cy+D.$$ This removes the need for `Classical.choose` when using determinant circles. -/ namespace DetCircleExplicit noncomputable section open ApTangentDet2 abbrev Pt : Type := ℝ × ℝ /-- The base matrix with the first row specialized at `(0,0)`. This depends only on the three defining points. -/ def baseMat (p1 p2 p3 : Pt) : Matrix (Fin 4) (Fin 4) ℝ := circleMat p1 p2 p3 0 0 /-- The explicit coefficient `A` of `x^2+y^2`. -/ def coefA (p1 p2 p3 : Pt) : ℝ := (Matrix.updateRow (baseMat p1 p2 p3) 0 (e 0)).det /-- The explicit coefficient `B` of `x`. -/ def coefB (p1 p2 p3 : Pt) : ℝ := (Matrix.updateRow (baseMat p1 p2 p3) 0 (e 1)).det /-- The explicit coefficient `C` of `y`. -/ def coefC (p1 p2 p3 : Pt) : ℝ := (Matrix.updateRow (baseMat p1 p2 p3) 0 (e 2)).det /-- The explicit constant coefficient `D`. -/ def coefD (p1 p2 p3 : Pt) : ℝ := (Matrix.updateRow (baseMat p1 p2 p3) 0 (e 3)).det /-- The explicit scaled circle equation associated to the determinant circle through three points. -/ def circleEq (p1 p2 p3 : Pt) : CircleEqScaled.CircleEq := ⟨coefA p1 p2 p3, coefB p1 p2 p3, coefC p1 p2 p3, coefD p1 p2 p3⟩ /-- The determinant circle polynomial equals the explicit quadratic-linear form. -/ lemma circlePoly_eq (p1 p2 p3 : Pt) (x y : ℝ) : circlePoly p1 p2 p3 x y = coefA p1 p2 p3 * (x^2+y^2) + coefB p1 p2 p3 * x + coefC p1 p2 p3 * y + coefD p1 p2 p3 := by classical -- This proof is adapted from `ApTangentDet2.circlePoly_eq_quadratic_linear`, but we keep the -- coefficients explicit by definition. let M : Matrix (Fin 4) (Fin 4) ℝ := baseMat p1 p2 p3 let A : ℝ := coefA p1 p2 p3 let B : ℝ := coefB p1 p2 p3 let C : ℝ := coefC p1 p2 p3 let D : ℝ := coefD p1 p2 p3 -- rewrite `circlePoly` using updateRow have hdet : circlePoly p1 p2 p3 x y = (Matrix.updateRow M 0 (uvec x y)).det := by unfold circlePoly -- `M` is definitionally `circleMat p1 p2 p3 0 0` -- now apply the updateRow lemma -- rewrite the matrix and reduce `M` have hm : circleMat p1 p2 p3 x y = (circleMat p1 p2 p3 0 0).updateRow 0 (uvec x y) := by simpa using (circleMat_eq_updateRow (p1:=p1) (p2:=p2) (p3:=p3) (x:=x) (y:=y)) simpa [baseMat, M] using congrArg Matrix.det hm -- decompose the updated row have hu : uvec x y = (x^2 + y^2) • e 0 + x • e 1 + y • e 2 + (1:ℝ) • e 3 := uvec_eq x y let u0 : Fin 4 → ℝ := (x^2 + y^2) • e 0 let u1 : Fin 4 → ℝ := x • e 1 let u2 : Fin 4 → ℝ := y • e 2 let u3 : Fin 4 → ℝ := (1:ℝ) • e 3 have hu' : uvec x y = u0 + u1 + u2 + u3 := by simp [u0, u1, u2, u3, hu, add_assoc] -- expand determinant using linearity in the updated row rw [hdet, hu'] have h3 : (Matrix.updateRow M 0 (u0 + u1 + u2 + u3)).det = (Matrix.updateRow M 0 (u0 + u1 + u2)).det + (Matrix.updateRow M 0 u3).det := by simpa [add_assoc] using (Matrix.det_updateRow_add M 0 (u0 + u1 + u2) u3) rw [h3] have h2 : (Matrix.updateRow M 0 (u0 + u1 + u2)).det = (Matrix.updateRow M 0 (u0 + u1)).det + (Matrix.updateRow M 0 u2).det := by simpa [add_assoc] using (Matrix.det_updateRow_add M 0 (u0 + u1) u2) rw [h2] have h1 : (Matrix.updateRow M 0 (u0 + u1)).det = (Matrix.updateRow M 0 u0).det + (Matrix.updateRow M 0 u1).det := by simpa using (Matrix.det_updateRow_add M 0 u0 u1) rw [h1] -- scale out coefficients have hs0 : (Matrix.updateRow M 0 u0).det = (x^2 + y^2) * A := by simp [u0, A, coefA, baseMat, M, Matrix.det_updateRow_smul] have hs1 : (Matrix.updateRow M 0 u1).det = x * B := by simp [u1, B, coefB, baseMat, M, Matrix.det_updateRow_smul] have hs2 : (Matrix.updateRow M 0 u2).det = y * C := by simp [u2, C, coefC, baseMat, M, Matrix.det_updateRow_smul] have hs3 : (Matrix.updateRow M 0 u3).det = D := by simpa [u3, D, coefD, baseMat, M, Matrix.det_updateRow_smul] -- finish simp [hs0, hs1, hs2, hs3, A, B, C, D, mul_add, add_mul, add_assoc, add_comm, add_left_comm] ring /-- Membership in the explicit circle equation corresponds to vanishing of the determinant polynomial. -/ lemma mem_circleEq_iff (p1 p2 p3 : Pt) (p : Pt) : (circleEq p1 p2 p3).Mem p ↔ circlePoly p1 p2 p3 p.1 p.2 = 0 := by -- Expand `Mem` and rewrite using `circlePoly_eq`. -- This is purely definitional. simp [CircleEqScaled.CircleEq.Mem, circleEq, circlePoly_eq, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] end end DetCircleExplicit