Average Error: 0.5 → 0.8
Time: 1.2m
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}{\frac{\sqrt{2}}{\mathsf{fma}\left(a1, a1, \left(a2 \cdot a2\right)\right)}}\]
\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}{\frac{\sqrt{2}}{\mathsf{fma}\left(a1, a1, \left(a2 \cdot a2\right)\right)}}
double f(double a1, double a2, double th) {
        double r9883346 = th;
        double r9883347 = cos(r9883346);
        double r9883348 = 2.0;
        double r9883349 = sqrt(r9883348);
        double r9883350 = r9883347 / r9883349;
        double r9883351 = a1;
        double r9883352 = r9883351 * r9883351;
        double r9883353 = r9883350 * r9883352;
        double r9883354 = a2;
        double r9883355 = r9883354 * r9883354;
        double r9883356 = r9883350 * r9883355;
        double r9883357 = r9883353 + r9883356;
        return r9883357;
}

double f(double a1, double a2, double th) {
        double r9883358 = th;
        double r9883359 = cos(r9883358);
        double r9883360 = 2.0;
        double r9883361 = sqrt(r9883360);
        double r9883362 = a1;
        double r9883363 = a2;
        double r9883364 = r9883363 * r9883363;
        double r9883365 = fma(r9883362, r9883362, r9883364);
        double r9883366 = r9883361 / r9883365;
        double r9883367 = r9883359 / r9883366;
        return r9883367;
}

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.8

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

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

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

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

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

Reproduce

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