Average Error: 37.8 → 13.1
Time: 4.6s
Precision: binary64
[x y z]: =sort([x y z])
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;z \leq 1.1159320986222001 \cdot 10^{-41}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 31844652.308985993:\\ \;\;\;\;\sqrt{z \cdot z + x \cdot x}\\ \mathbf{elif}\;z \leq 1.999825415585347 \cdot 10^{+59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.5165136515313232 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{z \cdot z + x \cdot x}\\ \mathbf{elif}\;z \leq 3.4920392089304095 \cdot 10^{+104}:\\ \;\;\;\;-x\\ \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.1159320986222001 \cdot 10^{-41}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 31844652.308985993:\\
\;\;\;\;\sqrt{z \cdot z + x \cdot x}\\

\mathbf{elif}\;z \leq 1.999825415585347 \cdot 10^{+59}:\\
\;\;\;\;-x\\

\mathbf{elif}\;z \leq 1.5165136515313232 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{z \cdot z + x \cdot x}\\

\mathbf{elif}\;z \leq 3.4920392089304095 \cdot 10^{+104}:\\
\;\;\;\;-x\\

\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.1159320986222001e-41)
   (- x)
   (if (<= z 31844652.308985993)
     (sqrt (+ (* z z) (* x x)))
     (if (<= z 1.999825415585347e+59)
       (- x)
       (if (<= z 1.5165136515313232e+91)
         (sqrt (+ (* z z) (* x x)))
         (if (<= z 3.4920392089304095e+104) (- x) 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.1159320986222001e-41) {
		tmp = -x;
	} else if (z <= 31844652.308985993) {
		tmp = sqrt((z * z) + (x * x));
	} else if (z <= 1.999825415585347e+59) {
		tmp = -x;
	} else if (z <= 1.5165136515313232e+91) {
		tmp = sqrt((z * z) + (x * x));
	} else if (z <= 3.4920392089304095e+104) {
		tmp = -x;
	} 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
Target19.8
Herbie13.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 3 regimes
  2. if z < 1.11593209862220009e-41 or 31844652.308985993 < z < 1.99982541558534707e59 or 1.51651365153132315e91 < z < 3.49203920893040948e104

    1. Initial program 27.8

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

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

    if 1.11593209862220009e-41 < z < 31844652.308985993 or 1.99982541558534707e59 < z < 1.51651365153132315e91

    1. Initial program 19.8

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

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

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

    if 3.49203920893040948e104 < z

    1. Initial program 54.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 1.1159320986222001 \cdot 10^{-41}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 31844652.308985993:\\ \;\;\;\;\sqrt{z \cdot z + x \cdot x}\\ \mathbf{elif}\;z \leq 1.999825415585347 \cdot 10^{+59}:\\ \;\;\;\;-x\\ \mathbf{elif}\;z \leq 1.5165136515313232 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{z \cdot z + x \cdot x}\\ \mathbf{elif}\;z \leq 3.4920392089304095 \cdot 10^{+104}:\\ \;\;\;\;-x\\ \mathbf{else}:\\ \;\;\;\;z\\ \end{array}\]

Reproduce

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