Average Error: 37.5 → 25.4
Time: 18.9s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\ \;\;\;\;\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 -4.839580010133738883814333111888121327705 \cdot 10^{89}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.537188568549186890366688724633159259389 \cdot 10^{101}:\\
\;\;\;\;\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 r438912 = x;
        double r438913 = r438912 * r438912;
        double r438914 = y;
        double r438915 = r438914 * r438914;
        double r438916 = r438913 + r438915;
        double r438917 = z;
        double r438918 = r438917 * r438917;
        double r438919 = r438916 + r438918;
        double r438920 = sqrt(r438919);
        return r438920;
}

double f(double x, double y, double z) {
        double r438921 = x;
        double r438922 = -4.839580010133739e+89;
        bool r438923 = r438921 <= r438922;
        double r438924 = -r438921;
        double r438925 = 1.537188568549187e+101;
        bool r438926 = r438921 <= r438925;
        double r438927 = r438921 * r438921;
        double r438928 = y;
        double r438929 = r438928 * r438928;
        double r438930 = r438927 + r438929;
        double r438931 = z;
        double r438932 = r438931 * r438931;
        double r438933 = r438930 + r438932;
        double r438934 = sqrt(r438933);
        double r438935 = r438926 ? r438934 : r438921;
        double r438936 = r438923 ? r438924 : r438935;
        return r438936;
}

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.5
Target25.3
Herbie25.4
\[\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 < -4.839580010133739e+89

    1. Initial program 52.1

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

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

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

    if -4.839580010133739e+89 < x < 1.537188568549187e+101

    1. Initial program 29.0

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

    if 1.537188568549187e+101 < x

    1. Initial program 55.1

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

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

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

Reproduce

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