Average Error: 25.8 → 25.8
Time: 12.4s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r2807143 = a;
        double r2807144 = c;
        double r2807145 = r2807143 * r2807144;
        double r2807146 = b;
        double r2807147 = d;
        double r2807148 = r2807146 * r2807147;
        double r2807149 = r2807145 + r2807148;
        double r2807150 = r2807144 * r2807144;
        double r2807151 = r2807147 * r2807147;
        double r2807152 = r2807150 + r2807151;
        double r2807153 = r2807149 / r2807152;
        return r2807153;
}

double f(double a, double b, double c, double d) {
        double r2807154 = 1.0;
        double r2807155 = c;
        double r2807156 = r2807155 * r2807155;
        double r2807157 = d;
        double r2807158 = r2807157 * r2807157;
        double r2807159 = r2807156 + r2807158;
        double r2807160 = sqrt(r2807159);
        double r2807161 = r2807154 / r2807160;
        double r2807162 = b;
        double r2807163 = r2807162 * r2807157;
        double r2807164 = a;
        double r2807165 = r2807164 * r2807155;
        double r2807166 = r2807163 + r2807165;
        double r2807167 = r2807161 * r2807166;
        double r2807168 = r2807167 / r2807160;
        return r2807168;
}

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.8
Target0.5
Herbie25.8
\[\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 25.8

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

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

    \[\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-inv25.8

    \[\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. Final simplification25.8

    \[\leadsto \frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \left(b \cdot d + a \cdot c\right)}{\sqrt{c \cdot c + d \cdot d}}\]

Reproduce

herbie shell --seed 2019139 +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))))