Average Error: 0.5 → 0.5
Time: 27.4s
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 r105904 = th;
        double r105905 = cos(r105904);
        double r105906 = 2.0;
        double r105907 = sqrt(r105906);
        double r105908 = r105905 / r105907;
        double r105909 = a1;
        double r105910 = r105909 * r105909;
        double r105911 = r105908 * r105910;
        double r105912 = a2;
        double r105913 = r105912 * r105912;
        double r105914 = r105908 * r105913;
        double r105915 = r105911 + r105914;
        return r105915;
}

double f(double a1, double a2, double th) {
        double r105916 = th;
        double r105917 = cos(r105916);
        double r105918 = a1;
        double r105919 = a2;
        double r105920 = r105919 * r105919;
        double r105921 = fma(r105918, r105918, r105920);
        double r105922 = 2.0;
        double r105923 = sqrt(r105922);
        double r105924 = r105921 / r105923;
        double r105925 = r105917 * r105924;
        return r105925;
}

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