Average Error: 38.0 → 25.7
Time: 4.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.89558649116172909 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\ \;\;\;\;\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 -1.89558649116172909 \cdot 10^{137}:\\
\;\;\;\;-1 \cdot x\\

\mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\
\;\;\;\;\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 r716806 = x;
        double r716807 = r716806 * r716806;
        double r716808 = y;
        double r716809 = r716808 * r716808;
        double r716810 = r716807 + r716809;
        double r716811 = z;
        double r716812 = r716811 * r716811;
        double r716813 = r716810 + r716812;
        double r716814 = sqrt(r716813);
        return r716814;
}

double f(double x, double y, double z) {
        double r716815 = x;
        double r716816 = -1.895586491161729e+137;
        bool r716817 = r716815 <= r716816;
        double r716818 = -1.0;
        double r716819 = r716818 * r716815;
        double r716820 = 7.792733426685086e+150;
        bool r716821 = r716815 <= r716820;
        double r716822 = r716815 * r716815;
        double r716823 = y;
        double r716824 = r716823 * r716823;
        double r716825 = r716822 + r716824;
        double r716826 = z;
        double r716827 = r716826 * r716826;
        double r716828 = r716825 + r716827;
        double r716829 = sqrt(r716828);
        double r716830 = r716821 ? r716829 : r716815;
        double r716831 = r716817 ? r716819 : r716830;
        return r716831;
}

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.0
Target25.4
Herbie25.7
\[\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 < -1.895586491161729e+137

    1. Initial program 60.9

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

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

    if -1.895586491161729e+137 < x < 7.792733426685086e+150

    1. Initial program 29.4

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

    if 7.792733426685086e+150 < x

    1. Initial program 63.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.89558649116172909 \cdot 10^{137}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 7.7927334266850862 \cdot 10^{150}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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