Average Error: 0.5 → 0.4
Time: 12.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)\]
\[\mathsf{hypot}\left(a1, a2\right) \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\cos th}}\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\mathsf{hypot}\left(a1, a2\right) \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\cos th}}
double f(double a1, double a2, double th) {
        double r89515 = th;
        double r89516 = cos(r89515);
        double r89517 = 2.0;
        double r89518 = sqrt(r89517);
        double r89519 = r89516 / r89518;
        double r89520 = a1;
        double r89521 = r89520 * r89520;
        double r89522 = r89519 * r89521;
        double r89523 = a2;
        double r89524 = r89523 * r89523;
        double r89525 = r89519 * r89524;
        double r89526 = r89522 + r89525;
        return r89526;
}

double f(double a1, double a2, double th) {
        double r89527 = a1;
        double r89528 = a2;
        double r89529 = hypot(r89527, r89528);
        double r89530 = 2.0;
        double r89531 = sqrt(r89530);
        double r89532 = th;
        double r89533 = cos(r89532);
        double r89534 = r89531 / r89533;
        double r89535 = r89529 / r89534;
        double r89536 = r89529 * r89535;
        return r89536;
}

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

    \[\leadsto \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)} \cdot \frac{\cos th}{\sqrt{2}}\]
  5. Applied associate-*l*0.5

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

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

    \[\leadsto \sqrt{\color{blue}{a1 \cdot a1 + a2 \cdot a2}} \cdot \frac{\mathsf{hypot}\left(a1, a2\right)}{\frac{\sqrt{2}}{\cos th}}\]
  9. Applied hypot-def0.4

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

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

Reproduce

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