Average Error: 26.3 → 26.3
Time: 4.1s
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 r106716 = a;
        double r106717 = c;
        double r106718 = r106716 * r106717;
        double r106719 = b;
        double r106720 = d;
        double r106721 = r106719 * r106720;
        double r106722 = r106718 + r106721;
        double r106723 = r106717 * r106717;
        double r106724 = r106720 * r106720;
        double r106725 = r106723 + r106724;
        double r106726 = r106722 / r106725;
        return r106726;
}

double f(double a, double b, double c, double d) {
        double r106727 = c;
        double r106728 = 1.4473657936297032e+65;
        bool r106729 = r106727 <= r106728;
        double r106730 = a;
        double r106731 = r106730 * r106727;
        double r106732 = b;
        double r106733 = d;
        double r106734 = r106732 * r106733;
        double r106735 = r106731 + r106734;
        double r106736 = r106727 * r106727;
        double r106737 = r106733 * r106733;
        double r106738 = r106736 + r106737;
        double r106739 = r106735 / r106738;
        double r106740 = sqrt(r106738);
        double r106741 = r106730 / r106740;
        double r106742 = r106729 ? r106739 : r106741;
        return r106742;
}

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