Average Error: 37.3 → 25.0
Time: 6.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.035831751923693585671752188644252048192 \cdot 10^{141}:\\ \;\;\;\;\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 -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.035831751923693585671752188644252048192 \cdot 10^{141}:\\
\;\;\;\;\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 r32717497 = x;
        double r32717498 = r32717497 * r32717497;
        double r32717499 = y;
        double r32717500 = r32717499 * r32717499;
        double r32717501 = r32717498 + r32717500;
        double r32717502 = z;
        double r32717503 = r32717502 * r32717502;
        double r32717504 = r32717501 + r32717503;
        double r32717505 = sqrt(r32717504);
        return r32717505;
}

double f(double x, double y, double z) {
        double r32717506 = x;
        double r32717507 = -5.2451292044032e+130;
        bool r32717508 = r32717506 <= r32717507;
        double r32717509 = -r32717506;
        double r32717510 = 1.0358317519236936e+141;
        bool r32717511 = r32717506 <= r32717510;
        double r32717512 = z;
        double r32717513 = r32717512 * r32717512;
        double r32717514 = y;
        double r32717515 = r32717514 * r32717514;
        double r32717516 = r32717506 * r32717506;
        double r32717517 = r32717515 + r32717516;
        double r32717518 = r32717513 + r32717517;
        double r32717519 = sqrt(r32717518);
        double r32717520 = r32717511 ? r32717519 : r32717506;
        double r32717521 = r32717508 ? r32717509 : r32717520;
        return r32717521;
}

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
Target25.0
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 < -5.2451292044032e+130

    1. Initial program 58.6

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

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

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

    if -5.2451292044032e+130 < x < 1.0358317519236936e+141

    1. Initial program 28.7

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

    if 1.0358317519236936e+141 < x

    1. Initial program 61.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.245129204403200253740971551147040838799 \cdot 10^{130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.035831751923693585671752188644252048192 \cdot 10^{141}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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