Average Error: 25.3 → 25.4
Time: 2.7m
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{\frac{1}{\frac{1}{c \cdot a + b \cdot d}}}{d \cdot d + c \cdot c}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{\frac{1}{\frac{1}{c \cdot a + b \cdot d}}}{d \cdot d + c \cdot c}
double f(double a, double b, double c, double d) {
        double r21916280 = a;
        double r21916281 = c;
        double r21916282 = r21916280 * r21916281;
        double r21916283 = b;
        double r21916284 = d;
        double r21916285 = r21916283 * r21916284;
        double r21916286 = r21916282 + r21916285;
        double r21916287 = r21916281 * r21916281;
        double r21916288 = r21916284 * r21916284;
        double r21916289 = r21916287 + r21916288;
        double r21916290 = r21916286 / r21916289;
        return r21916290;
}

double f(double a, double b, double c, double d) {
        double r21916291 = 1.0;
        double r21916292 = c;
        double r21916293 = a;
        double r21916294 = r21916292 * r21916293;
        double r21916295 = b;
        double r21916296 = d;
        double r21916297 = r21916295 * r21916296;
        double r21916298 = r21916294 + r21916297;
        double r21916299 = r21916291 / r21916298;
        double r21916300 = r21916291 / r21916299;
        double r21916301 = r21916296 * r21916296;
        double r21916302 = r21916292 * r21916292;
        double r21916303 = r21916301 + r21916302;
        double r21916304 = r21916300 / r21916303;
        return r21916304;
}

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.3
Target0.5
Herbie25.4
\[\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.3

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

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

    \[\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 *-un-lft-identity25.2

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

    \[\leadsto \frac{\frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{1 \cdot \sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  8. Applied times-frac25.2

    \[\leadsto \frac{\color{blue}{\frac{1}{1} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  9. Applied associate-/l*25.4

    \[\leadsto \color{blue}{\frac{\frac{1}{1}}{\frac{\sqrt{c \cdot c + d \cdot d}}{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}}\]
  10. Simplified25.4

    \[\leadsto \frac{\color{blue}{1}}{\frac{\sqrt{c \cdot c + d \cdot d}}{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}}\]
  11. Using strategy rm
  12. Applied div-inv25.4

    \[\leadsto \frac{1}{\frac{\sqrt{c \cdot c + d \cdot d}}{\color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}}\]
  13. Applied *-un-lft-identity25.4

    \[\leadsto \frac{1}{\frac{\color{blue}{1 \cdot \sqrt{c \cdot c + d \cdot d}}}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}}\]
  14. Applied times-frac25.6

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{a \cdot c + b \cdot d} \cdot \frac{\sqrt{c \cdot c + d \cdot d}}{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}}}\]
  15. Applied associate-/r*25.4

    \[\leadsto \color{blue}{\frac{\frac{1}{\frac{1}{a \cdot c + b \cdot d}}}{\frac{\sqrt{c \cdot c + d \cdot d}}{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}}}\]
  16. Simplified25.4

    \[\leadsto \frac{\frac{1}{\frac{1}{a \cdot c + b \cdot d}}}{\color{blue}{c \cdot c + d \cdot d}}\]
  17. Final simplification25.4

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

Reproduce

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