Average Error: 26.0 → 25.9
Time: 8.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r32162 = b;
        double r32163 = c;
        double r32164 = r32162 * r32163;
        double r32165 = a;
        double r32166 = d;
        double r32167 = r32165 * r32166;
        double r32168 = r32164 - r32167;
        double r32169 = r32163 * r32163;
        double r32170 = r32166 * r32166;
        double r32171 = r32169 + r32170;
        double r32172 = r32168 / r32171;
        return r32172;
}

double f(double a, double b, double c, double d) {
        double r32173 = 1.0;
        double r32174 = c;
        double r32175 = r32174 * r32174;
        double r32176 = d;
        double r32177 = r32176 * r32176;
        double r32178 = r32175 + r32177;
        double r32179 = sqrt(r32178);
        double r32180 = b;
        double r32181 = r32180 * r32174;
        double r32182 = a;
        double r32183 = r32182 * r32176;
        double r32184 = r32181 - r32183;
        double r32185 = r32179 / r32184;
        double r32186 = r32173 / r32185;
        double r32187 = r32186 / r32179;
        return r32187;
}

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.0
Target0.5
Herbie25.9
\[\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.0

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

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

    \[\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 clear-num25.9

    \[\leadsto \frac{\color{blue}{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot c - a \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Final simplification25.9

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

Reproduce

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