Average Error: 35.5 → 24.4
Time: 3.1s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.1295859422058697 \cdot 10^{+130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\ \;\;\;\;\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.1295859422058697 \cdot 10^{+130}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\
\;\;\;\;\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 r11633005 = x;
        double r11633006 = r11633005 * r11633005;
        double r11633007 = y;
        double r11633008 = r11633007 * r11633007;
        double r11633009 = r11633006 + r11633008;
        double r11633010 = z;
        double r11633011 = r11633010 * r11633010;
        double r11633012 = r11633009 + r11633011;
        double r11633013 = sqrt(r11633012);
        return r11633013;
}

double f(double x, double y, double z) {
        double r11633014 = x;
        double r11633015 = -1.1295859422058697e+130;
        bool r11633016 = r11633014 <= r11633015;
        double r11633017 = -r11633014;
        double r11633018 = 1.3936358732915887e+155;
        bool r11633019 = r11633014 <= r11633018;
        double r11633020 = z;
        double r11633021 = r11633020 * r11633020;
        double r11633022 = y;
        double r11633023 = r11633022 * r11633022;
        double r11633024 = r11633014 * r11633014;
        double r11633025 = r11633023 + r11633024;
        double r11633026 = r11633021 + r11633025;
        double r11633027 = sqrt(r11633026);
        double r11633028 = r11633019 ? r11633027 : r11633014;
        double r11633029 = r11633016 ? r11633017 : r11633028;
        return r11633029;
}

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.1
Herbie24.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.1295859422058697e+130

    1. Initial program 54.5

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

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

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

    if -1.1295859422058697e+130 < x < 1.3936358732915887e+155

    1. Initial program 27.9

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

    if 1.3936358732915887e+155 < x

    1. Initial program 59.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.1295859422058697 \cdot 10^{+130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 1.3936358732915887 \cdot 10^{+155}:\\ \;\;\;\;\sqrt{z \cdot z + \left(y \cdot y + x \cdot x\right)}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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