Average Error: 26.6 → 16.6
Time: 3.2s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -8.29857753110238368 \cdot 10^{124} \lor \neg \left(d \le 7.1886537093075794 \cdot 10^{50}\right):\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{d + \frac{{c}^{2}}{d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{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 \le -8.29857753110238368 \cdot 10^{124} \lor \neg \left(d \le 7.1886537093075794 \cdot 10^{50}\right):\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{d + \frac{{c}^{2}}{d}}\\

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

\end{array}
double code(double a, double b, double c, double d) {
	return ((double) (((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 VAR;
	if (((d <= -8.298577531102384e+124) || !(d <= 7.1886537093075794e+50))) {
		VAR = ((double) (((double) (((double) (b * c)) / ((double) (((double) (c * c)) + ((double) (d * d)))))) - ((double) (a / ((double) (d + ((double) (((double) pow(c, 2.0)) / d))))))));
	} else {
		VAR = ((double) (((double) (b * ((double) (c / ((double) (((double) (c * c)) + ((double) (d * d)))))))) - ((double) (((double) (a * d)) / ((double) (((double) (c * c)) + ((double) (d * d))))))));
	}
	return VAR;
}

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.6
Target0.4
Herbie16.6
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \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 < -8.29857753110238368e124 or 7.1886537093075794e50 < d

    1. Initial program 38.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub38.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 associate-/l*34.8

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\]
    6. Taylor expanded around 0 16.5

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

    if -8.29857753110238368e124 < d < 7.1886537093075794e50

    1. Initial program 19.1

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub19.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 *-un-lft-identity19.1

      \[\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-frac16.7

      \[\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. Simplified16.7

      \[\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 simplification16.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le -8.29857753110238368 \cdot 10^{124} \lor \neg \left(d \le 7.1886537093075794 \cdot 10^{50}\right):\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{d + \frac{{c}^{2}}{d}}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \end{array}\]

Reproduce

herbie shell --seed 2020149 
(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)))) (/ (+ (neg a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))