Average Error: 25.8 → 26.3
Time: 13.6s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 28148546215012511376658377374508777472:\\ \;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le 28148546215012511376658377374508777472:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r5884477 = a;
        double r5884478 = c;
        double r5884479 = r5884477 * r5884478;
        double r5884480 = b;
        double r5884481 = d;
        double r5884482 = r5884480 * r5884481;
        double r5884483 = r5884479 + r5884482;
        double r5884484 = r5884478 * r5884478;
        double r5884485 = r5884481 * r5884481;
        double r5884486 = r5884484 + r5884485;
        double r5884487 = r5884483 / r5884486;
        return r5884487;
}

double f(double a, double b, double c, double d) {
        double r5884488 = d;
        double r5884489 = 2.814854621501251e+37;
        bool r5884490 = r5884488 <= r5884489;
        double r5884491 = 1.0;
        double r5884492 = c;
        double r5884493 = r5884492 * r5884492;
        double r5884494 = r5884488 * r5884488;
        double r5884495 = r5884493 + r5884494;
        double r5884496 = sqrt(r5884495);
        double r5884497 = r5884491 / r5884496;
        double r5884498 = b;
        double r5884499 = r5884498 * r5884488;
        double r5884500 = a;
        double r5884501 = r5884492 * r5884500;
        double r5884502 = r5884499 + r5884501;
        double r5884503 = r5884502 / r5884496;
        double r5884504 = r5884497 * r5884503;
        double r5884505 = r5884498 / r5884496;
        double r5884506 = r5884490 ? r5884504 : r5884505;
        return r5884506;
}

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.8
Target0.4
Herbie26.3
\[\begin{array}{l} \mathbf{if}\;\left|d\right| \lt \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if d < 2.814854621501251e+37

    1. Initial program 22.8

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied *-un-lft-identity22.8

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

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

    if 2.814854621501251e+37 < d

    1. Initial program 35.3

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    4. Applied associate-/r*35.3

      \[\leadsto \color{blue}{\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    5. Taylor expanded around 0 37.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \le 28148546215012511376658377374508777472:\\ \;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019172 
(FPCore (a b c d)
  :name "Complex division, real part"

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))

  (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))