(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 (/ -1.0 (hypot c d))) (t_1 (* a (/ d (hypot c d)))))
(+
(fma (/ c (hypot c d)) (/ b (hypot c d)) (* t_1 t_0))
(fma t_0 t_1 (* (/ 1.0 (hypot c d)) t_1)))))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 = -1.0 / hypot(c, d);
double t_1 = a * (d / hypot(c, d));
return fma((c / hypot(c, d)), (b / hypot(c, d)), (t_1 * t_0)) + fma(t_0, t_1, ((1.0 / hypot(c, d)) * t_1));
}
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(-1.0 / hypot(c, d)) t_1 = Float64(a * Float64(d / hypot(c, d))) return Float64(fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(t_1 * t_0)) + fma(t_0, t_1, Float64(Float64(1.0 / hypot(c, d)) * t_1))) 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[(-1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(t$95$0 * t$95$1 + N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{-1}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := a \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}\\
\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, t_1 \cdot t_0\right) + \mathsf{fma}\left(t_0, t_1, \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot t_1\right)
\end{array}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 1.1 |
Initial program 26.3
Applied egg-rr15.6
Applied egg-rr1.6
Applied egg-rr1.1
Final simplification1.1
herbie shell --seed 2022166
(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))))