Average Error: 25.6 → 25.1
Time: 40.6s
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} \le 6.142565536588697 \cdot 10^{+301}:\\ \;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{\sqrt{c \cdot c + d \cdot d}} \cdot a\\ \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} \le 6.142565536588697 \cdot 10^{+301}:\\
\;\;\;\;\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot d + a \cdot c}{\sqrt{c \cdot c + d \cdot d}}\\

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

\end{array}
double f(double a, double b, double c, double d) {
        double r30746077 = a;
        double r30746078 = c;
        double r30746079 = r30746077 * r30746078;
        double r30746080 = b;
        double r30746081 = d;
        double r30746082 = r30746080 * r30746081;
        double r30746083 = r30746079 + r30746082;
        double r30746084 = r30746078 * r30746078;
        double r30746085 = r30746081 * r30746081;
        double r30746086 = r30746084 + r30746085;
        double r30746087 = r30746083 / r30746086;
        return r30746087;
}

double f(double a, double b, double c, double d) {
        double r30746088 = b;
        double r30746089 = d;
        double r30746090 = r30746088 * r30746089;
        double r30746091 = a;
        double r30746092 = c;
        double r30746093 = r30746091 * r30746092;
        double r30746094 = r30746090 + r30746093;
        double r30746095 = r30746092 * r30746092;
        double r30746096 = r30746089 * r30746089;
        double r30746097 = r30746095 + r30746096;
        double r30746098 = r30746094 / r30746097;
        double r30746099 = 6.142565536588697e+301;
        bool r30746100 = r30746098 <= r30746099;
        double r30746101 = 1.0;
        double r30746102 = sqrt(r30746097);
        double r30746103 = r30746101 / r30746102;
        double r30746104 = r30746094 / r30746102;
        double r30746105 = r30746103 * r30746104;
        double r30746106 = -1.0;
        double r30746107 = r30746106 / r30746102;
        double r30746108 = r30746107 * r30746091;
        double r30746109 = r30746100 ? r30746105 : r30746108;
        return r30746109;
}

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.6
Target0.5
Herbie25.1
\[\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 c) (* b d)) (+ (* c c) (* d d))) < 6.142565536588697e+301

    1. Initial program 14.1

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

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

      \[\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 6.142565536588697e+301 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

    1. Initial program 62.2

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

      \[\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-identity62.2

      \[\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-frac62.2

      \[\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}}}\]
    6. Taylor expanded around -inf 60.0

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\left(-1 \cdot a\right)}\]
    7. Simplified60.0

      \[\leadsto \frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \color{blue}{\left(-a\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.1

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

Reproduce

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