Average Error: 37.1 → 25.8
Time: 9.8s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\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 -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\
\;\;\;\;\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 r528746 = x;
        double r528747 = r528746 * r528746;
        double r528748 = y;
        double r528749 = r528748 * r528748;
        double r528750 = r528747 + r528749;
        double r528751 = z;
        double r528752 = r528751 * r528751;
        double r528753 = r528750 + r528752;
        double r528754 = sqrt(r528753);
        return r528754;
}

double f(double x, double y, double z) {
        double r528755 = x;
        double r528756 = -7.0606062487436015e+50;
        bool r528757 = r528755 <= r528756;
        double r528758 = -r528755;
        double r528759 = 7.898403675517638e+123;
        bool r528760 = r528755 <= r528759;
        double r528761 = z;
        double r528762 = r528761 * r528761;
        double r528763 = y;
        double r528764 = r528763 * r528763;
        double r528765 = r528755 * r528755;
        double r528766 = r528764 + r528765;
        double r528767 = r528762 + r528766;
        double r528768 = sqrt(r528767);
        double r528769 = r528760 ? r528768 : r528755;
        double r528770 = r528757 ? r528758 : r528769;
        return r528770;
}

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.1
Target24.8
Herbie25.8
\[\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 < -7.0606062487436015e+50

    1. Initial program 47.6

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

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

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

    if -7.0606062487436015e+50 < x < 7.898403675517638e+123

    1. Initial program 29.1

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

    if 7.898403675517638e+123 < x

    1. Initial program 58.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.060606248743601504632612473600212365221 \cdot 10^{50}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 7.898403675517637649655314019741343921642 \cdot 10^{123}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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