Average Error: 0.5 → 0.5
Time: 43.9s
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{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}} \cdot \cos th\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}} \cdot \cos th
double f(double a1, double a2, double th) {
        double r2564905 = th;
        double r2564906 = cos(r2564905);
        double r2564907 = 2.0;
        double r2564908 = sqrt(r2564907);
        double r2564909 = r2564906 / r2564908;
        double r2564910 = a1;
        double r2564911 = r2564910 * r2564910;
        double r2564912 = r2564909 * r2564911;
        double r2564913 = a2;
        double r2564914 = r2564913 * r2564913;
        double r2564915 = r2564909 * r2564914;
        double r2564916 = r2564912 + r2564915;
        return r2564916;
}

double f(double a1, double a2, double th) {
        double r2564917 = a1;
        double r2564918 = a2;
        double r2564919 = r2564918 * r2564918;
        double r2564920 = fma(r2564917, r2564917, r2564919);
        double r2564921 = 2.0;
        double r2564922 = sqrt(r2564921);
        double r2564923 = r2564920 / r2564922;
        double r2564924 = th;
        double r2564925 = cos(r2564924);
        double r2564926 = r2564923 * r2564925;
        return r2564926;
}

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, a2 \cdot a2\right)}}}\]
  3. Using strategy rm
  4. Applied div-inv0.8

    \[\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. Final simplification0.5

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

Reproduce

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