Average Error: 26.2 → 26.2
Time: 6.1s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r78551 = a;
        double r78552 = c;
        double r78553 = r78551 * r78552;
        double r78554 = b;
        double r78555 = d;
        double r78556 = r78554 * r78555;
        double r78557 = r78553 + r78556;
        double r78558 = r78552 * r78552;
        double r78559 = r78555 * r78555;
        double r78560 = r78558 + r78559;
        double r78561 = r78557 / r78560;
        return r78561;
}

double f(double a, double b, double c, double d) {
        double r78562 = a;
        double r78563 = c;
        double r78564 = r78562 * r78563;
        double r78565 = b;
        double r78566 = d;
        double r78567 = r78565 * r78566;
        double r78568 = r78564 + r78567;
        double r78569 = r78563 * r78563;
        double r78570 = r78566 * r78566;
        double r78571 = r78569 + r78570;
        double r78572 = r78568 / r78571;
        return r78572;
}

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.2
\[\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. Initial program 26.2

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

    \[\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. Final simplification26.2

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

Reproduce

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