Average Error: 0.5 → 0.4
Time: 50.2s
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{\left(a2 \cdot \cos th\right) \cdot a2}{\sqrt{2}} + \frac{a1 \cdot \cos th}{\sqrt{2}} \cdot a1\]
double f(double a1, double a2, double th) {
        double r5312401 = th;
        double r5312402 = cos(r5312401);
        double r5312403 = 2.0;
        double r5312404 = sqrt(r5312403);
        double r5312405 = r5312402 / r5312404;
        double r5312406 = a1;
        double r5312407 = r5312406 * r5312406;
        double r5312408 = r5312405 * r5312407;
        double r5312409 = a2;
        double r5312410 = r5312409 * r5312409;
        double r5312411 = r5312405 * r5312410;
        double r5312412 = r5312408 + r5312411;
        return r5312412;
}

double f(double a1, double a2, double th) {
        double r5312413 = a2;
        double r5312414 = th;
        double r5312415 = cos(r5312414);
        double r5312416 = r5312413 * r5312415;
        double r5312417 = r5312416 * r5312413;
        double r5312418 = 2.0;
        double r5312419 = sqrt(r5312418);
        double r5312420 = r5312417 / r5312419;
        double r5312421 = a1;
        double r5312422 = r5312421 * r5312415;
        double r5312423 = r5312422 / r5312419;
        double r5312424 = r5312423 * r5312421;
        double r5312425 = r5312420 + r5312424;
        return r5312425;
}

\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\frac{\left(a2 \cdot \cos th\right) \cdot a2}{\sqrt{2}} + \frac{a1 \cdot \cos th}{\sqrt{2}} \cdot a1

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. Using strategy rm
  3. Applied associate-*r*0.5

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left(\frac{\cos th}{\sqrt{2}} \cdot a2\right) \cdot a2}\]
  4. Taylor expanded around -inf 0.5

    \[\leadsto \color{blue}{\frac{{a1}^{2} \cdot \cos th}{\sqrt{2}}} + \left(\frac{\cos th}{\sqrt{2}} \cdot a2\right) \cdot a2\]
  5. Simplified0.5

    \[\leadsto \color{blue}{\frac{\cos th \cdot a1}{\frac{\sqrt{2}}{a1}}} + \left(\frac{\cos th}{\sqrt{2}} \cdot a2\right) \cdot a2\]
  6. Using strategy rm
  7. Applied associate-*l/0.4

    \[\leadsto \frac{\cos th \cdot a1}{\frac{\sqrt{2}}{a1}} + \color{blue}{\frac{\cos th \cdot a2}{\sqrt{2}}} \cdot a2\]
  8. Applied associate-*l/0.5

    \[\leadsto \frac{\cos th \cdot a1}{\frac{\sqrt{2}}{a1}} + \color{blue}{\frac{\left(\cos th \cdot a2\right) \cdot a2}{\sqrt{2}}}\]
  9. Using strategy rm
  10. Applied associate-/r/0.4

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

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

Reproduce

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