Average Error: 25.8 → 26.2
Time: 12.8s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le -1.300179201415138562389146100214075083549 \cdot 10^{53}:\\ \;\;\;\;-\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{d \cdot d + c \cdot c}{a \cdot c + b \cdot d}}\\ \end{array}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le -1.300179201415138562389146100214075083549 \cdot 10^{53}:\\
\;\;\;\;-\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r83272 = a;
        double r83273 = c;
        double r83274 = r83272 * r83273;
        double r83275 = b;
        double r83276 = d;
        double r83277 = r83275 * r83276;
        double r83278 = r83274 + r83277;
        double r83279 = r83273 * r83273;
        double r83280 = r83276 * r83276;
        double r83281 = r83279 + r83280;
        double r83282 = r83278 / r83281;
        return r83282;
}

double f(double a, double b, double c, double d) {
        double r83283 = d;
        double r83284 = -1.3001792014151386e+53;
        bool r83285 = r83283 <= r83284;
        double r83286 = b;
        double r83287 = r83283 * r83283;
        double r83288 = c;
        double r83289 = r83288 * r83288;
        double r83290 = r83287 + r83289;
        double r83291 = sqrt(r83290);
        double r83292 = r83286 / r83291;
        double r83293 = -r83292;
        double r83294 = 1.0;
        double r83295 = a;
        double r83296 = r83295 * r83288;
        double r83297 = r83286 * r83283;
        double r83298 = r83296 + r83297;
        double r83299 = r83290 / r83298;
        double r83300 = r83294 / r83299;
        double r83301 = r83285 ? r83293 : r83300;
        return r83301;
}

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.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 d < -1.3001792014151386e+53

    1. Initial program 35.6

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

      \[\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. Simplified35.6

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

      \[\leadsto \frac{\color{blue}{-1 \cdot b}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Simplified36.7

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

    if -1.3001792014151386e+53 < d

    1. Initial program 23.1

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

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

      \[\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. Simplified23.1

      \[\leadsto \frac{\color{blue}{\frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity23.1

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

      \[\leadsto \frac{\frac{b \cdot d + a \cdot c}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    9. Applied *-un-lft-identity23.1

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

      \[\leadsto \frac{\color{blue}{\frac{1}{\sqrt{1}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    11. Applied associate-/l*23.3

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

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

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

Reproduce

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