import Math.ApTangent import Math.ApTangentDet2 import Math.CircleEqScaled import Mathlib.Tactic.FinCases /-! # Connecting determinant circles with scaled circle equations (towards full formalization of [ajc59j]) This file provides a key bridge: * `ApTangentDet2.circlePoly` gives the determinant polynomial of the circle through three points. * `CircleEqScaled.CircleEq` packages a *scaled* circle equation $A(x^2+y^2)+Bx+Cy+D=0$. Using the coefficient extraction theorem from [qzbmbc], we build a `CircleEqScaled.CircleEq` whose equation agrees with the determinant polynomial, and prove that it contains the three defining points (using the repeated-row determinant argument). This is intended as infrastructure to remove the remaining `sorry` in `Math/ApTangent.lean`. -/ namespace ApTangentFormal noncomputable section open ApTangentDet2 abbrev Pt : Type := ℝ × ℝ /-- Determinant membership: the determinant-circle polynomial vanishes at its first defining point. -/ lemma circlePoly_self₁ (p1 p2 p3 : Pt) : circlePoly p1 p2 p3 p1.1 p1.2 = 0 := by have hrow : (circleMat p1 p2 p3 p1.1 p1.2) 0 = (circleMat p1 p2 p3 p1.1 p1.2) 1 := by funext j fin_cases j <;> simp [circleMat, sx] have : (circleMat p1 p2 p3 p1.1 p1.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := circleMat p1 p2 p3 p1.1 p1.2) (i_ne_j := by decide) hrow simpa [circlePoly] using this lemma circlePoly_self₂ (p1 p2 p3 : Pt) : circlePoly p1 p2 p3 p2.1 p2.2 = 0 := by have hrow : (circleMat p1 p2 p3 p2.1 p2.2) 0 = (circleMat p1 p2 p3 p2.1 p2.2) 2 := by funext j fin_cases j <;> simp [circleMat, sx] have : (circleMat p1 p2 p3 p2.1 p2.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := circleMat p1 p2 p3 p2.1 p2.2) (i_ne_j := by decide) hrow simpa [circlePoly] using this lemma circlePoly_self₃ (p1 p2 p3 : Pt) : circlePoly p1 p2 p3 p3.1 p3.2 = 0 := by have hrow : (circleMat p1 p2 p3 p3.1 p3.2) 0 = (circleMat p1 p2 p3 p3.1 p3.2) 3 := by funext j fin_cases j <;> simp [circleMat, sx] have : (circleMat p1 p2 p3 p3.1 p3.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := circleMat p1 p2 p3 p3.1 p3.2) (i_ne_j := by decide) hrow simpa [circlePoly] using this /-- For any three points, there exists a `CircleEqScaled.CircleEq` whose equation agrees with the associated determinant circle polynomial, hence contains the three points. No nondegeneracy is assumed; the resulting equation may represent a degenerate conic if the three points are collinear. -/ theorem exists_scaledCircle_through (p1 p2 p3 : Pt) : ∃ s : CircleEqScaled.CircleEq, s.Mem p1 ∧ s.Mem p2 ∧ s.Mem p3 := by classical rcases ApTangentDet2.circlePoly_eq_quadratic_linear (p1:=p1) (p2:=p2) (p3:=p3) with ⟨A, B, C, D, h⟩ refine ⟨⟨A, B, C, D⟩, ?_, ?_, ?_⟩ · -- p1 have hp : circlePoly p1 p2 p3 p1.1 p1.2 = 0 := circlePoly_self₁ p1 p2 p3 have hh : circlePoly p1 p2 p3 p1.1 p1.2 = A*(p1.1^2 + p1.2^2) + B*p1.1 + C*p1.2 + D := by simpa [pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using (h p1.1 p1.2) -- rewrite hp using hh -- `CircleEqScaled.CircleEq.Mem` matches the RHS expression. -- -- Note: `Mem` expects `A*(x^2+y^2)+...`, while hh uses `A*(x^2+y^2)` already. -- -- So we just rewrite. -- -- `simp` closes the arithmetic normalization. have : A * (p1.1 ^ 2 + p1.2 ^ 2) + B * p1.1 + C * p1.2 + D = 0 := by -- use hh to replace the LHS of hp simpa [hh] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this · -- p2 have hp : circlePoly p1 p2 p3 p2.1 p2.2 = 0 := circlePoly_self₂ p1 p2 p3 have hh : circlePoly p1 p2 p3 p2.1 p2.2 = A*(p2.1^2 + p2.2^2) + B*p2.1 + C*p2.2 + D := by simpa [pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using (h p2.1 p2.2) have : A * (p2.1 ^ 2 + p2.2 ^ 2) + B * p2.1 + C * p2.2 + D = 0 := by simpa [hh] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this · -- p3 have hp : circlePoly p1 p2 p3 p3.1 p3.2 = 0 := circlePoly_self₃ p1 p2 p3 have hh : circlePoly p1 p2 p3 p3.1 p3.2 = A*(p3.1^2 + p3.2^2) + B*p3.1 + C*p3.2 + D := by simpa [pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using (h p3.1 p3.2) have : A * (p3.1 ^ 2 + p3.2 ^ 2) + B * p3.1 + C * p3.2 + D = 0 := by simpa [hh] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this end end ApTangentFormal