Average Error: 25.8 → 25.8
Time: 9.7s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.7234357932591811 \cdot 10^{232}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + d \cdot b}}}{\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{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.7234357932591811 \cdot 10^{232}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{a \cdot c + d \cdot b}}}{\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 r78975 = a;
        double r78976 = c;
        double r78977 = r78975 * r78976;
        double r78978 = b;
        double r78979 = d;
        double r78980 = r78978 * r78979;
        double r78981 = r78977 + r78980;
        double r78982 = r78976 * r78976;
        double r78983 = r78979 * r78979;
        double r78984 = r78982 + r78983;
        double r78985 = r78981 / r78984;
        return r78985;
}

double f(double a, double b, double c, double d) {
        double r78986 = a;
        double r78987 = c;
        double r78988 = r78986 * r78987;
        double r78989 = b;
        double r78990 = d;
        double r78991 = r78989 * r78990;
        double r78992 = r78988 + r78991;
        double r78993 = r78987 * r78987;
        double r78994 = r78990 * r78990;
        double r78995 = r78993 + r78994;
        double r78996 = r78992 / r78995;
        double r78997 = 3.723435793259181e+232;
        bool r78998 = r78996 <= r78997;
        double r78999 = 1.0;
        double r79000 = sqrt(r78995);
        double r79001 = r78990 * r78989;
        double r79002 = r78988 + r79001;
        double r79003 = r79000 / r79002;
        double r79004 = r78999 / r79003;
        double r79005 = r79004 / r79000;
        double r79006 = -r78986;
        double r79007 = r79006 / r79000;
        double r79008 = r78998 ? r79005 : r79007;
        return r79008;
}

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
Herbie25.8
\[\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))) < 3.723435793259181e+232

    1. Initial program 13.9

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

      \[\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*13.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. Using strategy rm
    6. Applied clear-num13.8

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

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

    if 3.723435793259181e+232 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

    1. Initial program 60.0

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt60.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*60.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. Taylor expanded around -inf 59.9

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

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

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

Reproduce

herbie shell --seed 2020045 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

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