\sqrt{\frac{\left(x \cdot x + y \cdot y\right) + z \cdot z}{3}}\begin{array}{l}
\mathbf{if}\;z \le -1.1005165876387523 \cdot 10^{94}:\\
\;\;\;\;\frac{-z}{\sqrt{3}}\\
\mathbf{elif}\;z \le 2.7166609535198792 \cdot 10^{98}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(z, z, \mathsf{fma}\left(y, y, x \cdot x\right)\right)}}{\sqrt{3}}\\
\mathbf{else}:\\
\;\;\;\;z \cdot \sqrt{\frac{1}{3}}\\
\end{array}double f(double x, double y, double z) {
double r612081 = x;
double r612082 = r612081 * r612081;
double r612083 = y;
double r612084 = r612083 * r612083;
double r612085 = r612082 + r612084;
double r612086 = z;
double r612087 = r612086 * r612086;
double r612088 = r612085 + r612087;
double r612089 = 3.0;
double r612090 = r612088 / r612089;
double r612091 = sqrt(r612090);
return r612091;
}
double f(double x, double y, double z) {
double r612092 = z;
double r612093 = -1.1005165876387523e+94;
bool r612094 = r612092 <= r612093;
double r612095 = -r612092;
double r612096 = 3.0;
double r612097 = sqrt(r612096);
double r612098 = r612095 / r612097;
double r612099 = 2.7166609535198792e+98;
bool r612100 = r612092 <= r612099;
double r612101 = y;
double r612102 = x;
double r612103 = r612102 * r612102;
double r612104 = fma(r612101, r612101, r612103);
double r612105 = fma(r612092, r612092, r612104);
double r612106 = sqrt(r612105);
double r612107 = r612106 / r612097;
double r612108 = 1.0;
double r612109 = r612108 / r612096;
double r612110 = sqrt(r612109);
double r612111 = r612092 * r612110;
double r612112 = r612100 ? r612107 : r612111;
double r612113 = r612094 ? r612098 : r612112;
return r612113;
}




Bits error versus x




Bits error versus y




Bits error versus z
| Original | 37.9 |
|---|---|
| Target | 25.2 |
| Herbie | 25.5 |
if z < -1.1005165876387523e+94Initial program 54.0
Simplified54.0
rmApplied div-inv54.0
Applied sqrt-prod54.1
rmApplied sqrt-div54.1
Applied associate-*r/54.1
Simplified54.1
Taylor expanded around -inf 17.8
Simplified17.8
if -1.1005165876387523e+94 < z < 2.7166609535198792e+98Initial program 29.4
Simplified29.4
rmApplied div-inv29.4
Applied sqrt-prod29.5
rmApplied sqrt-div29.8
Applied associate-*r/29.5
Simplified29.5
if 2.7166609535198792e+98 < z Initial program 53.6
Simplified53.6
rmApplied div-inv53.7
Applied sqrt-prod53.7
Taylor expanded around inf 18.1
Final simplification25.5
herbie shell --seed 2019198 +o rules:numerics
(FPCore (x y z)
:name "Data.Array.Repa.Algorithms.Pixel:doubleRmsOfRGB8 from repa-algorithms-3.4.0.1"
: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)))