Average Error: 26.7 → 26.5
Time: 8.0s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 3.67504458165974214 \cdot 10^{89}:\\ \;\;\;\;\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{-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}\;d \le 3.67504458165974214 \cdot 10^{89}:\\
\;\;\;\;\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{-a}{\sqrt{c \cdot c + d \cdot d}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r121009 = b;
        double r121010 = c;
        double r121011 = r121009 * r121010;
        double r121012 = a;
        double r121013 = d;
        double r121014 = r121012 * r121013;
        double r121015 = r121011 - r121014;
        double r121016 = r121010 * r121010;
        double r121017 = r121013 * r121013;
        double r121018 = r121016 + r121017;
        double r121019 = r121015 / r121018;
        return r121019;
}

double f(double a, double b, double c, double d) {
        double r121020 = d;
        double r121021 = 3.675044581659742e+89;
        bool r121022 = r121020 <= r121021;
        double r121023 = b;
        double r121024 = c;
        double r121025 = r121023 * r121024;
        double r121026 = a;
        double r121027 = r121026 * r121020;
        double r121028 = r121025 - r121027;
        double r121029 = r121024 * r121024;
        double r121030 = r121020 * r121020;
        double r121031 = r121029 + r121030;
        double r121032 = sqrt(r121031);
        double r121033 = r121028 / r121032;
        double r121034 = r121033 / r121032;
        double r121035 = -r121026;
        double r121036 = r121035 / r121032;
        double r121037 = r121022 ? r121034 : r121036;
        return r121037;
}

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.5
Herbie26.5
\[\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 < 3.675044581659742e+89

    1. Initial program 23.7

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

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

      \[\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 3.675044581659742e+89 < d

    1. Initial program 38.6

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 3.67504458165974214 \cdot 10^{89}:\\ \;\;\;\;\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{-a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

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