Average Error: 38.1 → 0.4
Time: 12.8s
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 r883632 = x;
        double r883633 = r883632 * r883632;
        double r883634 = y;
        double r883635 = r883634 * r883634;
        double r883636 = r883633 + r883635;
        double r883637 = z;
        double r883638 = r883637 * r883637;
        double r883639 = r883636 + r883638;
        double r883640 = 3.0;
        double r883641 = r883639 / r883640;
        double r883642 = sqrt(r883641);
        return r883642;
}

double f(double x, double y, double z) {
        double r883643 = x;
        double r883644 = y;
        double r883645 = hypot(r883643, r883644);
        double r883646 = z;
        double r883647 = hypot(r883645, r883646);
        double r883648 = 3.0;
        double r883649 = sqrt(r883648);
        double r883650 = r883647 / r883649;
        double r883651 = fabs(r883650);
        return r883651;
}

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.1
Target26.0
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.1

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

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

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

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

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

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

    \[\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 *-un-lft-identity28.9

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

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

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

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

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

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

Reproduce

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