Average Error: 26.1 → 26.0
Time: 12.7s
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 r6175126 = b;
        double r6175127 = c;
        double r6175128 = r6175126 * r6175127;
        double r6175129 = a;
        double r6175130 = d;
        double r6175131 = r6175129 * r6175130;
        double r6175132 = r6175128 - r6175131;
        double r6175133 = r6175127 * r6175127;
        double r6175134 = r6175130 * r6175130;
        double r6175135 = r6175133 + r6175134;
        double r6175136 = r6175132 / r6175135;
        return r6175136;
}

double f(double a, double b, double c, double d) {
        double r6175137 = b;
        double r6175138 = c;
        double r6175139 = r6175137 * r6175138;
        double r6175140 = a;
        double r6175141 = d;
        double r6175142 = r6175140 * r6175141;
        double r6175143 = r6175139 - r6175142;
        double r6175144 = r6175138 * r6175138;
        double r6175145 = r6175141 * r6175141;
        double r6175146 = r6175144 + r6175145;
        double r6175147 = sqrt(r6175146);
        double r6175148 = r6175143 / r6175147;
        double r6175149 = r6175148 / r6175147;
        return r6175149;
}

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 2019179 
(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))))