Average Error: 38.3 → 11.8
Time: 8.5s
Precision: binary64
\[[x, y, z]=\mathsf{sort}([x, y, z])\]
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\begin{array}{l} \mathbf{if}\;z \leq 8.300356615998216 \cdot 10^{-137}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\ \mathbf{elif}\;z \leq 1.9929948001661953 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 1.5389623186968813 \cdot 10^{+44}:\\ \;\;\;\;-\sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\\ \mathbf{elif}\;z \leq 1.9982784290001902 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\begin{array}{l}
\mathbf{if}\;z \leq 8.300356615998216 \cdot 10^{-137}:\\
\;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\

\mathbf{elif}\;z \leq 1.9929948001661953 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{elif}\;z \leq 1.5389623186968813 \cdot 10^{+44}:\\
\;\;\;\;-\sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\\

\mathbf{elif}\;z \leq 1.9982784290001902 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\

\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\

\end{array}
(FPCore (x y z)
 :precision binary64
 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z)
 :precision binary64
 (if (<= z 8.300356615998216e-137)
   (-
    (*
     (sqrt (sqrt (* (cbrt 0.3333333333333333) (cbrt 0.3333333333333333))))
     (*
      (sqrt (sqrt (cbrt 0.3333333333333333)))
      (* x (sqrt (sqrt 0.3333333333333333))))))
   (if (<= z 1.9929948001661953e+32)
     (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0))
     (if (<= z 1.5389623186968813e+44)
       (-
        (*
         (sqrt (sqrt 0.3333333333333333))
         (* x (sqrt (sqrt 0.3333333333333333)))))
       (if (<= z 1.9982784290001902e+146)
         (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0))
         (* z (sqrt 0.3333333333333333)))))))
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 tmp;
	if (z <= 8.300356615998216e-137) {
		tmp = -(sqrt(sqrt(cbrt(0.3333333333333333) * cbrt(0.3333333333333333))) * (sqrt(sqrt(cbrt(0.3333333333333333))) * (x * sqrt(sqrt(0.3333333333333333)))));
	} else if (z <= 1.9929948001661953e+32) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
	} else if (z <= 1.5389623186968813e+44) {
		tmp = -(sqrt(sqrt(0.3333333333333333)) * (x * sqrt(sqrt(0.3333333333333333))));
	} else if (z <= 1.9982784290001902e+146) {
		tmp = sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
	} else {
		tmp = z * sqrt(0.3333333333333333);
	}
	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.3
Target19.9
Herbie11.8
\[\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 4 regimes
  2. if z < 8.3003566159982158e-137

    1. Initial program 35.3

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
    3. Simplified3.7

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary64_215833.7

      \[\leadsto -\color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{\sqrt{0.3333333333333333}}\right)} \cdot x\]
    6. Applied associate-*l*_binary64_215023.6

      \[\leadsto -\color{blue}{\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot x\right)}\]
    7. Simplified3.6

      \[\leadsto -\sqrt{\sqrt{0.3333333333333333}} \cdot \color{blue}{\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)}\]
    8. Using strategy rm
    9. Applied add-cube-cbrt_binary64_215963.6

      \[\leadsto -\sqrt{\sqrt{\color{blue}{\left(\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}\right) \cdot \sqrt[3]{0.3333333333333333}}}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\]
    10. Applied sqrt-prod_binary64_215773.6

      \[\leadsto -\sqrt{\color{blue}{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}} \cdot \sqrt{\sqrt[3]{0.3333333333333333}}}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\]
    11. Applied sqrt-prod_binary64_215773.6

      \[\leadsto -\color{blue}{\left(\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\]
    12. Applied associate-*l*_binary64_215023.6

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

    if 8.3003566159982158e-137 < z < 1.99299480016619532e32 or 1.5389623186968813e44 < z < 1.9982784290001902e146

    1. Initial program 19.4

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

    if 1.99299480016619532e32 < z < 1.5389623186968813e44

    1. Initial program 20.2

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
    3. Simplified31.6

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary64_2158331.6

      \[\leadsto -\color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{\sqrt{0.3333333333333333}}\right)} \cdot x\]
    6. Applied associate-*l*_binary64_2150231.6

      \[\leadsto -\color{blue}{\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot x\right)}\]
    7. Simplified31.6

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

    if 1.9982784290001902e146 < z

    1. Initial program 62.1

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

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot z}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification11.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq 8.300356615998216 \cdot 10^{-137}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\ \mathbf{elif}\;z \leq 1.9929948001661953 \cdot 10^{+32}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 1.5389623186968813 \cdot 10^{+44}:\\ \;\;\;\;-\sqrt{\sqrt{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\\ \mathbf{elif}\;z \leq 1.9982784290001902 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]

Reproduce

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