Average Error: 38.7 → 0.4
Time: 3.8s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right) \cdot \sqrt{\frac{1}{3}}\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right) \cdot \sqrt{\frac{1}{3}}
double f(double x, double y, double z) {
        double r837207 = x;
        double r837208 = r837207 * r837207;
        double r837209 = y;
        double r837210 = r837209 * r837209;
        double r837211 = r837208 + r837210;
        double r837212 = z;
        double r837213 = r837212 * r837212;
        double r837214 = r837211 + r837213;
        double r837215 = 3.0;
        double r837216 = r837214 / r837215;
        double r837217 = sqrt(r837216);
        return r837217;
}

double f(double x, double y, double z) {
        double r837218 = x;
        double r837219 = y;
        double r837220 = hypot(r837218, r837219);
        double r837221 = z;
        double r837222 = hypot(r837220, r837221);
        double r837223 = 1.0;
        double r837224 = 3.0;
        double r837225 = r837223 / r837224;
        double r837226 = sqrt(r837225);
        double r837227 = r837222 * r837226;
        return r837227;
}

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.7
Target26.3
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.7

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

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

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

    \[\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.5

    \[\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 hypot-def0.4

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

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

Reproduce

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