Average Error: 37.7 → 25.3
Time: 32.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.445373192608023995102518569819932542768 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left(y \cdot y + x \cdot x\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 -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\
\;\;\;\;-x\\

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

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

\end{array}
double f(double x, double y, double z) {
        double r33477287 = x;
        double r33477288 = r33477287 * r33477287;
        double r33477289 = y;
        double r33477290 = r33477289 * r33477289;
        double r33477291 = r33477288 + r33477290;
        double r33477292 = z;
        double r33477293 = r33477292 * r33477292;
        double r33477294 = r33477291 + r33477293;
        double r33477295 = sqrt(r33477294);
        return r33477295;
}

double f(double x, double y, double z) {
        double r33477296 = x;
        double r33477297 = -2.114597052343944e+96;
        bool r33477298 = r33477296 <= r33477297;
        double r33477299 = -r33477296;
        double r33477300 = 9.445373192608024e+93;
        bool r33477301 = r33477296 <= r33477300;
        double r33477302 = y;
        double r33477303 = r33477302 * r33477302;
        double r33477304 = r33477296 * r33477296;
        double r33477305 = r33477303 + r33477304;
        double r33477306 = z;
        double r33477307 = r33477306 * r33477306;
        double r33477308 = r33477305 + r33477307;
        double r33477309 = sqrt(r33477308);
        double r33477310 = r33477301 ? r33477309 : r33477296;
        double r33477311 = r33477298 ? r33477299 : r33477310;
        return r33477311;
}

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.7
Target25.8
Herbie25.3
\[\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 < -2.114597052343944e+96

    1. Initial program 54.0

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

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

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

    if -2.114597052343944e+96 < x < 9.445373192608024e+93

    1. Initial program 29.2

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

    if 9.445373192608024e+93 < x

    1. Initial program 53.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.114597052343943905521456364925785524812 \cdot 10^{96}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 9.445373192608023995102518569819932542768 \cdot 10^{93}:\\ \;\;\;\;\sqrt{\left(y \cdot y + x \cdot x\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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