(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 (pow (hypot d c) 2.0))
(t_1 (fma (/ b d) (/ c d) (/ (- a) d)))
(t_2 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -5.174874392946877e+44)
t_2
(if (<= c -1.6974732352827345e+24)
t_1
(if (<= c -1.7029803518844395e-105)
(* (- (* a d) (* c b)) (/ 1.0 (- t_0)))
(if (<= c 1.700724934216277e-110)
(/ (- (* b (/ c d)) a) d)
(if (<= c 1.948418831344656e+28)
(/ (- (* c b) (* a d)) t_0)
(if (<= c 6.489345394500517e+62) t_1 t_2))))))))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 = pow(hypot(d, c), 2.0);
double t_1 = fma((b / d), (c / d), (-a / d));
double t_2 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -5.174874392946877e+44) {
tmp = t_2;
} else if (c <= -1.6974732352827345e+24) {
tmp = t_1;
} else if (c <= -1.7029803518844395e-105) {
tmp = ((a * d) - (c * b)) * (1.0 / -t_0);
} else if (c <= 1.700724934216277e-110) {
tmp = ((b * (c / d)) - a) / d;
} else if (c <= 1.948418831344656e+28) {
tmp = ((c * b) - (a * d)) / t_0;
} else if (c <= 6.489345394500517e+62) {
tmp = t_1;
} else {
tmp = t_2;
}
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 = hypot(d, c) ^ 2.0 t_1 = fma(Float64(b / d), Float64(c / d), Float64(Float64(-a) / d)) t_2 = Float64(Float64(b / c) - Float64(Float64(a / c) * Float64(d / c))) tmp = 0.0 if (c <= -5.174874392946877e+44) tmp = t_2; elseif (c <= -1.6974732352827345e+24) tmp = t_1; elseif (c <= -1.7029803518844395e-105) tmp = Float64(Float64(Float64(a * d) - Float64(c * b)) * Float64(1.0 / Float64(-t_0))); elseif (c <= 1.700724934216277e-110) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); elseif (c <= 1.948418831344656e+28) tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / t_0); elseif (c <= 6.489345394500517e+62) tmp = t_1; else tmp = t_2; end return 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[Power[N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / d), $MachinePrecision] * N[(c / d), $MachinePrecision] + N[((-a) / d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(b / c), $MachinePrecision] - N[(N[(a / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.174874392946877e+44], t$95$2, If[LessEqual[c, -1.6974732352827345e+24], t$95$1, If[LessEqual[c, -1.7029803518844395e-105], N[(N[(N[(a * d), $MachinePrecision] - N[(c * b), $MachinePrecision]), $MachinePrecision] * N[(1.0 / (-t$95$0)), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.700724934216277e-110], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.948418831344656e+28], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], If[LessEqual[c, 6.489345394500517e+62], t$95$1, t$95$2]]]]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := {\left(\mathsf{hypot}\left(d, c\right)\right)}^{2}\\
t_1 := \mathsf{fma}\left(\frac{b}{d}, \frac{c}{d}, \frac{-a}{d}\right)\\
t_2 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -5.174874392946877 \cdot 10^{+44}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \leq -1.6974732352827345 \cdot 10^{+24}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -1.7029803518844395 \cdot 10^{-105}:\\
\;\;\;\;\left(a \cdot d - c \cdot b\right) \cdot \frac{1}{-t_0}\\
\mathbf{elif}\;c \leq 1.700724934216277 \cdot 10^{-110}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{elif}\;c \leq 1.948418831344656 \cdot 10^{+28}:\\
\;\;\;\;\frac{c \cdot b - a \cdot d}{t_0}\\
\mathbf{elif}\;c \leq 6.489345394500517 \cdot 10^{+62}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 12.4 |
if c < -5.1748743929468772e44 or 6.48934539450051737e62 < c Initial program 36.6
Simplified36.6
Applied egg-rr36.6
Applied egg-rr36.8
Taylor expanded in d around 0 17.7
Simplified12.6
if -5.1748743929468772e44 < c < -1.69747323528273453e24 or 1.9484188313446559e28 < c < 6.48934539450051737e62Initial program 20.7
Simplified20.7
Applied egg-rr20.7
Applied egg-rr21.3
Taylor expanded in d around inf 37.3
Simplified31.7
Applied egg-rr31.7
if -1.69747323528273453e24 < c < -1.70298035188443947e-105Initial program 14.1
Simplified14.1
Applied egg-rr14.1
if -1.70298035188443947e-105 < c < 1.70072493421627706e-110Initial program 22.2
Simplified22.2
Applied egg-rr22.7
Applied egg-rr23.2
Taylor expanded in d around inf 11.4
Simplified10.1
Applied egg-rr8.0
if 1.70072493421627706e-110 < c < 1.9484188313446559e28Initial program 13.8
Simplified13.8
Applied egg-rr13.8
Applied egg-rr13.8
Final simplification12.4
herbie shell --seed 2022150
(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))))