Average Error: 26.7 → 26.8
Time: 4.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;a \le 2.96629785101132302 \cdot 10^{277}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;a \le 2.96629785101132302 \cdot 10^{277}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r140339 = b;
        double r140340 = c;
        double r140341 = r140339 * r140340;
        double r140342 = a;
        double r140343 = d;
        double r140344 = r140342 * r140343;
        double r140345 = r140341 - r140344;
        double r140346 = r140340 * r140340;
        double r140347 = r140343 * r140343;
        double r140348 = r140346 + r140347;
        double r140349 = r140345 / r140348;
        return r140349;
}

double f(double a, double b, double c, double d) {
        double r140350 = a;
        double r140351 = 2.966297851011323e+277;
        bool r140352 = r140350 <= r140351;
        double r140353 = b;
        double r140354 = c;
        double r140355 = r140353 * r140354;
        double r140356 = d;
        double r140357 = r140350 * r140356;
        double r140358 = r140355 - r140357;
        double r140359 = r140354 * r140354;
        double r140360 = r140356 * r140356;
        double r140361 = r140359 + r140360;
        double r140362 = sqrt(r140361);
        double r140363 = r140358 / r140362;
        double r140364 = r140363 / r140362;
        double r140365 = -1.0;
        double r140366 = r140365 * r140350;
        double r140367 = r140366 / r140362;
        double r140368 = r140352 ? r140364 : r140367;
        return r140368;
}

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.7
Target0.6
Herbie26.8
\[\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 a < 2.966297851011323e+277

    1. Initial program 26.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt26.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*26.2

      \[\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 2.966297851011323e+277 < a

    1. Initial program 44.5

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

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

      \[\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 51.6

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

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

Reproduce

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