Average Error: 38.0 → 0.3
Time: 3.9s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\left(\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right) \cdot \sqrt{\sqrt{\frac{1}{3}}}\right) \cdot \sqrt{\sqrt{\frac{1}{3}}}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\left(\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right) \cdot \sqrt{\sqrt{\frac{1}{3}}}\right) \cdot \sqrt{\sqrt{\frac{1}{3}}}
double f(double x, double y, double z) {
        double r793821 = x;
        double r793822 = r793821 * r793821;
        double r793823 = y;
        double r793824 = r793823 * r793823;
        double r793825 = r793822 + r793824;
        double r793826 = z;
        double r793827 = r793826 * r793826;
        double r793828 = r793825 + r793827;
        double r793829 = 3.0;
        double r793830 = r793828 / r793829;
        double r793831 = sqrt(r793830);
        return r793831;
}

double f(double x, double y, double z) {
        double r793832 = 1.0;
        double r793833 = x;
        double r793834 = y;
        double r793835 = hypot(r793833, r793834);
        double r793836 = r793832 * r793835;
        double r793837 = z;
        double r793838 = hypot(r793836, r793837);
        double r793839 = 3.0;
        double r793840 = r793832 / r793839;
        double r793841 = sqrt(r793840);
        double r793842 = sqrt(r793841);
        double r793843 = r793838 * r793842;
        double r793844 = r793843 * r793842;
        return r793844;
}

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.0
Target26.0
Herbie0.3
\[\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 38.0

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

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

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

    \[\leadsto \sqrt{\color{blue}{\sqrt{x \cdot x + y \cdot y} \cdot \sqrt{x \cdot x + y \cdot y}} + z \cdot z} \cdot \sqrt{\frac{1}{3}}\]
  7. Applied hypot-def29.0

    \[\leadsto \color{blue}{\mathsf{hypot}\left(\sqrt{x \cdot x + y \cdot y}, z\right)} \cdot \sqrt{\frac{1}{3}}\]
  8. Using strategy rm
  9. Applied *-un-lft-identity29.0

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

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

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

    \[\leadsto \mathsf{hypot}\left(1 \cdot \color{blue}{\mathsf{hypot}\left(x, y\right)}, z\right) \cdot \sqrt{\frac{1}{3}}\]
  13. Using strategy rm
  14. Applied add-sqr-sqrt0.4

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

    \[\leadsto \mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right) \cdot \color{blue}{\left(\sqrt{\sqrt{\frac{1}{3}}} \cdot \sqrt{\sqrt{\frac{1}{3}}}\right)}\]
  16. Applied associate-*r*0.3

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

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

Reproduce

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