Average Error: 26.2 → 23.7
Time: 3.1s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -4.002330886974353 \cdot 10^{-17} \lor \neg \left(c \le 3.4366687886863465 \cdot 10^{63}\right):\\ \;\;\;\;\frac{b}{\frac{{c}^{2} + {d}^{2}}{c}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{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}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -4.002330886974353 \cdot 10^{-17} \lor \neg \left(c \le 3.4366687886863465 \cdot 10^{63}\right):\\
\;\;\;\;\frac{b}{\frac{{c}^{2} + {d}^{2}}{c}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;\frac{b \cdot c}{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}}\\

\end{array}
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 temp;
	if (((c <= -4.002330886974353e-17) || !(c <= 3.4366687886863465e+63))) {
		temp = ((b / ((pow(c, 2.0) + pow(d, 2.0)) / c)) - ((a * d) / ((c * c) + (d * d))));
	} else {
		temp = (((b * c) / ((c * c) + (d * d))) - ((a / sqrt(((c * c) + (d * d)))) * (d / sqrt(((c * c) + (d * d))))));
	}
	return temp;
}

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.2
Target0.4
Herbie23.7
\[\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 < -4.002330886974353e-17 or 3.4366687886863465e+63 < c

    1. Initial program 33.9

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

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

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

    if -4.002330886974353e-17 < c < 3.4366687886863465e+63

    1. Initial program 19.0

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

      \[\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-sqrt19.0

      \[\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-frac17.2

      \[\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}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification23.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -4.002330886974353 \cdot 10^{-17} \lor \neg \left(c \le 3.4366687886863465 \cdot 10^{63}\right):\\ \;\;\;\;\frac{b}{\frac{{c}^{2} + {d}^{2}}{c}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{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}}\\ \end{array}\]

Reproduce

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