Average Error: 26.2 → 26.1
Time: 11.6s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}
double f(double a, double b, double c, double d) {
        double r3699559 = a;
        double r3699560 = c;
        double r3699561 = r3699559 * r3699560;
        double r3699562 = b;
        double r3699563 = d;
        double r3699564 = r3699562 * r3699563;
        double r3699565 = r3699561 + r3699564;
        double r3699566 = r3699560 * r3699560;
        double r3699567 = r3699563 * r3699563;
        double r3699568 = r3699566 + r3699567;
        double r3699569 = r3699565 / r3699568;
        return r3699569;
}

double f(double a, double b, double c, double d) {
        double r3699570 = a;
        double r3699571 = c;
        double r3699572 = b;
        double r3699573 = d;
        double r3699574 = r3699572 * r3699573;
        double r3699575 = fma(r3699570, r3699571, r3699574);
        double r3699576 = r3699571 * r3699571;
        double r3699577 = fma(r3699573, r3699573, r3699576);
        double r3699578 = sqrt(r3699577);
        double r3699579 = r3699575 / r3699578;
        double r3699580 = r3699579 / r3699578;
        return r3699580;
}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus d

Target

Original26.2
Target0.3
Herbie26.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. Initial program 26.2

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt26.2

    \[\leadsto \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\color{blue}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot \sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
  5. Applied associate-/r*26.1

    \[\leadsto \color{blue}{\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}\]
  6. Final simplification26.1

    \[\leadsto \frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\]

Reproduce

herbie shell --seed 2019155 +o rules:numerics
(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))))