Average Error: 38.0 → 10.8
Time: 5.4s
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 4.403892363675905 \cdot 10^{-112}:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \frac{y}{x} + \frac{z}{\frac{x}{z}}\right) - x\\ \mathbf{elif}\;z \leq 132.10635457596226:\\ \;\;\;\;\sqrt{{x}^{2} + z \cdot z}\\ \mathbf{elif}\;z \leq 2.392365744457182 \cdot 10^{+43}:\\ \;\;\;\;-0.5 \cdot \left(\frac{y}{\frac{x}{y}} + \frac{z \cdot z}{x}\right) - x\\ \mathbf{elif}\;z \leq 4.6936553999927715 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;z \leq 4.403892363675905 \cdot 10^{-112}:\\
\;\;\;\;-0.5 \cdot \left(y \cdot \frac{y}{x} + \frac{z}{\frac{x}{z}}\right) - x\\

\mathbf{elif}\;z \leq 132.10635457596226:\\
\;\;\;\;\sqrt{{x}^{2} + z \cdot z}\\

\mathbf{elif}\;z \leq 2.392365744457182 \cdot 10^{+43}:\\
\;\;\;\;-0.5 \cdot \left(\frac{y}{\frac{x}{y}} + \frac{z \cdot z}{x}\right) - x\\

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

\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 4.403892363675905e-112)
   (- (* -0.5 (+ (* y (/ y x)) (/ z (/ x z)))) x)
   (if (<= z 132.10635457596226)
     (sqrt (+ (pow x 2.0) (* z z)))
     (if (<= z 2.392365744457182e+43)
       (- (* -0.5 (+ (/ y (/ x y)) (/ (* z z) x))) x)
       (if (<= z 4.6936553999927715e+146)
         (sqrt (+ (* z z) (+ (* x x) (* y y))))
         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 <= 4.403892363675905e-112) {
		tmp = (-0.5 * ((y * (y / x)) + (z / (x / z)))) - x;
	} else if (z <= 132.10635457596226) {
		tmp = sqrt(pow(x, 2.0) + (z * z));
	} else if (z <= 2.392365744457182e+43) {
		tmp = (-0.5 * ((y / (x / y)) + ((z * z) / x))) - x;
	} else if (z <= 4.6936553999927715e+146) {
		tmp = sqrt((z * z) + ((x * x) + (y * y)));
	} 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
Target18.8
Herbie10.8
\[\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 < 4.40389236367590516e-112

    1. Initial program 31.8

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

      \[\leadsto \color{blue}{-\left(0.5 \cdot \frac{{y}^{2}}{x} + \left(x + 0.5 \cdot \frac{{z}^{2}}{x}\right)\right)} \]
    3. Simplified9.1

      \[\leadsto \color{blue}{\left(-x\right) + -0.5 \cdot \left(\frac{y \cdot y}{x} + \frac{z \cdot z}{x}\right)} \]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary649.1

      \[\leadsto \left(-x\right) + -0.5 \cdot \left(\frac{y \cdot y}{\color{blue}{1 \cdot x}} + \frac{z \cdot z}{x}\right) \]
    6. Applied times-frac_binary644.0

      \[\leadsto \left(-x\right) + -0.5 \cdot \left(\color{blue}{\frac{y}{1} \cdot \frac{y}{x}} + \frac{z \cdot z}{x}\right) \]
    7. Simplified4.0

      \[\leadsto \left(-x\right) + -0.5 \cdot \left(\color{blue}{y} \cdot \frac{y}{x} + \frac{z \cdot z}{x}\right) \]
    8. Using strategy rm
    9. Applied associate-/l*_binary643.7

      \[\leadsto \left(-x\right) + -0.5 \cdot \left(y \cdot \frac{y}{x} + \color{blue}{\frac{z}{\frac{x}{z}}}\right) \]

    if 4.40389236367590516e-112 < z < 132.10635457596226

    1. Initial program 19.6

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

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

    if 132.10635457596226 < z < 2.39236574445718203e43

    1. Initial program 21.5

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

      \[\leadsto \color{blue}{-\left(0.5 \cdot \frac{{y}^{2}}{x} + \left(x + 0.5 \cdot \frac{{z}^{2}}{x}\right)\right)} \]
    3. Simplified28.5

      \[\leadsto \color{blue}{\left(-x\right) + -0.5 \cdot \left(\frac{y \cdot y}{x} + \frac{z \cdot z}{x}\right)} \]
    4. Using strategy rm
    5. Applied associate-/l*_binary6426.7

      \[\leadsto \left(-x\right) + -0.5 \cdot \left(\color{blue}{\frac{y}{\frac{x}{y}}} + \frac{z \cdot z}{x}\right) \]

    if 2.39236574445718203e43 < z < 4.693655399992771e146

    1. Initial program 17.0

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

    if 4.693655399992771e146 < z

    1. Initial program 62.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 4.403892363675905 \cdot 10^{-112}:\\ \;\;\;\;-0.5 \cdot \left(y \cdot \frac{y}{x} + \frac{z}{\frac{x}{z}}\right) - x\\ \mathbf{elif}\;z \leq 132.10635457596226:\\ \;\;\;\;\sqrt{{x}^{2} + z \cdot z}\\ \mathbf{elif}\;z \leq 2.392365744457182 \cdot 10^{+43}:\\ \;\;\;\;-0.5 \cdot \left(\frac{y}{\frac{x}{y}} + \frac{z \cdot z}{x}\right) - x\\ \mathbf{elif}\;z \leq 4.6936553999927715 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{z \cdot z + \left(x \cdot x + y \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array} \]

Reproduce

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