Average Error: 0.5 → 0.4
Time: 33.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)\]
\[\left(\cos th \cdot \mathsf{hypot}\left(a2, a1\right)\right) \cdot \frac{\mathsf{hypot}\left(a2, a1\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)
\left(\cos th \cdot \mathsf{hypot}\left(a2, a1\right)\right) \cdot \frac{\mathsf{hypot}\left(a2, a1\right)}{\sqrt{2}}
double f(double a1, double a2, double th) {
        double r3103203 = th;
        double r3103204 = cos(r3103203);
        double r3103205 = 2.0;
        double r3103206 = sqrt(r3103205);
        double r3103207 = r3103204 / r3103206;
        double r3103208 = a1;
        double r3103209 = r3103208 * r3103208;
        double r3103210 = r3103207 * r3103209;
        double r3103211 = a2;
        double r3103212 = r3103211 * r3103211;
        double r3103213 = r3103207 * r3103212;
        double r3103214 = r3103210 + r3103213;
        return r3103214;
}

double f(double a1, double a2, double th) {
        double r3103215 = th;
        double r3103216 = cos(r3103215);
        double r3103217 = a2;
        double r3103218 = a1;
        double r3103219 = hypot(r3103217, r3103218);
        double r3103220 = r3103216 * r3103219;
        double r3103221 = 2.0;
        double r3103222 = sqrt(r3103221);
        double r3103223 = r3103219 / r3103222;
        double r3103224 = r3103220 * r3103223;
        return r3103224;
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus th

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}}\]
  3. Using strategy rm
  4. Applied associate-/l*0.5

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

    \[\leadsto \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\frac{\sqrt{2}}{\color{blue}{1 \cdot \cos th}}}\]
  7. Applied *-un-lft-identity0.5

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

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

    \[\leadsto \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\color{blue}{\frac{\sqrt{1}}{1} \cdot \frac{\sqrt{2}}{\cos th}}}\]
  10. Applied add-sqr-sqrt0.5

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

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

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

    \[\leadsto \mathsf{hypot}\left(a2, a1\right) \cdot \color{blue}{\left(\cos th \cdot \frac{\mathsf{hypot}\left(a2, a1\right)}{\sqrt{2}}\right)}\]
  14. Using strategy rm
  15. Applied associate-*r*0.4

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

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

Reproduce

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