Average Error: 38.4 → 31.6
Time: 4.2s
Precision: binary64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4.807113950115273 \cdot 10^{+307}:\\ \;\;\;\;\sqrt{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right) \cdot 0.3333333333333333}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(z \cdot \sqrt{\frac{1}{\sqrt[3]{3}}}\right)\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 4.807113950115273 \cdot 10^{+307}:\\
\;\;\;\;\sqrt{\left(x \cdot x + \left(z \cdot z + y \cdot y\right)\right) \cdot 0.3333333333333333}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \left(z \cdot \sqrt{\frac{1}{\sqrt[3]{3}}}\right)\\

\end{array}
double code(double x, double y, double z) {
	return ((double) sqrt((((double) (((double) (((double) (x * x)) + ((double) (y * y)))) + ((double) (z * z)))) / 3.0)));
}
double code(double x, double y, double z) {
	double VAR;
	if ((((double) (z * z)) <= 4.807113950115273e+307)) {
		VAR = ((double) sqrt(((double) (((double) (((double) (x * x)) + ((double) (((double) (z * z)) + ((double) (y * y)))))) * 0.3333333333333333))));
	} else {
		VAR = ((double) (((double) sqrt((1.0 / ((double) (((double) cbrt(3.0)) * ((double) cbrt(3.0))))))) * ((double) (z * ((double) sqrt((1.0 / ((double) cbrt(3.0)))))))));
	}
	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

Original38.4
Target25.3
Herbie31.6
\[\begin{array}{l} \mathbf{if}\;z < -6.396479394109776 \cdot 10^{+136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z < 7.320293694404182 \cdot 10^{+117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (* z z) < 4.80711395011527317e307

    1. Initial program Error: 29.1 bits

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

      \[\leadsto \sqrt{\color{blue}{0.3333333333333333 \cdot {x}^{2} + \left(0.3333333333333333 \cdot {y}^{2} + 0.3333333333333333 \cdot {z}^{2}\right)}}\]
    3. SimplifiedError: 29.1 bits

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

    if 4.80711395011527317e307 < (* z z)

    1. Initial program Error: 63.9 bits

      \[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
    2. Using strategy rm
    3. Applied add-cube-cbrtError: 63.9 bits

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

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

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

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3}}}}\]
    7. SimplifiedError: 63.9 bits

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\sqrt{\frac{x \cdot x + \left(y \cdot y + z \cdot z\right)}{\sqrt[3]{3}}}}\]
    8. Taylor expanded around 0 Error: 38.4 bits

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt[3]{3}}} \cdot z\right)}\]
    9. SimplifiedError: 38.4 bits

      \[\leadsto \sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \color{blue}{\left(z \cdot \sqrt{\frac{1}{\sqrt[3]{3}}}\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplificationError: 31.6 bits

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

Reproduce

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