Average Error: 26.8 → 25.9
Time: 6.9s
Precision: binary64
\[\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} \leq -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 8.875741042111203 \cdot 10^{+280}\right):\\ \;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}{\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}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 8.875741042111203 \cdot 10^{+280}\right):\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}{\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 (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) (- INFINITY))
         (not
          (<=
           (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
           8.875741042111203e+280)))
   (/ (- a) (sqrt (+ (* c c) (* d d))))
   (/
    (/ 1.0 (/ (sqrt (+ (* c c) (* d d))) (- (* b c) (* a d))))
    (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 (((((b * c) - (a * d)) / ((c * c) + (d * d))) <= -((double) INFINITY)) || !((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 8.875741042111203e+280)) {
		tmp = -a / sqrt((c * c) + (d * d));
	} else {
		tmp = (1.0 / (sqrt((c * c) + (d * d)) / ((b * c) - (a * d)))) / 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

Original26.8
Target0.4
Herbie25.9
\[\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 (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0 or 8.87572e280 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 62.6

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

      \[\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. Simplified62.6

      \[\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}}\]
    6. Taylor expanded around 0 59.4

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified59.4

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

    if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 8.87572e280

    1. Initial program 12.3

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

      \[\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*_binary6412.2

      \[\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. Simplified12.2

      \[\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}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity_binary6412.2

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(c \cdot b - d \cdot a\right)}}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
    8. Applied associate-/l*_binary6412.3

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

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

Reproduce

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