Average Error: 25.6 → 25.6
Time: 13.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 r3994249 = a;
        double r3994250 = c;
        double r3994251 = r3994249 * r3994250;
        double r3994252 = b;
        double r3994253 = d;
        double r3994254 = r3994252 * r3994253;
        double r3994255 = r3994251 + r3994254;
        double r3994256 = r3994250 * r3994250;
        double r3994257 = r3994253 * r3994253;
        double r3994258 = r3994256 + r3994257;
        double r3994259 = r3994255 / r3994258;
        return r3994259;
}

double f(double a, double b, double c, double d) {
        double r3994260 = 1.0;
        double r3994261 = c;
        double r3994262 = r3994261 * r3994261;
        double r3994263 = d;
        double r3994264 = r3994263 * r3994263;
        double r3994265 = r3994262 + r3994264;
        double r3994266 = sqrt(r3994265);
        double r3994267 = r3994260 / r3994266;
        double r3994268 = b;
        double r3994269 = r3994268 * r3994263;
        double r3994270 = a;
        double r3994271 = r3994270 * r3994261;
        double r3994272 = r3994269 + r3994271;
        double r3994273 = r3994267 * r3994272;
        double r3994274 = r3994273 / r3994266;
        return r3994274;
}

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.6
Target0.6
Herbie25.6
\[\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.6

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

    \[\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.5

    \[\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.6

    \[\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.6

    \[\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 2019135 
(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))))