Average Error: 0.6 → 0.5
Time: 9.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{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 r120278 = th;
        double r120279 = cos(r120278);
        double r120280 = 2.0;
        double r120281 = sqrt(r120280);
        double r120282 = r120279 / r120281;
        double r120283 = a1;
        double r120284 = r120283 * r120283;
        double r120285 = r120282 * r120284;
        double r120286 = a2;
        double r120287 = r120286 * r120286;
        double r120288 = r120282 * r120287;
        double r120289 = r120285 + r120288;
        return r120289;
}

double f(double a1, double a2, double th) {
        double r120290 = th;
        double r120291 = cos(r120290);
        double r120292 = a1;
        double r120293 = a2;
        double r120294 = r120293 * r120293;
        double r120295 = fma(r120292, r120292, r120294);
        double r120296 = 2.0;
        double r120297 = sqrt(r120296);
        double r120298 = r120295 / r120297;
        double r120299 = r120291 * r120298;
        return r120299;
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus th

Derivation

  1. Initial program 0.6

    \[\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 2020039 +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))))