Average Error: 38.4 → 25.8
Time: 4.6s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.341981727027803 \cdot 10^{105}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.1552954141646482 \cdot 10^{112}:\\ \;\;\;\;\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.341981727027803 \cdot 10^{105}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 2.1552954141646482 \cdot 10^{112}:\\
\;\;\;\;\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 r715443 = x;
        double r715444 = r715443 * r715443;
        double r715445 = y;
        double r715446 = r715445 * r715445;
        double r715447 = r715444 + r715446;
        double r715448 = z;
        double r715449 = r715448 * r715448;
        double r715450 = r715447 + r715449;
        double r715451 = sqrt(r715450);
        return r715451;
}

double f(double x, double y, double z) {
        double r715452 = x;
        double r715453 = -4.341981727027803e+105;
        bool r715454 = r715452 <= r715453;
        double r715455 = -1.0;
        double r715456 = r715455 * r715452;
        double r715457 = 2.155295414164648e+112;
        bool r715458 = r715452 <= r715457;
        double r715459 = r715452 * r715452;
        double r715460 = y;
        double r715461 = r715460 * r715460;
        double r715462 = r715459 + r715461;
        double r715463 = z;
        double r715464 = r715463 * r715463;
        double r715465 = r715462 + r715464;
        double r715466 = sqrt(r715465);
        double r715467 = r715458 ? r715466 : r715452;
        double r715468 = r715454 ? r715456 : r715467;
        return r715468;
}

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.4
Target26.1
Herbie25.8
\[\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 < -4.341981727027803e+105

    1. Initial program 56.1

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

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

    if -4.341981727027803e+105 < x < 2.155295414164648e+112

    1. Initial program 29.6

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

    if 2.155295414164648e+112 < x

    1. Initial program 56.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.341981727027803 \cdot 10^{105}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 2.1552954141646482 \cdot 10^{112}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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