Average Error: 34.7 → 23.4
Time: 13.2s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.048501675377615 \cdot 10^{+153}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.3381067656623604 \cdot 10^{+154}:\\ \;\;\;\;\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 -1.048501675377615 \cdot 10^{+153}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.3381067656623604 \cdot 10^{+154}:\\
\;\;\;\;\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 r32560848 = x;
        double r32560849 = r32560848 * r32560848;
        double r32560850 = y;
        double r32560851 = r32560850 * r32560850;
        double r32560852 = r32560849 + r32560851;
        double r32560853 = z;
        double r32560854 = r32560853 * r32560853;
        double r32560855 = r32560852 + r32560854;
        double r32560856 = sqrt(r32560855);
        return r32560856;
}

double f(double x, double y, double z) {
        double r32560857 = x;
        double r32560858 = -1.048501675377615e+153;
        bool r32560859 = r32560857 <= r32560858;
        double r32560860 = -r32560857;
        double r32560861 = 1.3381067656623604e+154;
        bool r32560862 = r32560857 <= r32560861;
        double r32560863 = z;
        double r32560864 = r32560863 * r32560863;
        double r32560865 = y;
        double r32560866 = r32560865 * r32560865;
        double r32560867 = r32560857 * r32560857;
        double r32560868 = r32560866 + r32560867;
        double r32560869 = r32560864 + r32560868;
        double r32560870 = sqrt(r32560869);
        double r32560871 = r32560862 ? r32560870 : r32560857;
        double r32560872 = r32560859 ? r32560860 : r32560871;
        return r32560872;
}

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

Original34.7
Target23.4
Herbie23.4
\[\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 < -1.048501675377615e+153

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified14.4

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

    if -1.048501675377615e+153 < x < 1.3381067656623604e+154

    1. Initial program 26.7

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

    if 1.3381067656623604e+154 < x

    1. Initial program 59.3

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

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

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

Reproduce

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