{"verdict":"pass","decl":"EuclideanGeometry.pompeiu","lean_source":"import Mathlib.Analysis.Complex.Norm\nimport Mathlib.Analysis.Normed.Affine.Simplex\nimport Mathlib.Geometry.Euclidean.Circumcenter\nimport Mathlib.Tactic.LinearCombination\n\n/-!\n# Pompeiu's theorem\n\nWe compute the Heron polynomial of the three distances in complex coordinates,\nthen use its factorization to obtain the triangle inequalities and the equality case.\n-/\n\nnamespace EuclideanGeometry\n\nopen Complex\n\n/-- The Heron polynomial, with squared lengths as inputs. -/\nprivate def heronPolynomial (a b c : ℝ) : ℝ :=\n  2 * (a * b + b * c + c * a) - (a ^ 2 + b ^ 2 + c ^ 2)\n\nprivate theorem heronPolynomial_factor (a b c : ℝ) :\n    heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2) =\n      (a + b + c) * (b + c - a) * (c + a - b) * (a + b - c) := by\n  unfold heronPolynomial\n  ring\n\nprivate theorem le_add_of_heronPolynomial_nonneg {a b c : ℝ} (hb : 0 ≤ b) (hc : 0 ≤ c)\n    (h : 0 ≤ heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2)) : a ≤ b + c := by\n  by_contra! hlt\n  have hsum : 0 < a + b + c := by linarith\n  have ha' : b + c - a < 0 := by linarith\n  have hb' : 0 < c + a - b := by linarith\n  have hc' : 0 < a + b - c := by linarith\n  rw [heronPolynomial_factor] at h\n  exact (not_lt_of_ge h)\n    (mul_neg_of_neg_of_pos (mul_neg_of_neg_of_pos (mul_neg_of_pos_of_neg hsum ha') hb') hc')\n\nprivate theorem heronPolynomial_normalized (p c o : ℂ)\n    (hc : normSq c = 1) (hc₁ : normSq (c - 1) = 1)\n    (ho₁ : normSq (o - 1) = normSq o) (hoc : normSq (o - c) = normSq o) :\n    heronPolynomial (normSq p) (normSq (p - 1)) (normSq (p - c)) =\n      3 * (normSq (p - o) - normSq o) ^ 2 := by\n  simp only [normSq_apply, sub_re, sub_im, one_re, one_im, sub_zero] at hc hc₁ ho₁ hoc\n  -- The third vertex is at squared distance one from both zero and one.\n  have hcre : c.re = 1 / 2 := by nlinarith only [hc, hc₁]\n  have hcim : c.im ^ 2 = 3 / 4 := by\n    rw [hcre] at hc\n    nlinarith only [hc]\n  -- Equidistance from the vertices determines the center in the same coordinates.\n  have hore : o.re = 1 / 2 := by nlinarith only [ho₁]\n  have hoc' : o.im * c.im = 1 / 4 := by\n    rw [hore, hcre] at hoc\n    nlinarith only [hoc, hcim]\n  have hcim_ne : c.im ≠ 0 := by\n    intro h\n    norm_num [h] at hcim\n  have hoim : o.im = c.im / 3 := by\n    apply mul_right_cancel₀ hcim_ne\n    nlinarith only [hoc', hcim]\n  have hpb : normSq (p - 1) = normSq p + (1 - 2 * p.re) := by\n    simp only [normSq_apply, sub_re, sub_im, one_re, one_im, sub_zero]\n    ring\n  have hpc : normSq (p - c) = normSq p + (1 - p.re - 2 * p.im * c.im) := by\n    simp only [normSq_apply, sub_re, sub_im, hcre]\n    nlinarith only [hcim]\n  have hpo : normSq (p - o) - normSq o = normSq p - p.re - 2 * p.im * c.im / 3 := by\n    simp only [normSq_apply, sub_re, sub_im, hore, hoim]\n    ring\n  rw [hpb, hpc, hpo, normSq_apply]\n  unfold heronPolynomial\n  linear_combination -(16 / 3 : ℝ) * p.im ^ 2 * hcim\n\nprivate theorem heronPolynomial_eq (A B C O P : ℂ) (hAB : A ≠ B)\n    (hCA : dist C A = dist B A) (hCB : dist C B = dist B A)\n    (hOB : dist O B = dist O A) (hOC : dist O C = dist O A) :\n    heronPolynomial (dist P A ^ 2) (dist P B ^ 2) (dist P C ^ 2) =\n      3 * (dist P O ^ 2 - dist O A ^ 2) ^ 2 := by\n  -- Translate A to zero and divide by the directed side from A to B.\n  let d := B - A\n  let f (z : ℂ) := (z - A) / d\n  have hd : d ≠ 0 := sub_ne_zero.mpr hAB.symm\n  have hn : normSq d ≠ 0 := fun h ↦ hd (normSq_eq_zero.mp h)\n  have hA : f A = 0 := by simp [f]\n  have hB : f B = 1 := div_self hd\n  have hscale (z w : ℂ) : normSq (f z - f w) * normSq d = dist z w ^ 2 := by\n    rw [← normSq_mul, dist_eq_norm, Complex.sq_norm, sub_mul]\n    simp only [f, div_mul_cancel₀ _ hd, sub_sub_sub_cancel_right]\n  have hside : normSq d = dist B A ^ 2 := by\n    simpa only [hA, hB, sub_zero, map_one, one_mul] using hscale B A\n  have hc : normSq (f C) = 1 := by\n    apply mul_right_cancel₀ hn\n    simpa only [hA, sub_zero, hCA, ← hside, one_mul] using hscale C A\n  have hc₁ : normSq (f C - 1) = 1 := by\n    apply mul_right_cancel₀ hn\n    simpa only [hB, hCB, ← hside, one_mul] using hscale C B\n  have ho₁ : normSq (f O - 1) = normSq (f O) := by\n    apply mul_right_cancel₀ hn\n    rw [← hB, hscale, ← sub_zero (f O), ← hA, hscale, hOB]\n  have hoc : normSq (f O - f C) = normSq (f O) := by\n    apply mul_right_cancel₀ hn\n    rw [hscale, ← sub_zero (f O), ← hA, hscale, hOC]\n  calc\n    heronPolynomial (dist P A ^ 2) (dist P B ^ 2) (dist P C ^ 2) =\n        heronPolynomial (normSq (f P)) (normSq (f P - 1)) (normSq (f P - f C)) *\n          normSq d ^ 2 := by\n      rw [← hscale P A, ← hscale P B, ← hscale P C, hA, hB, sub_zero]\n      unfold heronPolynomial\n      ring\n    _ = (3 * (normSq (f P - f O) - normSq (f O)) ^ 2) * normSq d ^ 2 := by\n      rw [heronPolynomial_normalized _ _ _ hc hc₁ ho₁ hoc]\n    _ = 3 * (dist P O ^ 2 - dist O A ^ 2) ^ 2 := by\n      rw [← hscale P O, ← hscale O A, hA, sub_zero]\n      ring\n\n/-- **Pompeiu's theorem** (Wikidata Q3534036).\n“ABC is an equilateral triangle of positive side in the Euclidean plane and P is ANY point of\nthe plane. Then PA, PB, PC satisfy the three weak triangle inequalities (they are the sides of a\ntriangle), and all three are strict if and only if P is not on the circumcircle of ABC; on the\ncircumcircle the largest distance equals the sum of the other two (vertices included).”\n\nHere the Euclidean plane is represented by `ℂ`, and `t` is an equilateral triangle.\nThe final disjunction records which distance is the sum of the other two. -/\ntheorem pompeiu (t : Affine.Triangle ℝ ℂ) (ht : t.Equilateral) (P : ℂ) :\n    let a := dist P (t.points 0)\n    let b := dist P (t.points 1)\n    let c := dist P (t.points 2)\n    (a ≤ b + c ∧ b ≤ c + a ∧ c ≤ a + b) ∧\n    ((a < b + c ∧ b < c + a ∧ c < a + b) ↔ P ∉ t.circumsphere) ∧\n    ((a = b + c ∨ b = c + a ∨ c = a + b) ↔ P ∈ t.circumsphere) := by\n  intro a b c\n  have hAB : t.points 0 ≠ t.points 1 := fun h ↦\n    (by decide : (0 : Fin 3) ≠ 1) (t.independent.injective h)\n  have hCA : dist (t.points 2) (t.points 0) = dist (t.points 1) (t.points 0) :=\n    ht.dist_eq (by decide) (by decide)\n  have hCB : dist (t.points 2) (t.points 1) = dist (t.points 1) (t.points 0) :=\n    ht.dist_eq (by decide) (by decide)\n  have hheron : heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2) =\n      3 * (dist P t.circumcenter ^ 2 - t.circumradius ^ 2) ^ 2 := by\n    simpa only [t.dist_circumcenter_eq_circumradius'] using\n      heronPolynomial_eq _ _ _ t.circumcenter P hAB hCA hCB\n        (by simp) (by simp)\n  have hnonneg : 0 ≤ heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2) := by\n    rw [hheron]\n    positivity\n  have ha : a ≤ b + c := le_add_of_heronPolynomial_nonneg dist_nonneg dist_nonneg hnonneg\n  have hb : b ≤ c + a := by\n    apply le_add_of_heronPolynomial_nonneg dist_nonneg dist_nonneg\n    convert hnonneg using 1\n    unfold heronPolynomial\n    ring\n  have hc : c ≤ a + b := by\n    apply le_add_of_heronPolynomial_nonneg dist_nonneg dist_nonneg\n    convert hnonneg using 1\n    unfold heronPolynomial\n    ring\n  have hsum : a + b + c ≠ 0 := by\n    have hab : 0 < dist (t.points 0) (t.points 1) := dist_pos.mpr hAB\n    have hab' : dist (t.points 0) (t.points 1) ≤ a + b := by\n      simpa only [dist_comm (t.points 0) P] using dist_triangle (t.points 0) P (t.points 1)\n    have hc₀ : 0 ≤ c := dist_nonneg\n    apply ne_of_gt\n    linarith\n  have heq : (a = b + c ∨ b = c + a ∨ c = a + b) ↔\n      heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2) = 0 := by\n    rw [heronPolynomial_factor]\n    simp only [mul_eq_zero, hsum, false_or, sub_eq_zero, @eq_comm ℝ (b + c) a,\n      @eq_comm ℝ (c + a) b, @eq_comm ℝ (a + b) c, or_assoc]\n  have hzero : heronPolynomial (a ^ 2) (b ^ 2) (c ^ 2) = 0 ↔ P ∈ t.circumsphere := by\n    simp [hheron, mem_sphere, sub_eq_zero, sq_eq_sq₀ dist_nonneg t.circumradius_nonneg]\n  have hdegen := heq.trans hzero\n  refine ⟨⟨ha, hb, hc⟩, ?_, hdegen⟩\n  rw [← hdegen, not_or, not_or]\n  exact ⟨fun h ↦ ⟨ne_of_lt h.1, ne_of_lt h.2.1, ne_of_lt h.2.2⟩,\n    fun h ↦ ⟨lt_of_le_of_ne ha h.1, lt_of_le_of_ne hb h.2.1, lt_of_le_of_ne hc h.2.2⟩⟩\n\nend EuclideanGeometry\n\n#print axioms EuclideanGeometry.pompeiu\n","source_sha256":"8b4912e3dfbe84664275a39e0a84d5a10bb3920cbf68af3231e11352610c364a","build_output":"'EuclideanGeometry.pompeiu' depends on axioms: [propext, Classical.choice, Quot.sound]\n","fidelity_review":"Compiled with Lean 4.36.0 / Mathlib fc4f59e (bundle archives matched fetch.json sha256), `lean -DautoImplicit=false`, ~4s, no errors, no warnings, no sorry/native_decide in source (grep count 0). Axioms: propext, Classical.choice, Quot.sound. Clause review: (1) Plane = C, a 2-dim Euclidean affine space (allowed by the vetted generality). (2) t : Affine.Triangle R C with t.Equilateral (Mathlib: all edges equal length). Triangle gives affine independence so vertices are distinct, hence positive side; hypotheses satisfiable (e.g. 0, 1, e^{i pi/3}); conversely every positive equilateral triple is independent, so no loss of generality. No orientation assumption. (3) P : C arbitrary, vertices/centre/circle included. (4) Conjunct 1: all three weak triangle inequalities. (5) Conjunct 2: all three strict iff P not in t.circumsphere (Mathlib circumcircle). (6) Conjunct 3: some distance equals the sum of the other two iff P on circumcircle; given the weak inequalities that distance is the largest; vertices covered since they lie on circumsphere. Not weaker, not vacuous; both directions of iff proved. Proof uses the identity 2(ab+bc+ca)-(a^2+b^2+c^2)=3(PO^2-R^2)^2 for squared distances, a correct known identity (checked by compiler). Style notes: `let` in statement acceptable; helpers private; narrow imports. Only stated for C, not EuclideanSpace R (Fin 2) or general 2-dim spaces (allowed by brief).","prior_work":[{"search":"Mathlib master docs/1000.yaml","url":"https://raw.githubusercontent.com/leanprover-community/mathlib4/master/docs/1000.yaml","finding":"Q3534036 is title-only (Pompeiu's theorem), no decl field."},{"search":"1000-missing page","url":"https://leanprover-community.github.io/1000-missing.html","finding":"Q3534036 Pompeiu's theorem is listed as missing."},{"search":"Mathlib sources of the bundle (local grep -ri pompeiu)","url":"https://github.com/leanprover-community/mathlib4","finding":"No match in Mathlib/ at fc4f59e."},{"search":"Loogle name search","url":"https://loogle.lean-lang.org/json?q=%22Pompeiu%22","finding":"0 declarations containing Pompeiu."},{"search":"Mathlib issues/PRs search Pompeiu","url":"https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+Pompeiu","finding":"total_count 0."},{"search":"GitHub issues search Pompeiu equilateral lean4","url":"https://api.github.com/search/issues?q=Pompeiu+equilateral+lean4","finding":"total_count 0."},{"search":"Third-party repo lean-genius (found by the original worker)","url":"https://raw.githubusercontent.com/rjwalters/lean-genius/482da62461a4c5e6ff770aa1f6f8e91155444de7/proofs/Proofs/PompeiuTheorem.lean","finding":"A file proves the weak inequality via the complex identity (p-a)(b-c)+(p-b)(c-a)+(p-c)(a-b)=0, with norm hypotheses (allows side 0). I read only its first part: it is the inequality without the circumcircle iff; not in Mathlib or the 1000+ list. UNVERIFIED whether the rest of that file proves the iff."},{"search":"Lean Zulip, GitHub code search, open-PR browsing in the UI","url":"https://leanprover.zulipchat.com","finding":"UNVERIFIED: not searched."}],"explanation":"Take an equilateral triangle ABC (an Affine.Triangle in the complex plane) and any point P. Normalize A to 0 and B to 1; then C and the circumcentre O have explicit coordinates. With a=PA^2, b=PB^2, c=PC^2 one gets 2(ab+bc+ca)-(a^2+b^2+c^2)=3(PO^2-R^2)^2, which factors as (PA+PB+PC)(PB+PC-PA)(PC+PA-PB)(PA+PB-PC). The right side is nonnegative, which forces each weak triangle inequality; it vanishes exactly when P is on the circumcircle, giving the equality case, and strictness otherwise.","database_entry":{"wikidata_id":"Q3534036","declaration":"EuclideanGeometry.pompeiu","file":"Pompeiu.lean","yaml":"Q3534036:\n  title: Pompeiu's theorem\n  decl: EuclideanGeometry.pompeiu"},"repairs":"None required. Optional for upstreaming: place under Mathlib/Geometry/Euclidean/, add a version for general 2-dimensional spaces or EuclideanSpace R (Fin 2), remove the trailing #print axioms.","sources":["https://leanprover-community.github.io/1000-missing.html","https://raw.githubusercontent.com/leanprover-community/mathlib4/master/docs/1000.yaml","https://loogle.lean-lang.org/json?q=%22Pompeiu%22","https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/fetch.json"]}