\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\begin{array}{l}
\mathbf{if}\;z \leq 1.2351025899530227 \cdot 10^{-43}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 1.5219024465843806 \cdot 10^{+123}:\\
\;\;\;\;\sqrt{\left(x \cdot x + y \cdot y\right) + z \cdot z}\\
\mathbf{elif}\;z \leq 3.607133536644106 \cdot 10^{+130}:\\
\;\;\;\;-x\\
\mathbf{elif}\;z \leq 1.2922293721606246 \cdot 10^{+145}:\\
\;\;\;\;\sqrt{x \cdot x + z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}(FPCore (x y z) :precision binary64 (sqrt (+ (+ (* x x) (* y y)) (* z z))))
(FPCore (x y z)
:precision binary64
(if (<= z 1.2351025899530227e-43)
(- x)
(if (<= z 1.5219024465843806e+123)
(sqrt (+ (+ (* x x) (* y y)) (* z z)))
(if (<= z 3.607133536644106e+130)
(- x)
(if (<= z 1.2922293721606246e+145) (sqrt (+ (* x x) (* z z))) z)))))double code(double x, double y, double z) {
return sqrt(((x * x) + (y * y)) + (z * z));
}
double code(double x, double y, double z) {
double tmp;
if (z <= 1.2351025899530227e-43) {
tmp = -x;
} else if (z <= 1.5219024465843806e+123) {
tmp = sqrt(((x * x) + (y * y)) + (z * z));
} else if (z <= 3.607133536644106e+130) {
tmp = -x;
} else if (z <= 1.2922293721606246e+145) {
tmp = sqrt((x * x) + (z * z));
} else {
tmp = z;
}
return tmp;
}




Bits error versus x




Bits error versus y




Bits error versus z
Results
| Original | 37.8 |
|---|---|
| Target | 18.9 |
| Herbie | 11.1 |
if z < 1.2351025899530227e-43 or 1.5219024465843806e123 < z < 3.6071335366441058e130Initial program 29.4
Taylor expanded around -inf 9.0
Simplified9.0
if 1.2351025899530227e-43 < z < 1.5219024465843806e123Initial program 17.9
if 3.6071335366441058e130 < z < 1.29222937216062463e145Initial program 15.5
Taylor expanded around 0 15.5
Simplified15.5
if 1.29222937216062463e145 < z Initial program 61.9
Taylor expanded around inf 8.5
Final simplification11.1
herbie shell --seed 2021043
(FPCore (x y z)
:name "FRP.Yampa.Vector3:vector3Rho from Yampa-0.10.2"
:precision binary64
:herbie-target
(if (< z -6.396479394109776e+136) (- z) (if (< z 7.320293694404182e+117) (sqrt (+ (+ (* z z) (* x x)) (* y y))) z))
(sqrt (+ (+ (* x x) (* y y)) (* z z))))