Average Error: 37.9 → 26.4
Time: 4.9s
Precision: binary64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -4.0701656365416582 \cdot 10^{106}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 2.1069120080825549 \cdot 10^{-216}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \le 1.34129281756916036 \cdot 10^{-166}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 2.031375809460608 \cdot 10^{124}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -4.0701656365416582 \cdot 10^{106}:\\
\;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\

\mathbf{elif}\;x \le 2.1069120080825549 \cdot 10^{-216}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{elif}\;x \le 1.34129281756916036 \cdot 10^{-166}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

\mathbf{elif}\;x \le 2.031375809460608 \cdot 10^{124}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{\sqrt{3}}\\

\end{array}
double code(double x, double y, double z) {
	return ((double) sqrt(((double) (((double) (((double) (((double) (x * x)) + ((double) (y * y)))) + ((double) (z * z)))) / 3.0))));
}
double code(double x, double y, double z) {
	double VAR;
	if ((x <= -4.070165636541658e+106)) {
		VAR = ((double) (-1.0 * ((double) (x * ((double) sqrt(0.3333333333333333))))));
	} else {
		double VAR_1;
		if ((x <= 2.106912008082555e-216)) {
			VAR_1 = ((double) sqrt(((double) (((double) (((double) (((double) (x * x)) + ((double) (y * y)))) + ((double) (z * z)))) / 3.0))));
		} else {
			double VAR_2;
			if ((x <= 1.3412928175691604e-166)) {
				VAR_2 = ((double) (z * ((double) sqrt(0.3333333333333333))));
			} else {
				double VAR_3;
				if ((x <= 2.031375809460608e+124)) {
					VAR_3 = ((double) sqrt(((double) (((double) (((double) (((double) (x * x)) + ((double) (y * y)))) + ((double) (z * z)))) / 3.0))));
				} else {
					VAR_3 = ((double) (x / ((double) sqrt(3.0))));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

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.5
Herbie26.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if x < -4.0701656365416582e106

    1. Initial program 55.6

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)}\]

    if -4.0701656365416582e106 < x < 2.1069120080825549e-216 or 1.34129281756916036e-166 < x < 2.031375809460608e124

    1. Initial program 29.3

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

    if 2.1069120080825549e-216 < x < 1.34129281756916036e-166

    1. Initial program 33.7

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

      \[\leadsto \color{blue}{z \cdot \sqrt{0.333333333333333315}}\]

    if 2.031375809460608e124 < x

    1. Initial program 58.1

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt58.1

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied *-un-lft-identity58.1

      \[\leadsto \sqrt{\frac{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right)}}{\sqrt{3} \cdot \sqrt{3}}}\]
    5. Applied times-frac58.1

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\sqrt{3}} \cdot \frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt{3}}}}\]
    6. Applied sqrt-prod58.2

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{3}}} \cdot \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt{3}}}}\]
    7. Taylor expanded around inf 17.1

      \[\leadsto \color{blue}{\frac{x}{\sqrt{3}}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification26.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.0701656365416582 \cdot 10^{106}:\\ \;\;\;\;-1 \cdot \left(x \cdot \sqrt{0.333333333333333315}\right)\\ \mathbf{elif}\;x \le 2.1069120080825549 \cdot 10^{-216}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;x \le 1.34129281756916036 \cdot 10^{-166}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 2.031375809460608 \cdot 10^{124}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\sqrt{3}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020173 
(FPCore (x y z)
  :name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
  :precision binary64

  :herbie-target
  (if (< z -6.396479394109776e+136) (/ (neg z) (sqrt 3.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))