Average Error: 26.0 → 26.2
Time: 14.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 1.040801148335406884298745436678592487814 \cdot 10^{55}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le 1.040801148335406884298745436678592487814 \cdot 10^{55}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r5618264 = b;
        double r5618265 = c;
        double r5618266 = r5618264 * r5618265;
        double r5618267 = a;
        double r5618268 = d;
        double r5618269 = r5618267 * r5618268;
        double r5618270 = r5618266 - r5618269;
        double r5618271 = r5618265 * r5618265;
        double r5618272 = r5618268 * r5618268;
        double r5618273 = r5618271 + r5618272;
        double r5618274 = r5618270 / r5618273;
        return r5618274;
}

double f(double a, double b, double c, double d) {
        double r5618275 = d;
        double r5618276 = 1.0408011483354069e+55;
        bool r5618277 = r5618275 <= r5618276;
        double r5618278 = b;
        double r5618279 = c;
        double r5618280 = r5618278 * r5618279;
        double r5618281 = a;
        double r5618282 = r5618275 * r5618281;
        double r5618283 = r5618280 - r5618282;
        double r5618284 = r5618275 * r5618275;
        double r5618285 = r5618279 * r5618279;
        double r5618286 = r5618284 + r5618285;
        double r5618287 = sqrt(r5618286);
        double r5618288 = r5618283 / r5618287;
        double r5618289 = r5618288 / r5618287;
        double r5618290 = -r5618281;
        double r5618291 = r5618290 / r5618287;
        double r5618292 = r5618277 ? r5618289 : r5618291;
        return r5618292;
}

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

Original26.0
Target0.5
Herbie26.2
\[\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. Split input into 2 regimes
  2. if d < 1.0408011483354069e+55

    1. Initial program 23.3

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

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

      \[\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}}}\]

    if 1.0408011483354069e+55 < d

    1. Initial program 35.1

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

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

      \[\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. Taylor expanded around 0 36.3

      \[\leadsto \frac{\color{blue}{-1 \cdot a}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Simplified36.3

      \[\leadsto \frac{\color{blue}{-a}}{\sqrt{c \cdot c + d \cdot d}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 1.040801148335406884298745436678592487814 \cdot 10^{55}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Reproduce

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