import Mathlib.Data.Real.Basic import Mathlib.Tactic.Ring import Mathlib.Tactic.Linarith /-! # Tangency line parallel to AP (coordinate setup) This file contains an **analytic coordinate skeleton** for the geometry problem: > Two intersecting circles $\Omega,\Gamma$ with centers $M,N$; various derived > points $C,D,P,E,F,H$; prove the line through $H$ parallel to $AP$ is tangent > to the circumcircle of $\triangle BEF$. We normalize to coordinates in $\mathbb R^2$ with * $M=(0,0)$, * $N=(d,0)$ with $d>0$, * $\Omega: x^2+y^2=r^2$, * $\Gamma: (x-d)^2+y^2=R^2$, and take an intersection point $A=(x_0,y_0)$ with $y_0\neq 0$. We then define * $B=(x_0,-y_0)$, * $C=(-r,0)$, * $D=(d+R,0)$, * $P$ = circumcenter of $\triangle ACD$ (computed explicitly), * $E,F$ = second intersections of line $AP$ with $\Omega,\Gamma$ (encoded using the standard chord intersection formula), * $H$ = orthocenter of $\triangle PMN$ (computed explicitly). The final tangency statement is left as `sorry` for now; however, the file is structured so that the remaining work is **pure algebra**. -/ namespace ApTangent noncomputable section /-- A point in the affine plane, represented as a pair of reals. -/ abbrev Pt : Type := ℝ × ℝ @[simp] lemma fst_mk (x y : ℝ) : (((x, y) : Pt).1) = x := rfl @[simp] lemma snd_mk (x y : ℝ) : (((x, y) : Pt).2) = y := rfl /-- Dot product for `Pt`. -/ def dot (p q : Pt) : ℝ := p.1 * q.1 + p.2 * q.2 /-- Squared norm for `Pt`. -/ def normSq (p : Pt) : ℝ := dot p p @[simp] lemma dot_def (p q : Pt) : dot p q = p.1*q.1 + p.2*q.2 := rfl @[simp] lemma normSq_def (p : Pt) : normSq p = p.1^2 + p.2^2 := by simp [normSq, dot, pow_two] /-- Translate a point by a vector (represented again as a `Pt`). -/ def add (p v : Pt) : Pt := (p.1 + v.1, p.2 + v.2) /-- Scale a vector (represented as `Pt`) by a scalar. -/ def smul (t : ℝ) (v : Pt) : Pt := (t * v.1, t * v.2) /-- Subtract two points, as a vector. -/ def sub (p q : Pt) : Pt := (p.1 - q.1, p.2 - q.2) @[simp] lemma sub_fst (p q : Pt) : (sub p q).1 = p.1 - q.1 := rfl @[simp] lemma sub_snd (p q : Pt) : (sub p q).2 = p.2 - q.2 := rfl /-- A line through `p` in direction `v`: parametric form `p + t v`. -/ def line (p v : Pt) (t : ℝ) : Pt := add p (smul t v) /-- Circle of radius `ρ` centered at the origin, as an equation. -/ def onCircle0 (ρ : ℝ) (p : Pt) : Prop := normSq p = ρ^2 /-- Circle of radius `ρ` centered at `(d,0)`. -/ def onCircleN (d ρ : ℝ) (p : Pt) : Prop := (let q : Pt := sub p (d, 0); normSq q = ρ^2) section Coordinates variable {r R d x0 y0 : ℝ} -- Basic points abbrev M : Pt := (0, 0) abbrev N (d : ℝ) : Pt := (d, 0) abbrev A (x0 y0 : ℝ) : Pt := (x0, y0) abbrev B (x0 y0 : ℝ) : Pt := (x0, -y0) abbrev C (r : ℝ) : Pt := (-r, 0) abbrev D (d R : ℝ) : Pt := (d + R, 0) /-- Coordinate relations for $A$ lying on both circles. -/ structure IntersectData (r R d x0 y0 : ℝ) : Prop where hy0 : y0 ≠ 0 hΩ : onCircle0 r (A x0 y0) hΓ : onCircleN d R (A x0 y0) /-- The computed x-coordinate of the circumcenter of `A C D`. -/ def u (r R d : ℝ) : ℝ := (d + R - r) / 2 /-- The computed y-coordinate of the circumcenter of `A C D`. This is obtained by using that `P` lies on the perpendicular bisector of `CD` (hence has x-coordinate `u`) and the equation `PA = PC`. -/ def v (r R d x0 y0 : ℝ) : ℝ := -(u r R d) * (x0 + r) / y0 /-- The circumcenter point $P$ of triangle $ACD$ in our coordinates. -/ def P (r R d x0 y0 : ℝ) : Pt := (u r R d, v r R d x0 y0) /-- Direction vector of line $AP$. -/ def w (r R d x0 y0 : ℝ) : Pt := sub (P r R d x0 y0) (A x0 y0) /-- Scalar parameter giving the *second* intersection of line $AP$ with $\Omega$. For a circle centered at the origin: if $A$ is on the circle and $w\neq 0$, then the other intersection of $A + t w$ is given by $$t = -\frac{2\langle A, w\rangle}{\langle w, w\rangle}.$$ -/ def tE (r R d x0 y0 : ℝ) : ℝ := (let A0 : Pt := A x0 y0; let w0 : Pt := w r R d x0 y0; -2 * (dot A0 w0) / (dot w0 w0)) /-- The point $E$ (second intersection of $AP$ with $\Omega$) encoded algebraically. -/ def E (r R d x0 y0 : ℝ) : Pt := line (A x0 y0) (w r R d x0 y0) (tE r R d x0 y0) /-- Scalar parameter giving the *second* intersection of line $AP$ with $\Gamma$. -/ def tF (r R d x0 y0 : ℝ) : ℝ := (let AN : Pt := sub (A x0 y0) (N d); let w0 : Pt := w r R d x0 y0; -2 * (dot AN w0) / (dot w0 w0)) /-- The point $F$ (second intersection of $AP$ with $\Gamma$) encoded algebraically. -/ def F (r R d x0 y0 : ℝ) : Pt := line (A x0 y0) (w r R d x0 y0) (tF r R d x0 y0) /-- The orthocenter $H$ of triangle $P M N$ in these coordinates. Since $M,N$ lie on the $x$-axis, the altitude from $P$ is vertical, hence $x_H=u$. Intersecting with the altitude from $M$ gives the y-coordinate. -/ def H (r R d x0 y0 : ℝ) : Pt := (let u0 := u r R d; let v0 := v r R d x0 y0; (u0, -u0 * (u0 - d) / v0)) /-- A line through $H$ parallel to $AP$: in implicit form, it is the locus of points `X` such that `(X-H) × w = 0`. In coordinates we use the equivalent scalar equation $$(x-u)w_y - (y-y_H)w_x = 0.$$ We return coefficients `(a,b,c)` for an equation `a*x + b*y + c = 0`. -/ def lineThroughH_parallelAP (r R d x0 y0 : ℝ) : ℝ × ℝ × ℝ := (let w0 := w r R d x0 y0; let H0 := H r R d x0 y0; let a : ℝ := w0.2; let b : ℝ := -w0.1; let c : ℝ := -w0.2 * H0.1 + w0.1 * H0.2; (a, b, c)) /-! ## A small verified lemma We show the simplification used in the computation of `v`: $$(u-x_0)^2+y_0^2-(u+r)^2 = -2u(x_0+r).$$ This is a key step that makes later algebra manageable. -/ lemma key_simplification (u x0 y0 r : ℝ) (h : x0^2 + y0^2 = r^2) : (u - x0)^2 - (u + r)^2 + y0^2 = -2*u*(x0 + r) := by nlinarith [h] /- The final tangency statement, reduced to a pure algebraic identity. **Status**: TODO. The proof should proceed by: 1. writing the circumcircle of `B,E,F` in the form $x^2+y^2+\alpha x+\beta y+\gamma=0$; 2. expressing the center/radius in terms of $(\alpha,\beta,\gamma)$; 3. using the standard tangency criterion for a line $ax+by+c=0$; 4. substituting the explicit coordinates of `B,E,F,H,w`. The remaining work is substantial but does not involve new geometry. -/ /-- A circle in the plane, written in the standard algebraic form $$x^2+y^2+\alpha x+\beta y+\gamma=0.$$ -/ structure CircleEq where a : ℝ b : ℝ c : ℝ /-- A point lies on a `CircleEq`. -/ def CircleEq.Mem (c : CircleEq) (p : Pt) : Prop := p.1^2 + p.2^2 + c.a * p.1 + c.b * p.2 + c.c = 0 /-- The center of a `CircleEq`. -/ def CircleEq.center (c : CircleEq) : Pt := (-c.a / 2, -c.b / 2) /-- The squared radius of a `CircleEq` (may be negative if the coefficients are degenerate). -/ def CircleEq.radiusSq (c : CircleEq) : ℝ := (c.a^2 + c.b^2) / 4 - c.c /-- A line `a*x + b*y + c = 0`, represented by its coefficients. -/ abbrev LineEq : Type := ℝ × ℝ × ℝ /-- Evaluate a line equation at a point. -/ def LineEq.eval (L : LineEq) (p : Pt) : ℝ := L.1 * p.1 + L.2.1 * p.2 + L.2.2 /-- Tangency of a line to a circle expressed in algebraic form. If the circle has center $O$ and squared radius $\rho^2$, then tangency is the equality $$\mathrm{dist}(O,\ell)^2 = \rho^2.$$ For the line equation `a*x + b*y + c = 0`, the squared distance from $O$ is $$\frac{(aO_x+bO_y+c)^2}{a^2+b^2}.$$ We encode this equality, clearing denominators. -/ def isTangent (c : CircleEq) (L : LineEq) : Prop := let a : ℝ := L.1 let b : ℝ := L.2.1 let cL : ℝ := L.2.2 let O : Pt := c.center (a*O.1 + b*O.2 + cL)^2 = (a^2 + b^2) * c.radiusSq /-- **Main goal (coordinate form).** There exists a circle through $B,E,F$ such that the line through $H$ parallel to $AP$ is tangent to that circle. This theorem is the coordinate transcription of the original geometric claim. **Status**: the remaining proof is pure algebra; we leave it as `sorry` for now. -/ theorem tangency_main (hd : IntersectData r R d x0 y0) (hr : 0 < r) (hR : r < R) (hd' : 0 < d) -- extra nondegeneracy assumptions (to avoid division by 0) (hw : dot (w r R d x0 y0) (w r R d x0 y0) ≠ 0) (hv : v r R d x0 y0 ≠ 0) : ∃ c : CircleEq, c.Mem (B x0 y0) ∧ c.Mem (E r R d x0 y0) ∧ c.Mem (F r R d x0 y0) ∧ isTangent c (lineThroughH_parallelAP r R d x0 y0) := by -- TODO: solve for `c.a,c.b,c.c` from the three linear equations coming from the three points, -- then verify the tangency identity. -- This is exactly the computation described in the accompanying write-up. sorry end Coordinates end end ApTangent