Average Error: 38.0 → 26.8
Time: 9.3s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.62918886015480700245891178761632271543 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\ \;\;\;\;\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.62918886015480700245891178761632271543 \cdot 10^{100}:\\
\;\;\;\;-x\\

\mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\
\;\;\;\;\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 r418438 = x;
        double r418439 = r418438 * r418438;
        double r418440 = y;
        double r418441 = r418440 * r418440;
        double r418442 = r418439 + r418441;
        double r418443 = z;
        double r418444 = r418443 * r418443;
        double r418445 = r418442 + r418444;
        double r418446 = sqrt(r418445);
        return r418446;
}

double f(double x, double y, double z) {
        double r418447 = x;
        double r418448 = -1.629188860154807e+100;
        bool r418449 = r418447 <= r418448;
        double r418450 = -r418447;
        double r418451 = 5.393455774424304e-203;
        bool r418452 = r418447 <= r418451;
        double r418453 = r418447 * r418447;
        double r418454 = y;
        double r418455 = r418454 * r418454;
        double r418456 = r418453 + r418455;
        double r418457 = z;
        double r418458 = r418457 * r418457;
        double r418459 = r418456 + r418458;
        double r418460 = sqrt(r418459);
        double r418461 = 6.220903762266977e-149;
        bool r418462 = r418447 <= r418461;
        double r418463 = 2.9682675892586475e+95;
        bool r418464 = r418447 <= r418463;
        double r418465 = r418464 ? r418460 : r418447;
        double r418466 = r418462 ? r418457 : r418465;
        double r418467 = r418452 ? r418460 : r418466;
        double r418468 = r418449 ? r418450 : r418467;
        return r418468;
}

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.1
Herbie26.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 4 regimes
  2. if x < -1.629188860154807e+100

    1. Initial program 54.2

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified18.0

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

    if -1.629188860154807e+100 < x < 5.393455774424304e-203 or 6.220903762266977e-149 < x < 2.9682675892586475e+95

    1. Initial program 29.7

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

    if 5.393455774424304e-203 < x < 6.220903762266977e-149

    1. Initial program 28.3

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

      \[\leadsto \color{blue}{z}\]

    if 2.9682675892586475e+95 < x

    1. Initial program 54.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.62918886015480700245891178761632271543 \cdot 10^{100}:\\ \;\;\;\;-x\\ \mathbf{elif}\;x \le 5.393455774424303979141841773008550014111 \cdot 10^{-203}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 6.220903762266976634365825797418682714837 \cdot 10^{-149}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 2.968267589258647529892498409398170543145 \cdot 10^{95}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

herbie shell --seed 2019305 
(FPCore (x y z)
  :name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
  :precision binary64

  :herbie-target
  (if (< z -6.3964793941097758e136) (- z) (if (< z 7.3202936944041821e117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))

  (sqrt (+ (+ (* x x) (* y y)) (* z z))))