Average Error: 38.1 → 24.9
Time: 2.3s
Precision: binary64
\[\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\]
\[\begin{array}{l} \mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 3.824751598715583 \cdot 10^{+307}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\left|z\right|\\ \end{array}\]
\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 3.824751598715583 \cdot 10^{+307}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\left|z\right|\\

\end{array}
(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
 :precision binary64
 (if (<= (+ (+ (* x x) (* y y)) (* z z)) 3.824751598715583e+307)
   (sqrt (+ (+ (* x x) (* y y)) (* z z)))
   (fabs 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 ((((x * x) + (y * y)) + (z * z)) <= 3.824751598715583e+307) {
		tmp = sqrt(((x * x) + (y * y)) + (z * z));
	} else {
		tmp = fabs(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.1
Target25.6
Herbie24.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 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) < 3.82475159871558313e307

    1. Initial program 2.0

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

    if 3.82475159871558313e307 < (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z))

    1. Initial program 63.9

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

      \[\leadsto \sqrt{\color{blue}{0} + z \cdot z}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity_binary6462.7

      \[\leadsto \sqrt{\color{blue}{1 \cdot \left(0 + z \cdot z\right)}}\]
    5. Applied sqrt-prod_binary6462.7

      \[\leadsto \color{blue}{\sqrt{1} \cdot \sqrt{0 + z \cdot z}}\]
    6. Simplified62.7

      \[\leadsto \color{blue}{1} \cdot \sqrt{0 + z \cdot z}\]
    7. Simplified41.3

      \[\leadsto 1 \cdot \color{blue}{\left|z\right|}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification24.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 3.824751598715583 \cdot 10^{+307}:\\ \;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\left|z\right|\\ \end{array}\]

Reproduce

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