Average Error: 26.5 → 26.5
Time: 3.6s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1 \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{1 \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r120297 = a;
        double r120298 = c;
        double r120299 = r120297 * r120298;
        double r120300 = b;
        double r120301 = d;
        double r120302 = r120300 * r120301;
        double r120303 = r120299 + r120302;
        double r120304 = r120298 * r120298;
        double r120305 = r120301 * r120301;
        double r120306 = r120304 + r120305;
        double r120307 = r120303 / r120306;
        return r120307;
}

double f(double a, double b, double c, double d) {
        double r120308 = 1.0;
        double r120309 = a;
        double r120310 = c;
        double r120311 = r120309 * r120310;
        double r120312 = b;
        double r120313 = d;
        double r120314 = r120312 * r120313;
        double r120315 = r120311 + r120314;
        double r120316 = r120310 * r120310;
        double r120317 = r120313 * r120313;
        double r120318 = r120316 + r120317;
        double r120319 = sqrt(r120318);
        double r120320 = r120315 / r120319;
        double r120321 = r120308 * r120320;
        double r120322 = r120321 / r120319;
        return r120322;
}

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

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

    \[\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.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 *-un-lft-identity26.5

    \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\sqrt{\color{blue}{1 \cdot \left(c \cdot c + d \cdot d\right)}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  7. Applied sqrt-prod26.5

    \[\leadsto \frac{\frac{a \cdot c + b \cdot d}{\color{blue}{\sqrt{1} \cdot \sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
  8. Applied *-un-lft-identity26.5

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

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

    \[\leadsto \frac{\color{blue}{1} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
  11. Final simplification26.5

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

Reproduce

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