Average Error: 38.0 → 25.5
Time: 1.4s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.052922090158918936796058329983412299556 \cdot 10^{85}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.831723391366531742542950799194105898801 \cdot 10^{132}:\\ \;\;\;\;\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.052922090158918936796058329983412299556 \cdot 10^{85}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.831723391366531742542950799194105898801 \cdot 10^{132}:\\
\;\;\;\;\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 r713998 = x;
        double r713999 = r713998 * r713998;
        double r714000 = y;
        double r714001 = r714000 * r714000;
        double r714002 = r713999 + r714001;
        double r714003 = z;
        double r714004 = r714003 * r714003;
        double r714005 = r714002 + r714004;
        double r714006 = sqrt(r714005);
        return r714006;
}

double f(double x, double y, double z) {
        double r714007 = x;
        double r714008 = -1.052922090158919e+85;
        bool r714009 = r714007 <= r714008;
        double r714010 = -1.0;
        double r714011 = r714010 * r714007;
        double r714012 = 2.8317233913665317e+132;
        bool r714013 = r714007 <= r714012;
        double r714014 = r714007 * r714007;
        double r714015 = y;
        double r714016 = r714015 * r714015;
        double r714017 = r714014 + r714016;
        double r714018 = z;
        double r714019 = r714018 * r714018;
        double r714020 = r714017 + r714019;
        double r714021 = sqrt(r714020);
        double r714022 = r714013 ? r714021 : r714007;
        double r714023 = r714009 ? r714011 : r714022;
        return r714023;
}

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.0
Target25.8
Herbie25.5
\[\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.052922090158919e+85

    1. Initial program 53.4

      \[\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}\]

    if -1.052922090158919e+85 < x < 2.8317233913665317e+132

    1. Initial program 29.4

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

    if 2.8317233913665317e+132 < x

    1. Initial program 59.7

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

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

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

Reproduce

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