\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 r882963 = x;
double r882964 = r882963 * r882963;
double r882965 = y;
double r882966 = r882965 * r882965;
double r882967 = r882964 + r882966;
double r882968 = z;
double r882969 = r882968 * r882968;
double r882970 = r882967 + r882969;
double r882971 = 3.0;
double r882972 = r882970 / r882971;
double r882973 = sqrt(r882972);
return r882973;
}
double f(double x, double y, double z) {
double r882974 = x;
double r882975 = y;
double r882976 = hypot(r882974, r882975);
double r882977 = z;
double r882978 = hypot(r882976, r882977);
double r882979 = 1.0;
double r882980 = 3.0;
double r882981 = r882979 / r882980;
double r882982 = sqrt(r882981);
double r882983 = r882978 * r882982;
return r882983;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.9 |
|---|---|
| Target | 26.0 |
| Herbie | 0.4 |
Initial program 37.9
rmApplied div-inv37.9
Applied sqrt-prod38.0
rmApplied add-sqr-sqrt38.0
Applied hypot-def29.1
rmApplied hypot-def0.4
Final simplification0.4
herbie shell --seed 2020039 +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)))