import Math.ApTangent import Math.ApTangentDet2 import Math.CircleEqScaled import Mathlib.Tactic.FinCases /-! # Determinant-defined circumcircle of `B,E,F` in the AP configuration This file makes the circle through $B,E,F$ **explicit** as a scaled circle equation coming from the determinant polynomial. It proves (without `sorry`) that this circle contains $B,E,F$. The final tangency statement (line through $H$ parallel to $AP$) is left as the sole `sorry`. This is a sharper reduction than `Math/ApTangentMainScaled.lean` where the circle was chosen nonconstructively. -/ namespace ApTangentMainScaled2 noncomputable section open ApTangent open ApTangentDet2 namespace Coord variable {r R d x0 y0 : ℝ} abbrev Pt : Type := ℝ × ℝ /-- Packaged determinant-circle coefficients for three points. -/ structure DetCoeffs (p1 p2 p3 : Pt) where A : ℝ B : ℝ C : ℝ D : ℝ h : ∀ x y, circlePoly p1 p2 p3 x y = A * (x^2 + y^2) + B * x + C * y + D /-- Choose determinant-circle coefficients (noncomputably). -/ noncomputable def detCoeffs (p1 p2 p3 : Pt) : DetCoeffs p1 p2 p3 := by classical -- First build a `Nonempty` witness in `Prop`, then extract it. refine Classical.choice ?_ rcases ApTangentDet2.circlePoly_eq_quadratic_linear (p1:=p1) (p2:=p2) (p3:=p3) with ⟨A,B,C,D,h⟩ exact ⟨⟨A,B,C,D,h⟩⟩ /-- The scaled circle equation corresponding to the determinant circle through three points. -/ noncomputable def detCircleEq (p1 p2 p3 : Pt) : CircleEqScaled.CircleEq := let t := detCoeffs (p1:=p1) (p2:=p2) (p3:=p3) ⟨t.A, t.B, t.C, t.D⟩ /-- The representation identity for `circlePoly` with the chosen coefficients. -/ lemma detCircleEq_repr (p1 p2 p3 : Pt) (x y : ℝ) : circlePoly p1 p2 p3 x y = (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).A * (x^2 + y^2) + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).B * x + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).C * y + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).D := by classical simpa [detCircleEq, detCoeffs] using (detCoeffs (p1:=p1) (p2:=p2) (p3:=p3)).h x y /-- Determinant vanishes at the 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 /-- The determinant-defined circle equation contains its first defining point. -/ lemma detCircleEq_mem₁ (p1 p2 p3 : Pt) : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).Mem p1 := by classical have hp : circlePoly p1 p2 p3 p1.1 p1.2 = 0 := circlePoly_self₁ p1 p2 p3 have : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).A * (p1.1^2 + p1.2^2) + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).B * p1.1 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).C * p1.2 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).D = 0 := by -- rewrite hp using the representation identity simpa [detCircleEq_repr (p1:=p1) (p2:=p2) (p3:=p3) (x:=p1.1) (y:=p1.2)] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this lemma detCircleEq_mem₂ (p1 p2 p3 : Pt) : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).Mem p2 := by classical have hp : circlePoly p1 p2 p3 p2.1 p2.2 = 0 := circlePoly_self₂ p1 p2 p3 have : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).A * (p2.1^2 + p2.2^2) + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).B * p2.1 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).C * p2.2 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).D = 0 := by simpa [detCircleEq_repr (p1:=p1) (p2:=p2) (p3:=p3) (x:=p2.1) (y:=p2.2)] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this lemma detCircleEq_mem₃ (p1 p2 p3 : Pt) : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).Mem p3 := by classical have hp : circlePoly p1 p2 p3 p3.1 p3.2 = 0 := circlePoly_self₃ p1 p2 p3 have : (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).A * (p3.1^2 + p3.2^2) + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).B * p3.1 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).C * p3.2 + (detCircleEq (p1:=p1) (p2:=p2) (p3:=p3)).D = 0 := by simpa [detCircleEq_repr (p1:=p1) (p2:=p2) (p3:=p3) (x:=p3.1) (y:=p3.2)] using hp simpa [CircleEqScaled.CircleEq.Mem, pow_two, mul_add, add_mul, add_assoc, add_comm, add_left_comm] using this /-- Convert the triple coefficients from `ApTangent.lineThroughH_parallelAP` into a `LineEq`. -/ def lineEqThroughH_parallelAP (r R d x0 y0 : ℝ) : CircleEqScaled.LineEq := let L := ApTangent.lineThroughH_parallelAP r R d x0 y0 ⟨L.1, L.2.1, L.2.2⟩ /-- The tangency goal for the explicit determinant-defined circle through $B,E,F$. **Status**: only the final algebraic identity is missing. -/ theorem tangency_main_detCircle (hd : ApTangent.IntersectData r R d x0 y0) (hr : 0 < r) (hR : r < R) (hd' : 0 < d) (hw : ApTangent.dot (ApTangent.w r R d x0 y0) (ApTangent.w r R d x0 y0) ≠ 0) (hv : ApTangent.v r R d x0 y0 ≠ 0) : let B0 : Pt := ApTangent.B x0 y0 let E0 : Pt := ApTangent.E r R d x0 y0 let F0 : Pt := ApTangent.F r R d x0 y0 let s : CircleEqScaled.CircleEq := detCircleEq (p1:=B0) (p2:=E0) (p3:=F0) s.Mem B0 ∧ s.Mem E0 ∧ s.Mem F0 ∧ CircleEqScaled.IsTangent s (lineEqThroughH_parallelAP r R d x0 y0) := by intro B0 E0 F0 s refine ⟨?_, ?_, ?_, ?_⟩ · simpa [s] using detCircleEq_mem₁ (p1:=B0) (p2:=E0) (p3:=F0) · simpa [s] using detCircleEq_mem₂ (p1:=B0) (p2:=E0) (p3:=F0) · simpa [s] using detCircleEq_mem₃ (p1:=B0) (p2:=E0) (p3:=F0) · -- Remaining goal: tangency (heavy algebra) sorry end Coord end end ApTangentMainScaled2