Average Error: 25.8 → 25.8
Time: 11.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{-a \cdot d}{c \cdot c + d \cdot d} + \frac{b \cdot c}{c \cdot c + d \cdot d}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\frac{-a \cdot d}{c \cdot c + d \cdot d} + \frac{b \cdot c}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r80749 = b;
        double r80750 = c;
        double r80751 = r80749 * r80750;
        double r80752 = a;
        double r80753 = d;
        double r80754 = r80752 * r80753;
        double r80755 = r80751 - r80754;
        double r80756 = r80750 * r80750;
        double r80757 = r80753 * r80753;
        double r80758 = r80756 + r80757;
        double r80759 = r80755 / r80758;
        return r80759;
}

double f(double a, double b, double c, double d) {
        double r80760 = a;
        double r80761 = d;
        double r80762 = r80760 * r80761;
        double r80763 = -r80762;
        double r80764 = c;
        double r80765 = r80764 * r80764;
        double r80766 = r80761 * r80761;
        double r80767 = r80765 + r80766;
        double r80768 = r80763 / r80767;
        double r80769 = b;
        double r80770 = r80769 * r80764;
        double r80771 = r80770 / r80767;
        double r80772 = r80768 + r80771;
        return r80772;
}

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

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

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

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

    \[\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 add-sqr-sqrt25.7

    \[\leadsto \frac{\frac{b \cdot c}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \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}}\]
  9. Applied sqrt-prod25.8

    \[\leadsto \frac{\frac{b \cdot c}{\color{blue}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\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}}\]
  10. Applied times-frac24.1

    \[\leadsto \frac{\color{blue}{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\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}}\]
  11. Using strategy rm
  12. Applied add-sqr-sqrt24.1

    \[\leadsto \frac{\frac{b}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{c}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}}\]
  13. Applied sqrt-prod24.3

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

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

Reproduce

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