Average Error: 37.7 → 25.3
Time: 5.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.0394227355030043 \cdot 10^{122}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.8724218780029053 \cdot 10^{48}:\\ \;\;\;\;\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 -9.0394227355030043 \cdot 10^{122}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.8724218780029053 \cdot 10^{48}:\\
\;\;\;\;\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 r553619 = x;
        double r553620 = r553619 * r553619;
        double r553621 = y;
        double r553622 = r553621 * r553621;
        double r553623 = r553620 + r553622;
        double r553624 = z;
        double r553625 = r553624 * r553624;
        double r553626 = r553623 + r553625;
        double r553627 = sqrt(r553626);
        return r553627;
}

double f(double x, double y, double z) {
        double r553628 = x;
        double r553629 = -9.039422735503004e+122;
        bool r553630 = r553628 <= r553629;
        double r553631 = -r553628;
        double r553632 = 2.8724218780029053e+48;
        bool r553633 = r553628 <= r553632;
        double r553634 = r553628 * r553628;
        double r553635 = y;
        double r553636 = r553635 * r553635;
        double r553637 = r553634 + r553636;
        double r553638 = z;
        double r553639 = r553638 * r553638;
        double r553640 = r553637 + r553639;
        double r553641 = sqrt(r553640);
        double r553642 = r553633 ? r553641 : r553628;
        double r553643 = r553630 ? r553631 : r553642;
        return r553643;
}

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.7
Target25.6
Herbie25.3
\[\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 < -9.039422735503004e+122

    1. Initial program 58.1

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

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

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

    if -9.039422735503004e+122 < x < 2.8724218780029053e+48

    1. Initial program 29.0

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

    if 2.8724218780029053e+48 < x

    1. Initial program 48.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.0394227355030043 \cdot 10^{122}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.8724218780029053 \cdot 10^{48}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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