Average Error: 25.1 → 25.0
Time: 13.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{c \cdot b - 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{c \cdot b - 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 r4960218 = b;
        double r4960219 = c;
        double r4960220 = r4960218 * r4960219;
        double r4960221 = a;
        double r4960222 = d;
        double r4960223 = r4960221 * r4960222;
        double r4960224 = r4960220 - r4960223;
        double r4960225 = r4960219 * r4960219;
        double r4960226 = r4960222 * r4960222;
        double r4960227 = r4960225 + r4960226;
        double r4960228 = r4960224 / r4960227;
        return r4960228;
}

double f(double a, double b, double c, double d) {
        double r4960229 = c;
        double r4960230 = b;
        double r4960231 = r4960229 * r4960230;
        double r4960232 = a;
        double r4960233 = d;
        double r4960234 = r4960232 * r4960233;
        double r4960235 = r4960231 - r4960234;
        double r4960236 = r4960229 * r4960229;
        double r4960237 = r4960233 * r4960233;
        double r4960238 = r4960236 + r4960237;
        double r4960239 = sqrt(r4960238);
        double r4960240 = r4960235 / r4960239;
        double r4960241 = r4960240 / r4960239;
        return r4960241;
}

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.1
Target0.5
Herbie25.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 25.1

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt25.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*25.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. Using strategy rm
  6. Applied div-inv25.1

    \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Using strategy rm
  8. Applied associate-*r/25.0

    \[\leadsto \frac{\color{blue}{\frac{\left(b \cdot c - a \cdot d\right) \cdot 1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Simplified25.0

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

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

Reproduce

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