Average Error: 25.9 → 22.1
Time: 3.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{b}{\frac{\sqrt{c \cdot c + d \cdot d}}{c}} - \frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r113203 = b;
        double r113204 = c;
        double r113205 = r113203 * r113204;
        double r113206 = a;
        double r113207 = d;
        double r113208 = r113206 * r113207;
        double r113209 = r113205 - r113208;
        double r113210 = r113204 * r113204;
        double r113211 = r113207 * r113207;
        double r113212 = r113210 + r113211;
        double r113213 = r113209 / r113212;
        return r113213;
}

double f(double a, double b, double c, double d) {
        double r113214 = b;
        double r113215 = c;
        double r113216 = r113215 * r113215;
        double r113217 = d;
        double r113218 = r113217 * r113217;
        double r113219 = r113216 + r113218;
        double r113220 = sqrt(r113219);
        double r113221 = r113220 / r113215;
        double r113222 = r113214 / r113221;
        double r113223 = a;
        double r113224 = r113220 / r113217;
        double r113225 = r113223 / r113224;
        double r113226 = r113222 - r113225;
        double r113227 = r113226 / r113220;
        return r113227;
}

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.9
Target0.5
Herbie22.1
\[\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.9

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

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

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

    \[\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 associate-/l*24.0

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{c \cdot c + d \cdot d}} - \color{blue}{\frac{a}{\frac{\sqrt{c \cdot c + d \cdot d}}{d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Using strategy rm
  10. Applied associate-/l*22.1

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

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

Reproduce

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