Average Error: 26.6 → 14.8
Time: 11.4s
Precision: binary64
Cost: 15556
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq -2.623594142603243 \cdot 10^{+102}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -2.178304667980649 \cdot 10^{-161}:\\ \;\;\;\;\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 4.0526762739374186 \cdot 10^{-107}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \mathbf{elif}\;d \leq 5.943546987088161 \cdot 10^{+45}:\\ \;\;\;\;\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 \cdot c}{d \cdot d} - \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 -2.623594142603243 \cdot 10^{+102}:\\
\;\;\;\;\frac{-a}{d}\\

\mathbf{elif}\;d \leq -2.178304667980649 \cdot 10^{-161}:\\
\;\;\;\;\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 4.0526762739374186 \cdot 10^{-107}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\

\mathbf{elif}\;d \leq 5.943546987088161 \cdot 10^{+45}:\\
\;\;\;\;\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 \cdot c}{d \cdot d} - \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 -2.623594142603243e+102)
   (/ (- a) d)
   (if (<= d -2.178304667980649e-161)
     (/
      (/ (- (* b c) (* d a)) (sqrt (+ (* c c) (* d d))))
      (sqrt (+ (* c c) (* d d))))
     (if (<= d 4.0526762739374186e-107)
       (- (/ b c) (/ (* d a) (* c c)))
       (if (<= d 5.943546987088161e+45)
         (/
          (/ (- (* b c) (* d a)) (sqrt (+ (* c c) (* d d))))
          (sqrt (+ (* c c) (* d d))))
         (- (/ (* b c) (* d d)) (/ 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 <= -2.623594142603243e+102) {
		tmp = -a / d;
	} else if (d <= -2.178304667980649e-161) {
		tmp = (((b * c) - (d * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else if (d <= 4.0526762739374186e-107) {
		tmp = (b / c) - ((d * a) / (c * c));
	} else if (d <= 5.943546987088161e+45) {
		tmp = (((b * c) - (d * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
	} else {
		tmp = ((b * c) / (d * d)) - (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

Original26.6
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
Error27.1
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.3
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
Error27.0
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
Error26.7
Cost34112
\[\frac{\frac{1}{\sqrt{\sqrt{c \cdot c + d \cdot d}}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 5
Error26.6
Cost33984
\[\frac{\frac{\frac{b \cdot c - a \cdot d}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{\sqrt{c \cdot c + d \cdot d}}}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 6
Error27.0
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
Error27.0
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
Error27.0
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
Error27.0
Cost21184
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}}}{\sqrt[3]{c \cdot c + d \cdot d}}\]
Alternative 10
Error54.9
Cost15168
\[\frac{b \cdot c - a \cdot d}{{c}^{6} + {d}^{6}} \cdot \left(\left(c \cdot c\right) \cdot \left(c \cdot c\right) + \left(\left(d \cdot d\right) \cdot \left(d \cdot d\right) - \left(c \cdot c\right) \cdot \left(d \cdot d\right)\right)\right)\]
Alternative 11
Error40.3
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.6
Cost14400
\[\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 13
Error45.2
Cost14272
\[\sqrt{b \cdot c - a \cdot d} \cdot \frac{\sqrt{b \cdot c - a \cdot d}}{c \cdot c + d \cdot d}\]
Alternative 14
Error26.5
Cost14272
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 15
Error49.2
Cost14144
\[\frac{b \cdot c - a \cdot d}{{c}^{4} - {d}^{4}} \cdot \left(c \cdot c - d \cdot d\right)\]
Alternative 16
Error41.7
Cost13824
\[\sqrt[3]{{\left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\right)}^{3}}\]
Alternative 17
Error47.2
Cost7552
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{-d}\]
Alternative 18
Error47.1
Cost7552
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{-c}\]
Alternative 19
Error47.3
Cost7488
\[\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{d}\]
Alternative 20
Error46.9
Cost7360
\[\frac{\frac{a \cdot d}{c} - b}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 21
Error46.9
Cost7360
\[\frac{a - \frac{b \cdot c}{d}}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 22
Error47.1
Cost7360
\[\frac{\frac{b \cdot c}{d} - a}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 23
Error47.5
Cost6976
\[\frac{b}{\sqrt{c \cdot c + d \cdot d}}\]
Alternative 24
Error41.8
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 25
Error26.6
Cost1472
\[\frac{b \cdot c}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d}\]
Alternative 26
Error26.7
Cost1088
\[\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}\]
Alternative 27
Error26.7
Cost1088
\[\frac{1}{\frac{c \cdot c + d \cdot d}{b \cdot c - a \cdot d}}\]
Alternative 28
Error26.6
Cost960
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
Alternative 29
Error40.0
Cost768
\[\frac{a \cdot \left(-d\right)}{c \cdot c + d \cdot d}\]
Alternative 30
Error34.9
Cost704
\[\frac{b}{c} - \frac{a \cdot d}{c \cdot c}\]
Alternative 31
Error34.8
Cost704
\[\frac{b \cdot c}{d \cdot d} - \frac{a}{d}\]
Alternative 32
Error39.3
Cost704
\[\frac{b \cdot c}{c \cdot c + d \cdot d}\]
Alternative 33
Error37.5
Cost256
\[\frac{-a}{d}\]
Alternative 34
Error37.3
Cost192
\[\frac{b}{c}\]
Alternative 35
Error61.6
Cost64
\[1\]
Alternative 36
Error52.3
Cost64
\[0\]
Alternative 37
Error61.6
Cost64
\[-1\]

Error

Derivation

  1. Split input into 4 regimes
  2. if d < -2.6235941426032431e102

    1. Initial program 41.0

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

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

      \[\leadsto \color{blue}{\frac{-a}{d}}\]
    4. Simplified17.6

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

    if -2.6235941426032431e102 < d < -2.178304667980649e-161 or 4.0526762739374186e-107 < d < 5.943546987088161e45

    1. Initial program 15.6

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

      \[\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_206815.6

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

      \[\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 -2.178304667980649e-161 < d < 4.0526762739374186e-107

    1. Initial program 22.6

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

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

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

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

    if 5.943546987088161e45 < d

    1. Initial program 36.1

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

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{d \cdot d} - \frac{a}{d}}\]
    4. Simplified16.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.623594142603243 \cdot 10^{+102}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -2.178304667980649 \cdot 10^{-161}:\\ \;\;\;\;\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 4.0526762739374186 \cdot 10^{-107}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \mathbf{elif}\;d \leq 5.943546987088161 \cdot 10^{+45}:\\ \;\;\;\;\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 \cdot c}{d \cdot d} - \frac{a}{d}\\ \end{array}\]

Reproduce

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