Average Error: 26.1 → 14.6
Time: 7.1s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq -1.7583795913022137 \cdot 10^{+73}:\\ \;\;\;\;\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -3.8832875515775854 \cdot 10^{-129}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{elif}\;d \leq 7.370595873778618 \cdot 10^{-67}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.469351418967785 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -1.7583795913022137 \cdot 10^{+73}:\\
\;\;\;\;\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\\

\mathbf{elif}\;d \leq -3.8832875515775854 \cdot 10^{-129}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\

\mathbf{elif}\;d \leq 7.370595873778618 \cdot 10^{-67}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}\\

\mathbf{elif}\;d \leq 2.469351418967785 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\

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

\end{array}
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.7583795913022137e+73)
   (- (/ (* b c) (* d d)) (/ a d))
   (if (<= d -3.8832875515775854e-129)
     (/
      (/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
      (sqrt (+ (* d d) (* c c))))
     (if (<= d 7.370595873778618e-67)
       (- (/ b c) (/ (* d a) (pow c 2.0)))
       (if (<= d 2.469351418967785e+133)
         (/
          (/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
          (sqrt (+ (* d d) (* c c))))
         (- (/ (* b c) (* d d)) (/ a d)))))))
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 tmp;
	if (d <= -1.7583795913022137e+73) {
		tmp = ((b * c) / (d * d)) - (a / d);
	} else if (d <= -3.8832875515775854e-129) {
		tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
	} else if (d <= 7.370595873778618e-67) {
		tmp = (b / c) - ((d * a) / pow(c, 2.0));
	} else if (d <= 2.469351418967785e+133) {
		tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
	} else {
		tmp = ((b * c) / (d * d)) - (a / d);
	}
	return tmp;
}

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
Herbie14.6
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \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 d < -1.7583795913022137e73 or 2.4693514189677851e133 < d

    1. Initial program 40.7

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

      \[\leadsto \color{blue}{\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}}\]
    4. Simplified40.8

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}}\]
    6. Simplified17.1

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

    if -1.7583795913022137e73 < d < -3.88328755157758536e-129 or 7.3705958737786183e-67 < d < 2.4693514189677851e133

    1. Initial program 15.5

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

      \[\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*_binary6415.4

      \[\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. Simplified15.4

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

    if -3.88328755157758536e-129 < d < 7.3705958737786183e-67

    1. Initial program 21.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Taylor expanded around inf 11.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.7583795913022137 \cdot 10^{+73}:\\ \;\;\;\;\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -3.8832875515775854 \cdot 10^{-129}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{elif}\;d \leq 7.370595873778618 \cdot 10^{-67}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}\\ \mathbf{elif}\;d \leq 2.469351418967785 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\\ \end{array}\]

Reproduce

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