Average Error: 37.4 → 25.7
Time: 10.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.419201558872296734446973688765615482634 \cdot 10^{83}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.49462007451802192154576039190726965129 \cdot 10^{83}:\\ \;\;\;\;\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.419201558872296734446973688765615482634 \cdot 10^{83}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.49462007451802192154576039190726965129 \cdot 10^{83}:\\
\;\;\;\;\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 r540222 = x;
        double r540223 = r540222 * r540222;
        double r540224 = y;
        double r540225 = r540224 * r540224;
        double r540226 = r540223 + r540225;
        double r540227 = z;
        double r540228 = r540227 * r540227;
        double r540229 = r540226 + r540228;
        double r540230 = sqrt(r540229);
        return r540230;
}

double f(double x, double y, double z) {
        double r540231 = x;
        double r540232 = -2.4192015588722967e+83;
        bool r540233 = r540231 <= r540232;
        double r540234 = -r540231;
        double r540235 = 1.494620074518022e+83;
        bool r540236 = r540231 <= r540235;
        double r540237 = z;
        double r540238 = r540237 * r540237;
        double r540239 = y;
        double r540240 = r540239 * r540239;
        double r540241 = r540231 * r540231;
        double r540242 = r540240 + r540241;
        double r540243 = r540238 + r540242;
        double r540244 = sqrt(r540243);
        double r540245 = r540236 ? r540244 : r540231;
        double r540246 = r540233 ? r540234 : r540245;
        return r540246;
}

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.4
Target25.2
Herbie25.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 3 regimes
  2. if x < -2.4192015588722967e+83

    1. Initial program 51.0

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

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

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

    if -2.4192015588722967e+83 < x < 1.494620074518022e+83

    1. Initial program 28.9

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

    if 1.494620074518022e+83 < x

    1. Initial program 53.0

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

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

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

Reproduce

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