Average Error: 38.0 → 26.2
Time: 2.9s
Precision: binary64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \leq -2.1775431588860127 \cdot 10^{+114}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -9.91481798046696 \cdot 10^{-160}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq -1.1752862576324589 \cdot 10^{-195}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -4.738824455578195 \cdot 10^{-226}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq -5.606683175932588 \cdot 10^{-254}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.927780121112873 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq -2.1775431588860127 \cdot 10^{+114}:\\
\;\;\;\;-z\\

\mathbf{elif}\;z \leq -9.91481798046696 \cdot 10^{-160}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;z \leq -1.1752862576324589 \cdot 10^{-195}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq -4.738824455578195 \cdot 10^{-226}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;z \leq -5.606683175932588 \cdot 10^{-254}:\\
\;\;\;\;x\\

\mathbf{elif}\;z \leq 6.927780121112873 \cdot 10^{+149}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;z\\

\end{array}
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= z -2.1775431588860127e+114)
   (- z)
   (if (<= z -9.91481798046696e-160)
     (sqrt (+ (+ (* x x) (* y y)) (* z z)))
     (if (<= z -1.1752862576324589e-195)
       (- x)
       (if (<= z -4.738824455578195e-226)
         (sqrt (+ (+ (* x x) (* y y)) (* z z)))
         (if (<= z -5.606683175932588e-254)
           x
           (if (<= z 6.927780121112873e+149)
             (sqrt (+ (+ (* x x) (* y y)) (* z z)))
             z)))))))
double code(double x, double y, double z) {
	return sqrt(((x * x) + (y * y)) + (z * z));
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -2.1775431588860127e+114) {
		tmp = -z;
	} else if (z <= -9.91481798046696e-160) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else if (z <= -1.1752862576324589e-195) {
		tmp = -x;
	} else if (z <= -4.738824455578195e-226) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else if (z <= -5.606683175932588e-254) {
		tmp = x;
	} else if (z <= 6.927780121112873e+149) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else {
		tmp = z;
	}
	return tmp;
}

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.5
Herbie26.2
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z < 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 5 regimes
  2. if z < -2.1775431588860127e114

    1. Initial program 57.5

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

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

    if -2.1775431588860127e114 < z < -9.9148179804669601e-160 or -1.175286257632459e-195 < z < -4.7388244555781947e-226 or -5.60668317593258815e-254 < z < 6.9277801211128734e149

    1. Initial program 28.6

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

    if -9.9148179804669601e-160 < z < -1.175286257632459e-195

    1. Initial program 31.9

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

      \[\leadsto \color{blue}{-1 \cdot x}\]
    3. Simplified46.6

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

    if -4.7388244555781947e-226 < z < -5.60668317593258815e-254

    1. Initial program 33.7

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

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

    if 6.9277801211128734e149 < z

    1. Initial program 62.7

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

      \[\leadsto \color{blue}{z}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification26.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -2.1775431588860127 \cdot 10^{+114}:\\ \;\;\;\;-z\\ \mathbf{elif}\;z \leq -9.91481798046696 \cdot 10^{-160}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq -1.1752862576324589 \cdot 10^{-195}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq -4.738824455578195 \cdot 10^{-226}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq -5.606683175932588 \cdot 10^{-254}:\\ \;\;\;\;x\\ \mathbf{elif}\;z \leq 6.927780121112873 \cdot 10^{+149}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Reproduce

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