Average Error: 25.9 → 25.9
Time: 4.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r94646 = b;
        double r94647 = c;
        double r94648 = r94646 * r94647;
        double r94649 = a;
        double r94650 = d;
        double r94651 = r94649 * r94650;
        double r94652 = r94648 - r94651;
        double r94653 = r94647 * r94647;
        double r94654 = r94650 * r94650;
        double r94655 = r94653 + r94654;
        double r94656 = r94652 / r94655;
        return r94656;
}

double f(double a, double b, double c, double d) {
        double r94657 = b;
        double r94658 = c;
        double r94659 = r94657 * r94658;
        double r94660 = a;
        double r94661 = d;
        double r94662 = r94660 * r94661;
        double r94663 = r94659 - r94662;
        double r94664 = r94658 * r94658;
        double r94665 = r94661 * r94661;
        double r94666 = r94664 + r94665;
        double r94667 = r94663 / r94666;
        return r94667;
}

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
Herbie25.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.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 *-un-lft-identity25.8

    \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}}\]
  7. Applied sqrt-prod25.8

    \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
  8. Applied *-un-lft-identity25.8

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

    \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  10. Applied *-un-lft-identity25.8

    \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  11. Applied times-frac25.8

    \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}\]
  12. Applied times-frac25.8

    \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{1}}}{\sqrt{1}} \cdot \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
  13. Simplified25.8

    \[\leadsto \color{blue}{1} \cdot \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  14. Simplified25.9

    \[\leadsto 1 \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}}\]
  15. Final simplification25.9

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

Reproduce

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