Average Error: 26.9 → 26.9
Time: 12.0s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
double f(double a, double b, double c, double d) {
        double r93958 = a;
        double r93959 = c;
        double r93960 = r93958 * r93959;
        double r93961 = b;
        double r93962 = d;
        double r93963 = r93961 * r93962;
        double r93964 = r93960 + r93963;
        double r93965 = r93959 * r93959;
        double r93966 = r93962 * r93962;
        double r93967 = r93965 + r93966;
        double r93968 = r93964 / r93967;
        return r93968;
}

double f(double a, double b, double c, double d) {
        double r93969 = a;
        double r93970 = c;
        double r93971 = r93969 * r93970;
        double r93972 = b;
        double r93973 = d;
        double r93974 = r93972 * r93973;
        double r93975 = r93971 + r93974;
        double r93976 = r93970 * r93970;
        double r93977 = r93973 * r93973;
        double r93978 = r93976 + r93977;
        double r93979 = r93975 / r93978;
        return r93979;
}

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.9
Target0.4
Herbie26.9
\[\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.9

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

    \[\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.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. Final simplification26.9

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

Reproduce

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