Average Error: 37.2 → 25.0
Time: 8.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.148565344950028725232496783484818345221 \cdot 10^{70}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 6.199742548939528402480216762955632756493 \cdot 10^{137}:\\ \;\;\;\;\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.148565344950028725232496783484818345221 \cdot 10^{70}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 6.199742548939528402480216762955632756493 \cdot 10^{137}:\\
\;\;\;\;\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 r466822 = x;
        double r466823 = r466822 * r466822;
        double r466824 = y;
        double r466825 = r466824 * r466824;
        double r466826 = r466823 + r466825;
        double r466827 = z;
        double r466828 = r466827 * r466827;
        double r466829 = r466826 + r466828;
        double r466830 = sqrt(r466829);
        return r466830;
}

double f(double x, double y, double z) {
        double r466831 = x;
        double r466832 = -1.1485653449500287e+70;
        bool r466833 = r466831 <= r466832;
        double r466834 = -r466831;
        double r466835 = 6.199742548939528e+137;
        bool r466836 = r466831 <= r466835;
        double r466837 = r466831 * r466831;
        double r466838 = y;
        double r466839 = r466838 * r466838;
        double r466840 = r466837 + r466839;
        double r466841 = z;
        double r466842 = r466841 * r466841;
        double r466843 = r466840 + r466842;
        double r466844 = sqrt(r466843);
        double r466845 = r466836 ? r466844 : r466831;
        double r466846 = r466833 ? r466834 : r466845;
        return r466846;
}

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.2
Target24.7
Herbie25.0
\[\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.1485653449500287e+70

    1. Initial program 51.2

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

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

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

    if -1.1485653449500287e+70 < x < 6.199742548939528e+137

    1. Initial program 28.3

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

    if 6.199742548939528e+137 < x

    1. Initial program 60.8

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

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

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

Reproduce

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