Average Error: 26.4 → 26.3
Time: 15.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r10871792 = b;
        double r10871793 = c;
        double r10871794 = r10871792 * r10871793;
        double r10871795 = a;
        double r10871796 = d;
        double r10871797 = r10871795 * r10871796;
        double r10871798 = r10871794 - r10871797;
        double r10871799 = r10871793 * r10871793;
        double r10871800 = r10871796 * r10871796;
        double r10871801 = r10871799 + r10871800;
        double r10871802 = r10871798 / r10871801;
        return r10871802;
}

double f(double a, double b, double c, double d) {
        double r10871803 = b;
        double r10871804 = c;
        double r10871805 = r10871803 * r10871804;
        double r10871806 = a;
        double r10871807 = d;
        double r10871808 = r10871806 * r10871807;
        double r10871809 = r10871805 - r10871808;
        double r10871810 = r10871804 * r10871804;
        double r10871811 = r10871807 * r10871807;
        double r10871812 = r10871810 + r10871811;
        double r10871813 = sqrt(r10871812);
        double r10871814 = r10871809 / r10871813;
        double r10871815 = r10871814 / r10871813;
        return r10871815;
}

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.4
Target0.5
Herbie26.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 26.4

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

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

    \[\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. Final simplification26.3

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

Reproduce

herbie shell --seed 2019174 
(FPCore (a b c d)
  :name "Complex division, imag part"

  :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))))