Average Error: 37.8 → 0.4
Time: 4.5s
Precision: 64
\[\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\]
\[\left|\frac{\frac{\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right)}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|\]
\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}
\left|\frac{\frac{\mathsf{hypot}\left(\mathsf{hypot}\left(x, y\right), z\right)}{\left|\sqrt[3]{3}\right|}}{\sqrt{\sqrt[3]{3}}}\right|
double f(double x, double y, double z) {
        double r1037007 = x;
        double r1037008 = r1037007 * r1037007;
        double r1037009 = y;
        double r1037010 = r1037009 * r1037009;
        double r1037011 = r1037008 + r1037010;
        double r1037012 = z;
        double r1037013 = r1037012 * r1037012;
        double r1037014 = r1037011 + r1037013;
        double r1037015 = 3.0;
        double r1037016 = r1037014 / r1037015;
        double r1037017 = sqrt(r1037016);
        return r1037017;
}

double f(double x, double y, double z) {
        double r1037018 = x;
        double r1037019 = y;
        double r1037020 = hypot(r1037018, r1037019);
        double r1037021 = z;
        double r1037022 = hypot(r1037020, r1037021);
        double r1037023 = 3.0;
        double r1037024 = cbrt(r1037023);
        double r1037025 = fabs(r1037024);
        double r1037026 = r1037022 / r1037025;
        double r1037027 = sqrt(r1037024);
        double r1037028 = r1037026 / r1037027;
        double r1037029 = fabs(r1037028);
        return r1037029;
}

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.7
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;z \lt -6.396479394109775845820908799933348003545 \cdot 10^{136}:\\ \;\;\;\;\frac{-z}{\sqrt{3}}\\ \mathbf{elif}\;z \lt 7.320293694404182125923160810847974073098 \cdot 10^{117}:\\ \;\;\;\;\frac{\sqrt{\left(z \cdot z + x \cdot x\right) + y \cdot y}}{\sqrt{3}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.3333333333333333148296162562473909929395} \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-sqrt37.9

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

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

    \[\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. Using strategy rm
  13. Applied add-cube-cbrt0.4

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

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

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

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

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

Reproduce

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