Average Error: 38.1 → 26.2
Time: 4.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -18637040731758232623605069933264714596350:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\ \;\;\;\;\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 -18637040731758232623605069933264714596350:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.376373199179285827713056036389642308458 \cdot 10^{91}:\\
\;\;\;\;\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 r381881 = x;
        double r381882 = r381881 * r381881;
        double r381883 = y;
        double r381884 = r381883 * r381883;
        double r381885 = r381882 + r381884;
        double r381886 = z;
        double r381887 = r381886 * r381886;
        double r381888 = r381885 + r381887;
        double r381889 = sqrt(r381888);
        return r381889;
}

double f(double x, double y, double z) {
        double r381890 = x;
        double r381891 = -1.8637040731758233e+40;
        bool r381892 = r381890 <= r381891;
        double r381893 = -1.0;
        double r381894 = r381893 * r381890;
        double r381895 = 4.376373199179286e+91;
        bool r381896 = r381890 <= r381895;
        double r381897 = r381890 * r381890;
        double r381898 = y;
        double r381899 = r381898 * r381898;
        double r381900 = r381897 + r381899;
        double r381901 = z;
        double r381902 = r381901 * r381901;
        double r381903 = r381900 + r381902;
        double r381904 = sqrt(r381903);
        double r381905 = r381896 ? r381904 : r381890;
        double r381906 = r381892 ? r381894 : r381905;
        return r381906;
}

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.4
Herbie26.2
\[\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.8637040731758233e+40

    1. Initial program 48.9

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

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

    if -1.8637040731758233e+40 < x < 4.376373199179286e+91

    1. Initial program 29.6

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

    if 4.376373199179286e+91 < x

    1. Initial program 53.4

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

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

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

Reproduce

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