Average Error: 25.2 → 25.1
Time: 14.9s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \le 1.6421156666632428 \cdot 10^{+125}:\\ \;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\ \end{array}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \le 1.6421156666632428 \cdot 10^{+125}:\\
\;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\

\end{array}
double f(double a, double b, double c, double d) {
        double r4413492 = a;
        double r4413493 = c;
        double r4413494 = r4413492 * r4413493;
        double r4413495 = b;
        double r4413496 = d;
        double r4413497 = r4413495 * r4413496;
        double r4413498 = r4413494 + r4413497;
        double r4413499 = r4413493 * r4413493;
        double r4413500 = r4413496 * r4413496;
        double r4413501 = r4413499 + r4413500;
        double r4413502 = r4413498 / r4413501;
        return r4413502;
}

double f(double a, double b, double c, double d) {
        double r4413503 = d;
        double r4413504 = 1.6421156666632428e+125;
        bool r4413505 = r4413503 <= r4413504;
        double r4413506 = b;
        double r4413507 = r4413506 * r4413503;
        double r4413508 = a;
        double r4413509 = c;
        double r4413510 = r4413508 * r4413509;
        double r4413511 = r4413507 + r4413510;
        double r4413512 = r4413503 * r4413503;
        double r4413513 = r4413509 * r4413509;
        double r4413514 = r4413512 + r4413513;
        double r4413515 = r4413511 / r4413514;
        double r4413516 = sqrt(r4413514);
        double r4413517 = r4413506 / r4413516;
        double r4413518 = r4413505 ? r4413515 : r4413517;
        return r4413518;
}

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.2
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 d < 1.6421156666632428e+125

    1. Initial program 22.6

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity22.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d}\]
    4. Applied associate-/l*22.8

      \[\leadsto \color{blue}{\frac{1}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity22.8

      \[\leadsto \frac{1}{\color{blue}{1 \cdot \frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}}\]
    7. Applied *-un-lft-identity22.8

      \[\leadsto \frac{\color{blue}{1 \cdot 1}}{1 \cdot \frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}\]
    8. Applied times-frac22.8

      \[\leadsto \color{blue}{\frac{1}{1} \cdot \frac{1}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}}\]
    9. Simplified22.8

      \[\leadsto \color{blue}{1} \cdot \frac{1}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}\]
    10. Simplified22.6

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

    if 1.6421156666632428e+125 < d

    1. Initial program 39.4

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

      \[\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*39.4

      \[\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 div-inv39.4

      \[\leadsto \frac{\color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
    7. Taylor expanded around 0 38.7

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

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

Reproduce

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