Average Error: 0.5 → 0.5
Time: 22.7s
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{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\frac{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}
double f(double a1, double a2, double th) {
        double r62288 = th;
        double r62289 = cos(r62288);
        double r62290 = 2.0;
        double r62291 = sqrt(r62290);
        double r62292 = r62289 / r62291;
        double r62293 = a1;
        double r62294 = r62293 * r62293;
        double r62295 = r62292 * r62294;
        double r62296 = a2;
        double r62297 = r62296 * r62296;
        double r62298 = r62292 * r62297;
        double r62299 = r62295 + r62298;
        return r62299;
}

double f(double a1, double a2, double th) {
        double r62300 = th;
        double r62301 = cos(r62300);
        double r62302 = a1;
        double r62303 = a2;
        double r62304 = r62303 * r62303;
        double r62305 = fma(r62302, r62302, r62304);
        double r62306 = r62301 * r62305;
        double r62307 = 2.0;
        double r62308 = sqrt(r62307);
        double r62309 = r62306 / r62308;
        return r62309;
}

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-cube-cbrt0.5

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

    \[\leadsto \color{blue}{\frac{\frac{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt[3]{\sqrt{2}} \cdot \sqrt[3]{\sqrt{2}}}}{\sqrt[3]{\sqrt{2}}}}\]
  6. Using strategy rm
  7. Applied div-inv0.6

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

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

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

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

Reproduce

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