Average Error: 25.9 → 24.1
Time: 27.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;b \le -1.089565161161575170438760363444312591779 \cdot 10^{117}:\\ \;\;\;\;b \cdot \frac{c}{d \cdot d + c \cdot c} - \frac{a \cdot d}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;b \le -1.734488974883629676461830688176453620277 \cdot 10^{-216}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d + c \cdot c} - \frac{a}{\sqrt{d \cdot d + c \cdot c}} \cdot \frac{d}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d + c \cdot c}{c}} - \frac{a \cdot d}{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}\;b \le -1.089565161161575170438760363444312591779 \cdot 10^{117}:\\
\;\;\;\;b \cdot \frac{c}{d \cdot d + c \cdot c} - \frac{a \cdot d}{d \cdot d + c \cdot c}\\

\mathbf{elif}\;b \le -1.734488974883629676461830688176453620277 \cdot 10^{-216}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d + c \cdot c} - \frac{a}{\sqrt{d \cdot d + c \cdot c}} \cdot \frac{d}{\sqrt{d \cdot d + c \cdot c}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r7058628 = b;
        double r7058629 = c;
        double r7058630 = r7058628 * r7058629;
        double r7058631 = a;
        double r7058632 = d;
        double r7058633 = r7058631 * r7058632;
        double r7058634 = r7058630 - r7058633;
        double r7058635 = r7058629 * r7058629;
        double r7058636 = r7058632 * r7058632;
        double r7058637 = r7058635 + r7058636;
        double r7058638 = r7058634 / r7058637;
        return r7058638;
}

double f(double a, double b, double c, double d) {
        double r7058639 = b;
        double r7058640 = -1.0895651611615752e+117;
        bool r7058641 = r7058639 <= r7058640;
        double r7058642 = c;
        double r7058643 = d;
        double r7058644 = r7058643 * r7058643;
        double r7058645 = r7058642 * r7058642;
        double r7058646 = r7058644 + r7058645;
        double r7058647 = r7058642 / r7058646;
        double r7058648 = r7058639 * r7058647;
        double r7058649 = a;
        double r7058650 = r7058649 * r7058643;
        double r7058651 = r7058650 / r7058646;
        double r7058652 = r7058648 - r7058651;
        double r7058653 = -1.7344889748836297e-216;
        bool r7058654 = r7058639 <= r7058653;
        double r7058655 = r7058642 * r7058639;
        double r7058656 = r7058655 / r7058646;
        double r7058657 = sqrt(r7058646);
        double r7058658 = r7058649 / r7058657;
        double r7058659 = r7058643 / r7058657;
        double r7058660 = r7058658 * r7058659;
        double r7058661 = r7058656 - r7058660;
        double r7058662 = r7058646 / r7058642;
        double r7058663 = r7058639 / r7058662;
        double r7058664 = r7058663 - r7058651;
        double r7058665 = r7058654 ? r7058661 : r7058664;
        double r7058666 = r7058641 ? r7058652 : r7058665;
        return r7058666;
}

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

Original25.9
Target0.4
Herbie24.1
\[\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 b < -1.0895651611615752e+117

    1. Initial program 34.3

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity34.3

      \[\leadsto \frac{b \cdot c}{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    6. Applied times-frac30.2

      \[\leadsto \color{blue}{\frac{b}{1} \cdot \frac{c}{c \cdot c + d \cdot d}} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
    7. Simplified30.2

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

    if -1.0895651611615752e+117 < b < -1.7344889748836297e-216

    1. Initial program 23.2

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt23.2

      \[\leadsto \frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied times-frac21.6

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

    if -1.7344889748836297e-216 < b

    1. Initial program 25.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-sub25.0

      \[\leadsto \color{blue}{\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied associate-/l*23.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.089565161161575170438760363444312591779 \cdot 10^{117}:\\ \;\;\;\;b \cdot \frac{c}{d \cdot d + c \cdot c} - \frac{a \cdot d}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;b \le -1.734488974883629676461830688176453620277 \cdot 10^{-216}:\\ \;\;\;\;\frac{c \cdot b}{d \cdot d + c \cdot c} - \frac{a}{\sqrt{d \cdot d + c \cdot c}} \cdot \frac{d}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d + c \cdot c}{c}} - \frac{a \cdot d}{d \cdot d + c \cdot c}\\ \end{array}\]

Reproduce

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