Average Error: 27.0 → 26.9
Time: 13.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 r6514878 = b;
        double r6514879 = c;
        double r6514880 = r6514878 * r6514879;
        double r6514881 = a;
        double r6514882 = d;
        double r6514883 = r6514881 * r6514882;
        double r6514884 = r6514880 - r6514883;
        double r6514885 = r6514879 * r6514879;
        double r6514886 = r6514882 * r6514882;
        double r6514887 = r6514885 + r6514886;
        double r6514888 = r6514884 / r6514887;
        return r6514888;
}

double f(double a, double b, double c, double d) {
        double r6514889 = b;
        double r6514890 = c;
        double r6514891 = r6514889 * r6514890;
        double r6514892 = a;
        double r6514893 = d;
        double r6514894 = r6514892 * r6514893;
        double r6514895 = r6514891 - r6514894;
        double r6514896 = r6514890 * r6514890;
        double r6514897 = r6514893 * r6514893;
        double r6514898 = r6514896 + r6514897;
        double r6514899 = sqrt(r6514898);
        double r6514900 = r6514895 / r6514899;
        double r6514901 = r6514900 / r6514899;
        return r6514901;
}

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

Original27.0
Target0.4
Herbie26.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 27.0

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

    \[\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*26.9

    \[\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. Final simplification26.9

    \[\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 2019171 
(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))))