Average Error: 38.0 → 25.4
Time: 4.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.247629272160778236302167026642172876392 \cdot 10^{129}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.879788545217995887059617832949467600343 \cdot 10^{136}:\\ \;\;\;\;\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 -8.247629272160778236302167026642172876392 \cdot 10^{129}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.879788545217995887059617832949467600343 \cdot 10^{136}:\\
\;\;\;\;\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 r451004 = x;
        double r451005 = r451004 * r451004;
        double r451006 = y;
        double r451007 = r451006 * r451006;
        double r451008 = r451005 + r451007;
        double r451009 = z;
        double r451010 = r451009 * r451009;
        double r451011 = r451008 + r451010;
        double r451012 = sqrt(r451011);
        return r451012;
}

double f(double x, double y, double z) {
        double r451013 = x;
        double r451014 = -8.247629272160778e+129;
        bool r451015 = r451013 <= r451014;
        double r451016 = -1.0;
        double r451017 = r451016 * r451013;
        double r451018 = 1.879788545217996e+136;
        bool r451019 = r451013 <= r451018;
        double r451020 = r451013 * r451013;
        double r451021 = y;
        double r451022 = r451021 * r451021;
        double r451023 = r451020 + r451022;
        double r451024 = z;
        double r451025 = r451024 * r451024;
        double r451026 = r451023 + r451025;
        double r451027 = sqrt(r451026);
        double r451028 = r451019 ? r451027 : r451013;
        double r451029 = r451015 ? r451017 : r451028;
        return r451029;
}

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.0
Target25.3
Herbie25.4
\[\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.247629272160778e+129

    1. Initial program 59.0

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

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

    if -8.247629272160778e+129 < x < 1.879788545217996e+136

    1. Initial program 29.4

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

    if 1.879788545217996e+136 < x

    1. Initial program 60.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.247629272160778236302167026642172876392 \cdot 10^{129}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.879788545217995887059617832949467600343 \cdot 10^{136}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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