Average Error: 37.8 → 27.2
Time: 6.2s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\
\;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\

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

\mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\
\;\;\;\;z \cdot \sqrt{0.333333333333333315}\\

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

\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{0.333333333333333315}\\

\end{array}
double code(double x, double y, double z) {
	return sqrt(((((x * x) + (y * y)) + (z * z)) / 3.0));
}
double code(double x, double y, double z) {
	double temp;
	if ((x <= -2.016424411749676e+133)) {
		temp = (-1.0 * (x / sqrt(3.0)));
	} else {
		double temp_1;
		if ((x <= 1.4232710093281964e-37)) {
			temp_1 = sqrt((sqrt((((x * x) + (y * y)) + (z * z))) * (sqrt((((x * x) + (y * y)) + (z * z))) / 3.0)));
		} else {
			double temp_2;
			if ((x <= 5.4695075101521495e+42)) {
				temp_2 = (z * sqrt(0.3333333333333333));
			} else {
				double temp_3;
				if ((x <= 1.199826361110612e+75)) {
					temp_3 = sqrt((sqrt((((x * x) + (y * y)) + (z * z))) * (sqrt((((x * x) + (y * y)) + (z * z))) / 3.0)));
				} else {
					temp_3 = (x * sqrt(0.3333333333333333));
				}
				temp_2 = temp_3;
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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
Target25.7
Herbie27.2
\[\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 < -2.016424411749676e+133

    1. Initial program 59.7

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

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{\sqrt{3} \cdot \sqrt{3}}}}\]
    4. Applied add-sqr-sqrt59.7

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

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

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

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

    if -2.016424411749676e+133 < x < 1.4232710093281964e-37 or 5.4695075101521495e+42 < x < 1.199826361110612e+75

    1. Initial program 29.4

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity29.4

      \[\leadsto \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\color{blue}{1 \cdot 3}}}\]
    4. Applied add-sqr-sqrt29.4

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

      \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{1} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}}\]
    6. Simplified29.4

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

    if 1.4232710093281964e-37 < x < 5.4695075101521495e+42

    1. Initial program 27.8

      \[\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 1.199826361110612e+75 < x

    1. Initial program 52.4

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

      \[\leadsto \color{blue}{x \cdot \sqrt{0.333333333333333315}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification27.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.016424411749676 \cdot 10^{133}:\\ \;\;\;\;-1 \cdot \frac{x}{\sqrt{3}}\\ \mathbf{elif}\;x \le 1.4232710093281964 \cdot 10^{-37}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{elif}\;x \le 5.4695075101521495 \cdot 10^{42}:\\ \;\;\;\;z \cdot \sqrt{0.333333333333333315}\\ \mathbf{elif}\;x \le 1.199826361110612 \cdot 10^{75}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \sqrt{0.333333333333333315}\\ \end{array}\]

Reproduce

herbie shell --seed 2020049 +o rules:numerics
(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) (/ (- z) (sqrt 3)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.3333333333333333) z)))

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