Average Error: 26.2 → 26.3
Time: 16.3s
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 8.391246277230149 \cdot 10^{+244}:\\ \;\;\;\;\frac{b \cdot d + a \cdot c}{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} \le 8.391246277230149 \cdot 10^{+244}:\\
\;\;\;\;\frac{b \cdot d + a \cdot c}{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 r3659700 = a;
        double r3659701 = c;
        double r3659702 = r3659700 * r3659701;
        double r3659703 = b;
        double r3659704 = d;
        double r3659705 = r3659703 * r3659704;
        double r3659706 = r3659702 + r3659705;
        double r3659707 = r3659701 * r3659701;
        double r3659708 = r3659704 * r3659704;
        double r3659709 = r3659707 + r3659708;
        double r3659710 = r3659706 / r3659709;
        return r3659710;
}

double f(double a, double b, double c, double d) {
        double r3659711 = b;
        double r3659712 = d;
        double r3659713 = r3659711 * r3659712;
        double r3659714 = a;
        double r3659715 = c;
        double r3659716 = r3659714 * r3659715;
        double r3659717 = r3659713 + r3659716;
        double r3659718 = r3659715 * r3659715;
        double r3659719 = r3659712 * r3659712;
        double r3659720 = r3659718 + r3659719;
        double r3659721 = r3659717 / r3659720;
        double r3659722 = 8.391246277230149e+244;
        bool r3659723 = r3659721 <= r3659722;
        double r3659724 = -r3659714;
        double r3659725 = sqrt(r3659720);
        double r3659726 = r3659724 / r3659725;
        double r3659727 = r3659723 ? r3659721 : r3659726;
        return r3659727;
}

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.2
Target0.5
Herbie26.3
\[\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))) < 8.391246277230149e+244

    1. Initial program 14.2

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]

    if 8.391246277230149e+244 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))

    1. Initial program 59.2

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

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

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

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

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

Reproduce

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