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 r723551 = x;
        double r723552 = r723551 * r723551;
        double r723553 = y;
        double r723554 = r723553 * r723553;
        double r723555 = r723552 + r723554;
        double r723556 = z;
        double r723557 = r723556 * r723556;
        double r723558 = r723555 + r723557;
        double r723559 = sqrt(r723558);
        return r723559;
}

double f(double x, double y, double z) {
        double r723560 = x;
        double r723561 = -1.052922090158919e+85;
        bool r723562 = r723560 <= r723561;
        double r723563 = -1.0;
        double r723564 = r723563 * r723560;
        double r723565 = 2.8317233913665317e+132;
        bool r723566 = r723560 <= r723565;
        double r723567 = r723560 * r723560;
        double r723568 = y;
        double r723569 = r723568 * r723568;
        double r723570 = r723567 + r723569;
        double r723571 = z;
        double r723572 = r723571 * r723571;
        double r723573 = r723570 + r723572;
        double r723574 = sqrt(r723573);
        double r723575 = r723566 ? r723574 : r723560;
        double r723576 = r723562 ? r723564 : r723575;
        return r723576;
}

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))))