Average Error: 0.5 → 0.4
Time: 12.1s
Precision: binary64
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
\[\cos th \cdot \frac{\sqrt{\frac{1}{\sqrt{2}}} \cdot \mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}{\sqrt{\sqrt{2}}} \]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\cos th \cdot \frac{\sqrt{\frac{1}{\sqrt{2}}} \cdot \mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}{\sqrt{\sqrt{2}}}
(FPCore (a1 a2 th)
 :precision binary64
 (+
  (* (/ (cos th) (sqrt 2.0)) (* a1 a1))
  (* (/ (cos th) (sqrt 2.0)) (* a2 a2))))
(FPCore (a1 a2 th)
 :precision binary64
 (*
  (cos th)
  (/ (* (sqrt (/ 1.0 (sqrt 2.0))) (fma a2 a2 (* a1 a1))) (sqrt (sqrt 2.0)))))
double code(double a1, double a2, double th) {
	return ((cos(th) / sqrt(2.0)) * (a1 * a1)) + ((cos(th) / sqrt(2.0)) * (a2 * a2));
}
double code(double a1, double a2, double th) {
	return cos(th) * ((sqrt(1.0 / sqrt(2.0)) * fma(a2, a2, (a1 * a1))) / sqrt(sqrt(2.0)));
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus th

Derivation

  1. Initial program 0.5

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Simplified0.5

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  3. Applied add-sqr-sqrt_binary640.6

    \[\leadsto \cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\color{blue}{\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{2}}}} \]
  4. Applied associate-/r*_binary640.5

    \[\leadsto \cos th \cdot \color{blue}{\frac{\frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}} \]
  5. Taylor expanded in a1 around 0 0.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{\sqrt{\frac{1}{\sqrt{2}}} \cdot {a2}^{2} + {a1}^{2} \cdot \sqrt{\frac{1}{\sqrt{2}}}}}{\sqrt{\sqrt{2}}} \]
  6. Simplified0.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{\sqrt{\frac{1}{\sqrt{2}}} \cdot \mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}}{\sqrt{\sqrt{2}}} \]
  7. Final simplification0.4

    \[\leadsto \cos th \cdot \frac{\sqrt{\frac{1}{\sqrt{2}}} \cdot \mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}{\sqrt{\sqrt{2}}} \]

Reproduce

herbie shell --seed 2022004 
(FPCore (a1 a2 th)
  :name "Migdal et al, Equation (64)"
  :precision binary64
  (+ (* (/ (cos th) (sqrt 2.0)) (* a1 a1)) (* (/ (cos th) (sqrt 2.0)) (* a2 a2))))