These are the human proofs of Payne-Hanek argument reduction, at full length.
Payne-Hanek reduction returns the exact quadrant and an accurate reduced argument full
This proof shows: correctness.
Setting.x is a finite binary64 number with ∣x∣>fl(π/4). Write ∣x∣=M2E with M an integer, 0<M<253, and E≥−53. Write 2/π=∑i≥1bi2−i with bi∈{0,1}. The table holds b1,…,bN with N≥i1 for every exponent that occurs. P≥55 and Q≥1 are integers, and C is an integer with ∣C−2Qπ/2∣≤1/2. All of lines L2 to L8 except the last conversion in L8 are exact integer operations.
Theorem. Lines L1 to L10 return k∈{0,1,2,3} and floats rhi,rlo such that, for some integer j,
x=(4j+k)2π+r,r−2P+QFCσ≤253−P2π+2−Q−2,
where σ=sign(x), F is the value after line L7, and rhi=fl(σFC/2P+Q), rlo=fl(σFC/2P+Q−rhi). Also ∣FC/2P+Q∣≤π/4+2−Q−2.
Step 1 (the dropped head). Let H=∑1≤i<i0biM2E−i. If i0=1 the sum is empty. Otherwise i0=E−1, and each term has E−i≥2, so it is an integer multiple of M⋅4. In both cases H=4h for an integer h.
Step 2 (the window). By the definition in L4, W=∑i0≤i≤i1bi2i1−i. So
i0≤i≤i1∑biM2E−i=MW2E−i1=2PZ,
since i1−E=P. This is exact, because Z=MW is an exact integer product.
Step 3 (the dropped tail). Let T=∑i>i1biM2E−i. Then 0≤T≤M2E−i1∑t≥12−t=M2−P, and the inequality is strict because 2/π is irrational, so not all bi with i>i1 are 1. With M<253 this gives 0≤T<253−P.
Step 4 (the quadrant). Let Z=2PI+F0 with 0≤F0<2P, so L6 sets k0=Imod4 and F=F0. Steps 1 to 3 give
∣x∣π2=4h+I+2PF0+T.
If F0<2P−1, line L7 does nothing, and ∣x∣⋅2/π=4j′+k+F/2P+T with k=k0 and 4j′=4h+I−k0. If F0≥2P−1, line L7 sets k=(k0+1)mod4 and F=F0−2P. The same identity holds with I+F0/2P=(I+1)+F/2P. In both cases F/2P∈[−1/2,1/2), and 4j′+k is an integer congruent to k modulo 4. Multiply by π/2:
∣x∣=(4j′+k)2π+ρ,ρ=(2PF+T)2π.
This holds for whichever k is chosen. So k is never wrong: it is the quadrant that belongs to the returned reduced value.
Step 5 (the constant).2P+QFC−2PF2π=2P∣F∣⋅2Q∣C−2Qπ/2∣≤21⋅2Q+11=2−Q−2. With Step 3, ρ−2P+QFC≤T2π+2−Q−2<253−P2π+2−Q−2. Since ∣F∣/2P≤1/2, also ∣FC/2P+Q∣≤π/4+2−Q−2.
Step 6 (the sign). If x>0, take j=j′ and r=ρ. If x<0, then x=−∣x∣=(−4j′−k)2π−ρ. Write −4j′−k=4j+((−k)mod4) for an integer j. Line L9 returns (−k)mod4 and negates the reduced value, so r=−ρ, and the bound of Step 5 holds with σ=−1. Negation is exact in floating point, so negating rhi and rlo equals rounding the negated value under round to nearest. This proves the theorem.
Step 7 (the early exit). If ∣x∣≤fl(π/4), then ∣x∣<π/4, and (k,r)=(0,x) is exact with j=0.
Corollary (relative accuracy). The following fact is cited, not proved here: every binary64 x with ∣x∣>π/4 satisfies ∣r∣>2−62. Ng (1992) and Muller (2016, Chapter 11) obtained this by a continued-fraction search over all exponents. The smallest value, at x=6381956970095103⋅2797, is about 2−60.9. With P=Q=245, the bound of the theorem is below 2−190. Write r~=σFC/2P+Q. Then ∣r~−r∣<2−128∣r∣. The conversion in L8 gives rhi=fl(r~) and rlo=fl(r~−rhi), with no underflow because ∣r~∣>2−63. So ∣rhi+rlo−r~∣≤u∣r~−rhi∣≤u2∣r~∣ with u=2−53, and ∣rhi+rlo−r∣≤(2−106+2−127)∣r∣. ■