Average Error: 27.0 → 26.9
Time: 17.6s
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 r7693821 = b;
        double r7693822 = c;
        double r7693823 = r7693821 * r7693822;
        double r7693824 = a;
        double r7693825 = d;
        double r7693826 = r7693824 * r7693825;
        double r7693827 = r7693823 - r7693826;
        double r7693828 = r7693822 * r7693822;
        double r7693829 = r7693825 * r7693825;
        double r7693830 = r7693828 + r7693829;
        double r7693831 = r7693827 / r7693830;
        return r7693831;
}

double f(double a, double b, double c, double d) {
        double r7693832 = b;
        double r7693833 = c;
        double r7693834 = r7693832 * r7693833;
        double r7693835 = a;
        double r7693836 = d;
        double r7693837 = r7693835 * r7693836;
        double r7693838 = r7693834 - r7693837;
        double r7693839 = r7693833 * r7693833;
        double r7693840 = r7693836 * r7693836;
        double r7693841 = r7693839 + r7693840;
        double r7693842 = sqrt(r7693841);
        double r7693843 = r7693838 / r7693842;
        double r7693844 = r7693843 / r7693842;
        return r7693844;
}

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 +o rules:numerics
(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))))