Average Error: 25.7 → 22.9
Time: 3.2s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r95353 = b;
        double r95354 = c;
        double r95355 = r95353 * r95354;
        double r95356 = a;
        double r95357 = d;
        double r95358 = r95356 * r95357;
        double r95359 = r95355 - r95358;
        double r95360 = r95354 * r95354;
        double r95361 = r95357 * r95357;
        double r95362 = r95360 + r95361;
        double r95363 = r95359 / r95362;
        return r95363;
}

double f(double a, double b, double c, double d) {
        double r95364 = b;
        double r95365 = c;
        double r95366 = r95365 * r95365;
        double r95367 = d;
        double r95368 = r95367 * r95367;
        double r95369 = r95366 + r95368;
        double r95370 = sqrt(r95369);
        double r95371 = r95364 / r95370;
        double r95372 = r95365 / r95370;
        double r95373 = r95371 * r95372;
        double r95374 = a;
        double r95375 = r95374 / r95370;
        double r95376 = r95367 / r95370;
        double r95377 = r95375 * r95376;
        double r95378 = r95373 - r95377;
        return r95378;
}

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.7
Target0.4
Herbie22.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 25.7

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied div-sub25.7

    \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
  4. Using strategy rm
  5. Applied add-sqr-sqrt25.7

    \[\leadsto \frac{b \cdot c}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  6. Applied times-frac24.5

    \[\leadsto \color{blue}{\frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
  7. Using strategy rm
  8. Applied add-sqr-sqrt24.5

    \[\leadsto \frac{b}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  9. Applied times-frac22.9

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

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

Reproduce

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