Average Error: 25.9 → 26.0
Time: 5.1s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq 1.0135236429461193 \cdot 10^{+94} \lor \neg \left(d \leq 3.40778976921943 \cdot 10^{+151}\right):\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{c \cdot b - d \cdot a}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\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}\;d \leq 1.0135236429461193 \cdot 10^{+94} \lor \neg \left(d \leq 3.40778976921943 \cdot 10^{+151}\right):\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{c \cdot b - d \cdot a}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot 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 (or (<= d 1.0135236429461193e+94) (not (<= d 3.40778976921943e+151)))
   (/
    (/ 1.0 (/ (sqrt (+ (* c c) (* d d))) (- (* c b) (* d a))))
    (sqrt (+ (* c c) (* d d))))
   (/ (- a) (sqrt (+ (* c c) (* d 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.0135236429461193e+94) || !(d <= 3.40778976921943e+151)) {
		tmp = (1.0 / (sqrt((c * c) + (d * d)) / ((c * b) - (d * a)))) / sqrt((c * c) + (d * d));
	} else {
		tmp = -a / sqrt((c * c) + (d * 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

Original25.9
Target0.5
Herbie26.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 2 regimes
  2. if d < 1.0135236429461193e94 or 3.4077897692194302e151 < d

    1. Initial program 26.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt_binary6426.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*_binary6426.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. Using strategy rm
    6. Applied clear-num_binary6426.0

      \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified26.0

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

    if 1.0135236429461193e94 < d < 3.4077897692194302e151

    1. Initial program 23.2

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

      \[\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*_binary6423.1

      \[\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 0 25.6

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Simplified25.6

      \[\leadsto \frac{\color{blue}{-a}}{\sqrt{c \cdot c + d \cdot d}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 1.0135236429461193 \cdot 10^{+94} \lor \neg \left(d \leq 3.40778976921943 \cdot 10^{+151}\right):\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{c \cdot b - d \cdot a}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

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