Average Error: 25.8 → 24.3
Time: 15.1s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\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{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\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{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{c \cdot c + d \cdot d}}}
double f(double a, double b, double c, double d) {
        double r120798 = b;
        double r120799 = c;
        double r120800 = r120798 * r120799;
        double r120801 = a;
        double r120802 = d;
        double r120803 = r120801 * r120802;
        double r120804 = r120800 - r120803;
        double r120805 = r120799 * r120799;
        double r120806 = r120802 * r120802;
        double r120807 = r120805 + r120806;
        double r120808 = r120804 / r120807;
        return r120808;
}

double f(double a, double b, double c, double d) {
        double r120809 = b;
        double r120810 = c;
        double r120811 = r120810 * r120810;
        double r120812 = d;
        double r120813 = r120812 * r120812;
        double r120814 = r120811 + r120813;
        double r120815 = sqrt(r120814);
        double r120816 = sqrt(r120815);
        double r120817 = r120809 / r120816;
        double r120818 = r120810 / r120816;
        double r120819 = r120817 * r120818;
        double r120820 = a;
        double r120821 = r120820 * r120812;
        double r120822 = r120821 / r120815;
        double r120823 = r120819 - r120822;
        double r120824 = r120816 * r120816;
        double r120825 = r120823 / r120824;
        return r120825;
}

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
Herbie24.3
\[\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 simplification24.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}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt{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))))