Average Error: 37.4 → 25.1
Time: 1.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.56421241030458443 \cdot 10^{110}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 1.960163308790063 \cdot 10^{125}:\\ \;\;\;\;\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.56421241030458443 \cdot 10^{110}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 1.960163308790063 \cdot 10^{125}:\\
\;\;\;\;\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 r658020 = x;
        double r658021 = r658020 * r658020;
        double r658022 = y;
        double r658023 = r658022 * r658022;
        double r658024 = r658021 + r658023;
        double r658025 = z;
        double r658026 = r658025 * r658025;
        double r658027 = r658024 + r658026;
        double r658028 = sqrt(r658027);
        return r658028;
}

double f(double x, double y, double z) {
        double r658029 = x;
        double r658030 = -1.5642124103045844e+110;
        bool r658031 = r658029 <= r658030;
        double r658032 = -1.0;
        double r658033 = r658032 * r658029;
        double r658034 = 1.960163308790063e+125;
        bool r658035 = r658029 <= r658034;
        double r658036 = r658029 * r658029;
        double r658037 = y;
        double r658038 = r658037 * r658037;
        double r658039 = r658036 + r658038;
        double r658040 = z;
        double r658041 = r658040 * r658040;
        double r658042 = r658039 + r658041;
        double r658043 = sqrt(r658042);
        double r658044 = r658035 ? r658043 : r658029;
        double r658045 = r658031 ? r658033 : r658044;
        return r658045;
}

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.4
Herbie25.1
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.3202936944041821 \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.5642124103045844e+110

    1. Initial program 56.1

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

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

    if -1.5642124103045844e+110 < x < 1.960163308790063e+125

    1. Initial program 28.6

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

    if 1.960163308790063e+125 < x

    1. Initial program 58.0

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

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

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

Reproduce

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