Average Error: 26.1 → 23.0
Time: 3.5s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -1.9332834244083665 \cdot 10^{35} \lor \neg \left(c \le 9.04660525453447799 \cdot 10^{56}\right):\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\frac{{c}^{2} + {d}^{2}}{d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -1.9332834244083665 \cdot 10^{35} \lor \neg \left(c \le 9.04660525453447799 \cdot 10^{56}\right):\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\frac{{c}^{2} + {d}^{2}}{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 (((c <= -1.9332834244083665e+35) || !(c <= 9.046605254534478e+56))) {
		VAR = ((double) (((double) (((double) (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))) * ((double) (c / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))))) - ((double) (((double) (a * d)) / ((double) (((double) (c * c)) + ((double) (d * d))))))));
	} else {
		VAR = ((double) (((double) (((double) (b * c)) / ((double) (((double) (c * c)) + ((double) (d * d)))))) - ((double) (a / ((double) (((double) (((double) pow(c, 2.0)) + ((double) pow(d, 2.0)))) / 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.1
Target0.5
Herbie23.0
\[\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 c < -1.9332834244083665e+35 or 9.046605254534478e+56 < c

    1. Initial program 35.9

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

      \[\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-sqrt35.9

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

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

    if -1.9332834244083665e+35 < c < 9.046605254534478e+56

    1. Initial program 18.2

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

      \[\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*15.4

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \color{blue}{\frac{a}{\frac{c \cdot c + d \cdot d}{d}}}\]
    6. Simplified15.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -1.9332834244083665 \cdot 10^{35} \lor \neg \left(c \le 9.04660525453447799 \cdot 10^{56}\right):\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a}{\frac{{c}^{2} + {d}^{2}}{d}}\\ \end{array}\]

Reproduce

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