Average Error: 25.8 → 24.3
Time: 12.6s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}
double f(double a, double b, double c, double d) {
        double r120768 = b;
        double r120769 = c;
        double r120770 = r120768 * r120769;
        double r120771 = a;
        double r120772 = d;
        double r120773 = r120771 * r120772;
        double r120774 = r120770 - r120773;
        double r120775 = r120769 * r120769;
        double r120776 = r120772 * r120772;
        double r120777 = r120775 + r120776;
        double r120778 = r120774 / r120777;
        return r120778;
}

double f(double a, double b, double c, double d) {
        double r120779 = b;
        double r120780 = c;
        double r120781 = r120780 * r120780;
        double r120782 = d;
        double r120783 = r120782 * r120782;
        double r120784 = r120781 + r120783;
        double r120785 = sqrt(r120784);
        double r120786 = sqrt(r120785);
        double r120787 = r120779 / r120786;
        double r120788 = r120780 / r120786;
        double r120789 = r120787 * r120788;
        double r120790 = a;
        double r120791 = r120790 * r120782;
        double r120792 = r120791 / r120785;
        double r120793 = r120789 - r120792;
        double r120794 = r120786 * r120786;
        double r120795 = r120793 / r120794;
        return r120795;
}

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.8
Target0.4
Herbie24.3
\[\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.8

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

    \[\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*25.7

    \[\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 div-sub25.7

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  11. Using strategy rm
  12. Applied add-sqr-sqrt24.1

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

    \[\leadsto \frac{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}}\]
  14. Final simplification24.3

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

Reproduce

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