The law of cosines
ProvedFamousTheorems.law_of_cosinesThe law of cosines (the generalized Pythagorean theorem).
For any three points of a Euclidean affine space,
Setting the angle to recovers the Pythagorean theorem, and the cosine term measures exactly how far from a right angle the triangle is: acute angles shorten the opposite side, obtuse angles lengthen it. Unlike the Pythagorean theorem this is an unconditional identity — it holds for every triple with no hypothesis at all — which makes it the basic tool for solving triangles from side–angle–side data.
Euclid II.12 and II.13 give the obtuse and acute cases geometrically, without trigonometry; the statement in terms of cosine is due to al-Kashi in the 15th century, and the law is still called the théorème d'Al-Kashi in French. In the abstract form here it is the expansion of together with the definition of the angle as of the normalized inner product, so it is the analytic content of the inner product itself.
Formalization note. ∠ p₁ p₂ p₃ is the unoriented angle at . The result is Mathlib's
EuclideanGeometry.dist_sq_eq_dist_sq_add_dist_sq_sub_two_mul_dist_mul_dist_mul_cos_angle.
import Mathlib
namespace FamousTheorems
open scoped EuclideanGeometry Real
theorem law_of_cosines
{V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V]
[MetricSpace P] [NormedAddTorsor V P]
(p₁ p₂ p₃ : P) :
dist p₁ p₃ * dist p₁ p₃ = dist p₁ p₂ * dist p₁ p₂ + dist p₃ p₂ * dist p₃ p₂ -
2 * dist p₁ p₂ * dist p₃ p₂ * Real.cos (∠ p₁ p₂ p₃) := by sorry
end FamousTheorems