\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\begin{array}{l}
\mathbf{if}\;z \leq 1.9985349716331256 \cdot 10^{-128}:\\
\;\;\;\;-\sqrt{\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}}} \cdot \left(\left(x \cdot \sqrt{\sqrt{0.3333333333333333}}\right) \cdot \sqrt{\sqrt{\sqrt[3]{0.3333333333333333}}}\right)\\
\mathbf{elif}\;z \leq 1.0394913709992255 \cdot 10^{+105}:\\
\;\;\;\;\sqrt{\frac{\left(y \cdot y + x \cdot x\right) + z \cdot z}{3}}\\
\mathbf{elif}\;z \leq 1.19662711296931 \cdot 10^{+112}:\\
\;\;\;\;-\sqrt{\sqrt[3]{0.3333333333333333} \cdot \sqrt[3]{0.3333333333333333}} \cdot \left(x \cdot \sqrt{\sqrt[3]{0.3333333333333333}}\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{0.3333333333333333}\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) 3.0)))
(FPCore (x y z)
:precision binary64
(if (<= z 1.9985349716331256e-128)
(-
(*
(sqrt (sqrt (* (cbrt 0.3333333333333333) (cbrt 0.3333333333333333))))
(*
(* x (sqrt (sqrt 0.3333333333333333)))
(sqrt (sqrt (cbrt 0.3333333333333333))))))
(if (<= z 1.0394913709992255e+105)
(sqrt (/ (+ (+ (* y y) (* x x)) (* z z)) 3.0))
(if (<= z 1.19662711296931e+112)
(-
(*
(sqrt (* (cbrt 0.3333333333333333) (cbrt 0.3333333333333333)))
(* x (sqrt (cbrt 0.3333333333333333)))))
(* z (sqrt 0.3333333333333333))))))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 (z <= 1.9985349716331256e-128) {
tmp = -(sqrt(sqrt(cbrt(0.3333333333333333) * cbrt(0.3333333333333333))) * ((x * sqrt(sqrt(0.3333333333333333))) * sqrt(sqrt(cbrt(0.3333333333333333)))));
} else if (z <= 1.0394913709992255e+105) {
tmp = sqrt((((y * y) + (x * x)) + (z * z)) / 3.0);
} else if (z <= 1.19662711296931e+112) {
tmp = -(sqrt(cbrt(0.3333333333333333) * cbrt(0.3333333333333333)) * (x * sqrt(cbrt(0.3333333333333333))));
} else {
tmp = z * sqrt(0.3333333333333333);
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.6 |
|---|---|
| Target | 19.9 |
| Herbie | 11.8 |
if z < 1.99853497163312557e-128Initial program 34.1
Taylor expanded around -inf 3.8
Simplified3.8
rmApplied add-sqr-sqrt_binary643.8
Applied associate-*l*_binary643.8
Simplified3.8
rmApplied add-cube-cbrt_binary643.8
Applied sqrt-prod_binary643.8
Applied sqrt-prod_binary643.8
Applied associate-*l*_binary643.8
Simplified3.8
if 1.99853497163312557e-128 < z < 1.0394913709992255e105Initial program 19.5
rmApplied +-commutative_binary6419.5
if 1.0394913709992255e105 < z < 1.19662711296931008e112Initial program 23.1
Taylor expanded around -inf 35.2
Simplified35.2
rmApplied add-cube-cbrt_binary6435.2
Applied sqrt-prod_binary6435.2
Applied associate-*l*_binary6435.3
Simplified35.3
if 1.19662711296931008e112 < z Initial program 55.1
Taylor expanded around inf 10.3
Final simplification11.8
herbie shell --seed 2021118
(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)))