Average Error: 25.5 → 23.8
Time: 3.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{b \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r116589 = b;
        double r116590 = c;
        double r116591 = r116589 * r116590;
        double r116592 = a;
        double r116593 = d;
        double r116594 = r116592 * r116593;
        double r116595 = r116591 - r116594;
        double r116596 = r116590 * r116590;
        double r116597 = r116593 * r116593;
        double r116598 = r116596 + r116597;
        double r116599 = r116595 / r116598;
        return r116599;
}

double f(double a, double b, double c, double d) {
        double r116600 = b;
        double r116601 = c;
        double r116602 = r116601 * r116601;
        double r116603 = d;
        double r116604 = r116603 * r116603;
        double r116605 = r116602 + r116604;
        double r116606 = sqrt(r116605);
        double r116607 = r116601 / r116606;
        double r116608 = r116600 * r116607;
        double r116609 = r116608 / r116606;
        double r116610 = a;
        double r116611 = r116610 * r116603;
        double r116612 = r116611 / r116605;
        double r116613 = r116609 - r116612;
        return r116613;
}

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.5
Target0.5
Herbie23.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 25.5

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied div-sub25.5

    \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt25.5

    \[\leadsto \frac{b \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  6. Applied times-frac24.3

    \[\leadsto \color{blue}{\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  7. Using strategy rm
  8. Applied associate-*r/24.2

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

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

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

Reproduce

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