Average Error: 38.1 → 25.3
Time: 4.5s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.144079952779354130779551322736709562814 \cdot 10^{94}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.390985743981275148755905045732580516492 \cdot 10^{83}:\\ \;\;\;\;\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 -1.144079952779354130779551322736709562814 \cdot 10^{94}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.390985743981275148755905045732580516492 \cdot 10^{83}:\\
\;\;\;\;\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 r30099454 = x;
        double r30099455 = r30099454 * r30099454;
        double r30099456 = y;
        double r30099457 = r30099456 * r30099456;
        double r30099458 = r30099455 + r30099457;
        double r30099459 = z;
        double r30099460 = r30099459 * r30099459;
        double r30099461 = r30099458 + r30099460;
        double r30099462 = sqrt(r30099461);
        return r30099462;
}

double f(double x, double y, double z) {
        double r30099463 = x;
        double r30099464 = -1.1440799527793541e+94;
        bool r30099465 = r30099463 <= r30099464;
        double r30099466 = -r30099463;
        double r30099467 = 2.3909857439812751e+83;
        bool r30099468 = r30099463 <= r30099467;
        double r30099469 = z;
        double r30099470 = r30099469 * r30099469;
        double r30099471 = y;
        double r30099472 = r30099471 * r30099471;
        double r30099473 = r30099463 * r30099463;
        double r30099474 = r30099472 + r30099473;
        double r30099475 = r30099470 + r30099474;
        double r30099476 = sqrt(r30099475);
        double r30099477 = r30099468 ? r30099476 : r30099463;
        double r30099478 = r30099465 ? r30099466 : r30099477;
        return r30099478;
}

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.1
Target25.7
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 < -1.1440799527793541e+94

    1. Initial program 55.0

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

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

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

    if -1.1440799527793541e+94 < x < 2.3909857439812751e+83

    1. Initial program 29.1

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

    if 2.3909857439812751e+83 < x

    1. Initial program 52.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.144079952779354130779551322736709562814 \cdot 10^{94}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.390985743981275148755905045732580516492 \cdot 10^{83}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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