Average Error: 37.7 → 25.7
Time: 7.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -8.211230074550794807852274410189304665365 \cdot 10^{53}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.495231207769666567884408344017044329315 \cdot 10^{94}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;x \le -8.211230074550794807852274410189304665365 \cdot 10^{53}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 7.495231207769666567884408344017044329315 \cdot 10^{94}:\\
\;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
double f(double x, double y, double z) {
        double r33936726 = x;
        double r33936727 = r33936726 * r33936726;
        double r33936728 = y;
        double r33936729 = r33936728 * r33936728;
        double r33936730 = r33936727 + r33936729;
        double r33936731 = z;
        double r33936732 = r33936731 * r33936731;
        double r33936733 = r33936730 + r33936732;
        double r33936734 = sqrt(r33936733);
        return r33936734;
}

double f(double x, double y, double z) {
        double r33936735 = x;
        double r33936736 = -8.211230074550795e+53;
        bool r33936737 = r33936735 <= r33936736;
        double r33936738 = -r33936735;
        double r33936739 = 7.495231207769667e+94;
        bool r33936740 = r33936735 <= r33936739;
        double r33936741 = z;
        double r33936742 = r33936741 * r33936741;
        double r33936743 = y;
        double r33936744 = r33936743 * r33936743;
        double r33936745 = r33936735 * r33936735;
        double r33936746 = r33936744 + r33936745;
        double r33936747 = r33936742 + r33936746;
        double r33936748 = sqrt(r33936747);
        double r33936749 = r33936740 ? r33936748 : r33936735;
        double r33936750 = r33936737 ? r33936738 : r33936749;
        return r33936750;
}

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.7
\[\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 < -8.211230074550795e+53

    1. Initial program 49.0

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

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

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

    if -8.211230074550795e+53 < x < 7.495231207769667e+94

    1. Initial program 29.7

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

    if 7.495231207769667e+94 < x

    1. Initial program 52.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.211230074550794807852274410189304665365 \cdot 10^{53}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.495231207769666567884408344017044329315 \cdot 10^{94}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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

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