Average Error: 37.8 → 11.1
Time: 2.8s
Precision: binary64
\[[x, y, z]=\mathsf{sort}([x, y, z])\]
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \leq 1.2351025899530227 \cdot 10^{-43}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.5219024465843806 \cdot 10^{+123}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq 3.607133536644106 \cdot 10^{+130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.2922293721606246 \cdot 10^{+145}:\\ \;\;\;\;\sqrt{x \cdot x + 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 1.2351025899530227 \cdot 10^{-43}:\\
\;\;\;\;-x\\

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

\mathbf{elif}\;z \leq 3.607133536644106 \cdot 10^{+130}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 1.2922293721606246 \cdot 10^{+145}:\\
\;\;\;\;\sqrt{x \cdot x + 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 1.2351025899530227e-43)
   (- x)
   (if (<= z 1.5219024465843806e+123)
     (sqrt (+ (+ (* x x) (* y y)) (* z z)))
     (if (<= z 3.607133536644106e+130)
       (- x)
       (if (<= z 1.2922293721606246e+145) (sqrt (+ (* x x) (* 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 <= 1.2351025899530227e-43) {
		tmp = -x;
	} else if (z <= 1.5219024465843806e+123) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else if (z <= 3.607133536644106e+130) {
		tmp = -x;
	} else if (z <= 1.2922293721606246e+145) {
		tmp = sqrt((x * x) + (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

Original37.8
Target18.9
Herbie11.1
\[\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 4 regimes
  2. if z < 1.2351025899530227e-43 or 1.5219024465843806e123 < z < 3.6071335366441058e130

    1. Initial program 29.4

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

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

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

    if 1.2351025899530227e-43 < z < 1.5219024465843806e123

    1. Initial program 17.9

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

    if 3.6071335366441058e130 < z < 1.29222937216062463e145

    1. Initial program 15.5

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

      \[\leadsto \color{blue}{\sqrt{{z}^{2} + {x}^{2}}}\]
    3. Simplified15.5

      \[\leadsto \color{blue}{\sqrt{z \cdot z + x \cdot x}}\]

    if 1.29222937216062463e145 < z

    1. Initial program 61.9

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

      \[\leadsto \color{blue}{z}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1.2351025899530227 \cdot 10^{-43}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.5219024465843806 \cdot 10^{+123}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;z \leq 3.607133536644106 \cdot 10^{+130}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.2922293721606246 \cdot 10^{+145}:\\ \;\;\;\;\sqrt{x \cdot x + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Reproduce

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