Average Error: 27.0 → 26.9
Time: 15.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 r6702972 = b;
        double r6702973 = c;
        double r6702974 = r6702972 * r6702973;
        double r6702975 = a;
        double r6702976 = d;
        double r6702977 = r6702975 * r6702976;
        double r6702978 = r6702974 - r6702977;
        double r6702979 = r6702973 * r6702973;
        double r6702980 = r6702976 * r6702976;
        double r6702981 = r6702979 + r6702980;
        double r6702982 = r6702978 / r6702981;
        return r6702982;
}

double f(double a, double b, double c, double d) {
        double r6702983 = b;
        double r6702984 = c;
        double r6702985 = r6702983 * r6702984;
        double r6702986 = a;
        double r6702987 = d;
        double r6702988 = r6702986 * r6702987;
        double r6702989 = r6702985 - r6702988;
        double r6702990 = r6702984 * r6702984;
        double r6702991 = r6702987 * r6702987;
        double r6702992 = r6702990 + r6702991;
        double r6702993 = sqrt(r6702992);
        double r6702994 = r6702989 / r6702993;
        double r6702995 = r6702994 / r6702993;
        return r6702995;
}

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))))