(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (/ (- (* c b) (* d a)) (hypot d c)) (hypot d c))))
(if (<= c -2.9316931711396905e+167)
(/ (- b) (hypot d c))
(if (<= c -1.8647556737340625e-161)
t_0
(if (<= c 7.568560534795e-251)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= c 7.649344911276026e+60)
t_0
(/ (- b (/ (* d a) c)) (hypot d c))))))))double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c);
double tmp;
if (c <= -2.9316931711396905e+167) {
tmp = -b / hypot(d, c);
} else if (c <= -1.8647556737340625e-161) {
tmp = t_0;
} else if (c <= 7.568560534795e-251) {
tmp = ((c * b) / (d * d)) - (a / d);
} else if (c <= 7.649344911276026e+60) {
tmp = t_0;
} else {
tmp = (b - ((d * a) / c)) / hypot(d, c);
}
return tmp;
}
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
public static double code(double a, double b, double c, double d) {
double t_0 = (((c * b) - (d * a)) / Math.hypot(d, c)) / Math.hypot(d, c);
double tmp;
if (c <= -2.9316931711396905e+167) {
tmp = -b / Math.hypot(d, c);
} else if (c <= -1.8647556737340625e-161) {
tmp = t_0;
} else if (c <= 7.568560534795e-251) {
tmp = ((c * b) / (d * d)) - (a / d);
} else if (c <= 7.649344911276026e+60) {
tmp = t_0;
} else {
tmp = (b - ((d * a) / c)) / Math.hypot(d, c);
}
return tmp;
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d): t_0 = (((c * b) - (d * a)) / math.hypot(d, c)) / math.hypot(d, c) tmp = 0 if c <= -2.9316931711396905e+167: tmp = -b / math.hypot(d, c) elif c <= -1.8647556737340625e-161: tmp = t_0 elif c <= 7.568560534795e-251: tmp = ((c * b) / (d * d)) - (a / d) elif c <= 7.649344911276026e+60: tmp = t_0 else: tmp = (b - ((d * a) / c)) / math.hypot(d, c) return tmp
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function code(a, b, c, d) t_0 = Float64(Float64(Float64(Float64(c * b) - Float64(d * a)) / hypot(d, c)) / hypot(d, c)) tmp = 0.0 if (c <= -2.9316931711396905e+167) tmp = Float64(Float64(-b) / hypot(d, c)); elseif (c <= -1.8647556737340625e-161) tmp = t_0; elseif (c <= 7.568560534795e-251) tmp = Float64(Float64(Float64(c * b) / Float64(d * d)) - Float64(a / d)); elseif (c <= 7.649344911276026e+60) tmp = t_0; else tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / hypot(d, c)); end return tmp end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
function tmp_2 = code(a, b, c, d) t_0 = (((c * b) - (d * a)) / hypot(d, c)) / hypot(d, c); tmp = 0.0; if (c <= -2.9316931711396905e+167) tmp = -b / hypot(d, c); elseif (c <= -1.8647556737340625e-161) tmp = t_0; elseif (c <= 7.568560534795e-251) tmp = ((c * b) / (d * d)) - (a / d); elseif (c <= 7.649344911276026e+60) tmp = t_0; else tmp = (b - ((d * a) / c)) / hypot(d, c); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -2.9316931711396905e+167], N[((-b) / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -1.8647556737340625e-161], t$95$0, If[LessEqual[c, 7.568560534795e-251], N[(N[(N[(c * b), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 7.649344911276026e+60], t$95$0, N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -2.9316931711396905 \cdot 10^{+167}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \leq -1.8647556737340625 \cdot 10^{-161}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 7.568560534795 \cdot 10^{-251}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 7.649344911276026 \cdot 10^{+60}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.9 |
|---|---|
| Target | 0.5 |
| Herbie | 12.1 |
if c < -2.93169317113969053e167Initial program 43.6
Simplified43.6
Applied add-sqr-sqrt_binary6443.6
Applied *-un-lft-identity_binary6443.6
Applied times-frac_binary6443.6
Simplified43.6
Simplified30.4
Applied associate-*l/_binary6430.4
Simplified30.4
Taylor expanded in c around -inf 12.4
Simplified12.4
if -2.93169317113969053e167 < c < -1.86475567373406252e-161 or 7.5685605347949994e-251 < c < 7.64934491127602648e60Initial program 19.2
Simplified19.2
Applied add-sqr-sqrt_binary6419.2
Applied *-un-lft-identity_binary6419.2
Applied times-frac_binary6419.2
Simplified19.2
Simplified12.4
Applied associate-*l/_binary6412.2
Simplified12.2
if -1.86475567373406252e-161 < c < 7.5685605347949994e-251Initial program 25.4
Simplified25.4
Applied add-sqr-sqrt_binary6425.4
Applied *-un-lft-identity_binary6425.4
Applied times-frac_binary6425.4
Simplified25.4
Simplified14.9
Applied add-sqr-sqrt_binary6415.1
Applied *-un-lft-identity_binary6415.1
Applied times-frac_binary6415.2
Applied associate-*l*_binary6415.2
Simplified15.1
Taylor expanded in d around inf 9.0
Simplified9.0
if 7.64934491127602648e60 < c Initial program 37.6
Simplified37.6
Applied add-sqr-sqrt_binary6437.6
Applied *-un-lft-identity_binary6437.6
Applied times-frac_binary6437.7
Simplified37.7
Simplified25.8
Applied associate-*l/_binary6425.7
Simplified25.7
Taylor expanded in c around inf 13.9
Final simplification12.1
herbie shell --seed 2022129
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))