Average Error: 26.6 → 15.0
Time: 4.7s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \leq -6.473773710016467 \cdot 10^{+43}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot d}{c \cdot c}\\ \mathbf{elif}\;c \leq -4.543194765813328 \cdot 10^{-138}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.6776275404858526 \cdot 10^{-124}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 6.219416782523323 \cdot 10^{+140}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -6.473773710016467 \cdot 10^{+43}:\\
\;\;\;\;\frac{b}{c} - \frac{a \cdot d}{c \cdot c}\\

\mathbf{elif}\;c \leq -4.543194765813328 \cdot 10^{-138}:\\
\;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\

\mathbf{elif}\;c \leq 2.6776275404858526 \cdot 10^{-124}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\

\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 (<= c -6.473773710016467e+43)
   (- (/ b c) (/ (* a d) (* c c)))
   (if (<= c -4.543194765813328e-138)
     (/ (- (* c b) (* a d)) (+ (* c c) (* d d)))
     (if (<= c 2.6776275404858526e-124)
       (- (/ (* c b) (* d d)) (/ a d))
       (if (<= c 6.219416782523323e+140)
         (/
          (/ (- (* c b) (* a d)) (sqrt (+ (* c c) (* d d))))
          (sqrt (+ (* c c) (* d d))))
         (/ b c))))))
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 (c <= -6.473773710016467e+43) {
		tmp = (b / c) - ((a * d) / (c * c));
	} else if (c <= -4.543194765813328e-138) {
		tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 2.6776275404858526e-124) {
		tmp = ((c * b) / (d * d)) - (a / d);
	} else if (c <= 6.219416782523323e+140) {
		tmp = (((c * b) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else {
		tmp = b / c;
	}
	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.6
Target0.5
Herbie15.0
\[\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 5 regimes
  2. if c < -6.473773710016467e43

    1. Initial program 36.0

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

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

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

    if -6.473773710016467e43 < c < -4.54319476581332804e-138

    1. Initial program 13.9

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]

    if -4.54319476581332804e-138 < c < 2.6776275404858526e-124

    1. Initial program 23.4

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

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

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

    if 2.6776275404858526e-124 < c < 6.21941678252332329e140

    1. Initial program 18.1

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

      \[\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*_binary64_343218.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}}}\]

    if 6.21941678252332329e140 < c

    1. Initial program 43.3

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

      \[\leadsto \color{blue}{\frac{b}{c}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification15.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.473773710016467 \cdot 10^{+43}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot d}{c \cdot c}\\ \mathbf{elif}\;c \leq -4.543194765813328 \cdot 10^{-138}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.6776275404858526 \cdot 10^{-124}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 6.219416782523323 \cdot 10^{+140}:\\ \;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]

Reproduce

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