Average Error: 26.3 → 26.3
Time: 3.7s
Precision: 64
\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
\[\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}
double f(double a, double b, double c, double d) {
        double r104013 = a;
        double r104014 = c;
        double r104015 = r104013 * r104014;
        double r104016 = b;
        double r104017 = d;
        double r104018 = r104016 * r104017;
        double r104019 = r104015 + r104018;
        double r104020 = r104014 * r104014;
        double r104021 = r104017 * r104017;
        double r104022 = r104020 + r104021;
        double r104023 = r104019 / r104022;
        return r104023;
}

double f(double a, double b, double c, double d) {
        double r104024 = 1.0;
        double r104025 = c;
        double r104026 = r104025 * r104025;
        double r104027 = d;
        double r104028 = r104027 * r104027;
        double r104029 = r104026 + r104028;
        double r104030 = sqrt(r104029);
        double r104031 = r104024 / r104030;
        double r104032 = a;
        double r104033 = r104032 * r104025;
        double r104034 = b;
        double r104035 = r104034 * r104027;
        double r104036 = r104033 + r104035;
        double r104037 = r104036 / r104030;
        double r104038 = r104031 * r104037;
        return r104038;
}

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

    \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\]
  2. Using strategy rm
  3. Applied add-sqr-sqrt26.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 *-un-lft-identity26.3

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

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

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

Reproduce

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