# Dijkstra extends Pythagoras

Suppose a triangle has sides a, b, and c. Label the angles opposite these three sides α, β, and γ respectively.

Edsger Dijkstra published (EWD975) a note proving the following extension of the Pythagorean theorem:

sgn(α + β – γ) = sgn(a² + b² – c²).

Here the sgn function is -1, 0, or 1 depending on whether its input is negative, zero, or positive.

To see that this really is an extension of the Pythagorean theorem, if γ is a right angle, then α + β = γ and so the sgn on the left hand side evaluates to 0. This forces the right hand side to 0, which says a² + b² = c².

As Dijkstra points out, his is a theorem about triangles, not simply a theorem about right triangles.

## 3 thoughts on “Dijkstra extends Pythagoras”

1. I’m not sure if this way of looking at it is useful, since the cosine law has strictly more information.

Since α + β + γ = π, we can rewrite the left hand side as sgn(π – 2γ). And we can use the cosine rule to rewrite the left hand side as sgn(-2ab cos(γ)). Since multiplying by a negative constant flips the sign we can rewrite as

sgn(γ – π/2) = sgn(cos(γ))

and of course this is true in the range 0 < γ < π, which γ must fall in by the convention of how we describe angles in triangles.

2. Marnix Klooster

Yes! More EWD-related posts please! Thanks! :-)