Average Error: 37.5 → 0.4
Time: 3.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\left|\frac{\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}\right|\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\left|\frac{\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}\right|
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) {
	return fabs((hypot((1.0 * hypot(x, y)), z) / sqrt(3.0)));
}

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.5
Target25.6
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.3964793941097758 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.3202936944041821 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.333333333333333315} \cdot z\\ \end{array}\]

Derivation

  1. Initial program 37.5

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

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

    \[\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}}}{\sqrt{3} \cdot \sqrt{3}}}\]
  5. Applied times-frac37.6

    \[\leadsto \sqrt{\color{blue}{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}} \cdot \frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}}}\]
  6. Applied rem-sqrt-square37.6

    \[\leadsto \color{blue}{\left|\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{\sqrt{3}}\right|}\]
  7. Using strategy rm
  8. Applied add-sqr-sqrt37.6

    \[\leadsto \left|\frac{\sqrt{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} + z \cdot z}}{\sqrt{3}}\right|\]
  9. Applied hypot-def28.6

    \[\leadsto \left|\frac{\color{blue}{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}}{\sqrt{3}}\right|\]
  10. Using strategy rm
  11. Applied *-un-lft-identity28.6

    \[\leadsto \left|\frac{\mathsf{hypot}\left(\sqrt{\color{blue}{1 \cdot \left(x \cdot x + y \cdot y\right)}}, z\right)}{\sqrt{3}}\right|\]
  12. Applied sqrt-prod28.6

    \[\leadsto \left|\frac{\mathsf{hypot}\left(\color{blue}{\sqrt{1} \cdot \sqrt{x \cdot x + y \cdot y}}, z\right)}{\sqrt{3}}\right|\]
  13. Simplified28.6

    \[\leadsto \left|\frac{\mathsf{hypot}\left(\color{blue}{1} \cdot \sqrt{x \cdot x + y \cdot y}, z\right)}{\sqrt{3}}\right|\]
  14. Simplified0.4

    \[\leadsto \left|\frac{\mathsf{hypot}\left(1 \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}, z\right)}{\sqrt{3}}\right|\]
  15. Final simplification0.4

    \[\leadsto \left|\frac{\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}\right|\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(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)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3)) (* (sqrt 0.3333333333333333) z)))

  (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3)))