Average Error: 38.2 → 27.7
Time: 6.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -6.262510467894122398146122146983994190669 \cdot 10^{-101}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le -3.083119173599494214298429611120832543576 \cdot 10^{-255}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.426520176234258672400825846364268144842 \cdot 10^{-178}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 8.252108775591287015464362375075982533816 \cdot 10^{-164}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.315276344842777773594030791518369033541 \cdot 10^{143}:\\ \;\;\;\;\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 -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le -6.262510467894122398146122146983994190669 \cdot 10^{-101}:\\
\;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\

\mathbf{elif}\;x \le -3.083119173599494214298429611120832543576 \cdot 10^{-255}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 6.426520176234258672400825846364268144842 \cdot 10^{-178}:\\
\;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\

\mathbf{elif}\;x \le 8.252108775591287015464362375075982533816 \cdot 10^{-164}:\\
\;\;\;\;y\\

\mathbf{elif}\;x \le 6.315276344842777773594030791518369033541 \cdot 10^{143}:\\
\;\;\;\;\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 r563399 = x;
        double r563400 = r563399 * r563399;
        double r563401 = y;
        double r563402 = r563401 * r563401;
        double r563403 = r563400 + r563402;
        double r563404 = z;
        double r563405 = r563404 * r563404;
        double r563406 = r563403 + r563405;
        double r563407 = sqrt(r563406);
        return r563407;
}

double f(double x, double y, double z) {
        double r563408 = x;
        double r563409 = -2.1993493867760175e+110;
        bool r563410 = r563408 <= r563409;
        double r563411 = -r563408;
        double r563412 = -6.262510467894122e-101;
        bool r563413 = r563408 <= r563412;
        double r563414 = z;
        double r563415 = r563414 * r563414;
        double r563416 = y;
        double r563417 = r563416 * r563416;
        double r563418 = r563408 * r563408;
        double r563419 = r563417 + r563418;
        double r563420 = r563415 + r563419;
        double r563421 = sqrt(r563420);
        double r563422 = -3.083119173599494e-255;
        bool r563423 = r563408 <= r563422;
        double r563424 = 6.426520176234259e-178;
        bool r563425 = r563408 <= r563424;
        double r563426 = 8.252108775591287e-164;
        bool r563427 = r563408 <= r563426;
        double r563428 = 6.315276344842778e+143;
        bool r563429 = r563408 <= r563428;
        double r563430 = r563429 ? r563421 : r563408;
        double r563431 = r563427 ? r563416 : r563430;
        double r563432 = r563425 ? r563421 : r563431;
        double r563433 = r563423 ? r563416 : r563432;
        double r563434 = r563413 ? r563421 : r563433;
        double r563435 = r563410 ? r563411 : r563434;
        return r563435;
}

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.2
Target25.7
Herbie27.7
\[\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 4 regimes
  2. if x < -2.1993493867760175e+110

    1. Initial program 56.6

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

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

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

    if -2.1993493867760175e+110 < x < -6.262510467894122e-101 or -3.083119173599494e-255 < x < 6.426520176234259e-178 or 8.252108775591287e-164 < x < 6.315276344842778e+143

    1. Initial program 28.9

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

    if -6.262510467894122e-101 < x < -3.083119173599494e-255 or 6.426520176234259e-178 < x < 8.252108775591287e-164

    1. Initial program 32.0

      \[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt32.4

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \sqrt[3]{\left(x \cdot x + y \cdot y\right) + z \cdot z}\right) \cdot \sqrt[3]{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\]
    4. Simplified32.4

      \[\leadsto \sqrt{\color{blue}{\left(\sqrt[3]{\left(x \cdot x + z \cdot z\right) + {y}^{2}} \cdot \sqrt[3]{\left(x \cdot x + z \cdot z\right) + {y}^{2}}\right)} \cdot \sqrt[3]{\left(x \cdot x + y \cdot y\right) + z \cdot z}}\]
    5. Simplified32.4

      \[\leadsto \sqrt{\left(\sqrt[3]{\left(x \cdot x + z \cdot z\right) + {y}^{2}} \cdot \sqrt[3]{\left(x \cdot x + z \cdot z\right) + {y}^{2}}\right) \cdot \color{blue}{\sqrt[3]{\left(x \cdot x + z \cdot z\right) + {y}^{2}}}}\]
    6. Taylor expanded around 0 47.1

      \[\leadsto \color{blue}{y}\]

    if 6.315276344842778e+143 < x

    1. Initial program 61.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.199349386776017456661293481624717960114 \cdot 10^{110}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le -6.262510467894122398146122146983994190669 \cdot 10^{-101}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le -3.083119173599494214298429611120832543576 \cdot 10^{-255}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.426520176234258672400825846364268144842 \cdot 10^{-178}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{elif}\;x \le 8.252108775591287015464362375075982533816 \cdot 10^{-164}:\\ \;\;\;\;y\\ \mathbf{elif}\;x \le 6.315276344842777773594030791518369033541 \cdot 10^{143}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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