Average Error: 38.2 → 25.6
Time: 10.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.305761339015559 \cdot 10^{+151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.2252148173535669 \cdot 10^{+38}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -6.305761339015559 \cdot 10^{+151}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r31130751 = x;
        double r31130752 = r31130751 * r31130751;
        double r31130753 = y;
        double r31130754 = r31130753 * r31130753;
        double r31130755 = r31130752 + r31130754;
        double r31130756 = z;
        double r31130757 = r31130756 * r31130756;
        double r31130758 = r31130755 + r31130757;
        double r31130759 = sqrt(r31130758);
        return r31130759;
}

double f(double x, double y, double z) {
        double r31130760 = x;
        double r31130761 = -6.305761339015559e+151;
        bool r31130762 = r31130760 <= r31130761;
        double r31130763 = -r31130760;
        double r31130764 = 1.2252148173535669e+38;
        bool r31130765 = r31130760 <= r31130764;
        double r31130766 = z;
        double r31130767 = r31130766 * r31130766;
        double r31130768 = y;
        double r31130769 = r31130768 * r31130768;
        double r31130770 = r31130760 * r31130760;
        double r31130771 = r31130769 + r31130770;
        double r31130772 = r31130767 + r31130771;
        double r31130773 = sqrt(r31130772);
        double r31130774 = r31130765 ? r31130773 : r31130760;
        double r31130775 = r31130762 ? r31130763 : r31130774;
        return r31130775;
}

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

Original38.2
Target26.0
Herbie25.6
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182 \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 < -6.305761339015559e+151

    1. Initial program 63.4

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

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

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

    if -6.305761339015559e+151 < x < 1.2252148173535669e+38

    1. Initial program 29.3

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

    if 1.2252148173535669e+38 < x

    1. Initial program 49.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.305761339015559 \cdot 10^{+151}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.2252148173535669 \cdot 10^{+38}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

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