Average Error: 37.6 → 11.8
Time: 5.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}\;z \leq 1.9985349716331256 \cdot 10^{-128}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)\\ \mathbf{elif}\;z \leq 1.0394913709992255 \cdot 10^{+105}:\\ \;\;\;\;\sqrt{\frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 1.19662711296931 \cdot 10^{+112}:\\ \;\;\;\;-\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt[3]{0.3333333333333333}}\right)\\ \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 1.9985349716331256 \cdot 10^{-128}:\\
\;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)\\

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

\mathbf{elif}\;z \leq 1.19662711296931 \cdot 10^{+112}:\\
\;\;\;\;-\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt[3]{0.3333333333333333}}\right)\\

\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 1.9985349716331256e-128)
   (-
    (*
     (sqrt (sqrt (* (cbrt 0.3333333333333333) (cbrt 0.3333333333333333))))
     (*
      (* x (sqrt (sqrt 0.3333333333333333)))
      (sqrt (sqrt (cbrt 0.3333333333333333))))))
   (if (<= z 1.0394913709992255e+105)
     (sqrt (/ (+ (+ (* y y) (* x x)) (* z z)) 3.0))
     (if (<= z 1.19662711296931e+112)
       (-
        (*
         (sqrt (* (cbrt 0.3333333333333333) (cbrt 0.3333333333333333)))
         (* x (sqrt (cbrt 0.3333333333333333)))))
       (* 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 <= 1.9985349716331256e-128) {
		tmp = -(sqrt(sqrt(cbrt(0.3333333333333333) * cbrt(0.3333333333333333))) * ((x * sqrt(sqrt(0.3333333333333333))) * sqrt(sqrt(cbrt(0.3333333333333333)))));
	} else if (z <= 1.0394913709992255e+105) {
		tmp = sqrt((((y * y) + (x * x)) + (z * z)) / 3.0);
	} else if (z <= 1.19662711296931e+112) {
		tmp = -(sqrt(cbrt(0.3333333333333333) * cbrt(0.3333333333333333)) * (x * sqrt(cbrt(0.3333333333333333))));
	} 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

Original37.6
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 < 1.99853497163312557e-128

    1. Initial program 34.1

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

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

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

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

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

      \[\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_binary643.8

      \[\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_binary643.8

      \[\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_binary643.8

      \[\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*_binary643.8

      \[\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. Simplified3.8

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

    if 1.99853497163312557e-128 < z < 1.0394913709992255e105

    1. Initial program 19.5

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

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

    if 1.0394913709992255e105 < z < 1.19662711296931008e112

    1. Initial program 23.1

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

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

      \[\leadsto \color{blue}{-\sqrt{0.3333333333333333} \cdot x}\]
    4. Using strategy rm
    5. Applied add-cube-cbrt_binary6435.2

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

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

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

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

    if 1.19662711296931008e112 < z

    1. Initial program 55.1

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

      \[\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 1.9985349716331256 \cdot 10^{-128}:\\ \;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)\\ \mathbf{elif}\;z \leq 1.0394913709992255 \cdot 10^{+105}:\\ \;\;\;\;\sqrt{\frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}}\\ \mathbf{elif}\;z \leq 1.19662711296931 \cdot 10^{+112}:\\ \;\;\;\;-\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt[3]{0.3333333333333333}}\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \sqrt{0.3333333333333333}\\ \end{array}\]

Alternatives

Reproduce

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