Average Error: 25.3 → 12.7
Time: 26.7s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -5.5307531516126024 \cdot 10^{+200}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\ \mathbf{elif}\;c \le 1.6399786417077545 \cdot 10^{+162}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\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 -5.5307531516126024 \cdot 10^{+200}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\

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

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

\end{array}
double f(double a, double b, double c, double d) {
        double r4372128 = b;
        double r4372129 = c;
        double r4372130 = r4372128 * r4372129;
        double r4372131 = a;
        double r4372132 = d;
        double r4372133 = r4372131 * r4372132;
        double r4372134 = r4372130 - r4372133;
        double r4372135 = r4372129 * r4372129;
        double r4372136 = r4372132 * r4372132;
        double r4372137 = r4372135 + r4372136;
        double r4372138 = r4372134 / r4372137;
        return r4372138;
}

double f(double a, double b, double c, double d) {
        double r4372139 = c;
        double r4372140 = -5.5307531516126024e+200;
        bool r4372141 = r4372139 <= r4372140;
        double r4372142 = -1.0;
        double r4372143 = d;
        double r4372144 = hypot(r4372143, r4372139);
        double r4372145 = r4372142 / r4372144;
        double r4372146 = b;
        double r4372147 = r4372145 * r4372146;
        double r4372148 = 1.6399786417077545e+162;
        bool r4372149 = r4372139 <= r4372148;
        double r4372150 = r4372146 * r4372139;
        double r4372151 = a;
        double r4372152 = r4372143 * r4372151;
        double r4372153 = r4372150 - r4372152;
        double r4372154 = r4372153 / r4372144;
        double r4372155 = r4372154 / r4372144;
        double r4372156 = 1.0;
        double r4372157 = r4372156 / r4372144;
        double r4372158 = r4372146 * r4372157;
        double r4372159 = r4372149 ? r4372155 : r4372158;
        double r4372160 = r4372141 ? r4372147 : r4372159;
        return r4372160;
}

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.3
Target0.5
Herbie12.7
\[\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 < -5.5307531516126024e+200

    1. Initial program 40.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Simplified40.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-sqrt40.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*40.6

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt40.6

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}\]
    11. Applied add-sqr-sqrt40.6

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}}}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    12. Applied *-un-lft-identity40.6

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    13. Applied times-frac40.6

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

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

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

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

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

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

    if -5.5307531516126024e+200 < c < 1.6399786417077545e+162

    1. Initial program 20.5

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

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

      \[\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*20.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-udef20.4

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt20.6

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}\]
    11. Applied add-sqr-sqrt20.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}}}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    12. Applied *-un-lft-identity20.7

      \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    13. Applied times-frac20.8

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \color{blue}{\frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}\]
    17. Using strategy rm
    18. Applied associate-*r/12.8

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \left(c \cdot b - d \cdot a\right)}{\mathsf{hypot}\left(d, c\right)}}\]
    19. Simplified12.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 1.6399786417077545e+162 < c

    1. Initial program 44.7

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

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

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

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

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

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\mathsf{hypot}\left(d, c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt44.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}}\]
    11. Applied add-sqr-sqrt44.7

      \[\leadsto \frac{\frac{b \cdot c - a \cdot d}{\color{blue}{\sqrt{\mathsf{hypot}\left(d, c\right)} \cdot \sqrt{\mathsf{hypot}\left(d, c\right)}}}}{\sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
    12. Applied *-un-lft-identity44.7

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -5.5307531516126024 \cdot 10^{+200}:\\ \;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\ \mathbf{elif}\;c \le 1.6399786417077545 \cdot 10^{+162}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\\ \end{array}\]

Reproduce

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