Average Error: 26.5 → 26.0
Time: 3.5s
Precision: binary64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (-
  (* (/ c (sqrt (+ (* c c) (* d d)))) (/ b (sqrt (+ (* c c) (* d d)))))
  (* d (/ a (+ (* c c) (* d d))))))
double code(double a, double b, double c, double d) {
	return (((double) (((double) (b * c)) - ((double) (a * d)))) / ((double) (((double) (c * c)) + ((double) (d * d)))));
}
double code(double a, double b, double c, double d) {
	return ((double) (((double) ((c / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))) * (b / ((double) sqrt(((double) (((double) (c * c)) + ((double) (d * d))))))))) - ((double) (d * (a / ((double) (((double) (c * c)) + ((double) (d * d)))))))));
}

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.5
Target0.6
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. Initial program Error: 26.5 bits

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied div-subError: 26.5 bits

    \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
  4. SimplifiedError: 27.0 bits

    \[\leadsto \color{blue}{c \cdot \frac{b}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  5. SimplifiedError: 27.6 bits

    \[\leadsto c \cdot \frac{b}{c \cdot c + d \cdot d} - \color{blue}{d \cdot \frac{a}{c \cdot c + d \cdot d}}\]
  6. Using strategy rm
  7. Applied add-sqr-sqrtError: 27.6 bits

    \[\leadsto c \cdot \frac{b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
  8. Applied *-un-lft-identityError: 27.6 bits

    \[\leadsto c \cdot \frac{\color{blue}{1 \cdot b}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
  9. Applied times-fracError: 27.6 bits

    \[\leadsto c \cdot \color{blue}{\left(\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}\right)} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
  10. Applied associate-*r*Error: 26.1 bits

    \[\leadsto \color{blue}{\left(c \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}\right) \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
  11. SimplifiedError: 26.0 bits

    \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - d \cdot \frac{a}{c \cdot c + d \cdot d}\]
  12. Final simplificationError: 26.0 bits

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

Reproduce

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