Average Error: 37.6 → 25.0
Time: 8.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\ \;\;\;\;\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 -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\
\;\;\;\;\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 r16853492 = x;
        double r16853493 = r16853492 * r16853492;
        double r16853494 = y;
        double r16853495 = r16853494 * r16853494;
        double r16853496 = r16853493 + r16853495;
        double r16853497 = z;
        double r16853498 = r16853497 * r16853497;
        double r16853499 = r16853496 + r16853498;
        double r16853500 = sqrt(r16853499);
        return r16853500;
}

double f(double x, double y, double z) {
        double r16853501 = x;
        double r16853502 = -8.656892189523162e+102;
        bool r16853503 = r16853501 <= r16853502;
        double r16853504 = -r16853501;
        double r16853505 = 4.471707363468376e+118;
        bool r16853506 = r16853501 <= r16853505;
        double r16853507 = z;
        double r16853508 = r16853507 * r16853507;
        double r16853509 = y;
        double r16853510 = r16853509 * r16853509;
        double r16853511 = r16853501 * r16853501;
        double r16853512 = r16853510 + r16853511;
        double r16853513 = r16853508 + r16853512;
        double r16853514 = sqrt(r16853513);
        double r16853515 = r16853506 ? r16853514 : r16853501;
        double r16853516 = r16853503 ? r16853504 : r16853515;
        return r16853516;
}

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.6
Target25.3
Herbie25.0
\[\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 < -8.656892189523162e+102

    1. Initial program 55.3

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

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

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

    if -8.656892189523162e+102 < x < 4.471707363468376e+118

    1. Initial program 28.5

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

    if 4.471707363468376e+118 < x

    1. Initial program 57.1

      \[\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.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.65689218952316206016746897628479098224 \cdot 10^{102}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 4.471707363468376084214192176846928336007 \cdot 10^{118}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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