Average Error: 37.8 → 13.1
Time: 9.9s
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 2.4826679296397353 \cdot 10^{-132}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{elif}\;x \cdot x \leq 8.877649567199404 \cdot 10^{-12}:\\ \;\;\;\;\sqrt{\frac{1}{\frac{3}{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\\ \mathbf{elif}\;x \cdot x \leq 3.647553549943544 \cdot 10^{+42}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{elif}\;x \cdot x \leq 2.3636282655334077 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{1}{\frac{3}{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\\ \mathbf{elif}\;x \cdot x \leq 3.1679652483186795 \cdot 10^{+196}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{else}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\ \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 2.4826679296397353 \cdot 10^{-132}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot z\\

\mathbf{elif}\;x \cdot x \leq 8.877649567199404 \cdot 10^{-12}:\\
\;\;\;\;\sqrt{\frac{1}{\frac{3}{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\\

\mathbf{elif}\;x \cdot x \leq 3.647553549943544 \cdot 10^{+42}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot z\\

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

\mathbf{elif}\;x \cdot x \leq 3.1679652483186795 \cdot 10^{+196}:\\
\;\;\;\;\sqrt{0.3333333333333333} \cdot z\\

\mathbf{else}:\\
\;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\

\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) 2.4826679296397353e-132)
   (* (sqrt 0.3333333333333333) z)
   (if (<= (* x x) 8.877649567199404e-12)
     (sqrt (/ 1.0 (/ 3.0 (+ (+ (* x x) (* y y)) (* z z)))))
     (if (<= (* x x) 3.647553549943544e+42)
       (* (sqrt 0.3333333333333333) z)
       (if (<= (* x x) 2.3636282655334077e+154)
         (sqrt (/ 1.0 (/ 3.0 (+ (+ (* x x) (* y y)) (* z z)))))
         (if (<= (* x x) 3.1679652483186795e+196)
           (* (sqrt 0.3333333333333333) z)
           (-
            (*
             (sqrt (sqrt (cbrt 0.3333333333333333)))
             (*
              (sqrt (cbrt 0.3333333333333333))
              (* x (sqrt (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) <= 2.4826679296397353e-132) {
		tmp = sqrt(0.3333333333333333) * z;
	} else if ((x * x) <= 8.877649567199404e-12) {
		tmp = sqrt(1.0 / (3.0 / (((x * x) + (y * y)) + (z * z))));
	} else if ((x * x) <= 3.647553549943544e+42) {
		tmp = sqrt(0.3333333333333333) * z;
	} else if ((x * x) <= 2.3636282655334077e+154) {
		tmp = sqrt(1.0 / (3.0 / (((x * x) + (y * y)) + (z * z))));
	} else if ((x * x) <= 3.1679652483186795e+196) {
		tmp = sqrt(0.3333333333333333) * z;
	} else {
		tmp = -(sqrt(sqrt(cbrt(0.3333333333333333))) * (sqrt(cbrt(0.3333333333333333)) * (x * sqrt(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

Original37.8
Target20.1
Herbie13.1
\[\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 3 regimes
  2. if (*.f64 x x) < 2.4826679296397353e-132 or 8.8776495671994045e-12 < (*.f64 x x) < 3.6475535499435439e42 or 2.36362826553340767e154 < (*.f64 x x) < 3.16796524831867955e196

    1. Initial program 27.8

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

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

    if 2.4826679296397353e-132 < (*.f64 x x) < 8.8776495671994045e-12 or 3.6475535499435439e42 < (*.f64 x x) < 2.36362826553340767e154

    1. Initial program 21.2

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

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

    if 3.16796524831867955e196 < (*.f64 x x)

    1. Initial program 53.6

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

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

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

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

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

      \[\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_2159610.9

      \[\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_2157710.9

      \[\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_2157710.9

      \[\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_2150210.9

      \[\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)}\]
    13. Simplified10.9

      \[\leadsto -\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \color{blue}{\left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)}\]
    14. Using strategy rm
    15. Applied sqrt-prod_binary64_2157710.9

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

      \[\leadsto -\color{blue}{\left(\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)} \cdot \left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)\]
    17. Applied associate-*l*_binary64_2150211.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2.4826679296397353 \cdot 10^{-132}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{elif}\;x \cdot x \leq 8.877649567199404 \cdot 10^{-12}:\\ \;\;\;\;\sqrt{\frac{1}{\frac{3}{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\\ \mathbf{elif}\;x \cdot x \leq 3.647553549943544 \cdot 10^{+42}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{elif}\;x \cdot x \leq 2.3636282655334077 \cdot 10^{+154}:\\ \;\;\;\;\sqrt{\frac{1}{\frac{3}{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}\\ \mathbf{elif}\;x \cdot x \leq 3.1679652483186795 \cdot 10^{+196}:\\ \;\;\;\;\sqrt{0.3333333333333333} \cdot z\\ \mathbf{else}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}} \cdot \left(\sqrt{\sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right)\right)\\ \end{array}\]

Reproduce

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