Average Error: 25.5 → 12.9
Time: 12.8s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -3.54617340469776 \cdot 10^{+94}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 1.9951833757328278 \cdot 10^{+142}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 -3.54617340469776 \cdot 10^{+94}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{elif}\;c \le 1.9951833757328278 \cdot 10^{+142}:\\
\;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 r3132487 = b;
        double r3132488 = c;
        double r3132489 = r3132487 * r3132488;
        double r3132490 = a;
        double r3132491 = d;
        double r3132492 = r3132490 * r3132491;
        double r3132493 = r3132489 - r3132492;
        double r3132494 = r3132488 * r3132488;
        double r3132495 = r3132491 * r3132491;
        double r3132496 = r3132494 + r3132495;
        double r3132497 = r3132493 / r3132496;
        return r3132497;
}

double f(double a, double b, double c, double d) {
        double r3132498 = c;
        double r3132499 = -3.54617340469776e+94;
        bool r3132500 = r3132498 <= r3132499;
        double r3132501 = b;
        double r3132502 = -r3132501;
        double r3132503 = d;
        double r3132504 = hypot(r3132503, r3132498);
        double r3132505 = r3132502 / r3132504;
        double r3132506 = 1.9951833757328278e+142;
        bool r3132507 = r3132498 <= r3132506;
        double r3132508 = r3132501 * r3132498;
        double r3132509 = a;
        double r3132510 = r3132503 * r3132509;
        double r3132511 = r3132508 - r3132510;
        double r3132512 = 1.0;
        double r3132513 = r3132512 / r3132504;
        double r3132514 = r3132511 * r3132513;
        double r3132515 = r3132514 / r3132504;
        double r3132516 = r3132501 / r3132504;
        double r3132517 = r3132507 ? r3132515 : r3132516;
        double r3132518 = r3132500 ? r3132505 : r3132517;
        return r3132518;
}

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.5
Target0.5
Herbie12.9
\[\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 < -3.54617340469776e+94

    1. Initial program 38.3

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified38.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-sqrt38.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*38.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 fma-udef38.3

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

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\mathsf{hypot}\left(d, c\right)}\]
    10. Simplified16.2

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

    if -3.54617340469776e+94 < c < 1.9951833757328278e+142

    1. Initial program 18.6

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

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

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

      \[\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 fma-udef18.5

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\color{blue}{d \cdot d + c \cdot c}}}\]
    8. Applied hypot-def18.5

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity18.5

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

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

      \[\leadsto \frac{\color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}}{\mathsf{hypot}\left(d, c\right)}\]
    13. Using strategy rm
    14. Applied div-inv11.5

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

    if 1.9951833757328278e+142 < 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 fma-udef41.4

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -3.54617340469776 \cdot 10^{+94}:\\ \;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{elif}\;c \le 1.9951833757328278 \cdot 10^{+142}:\\ \;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 2019135 +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))))