Average Error: 37.7 → 25.5
Time: 4.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.934591556850648877179646504172286937752 \cdot 10^{139}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.758065253567775503978920400402254303936 \cdot 10^{99}:\\ \;\;\;\;\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 -7.934591556850648877179646504172286937752 \cdot 10^{139}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.758065253567775503978920400402254303936 \cdot 10^{99}:\\
\;\;\;\;\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 r449113 = x;
        double r449114 = r449113 * r449113;
        double r449115 = y;
        double r449116 = r449115 * r449115;
        double r449117 = r449114 + r449116;
        double r449118 = z;
        double r449119 = r449118 * r449118;
        double r449120 = r449117 + r449119;
        double r449121 = sqrt(r449120);
        return r449121;
}

double f(double x, double y, double z) {
        double r449122 = x;
        double r449123 = -7.934591556850649e+139;
        bool r449124 = r449122 <= r449123;
        double r449125 = -r449122;
        double r449126 = 1.7580652535677755e+99;
        bool r449127 = r449122 <= r449126;
        double r449128 = r449122 * r449122;
        double r449129 = y;
        double r449130 = r449129 * r449129;
        double r449131 = r449128 + r449130;
        double r449132 = z;
        double r449133 = r449132 * r449132;
        double r449134 = r449131 + r449133;
        double r449135 = sqrt(r449134);
        double r449136 = r449127 ? r449135 : r449122;
        double r449137 = r449124 ? r449125 : r449136;
        return r449137;
}

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.7
Target25.4
Herbie25.5
\[\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 < -7.934591556850649e+139

    1. Initial program 60.7

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

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

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

    if -7.934591556850649e+139 < x < 1.7580652535677755e+99

    1. Initial program 29.3

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

    if 1.7580652535677755e+99 < x

    1. Initial program 54.2

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

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

Reproduce

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

  :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))))