Average Error: 37.5 → 25.5
Time: 2.3s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.653486872877025328162949610044300723903 \cdot 10^{103}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 4.548512359051216215734424553488962080637 \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.653486872877025328162949610044300723903 \cdot 10^{103}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 4.548512359051216215734424553488962080637 \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 r541552 = x;
        double r541553 = r541552 * r541552;
        double r541554 = y;
        double r541555 = r541554 * r541554;
        double r541556 = r541553 + r541555;
        double r541557 = z;
        double r541558 = r541557 * r541557;
        double r541559 = r541556 + r541558;
        double r541560 = sqrt(r541559);
        return r541560;
}

double f(double x, double y, double z) {
        double r541561 = x;
        double r541562 = -1.6534868728770253e+103;
        bool r541563 = r541561 <= r541562;
        double r541564 = -1.0;
        double r541565 = r541564 * r541561;
        double r541566 = 4.548512359051216e+125;
        bool r541567 = r541561 <= r541566;
        double r541568 = r541561 * r541561;
        double r541569 = y;
        double r541570 = r541569 * r541569;
        double r541571 = r541568 + r541570;
        double r541572 = z;
        double r541573 = r541572 * r541572;
        double r541574 = r541571 + r541573;
        double r541575 = sqrt(r541574);
        double r541576 = r541567 ? r541575 : r541561;
        double r541577 = r541563 ? r541565 : r541576;
        return r541577;
}

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.1
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.6534868728770253e+103

    1. Initial program 54.4

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

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

    if -1.6534868728770253e+103 < x < 4.548512359051216e+125

    1. Initial program 29.1

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

    if 4.548512359051216e+125 < x

    1. Initial program 57.9

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

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

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

Reproduce

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