Average Error: 38.1 → 25.5
Time: 12.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\ \;\;\;\;\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 -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\
\;\;\;\;\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 r482144 = x;
        double r482145 = r482144 * r482144;
        double r482146 = y;
        double r482147 = r482146 * r482146;
        double r482148 = r482145 + r482147;
        double r482149 = z;
        double r482150 = r482149 * r482149;
        double r482151 = r482148 + r482150;
        double r482152 = sqrt(r482151);
        return r482152;
}

double f(double x, double y, double z) {
        double r482153 = x;
        double r482154 = -1.8843851882908976e+109;
        bool r482155 = r482153 <= r482154;
        double r482156 = -r482153;
        double r482157 = 1.9453302589220937e+138;
        bool r482158 = r482153 <= r482157;
        double r482159 = r482153 * r482153;
        double r482160 = y;
        double r482161 = r482160 * r482160;
        double r482162 = r482159 + r482161;
        double r482163 = z;
        double r482164 = r482163 * r482163;
        double r482165 = r482162 + r482164;
        double r482166 = sqrt(r482165);
        double r482167 = r482158 ? r482166 : r482153;
        double r482168 = r482155 ? r482156 : r482167;
        return r482168;
}

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.3
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 < -1.8843851882908976e+109

    1. Initial program 55.1

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

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

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

    if -1.8843851882908976e+109 < x < 1.9453302589220937e+138

    1. Initial program 29.6

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

    if 1.9453302589220937e+138 < x

    1. Initial program 60.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.884385188290897584934334479478417400382 \cdot 10^{109}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.945330258922093722171531403348915767504 \cdot 10^{138}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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