Average Error: 25.1 → 25.0
Time: 20.0s
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 r13006716 = b;
        double r13006717 = c;
        double r13006718 = r13006716 * r13006717;
        double r13006719 = a;
        double r13006720 = d;
        double r13006721 = r13006719 * r13006720;
        double r13006722 = r13006718 - r13006721;
        double r13006723 = r13006717 * r13006717;
        double r13006724 = r13006720 * r13006720;
        double r13006725 = r13006723 + r13006724;
        double r13006726 = r13006722 / r13006725;
        return r13006726;
}

double f(double a, double b, double c, double d) {
        double r13006727 = b;
        double r13006728 = c;
        double r13006729 = r13006727 * r13006728;
        double r13006730 = a;
        double r13006731 = d;
        double r13006732 = r13006730 * r13006731;
        double r13006733 = r13006729 - r13006732;
        double r13006734 = r13006728 * r13006728;
        double r13006735 = r13006731 * r13006731;
        double r13006736 = r13006734 + r13006735;
        double r13006737 = sqrt(r13006736);
        double r13006738 = r13006733 / r13006737;
        double r13006739 = r13006738 / r13006737;
        return r13006739;
}

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 un-div-inv25.0

    \[\leadsto \frac{\color{blue}{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Final simplification25.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 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))))