import Math.ApTangent import Math.ApTangentDet2 import Math.CircleEqScaled import Math.DetCircleExplicit import Mathlib.Tactic.FinCases /-! # Determinant-defined circumcircle of `B,E,F` in the AP configuration (explicit coefficients) This file constructs the circle through $B,E,F$ explicitly using determinant coefficients (`Math/DetCircleExplicit.lean`), packaged as a `CircleEqScaled.CircleEq`. 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`. -/ namespace ApTangentMainScaled2 noncomputable section open ApTangent namespace Coord variable {r R d x0 y0 : ℝ} abbrev Pt : Type := ℝ × ℝ /-- The explicit determinant-defined scaled circle equation through three points. -/ abbrev detCircleEq (p1 p2 p3 : Pt) : CircleEqScaled.CircleEq := DetCircleExplicit.circleEq p1 p2 p3 /-- 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 explicit determinant-defined circle equation contains its three defining points. -/ lemma detCircleEq_mem₁ (p1 p2 p3 : Pt) : (detCircleEq p1 p2 p3).Mem p1 := by -- translate to determinant vanishing have : ApTangentDet2.circlePoly p1 p2 p3 p1.1 p1.2 = 0 := by -- repeated-row determinant have hrow : (ApTangentDet2.circleMat p1 p2 p3 p1.1 p1.2) 0 = (ApTangentDet2.circleMat p1 p2 p3 p1.1 p1.2) 1 := by funext j fin_cases j <;> simp [ApTangentDet2.circleMat, ApTangentDet2.sx] have : (ApTangentDet2.circleMat p1 p2 p3 p1.1 p1.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := ApTangentDet2.circleMat p1 p2 p3 p1.1 p1.2) (i_ne_j := by decide) hrow simpa [ApTangentDet2.circlePoly] using this -- now use the equivalence lemma have hmem : (detCircleEq p1 p2 p3).Mem p1 := by have := (DetCircleExplicit.mem_circleEq_iff (p1:=p1) (p2:=p2) (p3:=p3) (p:=p1)).2 this simpa [detCircleEq] using this exact hmem lemma detCircleEq_mem₂ (p1 p2 p3 : Pt) : (detCircleEq p1 p2 p3).Mem p2 := by have : ApTangentDet2.circlePoly p1 p2 p3 p2.1 p2.2 = 0 := by have hrow : (ApTangentDet2.circleMat p1 p2 p3 p2.1 p2.2) 0 = (ApTangentDet2.circleMat p1 p2 p3 p2.1 p2.2) 2 := by funext j fin_cases j <;> simp [ApTangentDet2.circleMat, ApTangentDet2.sx] have : (ApTangentDet2.circleMat p1 p2 p3 p2.1 p2.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := ApTangentDet2.circleMat p1 p2 p3 p2.1 p2.2) (i_ne_j := by decide) hrow simpa [ApTangentDet2.circlePoly] using this have := (DetCircleExplicit.mem_circleEq_iff (p1:=p1) (p2:=p2) (p3:=p3) (p:=p2)).2 this simpa [detCircleEq] using this lemma detCircleEq_mem₃ (p1 p2 p3 : Pt) : (detCircleEq p1 p2 p3).Mem p3 := by have : ApTangentDet2.circlePoly p1 p2 p3 p3.1 p3.2 = 0 := by have hrow : (ApTangentDet2.circleMat p1 p2 p3 p3.1 p3.2) 0 = (ApTangentDet2.circleMat p1 p2 p3 p3.1 p3.2) 3 := by funext j fin_cases j <;> simp [ApTangentDet2.circleMat, ApTangentDet2.sx] have : (ApTangentDet2.circleMat p1 p2 p3 p3.1 p3.2).det = 0 := by simpa [hrow] using Matrix.det_zero_of_row_eq (M := ApTangentDet2.circleMat p1 p2 p3 p3.1 p3.2) (i_ne_j := by decide) hrow simpa [ApTangentDet2.circlePoly] using this have := (DetCircleExplicit.mem_circleEq_iff (p1:=p1) (p2:=p2) (p3:=p3) (p:=p3)).2 this simpa [detCircleEq] using this /-- Tangency goal using the explicit determinant-defined circumcircle of $B,E,F$. **Status**: only the final tangency 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 B0 E0 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