Average Error: 37.3 → 25.5
Time: 5.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r519731 = x;
        double r519732 = r519731 * r519731;
        double r519733 = y;
        double r519734 = r519733 * r519733;
        double r519735 = r519732 + r519734;
        double r519736 = z;
        double r519737 = r519736 * r519736;
        double r519738 = r519735 + r519737;
        double r519739 = sqrt(r519738);
        return r519739;
}

double f(double x, double y, double z) {
        double r519740 = x;
        double r519741 = -1.472200864118953e+97;
        bool r519742 = r519740 <= r519741;
        double r519743 = -r519740;
        double r519744 = 9.739776979507706e+134;
        bool r519745 = r519740 <= r519744;
        double r519746 = r519740 * r519740;
        double r519747 = y;
        double r519748 = r519747 * r519747;
        double r519749 = r519746 + r519748;
        double r519750 = z;
        double r519751 = r519750 * r519750;
        double r519752 = r519749 + r519751;
        double r519753 = sqrt(r519752);
        double r519754 = r519745 ? r519753 : r519740;
        double r519755 = r519742 ? r519743 : r519754;
        return r519755;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original37.3
Target24.7
Herbie25.5
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.472200864118953e+97

    1. Initial program 55.7

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Taylor expanded around -inf 19.7

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified19.7

      \[\leadsto \color{blue}{-x}\]

    if -1.472200864118953e+97 < x < 9.739776979507706e+134

    1. Initial program 28.8

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]

    if 9.739776979507706e+134 < x

    1. Initial program 59.9

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Taylor expanded around inf 15.2

      \[\leadsto \color{blue}{x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.472200864118953065071901202153872070472 \cdot 10^{97}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.739776979507705930755011088832346945497 \cdot 10^{134}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019303 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))