Average Error: 37.8 → 0.4
Time: 4.4s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\left|\frac{\mathsf{hypot}\left(\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(\mathsf{hypot}\left(x, y\right), z\right)}{\sqrt{3}}\right|
double f(double x, double y, double z) {
        double r1033387 = x;
        double r1033388 = r1033387 * r1033387;
        double r1033389 = y;
        double r1033390 = r1033389 * r1033389;
        double r1033391 = r1033388 + r1033390;
        double r1033392 = z;
        double r1033393 = r1033392 * r1033392;
        double r1033394 = r1033391 + r1033393;
        double r1033395 = 3.0;
        double r1033396 = r1033394 / r1033395;
        double r1033397 = sqrt(r1033396);
        return r1033397;
}

double f(double x, double y, double z) {
        double r1033398 = x;
        double r1033399 = y;
        double r1033400 = hypot(r1033398, r1033399);
        double r1033401 = z;
        double r1033402 = hypot(r1033400, r1033401);
        double r1033403 = 3.0;
        double r1033404 = sqrt(r1033403);
        double r1033405 = r1033402 / r1033404;
        double r1033406 = fabs(r1033405);
        return r1033406;
}

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.8
Target25.5
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.8

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

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

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

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

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

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

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

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

Reproduce

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