Average Error: 38.4 → 25.6
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.514147348156684897594805824258822056861 \cdot 10^{135}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\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.514147348156684897594805824258822056861 \cdot 10^{135}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\
\;\;\;\;\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 r435529 = x;
        double r435530 = r435529 * r435529;
        double r435531 = y;
        double r435532 = r435531 * r435531;
        double r435533 = r435530 + r435532;
        double r435534 = z;
        double r435535 = r435534 * r435534;
        double r435536 = r435533 + r435535;
        double r435537 = sqrt(r435536);
        return r435537;
}

double f(double x, double y, double z) {
        double r435538 = x;
        double r435539 = -1.514147348156685e+135;
        bool r435540 = r435538 <= r435539;
        double r435541 = -r435538;
        double r435542 = 2.2733836340085665e+132;
        bool r435543 = r435538 <= r435542;
        double r435544 = r435538 * r435538;
        double r435545 = y;
        double r435546 = r435545 * r435545;
        double r435547 = r435544 + r435546;
        double r435548 = z;
        double r435549 = r435548 * r435548;
        double r435550 = r435547 + r435549;
        double r435551 = sqrt(r435550);
        double r435552 = r435543 ? r435551 : r435538;
        double r435553 = r435540 ? r435541 : r435552;
        return r435553;
}

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.4
Target25.8
Herbie25.6
\[\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 < -1.514147348156685e+135

    1. Initial program 60.9

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

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

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

    if -1.514147348156685e+135 < x < 2.2733836340085665e+132

    1. Initial program 29.6

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

    if 2.2733836340085665e+132 < x

    1. Initial program 59.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.514147348156684897594805824258822056861 \cdot 10^{135}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 2.273383634008566533481719288833752498864 \cdot 10^{132}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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