Average Error: 26.3 → 26.3
Time: 9.4s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;c \le 1.44736579362970321 \cdot 10^{65}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{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}\;c \le 1.44736579362970321 \cdot 10^{65}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{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 r101445 = a;
        double r101446 = c;
        double r101447 = r101445 * r101446;
        double r101448 = b;
        double r101449 = d;
        double r101450 = r101448 * r101449;
        double r101451 = r101447 + r101450;
        double r101452 = r101446 * r101446;
        double r101453 = r101449 * r101449;
        double r101454 = r101452 + r101453;
        double r101455 = r101451 / r101454;
        return r101455;
}

double f(double a, double b, double c, double d) {
        double r101456 = c;
        double r101457 = 1.4473657936297032e+65;
        bool r101458 = r101456 <= r101457;
        double r101459 = a;
        double r101460 = r101459 * r101456;
        double r101461 = b;
        double r101462 = d;
        double r101463 = r101461 * r101462;
        double r101464 = r101460 + r101463;
        double r101465 = r101456 * r101456;
        double r101466 = r101462 * r101462;
        double r101467 = r101465 + r101466;
        double r101468 = r101464 / r101467;
        double r101469 = sqrt(r101467);
        double r101470 = r101459 / r101469;
        double r101471 = r101458 ? r101468 : r101470;
        return r101471;
}

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.3
Target0.4
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 c < 1.4473657936297032e+65

    1. Initial program 23.4

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

    if 1.4473657936297032e+65 < c

    1. Initial program 37.2

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

      \[\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}\;c \le 1.44736579362970321 \cdot 10^{65}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{\sqrt{c \cdot c + d \cdot d}}\\ \end{array}\]

Reproduce

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