Average Error: 26.1 → 22.5
Time: 4.1s
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 r131744 = b;
        double r131745 = c;
        double r131746 = r131744 * r131745;
        double r131747 = a;
        double r131748 = d;
        double r131749 = r131747 * r131748;
        double r131750 = r131746 - r131749;
        double r131751 = r131745 * r131745;
        double r131752 = r131748 * r131748;
        double r131753 = r131751 + r131752;
        double r131754 = r131750 / r131753;
        return r131754;
}

double f(double a, double b, double c, double d) {
        double r131755 = b;
        double r131756 = c;
        double r131757 = r131756 * r131756;
        double r131758 = d;
        double r131759 = r131758 * r131758;
        double r131760 = r131757 + r131759;
        double r131761 = sqrt(r131760);
        double r131762 = r131761 / r131756;
        double r131763 = r131755 / r131762;
        double r131764 = a;
        double r131765 = r131761 / r131758;
        double r131766 = r131764 / r131765;
        double r131767 = r131763 - r131766;
        double r131768 = r131767 / r131761;
        return r131768;
}

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.1
Target0.4
Herbie22.5
\[\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.1

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

    \[\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.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. Using strategy rm
  6. Applied add-sqr-sqrt26.1

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

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

    \[\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.4

    \[\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.5

    \[\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.5

    \[\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 2019318 
(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))))