Average Error: 26.6 → 27.2
Time: 15.8s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;a \le 6.495480430581795464113836761587821513134 \cdot 10^{224}:\\ \;\;\;\;\frac{\frac{b \cdot d + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;a \le 6.495480430581795464113836761587821513134 \cdot 10^{224}:\\
\;\;\;\;\frac{\frac{b \cdot d + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r5908121 = a;
        double r5908122 = c;
        double r5908123 = r5908121 * r5908122;
        double r5908124 = b;
        double r5908125 = d;
        double r5908126 = r5908124 * r5908125;
        double r5908127 = r5908123 + r5908126;
        double r5908128 = r5908122 * r5908122;
        double r5908129 = r5908125 * r5908125;
        double r5908130 = r5908128 + r5908129;
        double r5908131 = r5908127 / r5908130;
        return r5908131;
}

double f(double a, double b, double c, double d) {
        double r5908132 = a;
        double r5908133 = 6.4954804305817955e+224;
        bool r5908134 = r5908132 <= r5908133;
        double r5908135 = b;
        double r5908136 = d;
        double r5908137 = r5908135 * r5908136;
        double r5908138 = c;
        double r5908139 = r5908138 * r5908132;
        double r5908140 = r5908137 + r5908139;
        double r5908141 = r5908136 * r5908136;
        double r5908142 = r5908138 * r5908138;
        double r5908143 = r5908141 + r5908142;
        double r5908144 = sqrt(r5908143);
        double r5908145 = r5908140 / r5908144;
        double r5908146 = r5908145 / r5908144;
        double r5908147 = -r5908132;
        double r5908148 = r5908147 / r5908144;
        double r5908149 = r5908134 ? r5908146 : r5908148;
        return r5908149;
}

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.6
Target0.5
Herbie27.2
\[\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 a < 6.4954804305817955e+224

    1. Initial program 25.6

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

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

      \[\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}}}\]

    if 6.4954804305817955e+224 < a

    1. Initial program 42.0

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

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

      \[\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 -inf 52.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \le 6.495480430581795464113836761587821513134 \cdot 10^{224}:\\ \;\;\;\;\frac{\frac{b \cdot d + c \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019171 
(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))))