Average Error: 26.6 → 27.2
Time: 14.6s
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 r6018890 = a;
        double r6018891 = c;
        double r6018892 = r6018890 * r6018891;
        double r6018893 = b;
        double r6018894 = d;
        double r6018895 = r6018893 * r6018894;
        double r6018896 = r6018892 + r6018895;
        double r6018897 = r6018891 * r6018891;
        double r6018898 = r6018894 * r6018894;
        double r6018899 = r6018897 + r6018898;
        double r6018900 = r6018896 / r6018899;
        return r6018900;
}

double f(double a, double b, double c, double d) {
        double r6018901 = a;
        double r6018902 = 6.4954804305817955e+224;
        bool r6018903 = r6018901 <= r6018902;
        double r6018904 = b;
        double r6018905 = d;
        double r6018906 = r6018904 * r6018905;
        double r6018907 = c;
        double r6018908 = r6018907 * r6018901;
        double r6018909 = r6018906 + r6018908;
        double r6018910 = r6018905 * r6018905;
        double r6018911 = r6018907 * r6018907;
        double r6018912 = r6018910 + r6018911;
        double r6018913 = sqrt(r6018912);
        double r6018914 = r6018909 / r6018913;
        double r6018915 = r6018914 / r6018913;
        double r6018916 = -r6018901;
        double r6018917 = r6018916 / r6018913;
        double r6018918 = r6018903 ? r6018915 : r6018917;
        return r6018918;
}

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))))