Average Error: 37.6 → 25.9
Time: 2.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.207631717301471474364012207343494600957 \cdot 10^{99}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.717722011770095916416968397525555482885 \cdot 10^{95}:\\ \;\;\;\;\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 -9.207631717301471474364012207343494600957 \cdot 10^{99}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.717722011770095916416968397525555482885 \cdot 10^{95}:\\
\;\;\;\;\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 r451979 = x;
        double r451980 = r451979 * r451979;
        double r451981 = y;
        double r451982 = r451981 * r451981;
        double r451983 = r451980 + r451982;
        double r451984 = z;
        double r451985 = r451984 * r451984;
        double r451986 = r451983 + r451985;
        double r451987 = sqrt(r451986);
        return r451987;
}

double f(double x, double y, double z) {
        double r451988 = x;
        double r451989 = -9.207631717301471e+99;
        bool r451990 = r451988 <= r451989;
        double r451991 = -r451988;
        double r451992 = 2.717722011770096e+95;
        bool r451993 = r451988 <= r451992;
        double r451994 = r451988 * r451988;
        double r451995 = y;
        double r451996 = r451995 * r451995;
        double r451997 = r451994 + r451996;
        double r451998 = z;
        double r451999 = r451998 * r451998;
        double r452000 = r451997 + r451999;
        double r452001 = sqrt(r452000);
        double r452002 = r451993 ? r452001 : r451988;
        double r452003 = r451990 ? r451991 : r452002;
        return r452003;
}

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.9
\[\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 < -9.207631717301471e+99

    1. Initial program 54.5

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

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

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

    if -9.207631717301471e+99 < x < 2.717722011770096e+95

    1. Initial program 29.2

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

    if 2.717722011770096e+95 < x

    1. Initial program 53.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.207631717301471474364012207343494600957 \cdot 10^{99}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.717722011770095916416968397525555482885 \cdot 10^{95}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019235 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))