Average Error: 0.5 → 0.4
Time: 33.7s
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 r3103801 = th;
        double r3103802 = cos(r3103801);
        double r3103803 = 2.0;
        double r3103804 = sqrt(r3103803);
        double r3103805 = r3103802 / r3103804;
        double r3103806 = a1;
        double r3103807 = r3103806 * r3103806;
        double r3103808 = r3103805 * r3103807;
        double r3103809 = a2;
        double r3103810 = r3103809 * r3103809;
        double r3103811 = r3103805 * r3103810;
        double r3103812 = r3103808 + r3103811;
        return r3103812;
}

double f(double a1, double a2, double th) {
        double r3103813 = th;
        double r3103814 = cos(r3103813);
        double r3103815 = a2;
        double r3103816 = a1;
        double r3103817 = hypot(r3103815, r3103816);
        double r3103818 = r3103814 * r3103817;
        double r3103819 = 2.0;
        double r3103820 = sqrt(r3103819);
        double r3103821 = r3103817 / r3103820;
        double r3103822 = r3103818 * r3103821;
        return r3103822;
}

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