Average Error: 38.0 → 25.7
Time: 13.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.98369446481531483 \cdot 10^{143}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -1.53786150967003364 \cdot 10^{-273}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.119152176003768 \cdot 10^{99}:\\ \;\;\;\;\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 -3.98369446481531483 \cdot 10^{143}:\\
\;\;\;\;-x\\

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

\mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.119152176003768 \cdot 10^{99}:\\
\;\;\;\;\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 r462085 = x;
        double r462086 = r462085 * r462085;
        double r462087 = y;
        double r462088 = r462087 * r462087;
        double r462089 = r462086 + r462088;
        double r462090 = z;
        double r462091 = r462090 * r462090;
        double r462092 = r462089 + r462091;
        double r462093 = sqrt(r462092);
        return r462093;
}

double f(double x, double y, double z) {
        double r462094 = x;
        double r462095 = -3.983694464815315e+143;
        bool r462096 = r462094 <= r462095;
        double r462097 = -r462094;
        double r462098 = -1.5378615096700336e-273;
        bool r462099 = r462094 <= r462098;
        double r462100 = r462094 * r462094;
        double r462101 = y;
        double r462102 = r462101 * r462101;
        double r462103 = r462100 + r462102;
        double r462104 = z;
        double r462105 = r462104 * r462104;
        double r462106 = r462103 + r462105;
        double r462107 = sqrt(r462106);
        double r462108 = -1.7754786637459033e-299;
        bool r462109 = r462094 <= r462108;
        double r462110 = 1.119152176003768e+99;
        bool r462111 = r462094 <= r462110;
        double r462112 = r462111 ? r462107 : r462094;
        double r462113 = r462109 ? r462104 : r462112;
        double r462114 = r462099 ? r462107 : r462113;
        double r462115 = r462096 ? r462097 : r462114;
        return r462115;
}

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.0
Target25.4
Herbie25.7
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \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 4 regimes
  2. if x < -3.983694464815315e+143

    1. Initial program 61.8

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified14.8

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

    if -3.983694464815315e+143 < x < -1.5378615096700336e-273 or -1.7754786637459033e-299 < x < 1.119152176003768e+99

    1. Initial program 29.2

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

    if -1.5378615096700336e-273 < x < -1.7754786637459033e-299

    1. Initial program 32.2

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

      \[\leadsto \color{blue}{z}\]

    if 1.119152176003768e+99 < x

    1. Initial program 54.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.98369446481531483 \cdot 10^{143}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -1.53786150967003364 \cdot 10^{-273}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le -1.77547866374590335 \cdot 10^{-299}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.119152176003768 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019199 
(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))))