\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.0565595159497016 \cdot 10^{-69}:\\
\;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\
\mathbf{elif}\;x \cdot x \leq 6.412866807444753 \cdot 10^{+56}:\\
\;\;\;\;\sqrt{\frac{1}{\sqrt[3]{3} \cdot \sqrt[3]{3}}} \cdot \sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{\sqrt[3]{3}}}\\
\mathbf{elif}\;x \cdot x \leq 1.9227738798845486 \cdot 10^{+126}:\\
\;\;\;\;\sqrt{\sqrt{0.3333333333333333}} \cdot \left(\sqrt{\sqrt{0.3333333333333333}} \cdot z\right)\\
\mathbf{elif}\;x \cdot x \leq 4.0316350048513144 \cdot 10^{+234}:\\
\;\;\;\;\sqrt{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}} \cdot \sqrt{\frac{\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}}{3}}\\
\mathbf{else}:\\
\;\;\;\;-x \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 (<= (* x x) 1.0565595159497016e-69)
(* (sqrt (sqrt 0.3333333333333333)) (* (sqrt (sqrt 0.3333333333333333)) z))
(if (<= (* x x) 6.412866807444753e+56)
(*
(sqrt (/ 1.0 (* (cbrt 3.0) (cbrt 3.0))))
(sqrt (/ (+ (+ (* x x) (* y y)) (* z z)) (cbrt 3.0))))
(if (<= (* x x) 1.9227738798845486e+126)
(*
(sqrt (sqrt 0.3333333333333333))
(* (sqrt (sqrt 0.3333333333333333)) z))
(if (<= (* x x) 4.0316350048513144e+234)
(*
(sqrt (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(sqrt (/ (sqrt (+ (+ (* x x) (* y y)) (* z z))) 3.0)))
(- (* x (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 ((x * x) <= 1.0565595159497016e-69) {
tmp = sqrt(sqrt(0.3333333333333333)) * (sqrt(sqrt(0.3333333333333333)) * z);
} else if ((x * x) <= 6.412866807444753e+56) {
tmp = sqrt(1.0 / (cbrt(3.0) * cbrt(3.0))) * sqrt((((x * x) + (y * y)) + (z * z)) / cbrt(3.0));
} else if ((x * x) <= 1.9227738798845486e+126) {
tmp = sqrt(sqrt(0.3333333333333333)) * (sqrt(sqrt(0.3333333333333333)) * z);
} else if ((x * x) <= 4.0316350048513144e+234) {
tmp = sqrt(sqrt(((x * x) + (y * y)) + (z * z))) * sqrt(sqrt(((x * x) + (y * y)) + (z * z)) / 3.0);
} else {
tmp = -(x * sqrt(0.3333333333333333));
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 38.3 |
|---|---|
| Target | 20.3 |
| Herbie | 12.6 |
if (*.f64 x x) < 1.05655951594970156e-69 or 6.41286680744475321e56 < (*.f64 x x) < 1.9227738798845486e126Initial program 28.3
Taylor expanded around inf 11.3
Simplified11.3
rmApplied add-sqr-sqrt_binary64_2294711.6
Simplified11.6
Simplified11.6
rmApplied sqrt-prod_binary64_2294111.5
Applied associate-*l*_binary64_2286611.5
Simplified11.5
Taylor expanded around 0 11.3
Simplified11.3
if 1.05655951594970156e-69 < (*.f64 x x) < 6.41286680744475321e56Initial program 22.2
rmApplied add-cube-cbrt_binary64_2296022.2
Applied *-un-lft-identity_binary64_2292522.2
Applied times-frac_binary64_2293122.2
Applied sqrt-prod_binary64_2294122.3
if 1.9227738798845486e126 < (*.f64 x x) < 4.03163500485131444e234Initial program 19.3
rmApplied *-un-lft-identity_binary64_2292519.3
Applied add-sqr-sqrt_binary64_2294719.3
Applied times-frac_binary64_2293119.3
Applied sqrt-prod_binary64_2294119.4
if 4.03163500485131444e234 < (*.f64 x x) Initial program 56.1
Taylor expanded around -inf 10.4
Final simplification12.6
herbie shell --seed 2021098
(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)))