Average Error: 38.3 → 12.6
Time: 9.8s
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}\;x \cdot x \leq 1.0565595159497016 \cdot 10^{-69}:\\ \;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\ \mathbf{elif}\;x \cdot x \leq 6.412866807444753 \cdot 10^{+56}:\\ \;\;\;\;\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}}}\\ \mathbf{elif}\;x \cdot x \leq 1.9227738798845486 \cdot 10^{+126}:\\ \;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\ \mathbf{elif}\;x \cdot x \leq 4.0316350048513144 \cdot 10^{+234}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;-x \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}\;x \cdot x \leq 1.0565595159497016 \cdot 10^{-69}:\\
\;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\

\mathbf{elif}\;x \cdot x \leq 6.412866807444753 \cdot 10^{+56}:\\
\;\;\;\;\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}}}\\

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

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

\mathbf{else}:\\
\;\;\;\;-x \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 (<= (* x x) 1.0565595159497016e-69)
   (* (sqrt (sqrt 0.3333333333333333)) (* (sqrt (sqrt 0.3333333333333333)) z))
   (if (<= (* x x) 6.412866807444753e+56)
     (*
      (sqrt (/ 1.0 (* (cbrt 3.0) (cbrt 3.0))))
      (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) (cbrt 3.0))))
     (if (<= (* x x) 1.9227738798845486e+126)
       (*
        (sqrt (sqrt 0.3333333333333333))
        (* (sqrt (sqrt 0.3333333333333333)) z))
       (if (<= (* x x) 4.0316350048513144e+234)
         (*
          (sqrt (sqrt (+ (+ (* x x) (* y y)) (* z z))))
          (sqrt (/ (sqrt (+ (+ (* x x) (* y y)) (* z z))) 3.0)))
         (- (* x (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 ((x * x) <= 1.0565595159497016e-69) {
		tmp = sqrt(sqrt(0.3333333333333333)) * (sqrt(sqrt(0.3333333333333333)) * z);
	} else if ((x * x) <= 6.412866807444753e+56) {
		tmp = sqrt(1.0 / (cbrt(3.0) * cbrt(3.0))) * sqrt((((x * x) + (y * y)) + (z * z)) / cbrt(3.0));
	} else if ((x * x) <= 1.9227738798845486e+126) {
		tmp = sqrt(sqrt(0.3333333333333333)) * (sqrt(sqrt(0.3333333333333333)) * z);
	} else if ((x * x) <= 4.0316350048513144e+234) {
		tmp = sqrt(sqrt(((x * x) + (y * y)) + (z * z))) * sqrt(sqrt(((x * x) + (y * y)) + (z * z)) / 3.0);
	} else {
		tmp = -(x * 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
Target20.3
Herbie12.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 4 regimes
  2. if (*.f64 x x) < 1.05655951594970156e-69 or 6.41286680744475321e56 < (*.f64 x x) < 1.9227738798845486e126

    1. Initial program 28.3

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

      \[\leadsto \color{blue}{\sqrt{0.3333333333333333} \cdot z}\]
    3. Simplified11.3

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

      \[\leadsto \color{blue}{\sqrt{z \cdot \sqrt{0.3333333333333333}} \cdot \sqrt{z \cdot \sqrt{0.3333333333333333}}}\]
    6. Simplified11.6

      \[\leadsto \color{blue}{\sqrt{\sqrt{0.3333333333333333} \cdot z}} \cdot \sqrt{z \cdot \sqrt{0.3333333333333333}}\]
    7. Simplified11.6

      \[\leadsto \sqrt{\sqrt{0.3333333333333333} \cdot z} \cdot \color{blue}{\sqrt{\sqrt{0.3333333333333333} \cdot z}}\]
    8. Using strategy rm
    9. Applied sqrt-prod_binary64_2294111.5

      \[\leadsto \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot \sqrt{z}\right)} \cdot \sqrt{\sqrt{0.3333333333333333} \cdot z}\]
    10. Applied associate-*l*_binary64_2286611.5

      \[\leadsto \color{blue}{\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{z} \cdot \sqrt{\sqrt{0.3333333333333333} \cdot z}\right)}\]
    11. Simplified11.5

      \[\leadsto \sqrt{\sqrt{0.3333333333333333}} \cdot \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333} \cdot z} \cdot \sqrt{z}\right)}\]
    12. Taylor expanded around 0 11.3

      \[\leadsto \sqrt{\sqrt{0.3333333333333333}} \cdot \color{blue}{\left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)}\]
    13. Simplified11.3

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

    if 1.05655951594970156e-69 < (*.f64 x x) < 6.41286680744475321e56

    1. Initial program 22.2

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

      \[\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-identity_binary64_2292522.2

      \[\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-frac_binary64_2293122.2

      \[\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-prod_binary64_2294122.3

      \[\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}}}}\]

    if 1.9227738798845486e126 < (*.f64 x x) < 4.03163500485131444e234

    1. Initial program 19.3

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

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

      \[\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-frac_binary64_2293119.3

      \[\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. Applied sqrt-prod_binary64_2294119.4

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

    if 4.03163500485131444e234 < (*.f64 x x)

    1. Initial program 56.1

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \sqrt{0.3333333333333333}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.0565595159497016 \cdot 10^{-69}:\\ \;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\ \mathbf{elif}\;x \cdot x \leq 6.412866807444753 \cdot 10^{+56}:\\ \;\;\;\;\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}}}\\ \mathbf{elif}\;x \cdot x \leq 1.9227738798845486 \cdot 10^{+126}:\\ \;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\ \mathbf{elif}\;x \cdot x \leq 4.0316350048513144 \cdot 10^{+234}:\\ \;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\ \mathbf{else}:\\ \;\;\;\;-x \cdot \sqrt{0.3333333333333333}\\ \end{array}\]

Reproduce

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