Average Error: 35.5 → 23.9
Time: 3.0s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -6.900273676134784 \cdot 10^{+153}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.003534834317306 \cdot 10^{+165}:\\ \;\;\;\;\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 -6.900273676134784 \cdot 10^{+153}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 3.003534834317306 \cdot 10^{+165}:\\
\;\;\;\;\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 r28442656 = x;
        double r28442657 = r28442656 * r28442656;
        double r28442658 = y;
        double r28442659 = r28442658 * r28442658;
        double r28442660 = r28442657 + r28442659;
        double r28442661 = z;
        double r28442662 = r28442661 * r28442661;
        double r28442663 = r28442660 + r28442662;
        double r28442664 = sqrt(r28442663);
        return r28442664;
}

double f(double x, double y, double z) {
        double r28442665 = x;
        double r28442666 = -6.900273676134784e+153;
        bool r28442667 = r28442665 <= r28442666;
        double r28442668 = -r28442665;
        double r28442669 = 3.003534834317306e+165;
        bool r28442670 = r28442665 <= r28442669;
        double r28442671 = z;
        double r28442672 = r28442671 * r28442671;
        double r28442673 = y;
        double r28442674 = r28442673 * r28442673;
        double r28442675 = r28442665 * r28442665;
        double r28442676 = r28442674 + r28442675;
        double r28442677 = r28442672 + r28442676;
        double r28442678 = sqrt(r28442677);
        double r28442679 = r28442670 ? r28442678 : r28442665;
        double r28442680 = r28442667 ? r28442668 : r28442679;
        return r28442680;
}

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

Original35.5
Target24.6
Herbie23.9
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \lt 7.320293694404182 \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 < -6.900273676134784e+153

    1. Initial program 59.2

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

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

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

    if -6.900273676134784e+153 < x < 3.003534834317306e+165

    1. Initial program 27.6

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

    if 3.003534834317306e+165 < x

    1. Initial program 59.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -6.900273676134784 \cdot 10^{+153}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 3.003534834317306 \cdot 10^{+165}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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