Average Error: 38.3 → 0.4
Time: 4.6s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\frac{\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\frac{\mathsf{hypot}\left(1 \cdot \mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}
double f(double x, double y, double z) {
        double r906060 = x;
        double r906061 = r906060 * r906060;
        double r906062 = y;
        double r906063 = r906062 * r906062;
        double r906064 = r906061 + r906063;
        double r906065 = z;
        double r906066 = r906065 * r906065;
        double r906067 = r906064 + r906066;
        double r906068 = 3.0;
        double r906069 = r906067 / r906068;
        double r906070 = sqrt(r906069);
        return r906070;
}

double f(double x, double y, double z) {
        double r906071 = 1.0;
        double r906072 = x;
        double r906073 = y;
        double r906074 = hypot(r906072, r906073);
        double r906075 = r906071 * r906074;
        double r906076 = z;
        double r906077 = hypot(r906075, r906076);
        double r906078 = 3.0;
        double r906079 = sqrt(r906078);
        double r906080 = r906077 / r906079;
        return r906080;
}

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.3
Target25.7
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 38.3

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

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

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

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

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

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

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

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

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

Reproduce

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