\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 r987716 = x;
double r987717 = r987716 * r987716;
double r987718 = y;
double r987719 = r987718 * r987718;
double r987720 = r987717 + r987719;
double r987721 = z;
double r987722 = r987721 * r987721;
double r987723 = r987720 + r987722;
double r987724 = 3.0;
double r987725 = r987723 / r987724;
double r987726 = sqrt(r987725);
return r987726;
}
double f(double x, double y, double z) {
double r987727 = x;
double r987728 = y;
double r987729 = hypot(r987727, r987728);
double r987730 = z;
double r987731 = hypot(r987729, r987730);
double r987732 = 1.0;
double r987733 = 3.0;
double r987734 = r987732 / r987733;
double r987735 = sqrt(r987734);
double r987736 = r987731 * r987735;
return r987736;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 38.4 |
|---|---|
| Target | 26.0 |
| Herbie | 0.4 |
Initial program 38.4
rmApplied div-inv38.4
Applied sqrt-prod38.5
rmApplied add-sqr-sqrt38.5
Applied hypot-def29.2
rmApplied hypot-def0.4
Final simplification0.4
herbie shell --seed 2020083 +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)))