Average Error: 26.3 → 25.0
Time: 9.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 5.085210929411777452302962127466150247434 \cdot 10^{305}\right):\\ \;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\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}}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 5.085210929411777452302962127466150247434 \cdot 10^{305}\right):\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\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}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r123391 = b;
        double r123392 = c;
        double r123393 = r123391 * r123392;
        double r123394 = a;
        double r123395 = d;
        double r123396 = r123394 * r123395;
        double r123397 = r123393 - r123396;
        double r123398 = r123392 * r123392;
        double r123399 = r123395 * r123395;
        double r123400 = r123398 + r123399;
        double r123401 = r123397 / r123400;
        return r123401;
}

double f(double a, double b, double c, double d) {
        double r123402 = b;
        double r123403 = c;
        double r123404 = r123402 * r123403;
        double r123405 = a;
        double r123406 = d;
        double r123407 = r123405 * r123406;
        double r123408 = r123404 - r123407;
        double r123409 = r123403 * r123403;
        double r123410 = r123406 * r123406;
        double r123411 = r123409 + r123410;
        double r123412 = r123408 / r123411;
        double r123413 = -inf.0;
        bool r123414 = r123412 <= r123413;
        double r123415 = 5.0852109294117775e+305;
        bool r123416 = r123412 <= r123415;
        double r123417 = !r123416;
        bool r123418 = r123414 || r123417;
        double r123419 = -r123405;
        double r123420 = sqrt(r123411);
        double r123421 = r123419 / r123420;
        double r123422 = 1.0;
        double r123423 = r123422 / r123420;
        double r123424 = r123408 * r123423;
        double r123425 = r123424 / r123420;
        double r123426 = r123418 ? r123421 : r123425;
        return r123426;
}

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.3
Target0.5
Herbie25.0
\[\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 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -inf.0 or 5.0852109294117775e+305 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))

    1. Initial program 63.9

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

      \[\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*63.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. Taylor expanded around 0 59.5

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

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

    if -inf.0 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 5.0852109294117775e+305

    1. Initial program 11.8

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

      \[\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-inv11.8

      \[\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}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 5.085210929411777452302962127466150247434 \cdot 10^{305}\right):\\ \;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\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}}\\ \end{array}\]

Reproduce

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