Average Error: 26.1 → 26.0
Time: 12.6s
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 r5174291 = b;
        double r5174292 = c;
        double r5174293 = r5174291 * r5174292;
        double r5174294 = a;
        double r5174295 = d;
        double r5174296 = r5174294 * r5174295;
        double r5174297 = r5174293 - r5174296;
        double r5174298 = r5174292 * r5174292;
        double r5174299 = r5174295 * r5174295;
        double r5174300 = r5174298 + r5174299;
        double r5174301 = r5174297 / r5174300;
        return r5174301;
}

double f(double a, double b, double c, double d) {
        double r5174302 = b;
        double r5174303 = c;
        double r5174304 = r5174302 * r5174303;
        double r5174305 = a;
        double r5174306 = d;
        double r5174307 = r5174305 * r5174306;
        double r5174308 = r5174304 - r5174307;
        double r5174309 = r5174303 * r5174303;
        double r5174310 = r5174306 * r5174306;
        double r5174311 = r5174309 + r5174310;
        double r5174312 = sqrt(r5174311);
        double r5174313 = r5174308 / r5174312;
        double r5174314 = r5174313 / r5174312;
        return r5174314;
}

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
Herbie26.0
\[\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.0

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

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