Average Error: 37.9 → 33.9
Time: 5.7s
Precision: binary64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;x \leq -9.250767270340031 \cdot 10^{-298}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \leq 5.592279530727493 \cdot 10^{-180}:\\ \;\;\;\;z + 0.5 \cdot \frac{x \cdot x}{z}\\ \mathbf{elif}\;x \leq 4.259597241345245 \cdot 10^{+42}:\\ \;\;\;\;\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 \leq -9.250767270340031 \cdot 10^{-298}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{elif}\;x \leq 5.592279530727493 \cdot 10^{-180}:\\
\;\;\;\;z + 0.5 \cdot \frac{x \cdot x}{z}\\

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

\mathbf{else}:\\
\;\;\;\;x\\

\end{array}
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= x -9.250767270340031e-298)
   (sqrt (+ (+ (* x x) (* y y)) (* z z)))
   (if (<= x 5.592279530727493e-180)
     (+ z (* 0.5 (/ (* x x) z)))
     (if (<= x 4.259597241345245e+42)
       (sqrt (+ (+ (* x x) (* y y)) (* z z)))
       x))))
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 (x <= -9.250767270340031e-298) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else if (x <= 5.592279530727493e-180) {
		tmp = z + (0.5 * ((x * x) / z));
	} else if (x <= 4.259597241345245e+42) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else {
		tmp = x;
	}
	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.9
Target25.1
Herbie33.9
\[\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 x < -9.2507672703400312e-298 or 5.5922795307274933e-180 < x < 4.259597241345245e42

    1. Initial program 35.4

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

    if -9.2507672703400312e-298 < x < 5.5922795307274933e-180

    1. Initial program 33.1

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

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

      \[\leadsto \color{blue}{\sqrt{x \cdot x + z \cdot z}}\]
    4. Taylor expanded around 0 47.1

      \[\leadsto \color{blue}{z + 0.5 \cdot \frac{{x}^{2}}{z}}\]
    5. Simplified47.1

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

    if 4.259597241345245e42 < x

    1. Initial program 48.0

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

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

      \[\leadsto \color{blue}{\sqrt{x \cdot x + z \cdot z}}\]
    4. Taylor expanded around 0 22.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.250767270340031 \cdot 10^{-298}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{elif}\;x \leq 5.592279530727493 \cdot 10^{-180}:\\ \;\;\;\;z + 0.5 \cdot \frac{x \cdot x}{z}\\ \mathbf{elif}\;x \leq 4.259597241345245 \cdot 10^{+42}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array}\]

Reproduce

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