Average Error: 0.5 → 0.5
Time: 26.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 \mathsf{fma}\left(\frac{a1}{\sqrt{2}}, a1, \frac{a2 \cdot a2}{\sqrt{2}}\right)\]
\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 \mathsf{fma}\left(\frac{a1}{\sqrt{2}}, a1, \frac{a2 \cdot a2}{\sqrt{2}}\right)
double f(double a1, double a2, double th) {
        double r3144458 = th;
        double r3144459 = cos(r3144458);
        double r3144460 = 2.0;
        double r3144461 = sqrt(r3144460);
        double r3144462 = r3144459 / r3144461;
        double r3144463 = a1;
        double r3144464 = r3144463 * r3144463;
        double r3144465 = r3144462 * r3144464;
        double r3144466 = a2;
        double r3144467 = r3144466 * r3144466;
        double r3144468 = r3144462 * r3144467;
        double r3144469 = r3144465 + r3144468;
        return r3144469;
}

double f(double a1, double a2, double th) {
        double r3144470 = th;
        double r3144471 = cos(r3144470);
        double r3144472 = a1;
        double r3144473 = 2.0;
        double r3144474 = sqrt(r3144473);
        double r3144475 = r3144472 / r3144474;
        double r3144476 = a2;
        double r3144477 = r3144476 * r3144476;
        double r3144478 = r3144477 / r3144474;
        double r3144479 = fma(r3144475, r3144472, r3144478);
        double r3144480 = r3144471 * r3144479;
        return r3144480;
}

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

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

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

    \[\leadsto \cos th \cdot \color{blue}{\frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}}\]
  6. Taylor expanded around 0 0.5

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

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

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

Reproduce

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