Average Error: 26.8 → 23.1
Time: 3.9s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq -2.024796178527634 \cdot 10^{-05} \lor \neg \left(d \leq 7.741980536026424 \cdot 10^{-194}\right):\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{d \cdot a}{c \cdot c + d \cdot d}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -2.024796178527634 \cdot 10^{-05} \lor \neg \left(d \leq 7.741980536026424 \cdot 10^{-194}\right):\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{d \cdot a}{c \cdot c + d \cdot d}\\

\end{array}
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -2.024796178527634e-05) (not (<= d 7.741980536026424e-194)))
   (-
    (* (/ b (sqrt (+ (* c c) (* d d)))) (/ c (sqrt (+ (* c c) (* d d)))))
    (* (/ a (sqrt (+ (* c c) (* d d)))) (/ d (sqrt (+ (* c c) (* d d))))))
   (- (* b (/ c (+ (* c c) (* d d)))) (/ (* d a) (+ (* c c) (* d d))))))
double code(double a, double b, double c, double d) {
	return (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))));
}
double code(double a, double b, double c, double d) {
	double tmp;
	if (((d <= -2.024796178527634e-05) || !(d <= 7.741980536026424e-194))) {
		tmp = ((double) (((double) ((b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (c / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))))) - ((double) ((a / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (d / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))))));
	} else {
		tmp = ((double) (((double) (b * (c / ((double) (((double) (c * c)) + ((double) (d * d))))))) - (((double) (d * a)) / ((double) (((double) (c * c)) + ((double) (d * d)))))));
	}
	return tmp;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original26.8
Target0.4
Herbie23.1
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if d < -2.02479617852763408e-5 or 7.74198053602642366e-194 < d

    1. Initial program 29.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub_binary6429.1

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary6429.1

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied times-frac_binary6426.3

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt_binary6426.3

      \[\leadsto \frac{b \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\]
    9. Applied times-frac_binary6425.2

      \[\leadsto \color{blue}{\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\]

    if -2.02479617852763408e-5 < d < 7.74198053602642366e-194

    1. Initial program 21.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub_binary6421.5

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary6421.5

      \[\leadsto \frac{b \cdot c}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    6. Applied times-frac_binary6418.6

      \[\leadsto \color{blue}{\frac{b}{1} \cdot \frac{c}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    7. Simplified18.6

      \[\leadsto \color{blue}{b} \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification23.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.024796178527634 \cdot 10^{-05} \lor \neg \left(d \leq 7.741980536026424 \cdot 10^{-194}\right):\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{d \cdot a}{c \cdot c + d \cdot d}\\ \end{array}\]

Reproduce

herbie shell --seed 2020210 
(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))))