Average Error: 0.5 → 0.5
Time: 6.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)\]
\[\left(\mathsf{hypot}\left(a1, a2\right) \cdot \cos th\right) \cdot \frac{\mathsf{hypot}\left(a1, 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)
\left(\mathsf{hypot}\left(a1, a2\right) \cdot \cos th\right) \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\sqrt{2}}
double f(double a1, double a2, double th) {
        double r76051 = th;
        double r76052 = cos(r76051);
        double r76053 = 2.0;
        double r76054 = sqrt(r76053);
        double r76055 = r76052 / r76054;
        double r76056 = a1;
        double r76057 = r76056 * r76056;
        double r76058 = r76055 * r76057;
        double r76059 = a2;
        double r76060 = r76059 * r76059;
        double r76061 = r76055 * r76060;
        double r76062 = r76058 + r76061;
        return r76062;
}

double f(double a1, double a2, double th) {
        double r76063 = a1;
        double r76064 = a2;
        double r76065 = hypot(r76063, r76064);
        double r76066 = th;
        double r76067 = cos(r76066);
        double r76068 = r76065 * r76067;
        double r76069 = 2.0;
        double r76070 = sqrt(r76069);
        double r76071 = r76065 / r76070;
        double r76072 = r76068 * r76071;
        return r76072;
}

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{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt0.5

    \[\leadsto \frac{\cos th \cdot \color{blue}{\left(\sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)} \cdot \sqrt{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}\right)}}{\sqrt{2}}\]
  5. Applied associate-*r*0.5

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

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

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

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

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

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

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

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

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

Reproduce

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