Average Error: 26.1 → 24.4
Time: 3.7s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -inf.0:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 8.4881995002292849 \cdot 10^{286}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;e^{\log b - \log c}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -inf.0:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 8.4881995002292849 \cdot 10^{286}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;e^{\log b - \log c}\\

\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 ((((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))))) <= -inf.0)) {
		VAR = ((double) (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))));
	} else {
		double VAR_1;
		if ((((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))))) <= 8.488199500229285e+286)) {
			VAR_1 = ((double) (((double) (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d)))))))) / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))));
		} else {
			VAR_1 = ((double) exp(((double) (((double) log(b)) - ((double) log(c))))));
		}
		VAR = VAR_1;
	}
	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.4
Herbie24.4
\[\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 3 regimes
  2. if (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -inf.0

    1. Initial program 64.0

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*64.0

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    5. Taylor expanded around inf 55.5

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

    if -inf.0 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 8.488199500229285e+286

    1. Initial program 11.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt11.6

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*11.5

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

    if 8.488199500229285e+286 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))

    1. Initial program 63.0

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

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{e^{\log \left(c \cdot c + d \cdot d\right)}}}\]
    4. Applied add-exp-log63.1

      \[\leadsto \frac{\color{blue}{e^{\log \left(b \cdot c - a \cdot d\right)}}}{e^{\log \left(c \cdot c + d \cdot d\right)}}\]
    5. Applied div-exp63.1

      \[\leadsto \color{blue}{e^{\log \left(b \cdot c - a \cdot d\right) - \log \left(c \cdot c + d \cdot d\right)}}\]
    6. Simplified63.1

      \[\leadsto e^{\color{blue}{\log \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\right)}}\]
    7. Taylor expanded around inf 57.6

      \[\leadsto e^{\color{blue}{\log \left(\frac{1}{c}\right) - \log \left(\frac{1}{b}\right)}}\]
    8. Simplified57.6

      \[\leadsto e^{\color{blue}{\log b - \log c}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -inf.0:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 8.4881995002292849 \cdot 10^{286}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;e^{\log b - \log c}\\ \end{array}\]

Reproduce

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