\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + y \cdot y\right) + z \cdot z \leq 1.497190811277626 \cdot 10^{+303}:\\
\;\;\;\;\sqrt{\left(\left(x \cdot x + y \cdot y\right) + z \cdot z\right) \cdot 0.3333333333333333}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\sqrt{3}}\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z) :precision binary64 (if (<= (+ (+ (* x x) (* y y)) (* z z)) 1.497190811277626e+303) (sqrt (* (+ (+ (* x x) (* y y)) (* z z)) 0.3333333333333333)) (/ y (sqrt 3.0))))
double code(double x, double y, double z) {
return sqrt((((x * x) + (y * y)) + (z * z)) / 3.0);
}
double code(double x, double y, double z) {
double tmp;
if ((((x * x) + (y * y)) + (z * z)) <= 1.497190811277626e+303) {
tmp = sqrt((((x * x) + (y * y)) + (z * z)) * 0.3333333333333333);
} else {
tmp = y / sqrt(3.0);
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 38.3 |
|---|---|
| Target | 25.8 |
| Herbie | 31.9 |
if (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) < 1.4971908112776259e303Initial program 2.4
rmApplied div-inv_binary64_195122.4
Simplified2.4
if 1.4971908112776259e303 < (+.f64 (+.f64 (*.f64 x x) (*.f64 y y)) (*.f64 z z)) Initial program 63.2
rmApplied sqrt-div_binary64_1953263.2
Taylor expanded around 0 62.9
Simplified62.9
Taylor expanded around 0 52.4
Final simplification31.9
herbie shell --seed 2020344
(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.0)) (if (< z 7.320293694404182e+117) (/ (sqrt (+ (+ (* z z) (* x x)) (* y y))) (sqrt 3.0)) (* (sqrt 0.3333333333333333) z)))
(sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))