Average Error: 26.5 → 25.4
Time: 10.5s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.126077854837793543272902488688401092988 \cdot 10^{280}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot d + a \cdot c}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\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}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.126077854837793543272902488688401092988 \cdot 10^{280}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot d + a \cdot c}}}{\sqrt{c \cdot c + d \cdot d}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r79219 = a;
        double r79220 = c;
        double r79221 = r79219 * r79220;
        double r79222 = b;
        double r79223 = d;
        double r79224 = r79222 * r79223;
        double r79225 = r79221 + r79224;
        double r79226 = r79220 * r79220;
        double r79227 = r79223 * r79223;
        double r79228 = r79226 + r79227;
        double r79229 = r79225 / r79228;
        return r79229;
}

double f(double a, double b, double c, double d) {
        double r79230 = b;
        double r79231 = d;
        double r79232 = r79230 * r79231;
        double r79233 = a;
        double r79234 = c;
        double r79235 = r79233 * r79234;
        double r79236 = r79232 + r79235;
        double r79237 = r79234 * r79234;
        double r79238 = r79231 * r79231;
        double r79239 = r79237 + r79238;
        double r79240 = r79236 / r79239;
        double r79241 = -inf.0;
        bool r79242 = r79240 <= r79241;
        double r79243 = sqrt(r79239);
        double r79244 = r79230 / r79243;
        double r79245 = 1.1260778548377935e+280;
        bool r79246 = r79240 <= r79245;
        double r79247 = 1.0;
        double r79248 = r79243 / r79236;
        double r79249 = r79247 / r79248;
        double r79250 = r79249 / r79243;
        double r79251 = r79233 / r79243;
        double r79252 = r79246 ? r79250 : r79251;
        double r79253 = r79242 ? r79244 : r79252;
        return r79253;
}

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.5
Herbie25.4
\[\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 3 regimes
  2. if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0

    1. Initial program 64.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt64.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*64.0

      \[\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. Simplified64.0

      \[\leadsto \frac{\color{blue}{\frac{d \cdot b + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Taylor expanded around inf 52.5

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

    if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.1260778548377935e+280

    1. Initial program 11.8

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt11.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 associate-/r*11.7

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

      \[\leadsto \frac{\color{blue}{\frac{d \cdot b + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Using strategy rm
    7. Applied clear-num11.8

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

    if 1.1260778548377935e+280 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

    1. Initial program 62.8

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt62.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 associate-/r*62.8

      \[\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. Simplified62.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\ \;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.126077854837793543272902488688401092988 \cdot 10^{280}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{b \cdot d + a \cdot c}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

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