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

\mathbf{elif}\;x \le 1.776008856932964701291342974326440851158 \cdot 10^{76}:\\
\;\;\;\;\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 r534710 = x;
        double r534711 = r534710 * r534710;
        double r534712 = y;
        double r534713 = r534712 * r534712;
        double r534714 = r534711 + r534713;
        double r534715 = z;
        double r534716 = r534715 * r534715;
        double r534717 = r534714 + r534716;
        double r534718 = sqrt(r534717);
        return r534718;
}

double f(double x, double y, double z) {
        double r534719 = x;
        double r534720 = -4.394319598461054e+128;
        bool r534721 = r534719 <= r534720;
        double r534722 = -r534719;
        double r534723 = 1.7760088569329647e+76;
        bool r534724 = r534719 <= r534723;
        double r534725 = r534719 * r534719;
        double r534726 = y;
        double r534727 = r534726 * r534726;
        double r534728 = r534725 + r534727;
        double r534729 = z;
        double r534730 = r534729 * r534729;
        double r534731 = r534728 + r534730;
        double r534732 = sqrt(r534731);
        double r534733 = r534724 ? r534732 : r534719;
        double r534734 = r534721 ? r534722 : r534733;
        return r534734;
}

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.2
Herbie25.3
\[\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 < -4.394319598461054e+128

    1. Initial program 58.2

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

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

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

    if -4.394319598461054e+128 < x < 1.7760088569329647e+76

    1. Initial program 29.0

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

    if 1.7760088569329647e+76 < x

    1. Initial program 51.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.394319598461054288703127888846215955555 \cdot 10^{128}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.776008856932964701291342974326440851158 \cdot 10^{76}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019212 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))