Average Error: 25.7 → 14.8
Time: 8.7s
Precision: binary64
Cost: 15877
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq -1.1437132202364462 \cdot 10^{+93}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -7.2230969502839745 \cdot 10^{-140}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;d \leq -1.3434382879141502 \cdot 10^{-278}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \mathbf{elif}\;d \leq 1.0231125141194154 \cdot 10^{-128}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 2.405852373616342 \cdot 10^{+98}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \end{array}\]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;d \leq -1.1437132202364462 \cdot 10^{+93}:\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{elif}\;d \leq -7.2230969502839745 \cdot 10^{-140}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{elif}\;d \leq -1.3434382879141502 \cdot 10^{-278}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\

\mathbf{elif}\;d \leq 1.0231125141194154 \cdot 10^{-128}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;d \leq 2.405852373616342 \cdot 10^{+98}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\

\end{array}
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (if (<= d -1.1437132202364462e+93)
   (/ (- a) d)
   (if (<= d -7.2230969502839745e-140)
     (/
      (/ (- (* b c) (* d a)) (sqrt (+ (* c c) (* d d))))
      (sqrt (+ (* c c) (* d d))))
     (if (<= d -1.3434382879141502e-278)
       (- (/ b c) (/ a (/ (* c c) d)))
       (if (<= d 1.0231125141194154e-128)
         (/ b c)
         (if (<= d 2.405852373616342e+98)
           (/
            (/ (- (* b c) (* d a)) (sqrt (+ (* c c) (* d d))))
            (sqrt (+ (* c c) (* d d))))
           (- (/ b (/ (* d d) c)) (/ a d))))))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.1437132202364462e+93) {
		tmp = -a / d;
	} else if (d <= -7.2230969502839745e-140) {
		tmp = (((b * c) - (d * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else if (d <= -1.3434382879141502e-278) {
		tmp = (b / c) - (a / ((c * c) / d));
	} else if (d <= 1.0231125141194154e-128) {
		tmp = b / c;
	} else if (d <= 2.405852373616342e+98) {
		tmp = (((b * c) - (d * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else {
		tmp = (b / ((d * d) / c)) - (a / d);
	}
	return tmp;
}

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.7
Target0.5
Herbie14.8
\[\begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array}\]

Alternatives

Alternative 1
Error26.3
Cost41408
\[\frac{\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d}}\]
Alternative 2
Error45.0
Cost34496
\[\frac{\sqrt{b \cdot c - a \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{\sqrt{b \cdot c - a \cdot d}}{\sqrt[3]{c \cdot c + d \cdot d}}\]
Alternative 3
Error26.2
Cost34496
\[\frac{\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 4
Error44.8
Cost27584
\[\frac{\sqrt{b \cdot c - a \cdot d}}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{\sqrt{b \cdot c - a \cdot d}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 5
Error27.5
Cost27072
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{e^{\log \left(\sqrt{c \cdot c + d \cdot d}\right)}}\]
Alternative 6
Error26.2
Cost22208
\[\sqrt[3]{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}} \cdot \left(\sqrt[3]{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}} \cdot \sqrt[3]{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}}\right)\]
Alternative 7
Error26.2
Cost21312
\[\frac{1}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt[3]{c \cdot c + d \cdot d}}\]
Alternative 8
Error26.2
Cost21184
\[\left(\sqrt[3]{b \cdot c - a \cdot d} \cdot \sqrt[3]{b \cdot c - a \cdot d}\right) \cdot \frac{\sqrt[3]{b \cdot c - a \cdot d}}{c \cdot c + d \cdot d}\]
Alternative 9
Error47.1
Cost15424
\[\frac{\frac{{\left(b \cdot c\right)}^{3} - {\left(a \cdot d\right)}^{3}}{c \cdot c + d \cdot d}}{\left(b \cdot c\right) \cdot \left(b \cdot c\right) + \left(\left(a \cdot d\right) \cdot \left(a \cdot d\right) + \left(b \cdot c\right) \cdot \left(a \cdot d\right)\right)}\]
Alternative 10
Error47.7
Cost15168
\[\frac{{\left(b \cdot c\right)}^{3} - {\left(a \cdot d\right)}^{3}}{\left(c \cdot c + d \cdot d\right) \cdot \left(\left(b \cdot c\right) \cdot \left(b \cdot c\right) + a \cdot \left(d \cdot \left(b \cdot c + a \cdot d\right)\right)\right)}\]
Alternative 11
Error39.6
Cost14784
\[\sqrt{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}}\]
Alternative 12
Error26.0
Cost14528
\[\left(b \cdot c - a \cdot d\right) \cdot \left(\sqrt{\frac{1}{c \cdot c + d \cdot d}} \cdot \sqrt{\frac{1}{c \cdot c + d \cdot d}}\right)\]
Alternative 13
Error26.0
Cost14528
\[\sqrt{\frac{1}{c \cdot c + d \cdot d}} \cdot \left(\left(b \cdot c - a \cdot d\right) \cdot \sqrt{\frac{1}{c \cdot c + d \cdot d}}\right)\]
Alternative 14
Error25.7
Cost14400
\[\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 15
Error25.9
Cost14400
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 16
Error44.8
Cost14272
\[\sqrt{b \cdot c - a \cdot d} \cdot \frac{\sqrt{b \cdot c - a \cdot d}}{c \cdot c + d \cdot d}\]
Alternative 17
Error25.7
Cost14272
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 18
Error48.5
Cost14144
\[\frac{b \cdot c - a \cdot d}{{c}^{4} - {d}^{4}} \cdot \left(c \cdot c - d \cdot d\right)\]
Alternative 19
Error40.9
Cost13824
\[\sqrt[3]{{\left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\right)}^{3}}\]
Alternative 20
Error46.5
Cost7680
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{-d}\]
Alternative 21
Error46.3
Cost7616
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{d}\]
Alternative 22
Error46.2
Cost7488
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{c}\]
Alternative 23
Error46.1
Cost7360
\[\frac{b - \frac{a \cdot d}{c}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 24
Error47.1
Cost7040
\[\frac{-b}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 25
Error46.7
Cost7040
\[\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 26
Error40.9
Cost1984
\[\frac{\left(b \cdot c\right) \cdot \left(b \cdot c\right) - \left(a \cdot d\right) \cdot \left(a \cdot d\right)}{\left(c \cdot c + d \cdot d\right) \cdot \left(b \cdot c + a \cdot d\right)}\]
Alternative 27
Error25.9
Cost1088
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}\]
Alternative 28
Error25.9
Cost1088
\[\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}\]
Alternative 29
Error25.7
Cost960
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
Alternative 30
Error43.8
Cost832
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{d \cdot d}\]
Alternative 31
Error38.9
Cost768
\[\frac{a \cdot \left(-d\right)}{c \cdot c + d \cdot d}\]
Alternative 32
Error35.2
Cost704
\[\frac{b}{c} - \frac{a \cdot d}{c \cdot c}\]
Alternative 33
Error34.1
Cost704
\[\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\]
Alternative 34
Error38.8
Cost704
\[\frac{b \cdot c}{c \cdot c + d \cdot d}\]
Alternative 35
Error35.0
Cost704
\[\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\]
Alternative 36
Error34.1
Cost704
\[\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\]
Alternative 37
Error37.0
Cost256
\[\frac{-a}{d}\]
Alternative 38
Error37.7
Cost192
\[\frac{b}{c}\]
Alternative 39
Error61.6
Cost64
\[1\]
Alternative 40
Error51.6
Cost64
\[0\]
Alternative 41
Error61.7
Cost64
\[-1\]

Error

Derivation

  1. Split input into 5 regimes
  2. if d < -1.1437132202364462e93

    1. Initial program 38.0

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Taylor expanded around 0 16.1

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}}\]
    3. Simplified16.1

      \[\leadsto \color{blue}{\frac{-a}{d}}\]
    4. Simplified16.1

      \[\leadsto \color{blue}{\frac{-a}{d}}\]

    if -1.1437132202364462e93 < d < -7.22309695028397451e-140 or 1.0231125141194154e-128 < d < 2.40585237361634206e98

    1. Initial program 15.2

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]

    if -7.22309695028397451e-140 < d < -1.3434382879141502e-278

    1. Initial program 22.8

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

      \[\leadsto \color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary64_442223.3

      \[\leadsto \left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied associate-/r*_binary64_434423.3

      \[\leadsto \left(b \cdot c - a \cdot d\right) \cdot \color{blue}{\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    7. Taylor expanded around inf 10.3

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{d \cdot a}{{c}^{2}}}\]
    8. Simplified10.7

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}}\]
    9. Simplified10.7

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}}\]

    if -1.3434382879141502e-278 < d < 1.0231125141194154e-128

    1. Initial program 23.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Taylor expanded around inf 15.0

      \[\leadsto \color{blue}{\frac{b}{c}}\]
    3. Simplified15.0

      \[\leadsto \color{blue}{\frac{b}{c}}\]

    if 2.40585237361634206e98 < d

    1. Initial program 38.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
    2. Using strategy rm
    3. Applied div-inv_binary64_439738.7

      \[\leadsto \color{blue}{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}}\]
    4. Using strategy rm
    5. Applied add-sqr-sqrt_binary64_442238.7

      \[\leadsto \left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\]
    6. Applied associate-/r*_binary64_434438.7

      \[\leadsto \left(b \cdot c - a \cdot d\right) \cdot \color{blue}{\frac{\frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}}\]
    7. Taylor expanded around 0 15.7

      \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}}\]
    8. Simplified15.0

      \[\leadsto \color{blue}{\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}}\]
    9. Simplified15.0

      \[\leadsto \color{blue}{\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification14.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.1437132202364462 \cdot 10^{+93}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -7.2230969502839745 \cdot 10^{-140}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{elif}\;d \leq -1.3434382879141502 \cdot 10^{-278}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \mathbf{elif}\;d \leq 1.0231125141194154 \cdot 10^{-128}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 2.405852373616342 \cdot 10^{+98}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \end{array}\]

Reproduce

herbie shell --seed 2021042 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :herbie-target
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))