Average Error: 26.5 → 22.8
Time: 3.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r118214 = b;
        double r118215 = c;
        double r118216 = r118214 * r118215;
        double r118217 = a;
        double r118218 = d;
        double r118219 = r118217 * r118218;
        double r118220 = r118216 - r118219;
        double r118221 = r118215 * r118215;
        double r118222 = r118218 * r118218;
        double r118223 = r118221 + r118222;
        double r118224 = r118220 / r118223;
        return r118224;
}

double f(double a, double b, double c, double d) {
        double r118225 = b;
        double r118226 = c;
        double r118227 = r118226 * r118226;
        double r118228 = d;
        double r118229 = r118228 * r118228;
        double r118230 = r118227 + r118229;
        double r118231 = sqrt(r118230);
        double r118232 = r118231 / r118226;
        double r118233 = r118225 / r118232;
        double r118234 = a;
        double r118235 = r118231 / r118228;
        double r118236 = r118234 / r118235;
        double r118237 = r118233 - r118236;
        double r118238 = r118237 / r118231;
        return r118238;
}

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.4
Herbie22.8
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \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 26.5

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

    \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Applied sqrt-prod26.5

    \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  8. Using strategy rm
  9. Applied div-sub26.5

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

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

    \[\leadsto \frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \color{blue}{\frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  12. Final simplification22.8

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

Reproduce

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