Average Error: 26.1 → 13.0
Time: 16.7s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -4.431736220616081 \cdot 10^{+97}:\\ \;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 6.920723654382158 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -4.431736220616081 \cdot 10^{+97}:\\
\;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \le 6.920723654382158 \cdot 10^{+133}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r2593306 = b;
        double r2593307 = c;
        double r2593308 = r2593306 * r2593307;
        double r2593309 = a;
        double r2593310 = d;
        double r2593311 = r2593309 * r2593310;
        double r2593312 = r2593308 - r2593311;
        double r2593313 = r2593307 * r2593307;
        double r2593314 = r2593310 * r2593310;
        double r2593315 = r2593313 + r2593314;
        double r2593316 = r2593312 / r2593315;
        return r2593316;
}

double f(double a, double b, double c, double d) {
        double r2593317 = c;
        double r2593318 = -4.431736220616081e+97;
        bool r2593319 = r2593317 <= r2593318;
        double r2593320 = b;
        double r2593321 = d;
        double r2593322 = hypot(r2593321, r2593317);
        double r2593323 = r2593320 / r2593322;
        double r2593324 = -r2593323;
        double r2593325 = 6.920723654382158e+133;
        bool r2593326 = r2593317 <= r2593325;
        double r2593327 = r2593320 * r2593317;
        double r2593328 = a;
        double r2593329 = r2593321 * r2593328;
        double r2593330 = r2593327 - r2593329;
        double r2593331 = r2593330 / r2593322;
        double r2593332 = r2593331 / r2593322;
        double r2593333 = r2593326 ? r2593332 : r2593323;
        double r2593334 = r2593319 ? r2593324 : r2593333;
        return r2593334;
}

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.1
Target0.5
Herbie13.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 3 regimes
  2. if c < -4.431736220616081e+97

    1. Initial program 39.3

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

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt39.3

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*39.3

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied div-inv39.3

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    8. Using strategy rm
    9. Applied fma-udef39.3

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    10. Applied hypot-def39.3

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    11. Taylor expanded around -inf 17.3

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\mathsf{hypot}\left(d, c\right)}\]
    12. Simplified17.3

      \[\leadsto \frac{\color{blue}{-b}}{\mathsf{hypot}\left(d, c\right)}\]

    if -4.431736220616081e+97 < c < 6.920723654382158e+133

    1. Initial program 19.0

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

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt19.0

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*18.9

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied div-inv19.0

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    8. Using strategy rm
    9. Applied fma-udef19.0

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    10. Applied hypot-def19.0

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    11. Using strategy rm
    12. Applied *-un-lft-identity19.0

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{1 \cdot \mathsf{hypot}\left(d, c\right)}}\]
    13. Applied associate-/r*19.0

      \[\leadsto \color{blue}{\frac{\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{1}}{\mathsf{hypot}\left(d, c\right)}}\]
    14. Simplified11.7

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\]

    if 6.920723654382158e+133 < c

    1. Initial program 41.4

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

      \[\leadsto \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt41.4

      \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    5. Applied associate-/r*41.4

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    6. Using strategy rm
    7. Applied div-inv41.4

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    8. Using strategy rm
    9. Applied fma-udef41.4

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    10. Applied hypot-def41.4

      \[\leadsto \frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    11. Taylor expanded around inf 13.7

      \[\leadsto \frac{\color{blue}{b}}{\mathsf{hypot}\left(d, c\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -4.431736220616081 \cdot 10^{+97}:\\ \;\;\;\;-\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 6.920723654382158 \cdot 10^{+133}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2019146 +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))))