Average Error: 26.2 → 26.2
Time: 5.7s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 4.45466791069368503819326346032185071724 \cdot 10^{108}:\\ \;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;d \le 4.152810026092194573941460896261674354973 \cdot 10^{143}:\\ \;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\left|\sqrt[3]{c \cdot c + d \cdot d}\right| \cdot \sqrt{\sqrt[3]{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}\;d \le 4.45466791069368503819326346032185071724 \cdot 10^{108}:\\
\;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;d \le 4.152810026092194573941460896261674354973 \cdot 10^{143}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\left|\sqrt[3]{c \cdot c + d \cdot d}\right| \cdot \sqrt{\sqrt[3]{c \cdot c + d \cdot d}}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r91485 = b;
        double r91486 = c;
        double r91487 = r91485 * r91486;
        double r91488 = a;
        double r91489 = d;
        double r91490 = r91488 * r91489;
        double r91491 = r91487 - r91490;
        double r91492 = r91486 * r91486;
        double r91493 = r91489 * r91489;
        double r91494 = r91492 + r91493;
        double r91495 = r91491 / r91494;
        return r91495;
}

double f(double a, double b, double c, double d) {
        double r91496 = d;
        double r91497 = 4.454667910693685e+108;
        bool r91498 = r91496 <= r91497;
        double r91499 = b;
        double r91500 = c;
        double r91501 = r91499 * r91500;
        double r91502 = a;
        double r91503 = r91502 * r91496;
        double r91504 = r91501 - r91503;
        double r91505 = 1.0;
        double r91506 = r91500 * r91500;
        double r91507 = r91496 * r91496;
        double r91508 = r91506 + r91507;
        double r91509 = sqrt(r91508);
        double r91510 = r91505 / r91509;
        double r91511 = r91504 * r91510;
        double r91512 = r91511 / r91509;
        double r91513 = 4.152810026092195e+143;
        bool r91514 = r91496 <= r91513;
        double r91515 = -1.0;
        double r91516 = r91515 * r91502;
        double r91517 = r91516 / r91509;
        double r91518 = r91504 / r91509;
        double r91519 = cbrt(r91508);
        double r91520 = fabs(r91519);
        double r91521 = sqrt(r91519);
        double r91522 = r91520 * r91521;
        double r91523 = r91518 / r91522;
        double r91524 = r91514 ? r91517 : r91523;
        double r91525 = r91498 ? r91512 : r91524;
        return r91525;
}

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.2
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 3 regimes
  2. if d < 4.454667910693685e+108

    1. Initial program 23.2

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

      \[\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.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. Using strategy rm
    6. Applied div-inv23.2

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]

    if 4.454667910693685e+108 < d < 4.152810026092195e+143

    1. Initial program 23.6

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

      \[\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.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 26.2

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

    if 4.152810026092195e+143 < d

    1. Initial program 43.8

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

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

      \[\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. Using strategy rm
    6. Applied add-cube-cbrt43.8

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{\color{blue}{\left(\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}\right) \cdot \sqrt[3]{c \cdot c + d \cdot d}}}}\]
    7. Applied sqrt-prod43.8

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\color{blue}{\sqrt{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \sqrt{\sqrt[3]{c \cdot c + d \cdot d}}}}\]
    8. Simplified43.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 4.45466791069368503819326346032185071724 \cdot 10^{108}:\\ \;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;d \le 4.152810026092194573941460896261674354973 \cdot 10^{143}:\\ \;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\left|\sqrt[3]{c \cdot c + d \cdot d}\right| \cdot \sqrt{\sqrt[3]{c \cdot c + d \cdot d}}}\\ \end{array}\]

Reproduce

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