Average Error: 37.6 → 0.4
Time: 6.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\sqrt{\frac{1}{3}} \cdot \mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right)\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\sqrt{\frac{1}{3}} \cdot \mathsf{hypot}\left(z, \mathsf{hypot}\left(x, y\right)\right)
double f(double x, double y, double z) {
        double r901776 = x;
        double r901777 = r901776 * r901776;
        double r901778 = y;
        double r901779 = r901778 * r901778;
        double r901780 = r901777 + r901779;
        double r901781 = z;
        double r901782 = r901781 * r901781;
        double r901783 = r901780 + r901782;
        double r901784 = 3.0;
        double r901785 = r901783 / r901784;
        double r901786 = sqrt(r901785);
        return r901786;
}

double f(double x, double y, double z) {
        double r901787 = 1.0;
        double r901788 = 3.0;
        double r901789 = r901787 / r901788;
        double r901790 = sqrt(r901789);
        double r901791 = z;
        double r901792 = x;
        double r901793 = y;
        double r901794 = hypot(r901792, r901793);
        double r901795 = hypot(r901791, r901794);
        double r901796 = r901790 * r901795;
        return r901796;
}

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
Target25.2
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.6

    \[\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{\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}}}{3}}\]
  4. Applied associate-/l*37.6

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

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

    \[\leadsto \sqrt{\frac{\color{blue}{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}}{\frac{3}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}\]
  8. Using strategy rm
  9. Applied div-inv37.6

    \[\leadsto \sqrt{\frac{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)}{\color{blue}{3 \cdot \frac{1}{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}}}}\]
  10. Applied *-un-lft-identity37.6

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

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

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

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

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

Reproduce

herbie shell --seed 2020035 +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)))