Average Error: 26.5 → 4.8
Time: 3.9s
Precision: 64
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le -2.2616143508082277 \cdot 10^{79} \lor \neg \left(c \le 1.03827084215452011 \cdot 10^{-35}\right):\\ \;\;\;\;1 \cdot \left(\frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a}{1}}{\frac{\mathsf{hypot}\left(c, d\right)}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}\right)\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \le -2.2616143508082277 \cdot 10^{79} \lor \neg \left(c \le 1.03827084215452011 \cdot 10^{-35}\right):\\
\;\;\;\;1 \cdot \left(\frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r118597 = b;
        double r118598 = c;
        double r118599 = r118597 * r118598;
        double r118600 = a;
        double r118601 = d;
        double r118602 = r118600 * r118601;
        double r118603 = r118599 - r118602;
        double r118604 = r118598 * r118598;
        double r118605 = r118601 * r118601;
        double r118606 = r118604 + r118605;
        double r118607 = r118603 / r118606;
        return r118607;
}

double f(double a, double b, double c, double d) {
        double r118608 = c;
        double r118609 = -2.2616143508082277e+79;
        bool r118610 = r118608 <= r118609;
        double r118611 = 1.0382708421545201e-35;
        bool r118612 = r118608 <= r118611;
        double r118613 = !r118612;
        bool r118614 = r118610 || r118613;
        double r118615 = 1.0;
        double r118616 = b;
        double r118617 = d;
        double r118618 = hypot(r118608, r118617);
        double r118619 = r118618 / r118608;
        double r118620 = r118616 / r118619;
        double r118621 = r118620 / r118618;
        double r118622 = a;
        double r118623 = r118622 * r118617;
        double r118624 = r118623 / r118618;
        double r118625 = r118624 / r118618;
        double r118626 = r118621 - r118625;
        double r118627 = r118615 * r118626;
        double r118628 = r118616 * r118608;
        double r118629 = r118628 / r118618;
        double r118630 = r118629 / r118618;
        double r118631 = r118622 / r118615;
        double r118632 = r118617 / r118618;
        double r118633 = r118618 / r118632;
        double r118634 = r118631 / r118633;
        double r118635 = r118630 - r118634;
        double r118636 = r118615 * r118635;
        double r118637 = r118614 ? r118627 : r118636;
        return r118637;
}

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.5
Target0.4
Herbie4.8
\[\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 c < -2.2616143508082277e+79 or 1.0382708421545201e-35 < c

    1. Initial program 33.6

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

      \[\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 *-un-lft-identity33.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac33.6

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity23.3

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*23.3

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

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

      \[\leadsto 1 \cdot \frac{\color{blue}{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}\]
    14. Applied div-sub23.2

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}\]
    15. Using strategy rm
    16. Applied associate-/l*7.8

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

    if -2.2616143508082277e+79 < c < 1.0382708421545201e-35

    1. Initial program 19.6

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

      \[\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 *-un-lft-identity19.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(b \cdot c - a \cdot d\right)}}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\]
    5. Applied times-frac19.6

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1} \cdot \color{blue}{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}\]
    8. Using strategy rm
    9. Applied *-un-lft-identity11.8

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{\mathsf{hypot}\left(c, d\right) \cdot 1}\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}\]
    10. Applied associate-*l*11.8

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

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

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

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)}\]
    15. Using strategy rm
    16. Applied *-un-lft-identity11.7

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

      \[\leadsto 1 \cdot \left(\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\color{blue}{\frac{a}{1} \cdot \frac{d}{\mathsf{hypot}\left(c, d\right)}}}{\mathsf{hypot}\left(c, d\right)}\right)\]
    18. Applied associate-/l*1.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \le -2.2616143508082277 \cdot 10^{79} \lor \neg \left(c \le 1.03827084215452011 \cdot 10^{-35}\right):\\ \;\;\;\;1 \cdot \left(\frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;1 \cdot \left(\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a}{1}}{\frac{\mathsf{hypot}\left(c, d\right)}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}\right)\\ \end{array}\]

Reproduce

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