Average Error: 0.5 → 0.5
Time: 7.1s
Precision: 64
\[\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{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}\]
\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{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}
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) * (hypot(a1, a2) / (sqrt(2.0) / hypot(a1, a2))));
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus th

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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}{\frac{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt0.5

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

    \[\leadsto \frac{\color{blue}{\left(\cos th \cdot \sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}\right) \cdot \sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}}{\sqrt{2}}\]
  6. Simplified0.5

    \[\leadsto \frac{\color{blue}{\left(\cos th \cdot \mathsf{hypot}\left(a1, a2\right)\right)} \cdot \sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}}\]
  7. Using strategy rm
  8. Applied associate-/l*0.5

    \[\leadsto \color{blue}{\frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}}}\]
  9. Simplified0.5

    \[\leadsto \frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\color{blue}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}}\]
  10. Using strategy rm
  11. Applied *-un-lft-identity0.5

    \[\leadsto \frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\color{blue}{1 \cdot \mathsf{hypot}\left(a1, a2\right)}}}\]
  12. Applied *-un-lft-identity0.5

    \[\leadsto \frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{\color{blue}{1 \cdot 2}}}{1 \cdot \mathsf{hypot}\left(a1, a2\right)}}\]
  13. Applied sqrt-prod0.5

    \[\leadsto \frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\frac{\color{blue}{\sqrt{1} \cdot \sqrt{2}}}{1 \cdot \mathsf{hypot}\left(a1, a2\right)}}\]
  14. Applied times-frac0.5

    \[\leadsto \frac{\cos th \cdot \mathsf{hypot}\left(a1, a2\right)}{\color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}}\]
  15. Applied times-frac0.5

    \[\leadsto \color{blue}{\frac{\cos th}{\frac{\sqrt{1}}{1}} \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}}\]
  16. Simplified0.5

    \[\leadsto \color{blue}{\cos th} \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}\]
  17. Final simplification0.5

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

Reproduce

herbie shell --seed 2020106 +o rules:numerics
(FPCore (a1 a2 th)
  :name "Migdal et al, Equation (64)"
  :precision binary64
  (+ (* (/ (cos th) (sqrt 2)) (* a1 a1)) (* (/ (cos th) (sqrt 2)) (* a2 a2))))