Average Error: 37.7 → 25.8
Time: 1.3s
Precision: 64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\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 -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\
\;\;\;\;-1 \cdot x\\

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

\mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\
\;\;\;\;z\\

\mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\
\;\;\;\;\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 r662659 = x;
        double r662660 = r662659 * r662659;
        double r662661 = y;
        double r662662 = r662661 * r662661;
        double r662663 = r662660 + r662662;
        double r662664 = z;
        double r662665 = r662664 * r662664;
        double r662666 = r662663 + r662665;
        double r662667 = sqrt(r662666);
        return r662667;
}

double f(double x, double y, double z) {
        double r662668 = x;
        double r662669 = -3.5794877859546974e+94;
        bool r662670 = r662668 <= r662669;
        double r662671 = -1.0;
        double r662672 = r662671 * r662668;
        double r662673 = 6.058132317483692e-184;
        bool r662674 = r662668 <= r662673;
        double r662675 = r662668 * r662668;
        double r662676 = y;
        double r662677 = r662676 * r662676;
        double r662678 = r662675 + r662677;
        double r662679 = z;
        double r662680 = r662679 * r662679;
        double r662681 = r662678 + r662680;
        double r662682 = sqrt(r662681);
        double r662683 = 4.463507529461489e-156;
        bool r662684 = r662668 <= r662683;
        double r662685 = 1.3881517315915455e+99;
        bool r662686 = r662668 <= r662685;
        double r662687 = r662686 ? r662682 : r662668;
        double r662688 = r662684 ? r662679 : r662687;
        double r662689 = r662674 ? r662682 : r662688;
        double r662690 = r662670 ? r662672 : r662689;
        return r662690;
}

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

Original37.7
Target25.5
Herbie25.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 < -3.5794877859546974e+94

    1. Initial program 52.6

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

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

    if -3.5794877859546974e+94 < x < 6.058132317483692e-184 or 4.463507529461489e-156 < x < 1.3881517315915455e+99

    1. Initial program 29.0

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

    if 6.058132317483692e-184 < x < 4.463507529461489e-156

    1. Initial program 31.8

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

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

    if 1.3881517315915455e+99 < x

    1. Initial program 54.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.579487785954697432023486781062392489463 \cdot 10^{94}:\\ \;\;\;\;-1 \cdot x\\ \mathbf{elif}\;x \le 6.058132317483692417052640734859374750552 \cdot 10^{-184}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \le 4.463507529461488747590627312338750545799 \cdot 10^{-156}:\\ \;\;\;\;z\\ \mathbf{elif}\;x \le 1.388151731591545501959511120790879854274 \cdot 10^{99}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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