Average Error: 0.5 → 0.7
Time: 22.9s
Precision: 64
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\]
\[\frac{\mathsf{hypot}\left(a2, a1\right) \cdot \cos th}{\sqrt{\frac{2}{\mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}}}\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\frac{\mathsf{hypot}\left(a2, a1\right) \cdot \cos th}{\sqrt{\frac{2}{\mathsf{fma}\left(a2, a2, a1 \cdot a1\right)}}}
double f(double a1, double a2, double th) {
        double r54688 = th;
        double r54689 = cos(r54688);
        double r54690 = 2.0;
        double r54691 = sqrt(r54690);
        double r54692 = r54689 / r54691;
        double r54693 = a1;
        double r54694 = r54693 * r54693;
        double r54695 = r54692 * r54694;
        double r54696 = a2;
        double r54697 = r54696 * r54696;
        double r54698 = r54692 * r54697;
        double r54699 = r54695 + r54698;
        return r54699;
}

double f(double a1, double a2, double th) {
        double r54700 = a2;
        double r54701 = a1;
        double r54702 = hypot(r54700, r54701);
        double r54703 = th;
        double r54704 = cos(r54703);
        double r54705 = r54702 * r54704;
        double r54706 = 2.0;
        double r54707 = r54701 * r54701;
        double r54708 = fma(r54700, r54700, r54707);
        double r54709 = r54706 / r54708;
        double r54710 = sqrt(r54709);
        double r54711 = r54705 / r54710;
        return r54711;
}

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}{\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(\mathsf{hypot}\left(a2, a1\right) \cdot \cos th\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{\mathsf{hypot}\left(a2, a1\right) \cdot \cos th}{\frac{\sqrt{2}}{\sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}}}\]
  9. Simplified0.4

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

    \[\leadsto \frac{\mathsf{hypot}\left(a2, a1\right) \cdot \cos th}{\frac{\sqrt{2}}{\color{blue}{\sqrt{a2 \cdot a2 + a1 \cdot a1}}}}\]
  12. Applied sqrt-undiv0.7

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

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

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

Reproduce

herbie shell --seed 2019322 +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))))