Average Error: 0.5 → 0.5
Time: 27.5s
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{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)
\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}
double f(double a1, double a2, double th) {
        double r87281 = th;
        double r87282 = cos(r87281);
        double r87283 = 2.0;
        double r87284 = sqrt(r87283);
        double r87285 = r87282 / r87284;
        double r87286 = a1;
        double r87287 = r87286 * r87286;
        double r87288 = r87285 * r87287;
        double r87289 = a2;
        double r87290 = r87289 * r87289;
        double r87291 = r87285 * r87290;
        double r87292 = r87288 + r87291;
        return r87292;
}

double f(double a1, double a2, double th) {
        double r87293 = th;
        double r87294 = cos(r87293);
        double r87295 = a1;
        double r87296 = a2;
        double r87297 = r87296 * r87296;
        double r87298 = fma(r87295, r87295, r87297);
        double r87299 = 2.0;
        double r87300 = sqrt(r87299);
        double r87301 = r87298 / r87300;
        double r87302 = r87294 * r87301;
        return r87302;
}

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 *-un-lft-identity0.5

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

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

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

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

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

Reproduce

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