(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 (- (* b (/ (/ c d) d)) (/ a d))))
(if (<= d -1.692033155006485e+165)
t_0
(if (<= d 1.0364479188939085e+154)
(-
(* b (* (/ 1.0 (hypot c d)) (/ c (hypot c d))))
(/ (/ (* d a) (hypot c d)) (hypot c d)))
t_0))))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 = (b * ((c / d) / d)) - (a / d);
double tmp;
if (d <= -1.692033155006485e+165) {
tmp = t_0;
} else if (d <= 1.0364479188939085e+154) {
tmp = (b * ((1.0 / hypot(c, d)) * (c / hypot(c, d)))) - (((d * a) / hypot(c, d)) / hypot(c, d));
} else {
tmp = t_0;
}
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 = (b * ((c / d) / d)) - (a / d);
double tmp;
if (d <= -1.692033155006485e+165) {
tmp = t_0;
} else if (d <= 1.0364479188939085e+154) {
tmp = (b * ((1.0 / Math.hypot(c, d)) * (c / Math.hypot(c, d)))) - (((d * a) / Math.hypot(c, d)) / Math.hypot(c, d));
} else {
tmp = t_0;
}
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 = (b * ((c / d) / d)) - (a / d) tmp = 0 if d <= -1.692033155006485e+165: tmp = t_0 elif d <= 1.0364479188939085e+154: tmp = (b * ((1.0 / math.hypot(c, d)) * (c / math.hypot(c, d)))) - (((d * a) / math.hypot(c, d)) / math.hypot(c, d)) else: tmp = t_0 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(b * Float64(Float64(c / d) / d)) - Float64(a / d)) tmp = 0.0 if (d <= -1.692033155006485e+165) tmp = t_0; elseif (d <= 1.0364479188939085e+154) tmp = Float64(Float64(b * Float64(Float64(1.0 / hypot(c, d)) * Float64(c / hypot(c, d)))) - Float64(Float64(Float64(d * a) / hypot(c, d)) / hypot(c, d))); else tmp = t_0; 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 = (b * ((c / d) / d)) - (a / d); tmp = 0.0; if (d <= -1.692033155006485e+165) tmp = t_0; elseif (d <= 1.0364479188939085e+154) tmp = (b * ((1.0 / hypot(c, d)) * (c / hypot(c, d)))) - (((d * a) / hypot(c, d)) / hypot(c, d)); else tmp = t_0; 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[(b * N[(N[(c / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1.692033155006485e+165], t$95$0, If[LessEqual[d, 1.0364479188939085e+154], N[(N[(b * N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(d * a), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\
\mathbf{if}\;d \leq -1.692033155006485 \cdot 10^{+165}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 1.0364479188939085 \cdot 10^{+154}:\\
\;\;\;\;b \cdot \left(\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c}{\mathsf{hypot}\left(c, d\right)}\right) - \frac{\frac{d \cdot a}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.6 |
|---|---|
| Target | 0.5 |
| Herbie | 6.2 |
if d < -1.69203315500648505e165 or 1.0364479188939085e154 < d Initial program 44.3
Simplified44.3
Applied egg-rr44.3
Taylor expanded in d around inf 15.6
Simplified11.6
if -1.69203315500648505e165 < d < 1.0364479188939085e154Initial program 19.3
Simplified19.3
Applied egg-rr19.5
Taylor expanded in a around 0 19.3
Simplified18.8
Applied egg-rr15.9
Applied egg-rr4.4
Final simplification6.2
herbie shell --seed 2022153
(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))))