Average Error: 25.5 → 12.6
Time: 45.3s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -4.5554482331281827 \cdot 10^{+198}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.251215078496209 \cdot 10^{+155}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{\sqrt{d^2 + c^2}^*} \cdot \frac{1}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]
double f(double a, double b, double c, double d) {
        double r17324927 = b;
        double r17324928 = c;
        double r17324929 = r17324927 * r17324928;
        double r17324930 = a;
        double r17324931 = d;
        double r17324932 = r17324930 * r17324931;
        double r17324933 = r17324929 - r17324932;
        double r17324934 = r17324928 * r17324928;
        double r17324935 = r17324931 * r17324931;
        double r17324936 = r17324934 + r17324935;
        double r17324937 = r17324933 / r17324936;
        return r17324937;
}

double f(double a, double b, double c, double d) {
        double r17324938 = c;
        double r17324939 = -4.5554482331281827e+198;
        bool r17324940 = r17324938 <= r17324939;
        double r17324941 = b;
        double r17324942 = -r17324941;
        double r17324943 = d;
        double r17324944 = hypot(r17324943, r17324938);
        double r17324945 = r17324942 / r17324944;
        double r17324946 = 2.251215078496209e+155;
        bool r17324947 = r17324938 <= r17324946;
        double r17324948 = r17324941 * r17324938;
        double r17324949 = a;
        double r17324950 = r17324943 * r17324949;
        double r17324951 = r17324948 - r17324950;
        double r17324952 = r17324951 / r17324944;
        double r17324953 = 1.0;
        double r17324954 = r17324953 / r17324944;
        double r17324955 = r17324952 * r17324954;
        double r17324956 = r17324941 / r17324944;
        double r17324957 = r17324947 ? r17324955 : r17324956;
        double r17324958 = r17324940 ? r17324945 : r17324957;
        return r17324958;
}

\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -4.5554482331281827 \cdot 10^{+198}:\\
\;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\

\mathbf{elif}\;c \le 2.251215078496209 \cdot 10^{+155}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{\sqrt{d^2 + c^2}^*} \cdot \frac{1}{\sqrt{d^2 + c^2}^*}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\

\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original25.5
Target0.4
Herbie12.6
\[\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 c < -4.5554482331281827e+198

    1. Initial program 42.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified42.2

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt42.2

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied associate-/r*42.2

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef42.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Applied hypot-def42.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{d^2 + c^2}^*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef42.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def28.4

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\color{blue}{\sqrt{d^2 + c^2}^*}}\]
    12. Taylor expanded around -inf 11.7

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{d^2 + c^2}^*}\]
    13. Simplified11.7

      \[\leadsto \frac{\color{blue}{-b}}{\sqrt{d^2 + c^2}^*}\]

    if -4.5554482331281827e+198 < c < 2.251215078496209e+155

    1. Initial program 20.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified20.6

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt20.6

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied associate-/r*20.5

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef20.5

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Applied hypot-def20.5

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{d^2 + c^2}^*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef20.5

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def12.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\color{blue}{\sqrt{d^2 + c^2}^*}}\]
    12. Using strategy rm
    13. Applied div-inv12.4

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

    if 2.251215078496209e+155 < c

    1. Initial program 44.2

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified44.2

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{(d \cdot d + \left(c \cdot c\right))_*}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt44.2

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*} \cdot \sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    5. Applied associate-/r*44.2

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}}\]
    6. Using strategy rm
    7. Applied fma-udef44.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    8. Applied hypot-def44.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{d^2 + c^2}^*}}}{\sqrt{(d \cdot d + \left(c \cdot c\right))_*}}\]
    9. Using strategy rm
    10. Applied fma-udef44.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    11. Applied hypot-def28.2

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{d^2 + c^2}^*}}{\color{blue}{\sqrt{d^2 + c^2}^*}}\]
    12. Taylor expanded around inf 14.6

      \[\leadsto \frac{\color{blue}{b}}{\sqrt{d^2 + c^2}^*}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -4.5554482331281827 \cdot 10^{+198}:\\ \;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\ \mathbf{elif}\;c \le 2.251215078496209 \cdot 10^{+155}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{\sqrt{d^2 + c^2}^*} \cdot \frac{1}{\sqrt{d^2 + c^2}^*}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d^2 + c^2}^*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019101 +o rules:numerics
(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))))