Average Error: 26.0 → 8.8
Time: 3.5s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -1.32733267246339254 \cdot 10^{154} \lor \neg \left(d \le 1.33619704567748062 \cdot 10^{154}\right):\\ \;\;\;\;\frac{b}{\frac{c \cdot c + d \cdot d}{c}} - \frac{a}{d + \frac{{c}^{2}}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{{d}^{2}}{c} + c} - \frac{a}{\frac{c \cdot c + d \cdot d}{d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le -1.32733267246339254 \cdot 10^{154} \lor \neg \left(d \le 1.33619704567748062 \cdot 10^{154}\right):\\
\;\;\;\;\frac{b}{\frac{c \cdot c + d \cdot d}{c}} - \frac{a}{d + \frac{{c}^{2}}{d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\frac{{d}^{2}}{c} + c} - \frac{a}{\frac{c \cdot c + d \cdot d}{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 (((d <= -1.3273326724633925e+154) || !(d <= 1.3361970456774806e+154))) {
		temp = ((b / (((c * c) + (d * d)) / c)) - (a / (d + (pow(c, 2.0) / d))));
	} else {
		temp = ((b / ((pow(d, 2.0) / c) + c)) - (a / (((c * c) + (d * 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.0
Target0.5
Herbie8.8
\[\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 < -1.3273326724633925e+154 or 1.3361970456774806e+154 < d

    1. Initial program 45.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity45.2

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}\]
    4. Using strategy rm
    5. Applied div-sub45.2

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{c}}} - \frac{a \cdot d}{1 \cdot \left(c \cdot c + d \cdot d\right)}\]
    7. Simplified44.1

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

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

    if -1.3273326724633925e+154 < d < 1.3361970456774806e+154

    1. Initial program 19.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity19.3

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}\]
    4. Using strategy rm
    5. Applied div-sub19.3

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

      \[\leadsto \color{blue}{\frac{b}{\frac{c \cdot c + d \cdot d}{c}}} - \frac{a \cdot d}{1 \cdot \left(c \cdot c + d \cdot d\right)}\]
    7. Simplified15.5

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

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

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

Reproduce

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