## Generating Approximate Pythagorean Angles (ADDENDUM) – Simplified Method

In a recent post I described a method of generating the simplest primitive Pythagorean triple (a,b,c) where one of the angles of the triangle with sides a, b and c is θ° to within some (small) error bound Δθ°.

One of the steps was, given the cosine C of the angle [from step (2)]:

(3) Calculate the Farey ratio approximant …

$R = \sqrt{\dfrac{1-C}{1+C}}$

Now, that function

$f(C) = \sqrt{\dfrac{1-C}{1+C}}$

seemed semi-familiar, resembling functions that occur in trigonometric or hyperbolic identities.
An example is:

$\cos( \tan^{-1}(t)) = \sqrt{\dfrac{1}{t^2 + 1}}$

A little further investigation, and reading around, including the Wikipedia articles on trigonometric identities, and in particular on those of the tangent half-angle, revealed that the Farey ratio approximant does in fact correspond directly to a simple trigonometric function of the angle:

$\tan \left( \dfrac{\theta}{2} \right) = \dfrac{1 - \cos \theta}{\sin \theta} = \dfrac{1 - \cos \theta}{\sqrt{1 - \cos^2 \theta}} = \dfrac{\sqrt{(1 - \cos \theta)^2}}{\sqrt{(1 - \cos \theta)(1 + \cos \theta)}} = \sqrt{\dfrac{1 - \cos \theta}{1 + \cos \theta}}$

The slightly simplified method follows.

### The method (simplified)

(I use τ = 2π.)

Steps (1), (4) and (5) are essentially as before, and the variants of (4) described in the earlier post are likewise applicable as before. Step (2½) below replaces steps (2) and (3) in the earlier description.

(1) Convert the angles from degrees to radians:

θ = (θ°) × τ / 360
Δθ = (Δθ°) × τ / 360

(2½) Calculate the required half-tangent and its error bound:

$T = \tan \left( \dfrac{\theta}{2} \right)$
$\Delta T = \dfrac{\Delta \theta}{2 \cos^2 \left( \dfrac{\theta}{2} \right)}$

(4) Now iteratively generate Farey ratios to find numbers (u, v) such that (u/v) is ΔT-close to T:

Begin with u₀=0, v₀=1;
and u₂=1, v₂=1.

We have $\dfrac{u_0}{v_0} < T < \dfrac{u_2}{v_2}$

Produce the mediant (the ‘wrong sum’) u₁ = u₀ + u₂, v₁ = v₀ + v₂.

If $\left| \dfrac{u_1}{v_1} - T \right| \le \Delta T$
then (u₁,v₁) is the required (u,v)

Otherwise if $\dfrac{u_0}{v_0} \le T \le \dfrac{u_1}{v_1}$,
so let (u₁,v₁) be the new (u₂,v₂), and repeat

Otherwise $\dfrac{u_1}{v_1} \le T \le \dfrac{u_2}{v_2}$
so let (u₁,v₁) be the new (u₀,v₀), and repeat.

(5) Once the pair (u,v) has been obtained, then:

if u and v are both odd, then let:

a = (v² − u²) / 2,
b = uv,
c = (v² + u²) / 2

otherwise let:

a = v² − u²,
b = 2uv,
c = v² + u²

Now:

a⊥b,
a⊥c,
b⊥c;
a² + b² = c²; and
|cos−1(a/c) − θ| ≲ Δθ.