Average Error: 26.2 → 14.8
Time: 9.8s
Precision: binary64
Cost: 15556
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\]
\[\begin{array}{l} \mathbf{if}\;d \leq -3.2563987087522574 \cdot 10^{+81}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -8.232708701844971 \cdot 10^{-48}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{elif}\;d \leq 1.8192329406445362 \cdot 10^{-149}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \mathbf{elif}\;d \leq 2.0139063475555305 \cdot 10^{+69}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \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 -3.2563987087522574 \cdot 10^{+81}:\\
\;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\

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

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

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

\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 -3.2563987087522574e+81)
   (- (/ b (/ (* d d) c)) (/ a d))
   (if (<= d -8.232708701844971e-48)
     (/
      (/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
      (sqrt (+ (* d d) (* c c))))
     (if (<= d 1.8192329406445362e-149)
       (- (/ b c) (/ (* d a) (* c c)))
       (if (<= d 2.0139063475555305e+69)
         (/
          (/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
          (sqrt (+ (* d d) (* c c))))
         (- (/ 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 <= -3.2563987087522574e+81) {
		tmp = (b / ((d * d) / c)) - (a / d);
	} else if (d <= -8.232708701844971e-48) {
		tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
	} else if (d <= 1.8192329406445362e-149) {
		tmp = (b / c) - ((d * a) / (c * c));
	} else if (d <= 2.0139063475555305e+69) {
		tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
	} 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

Original26.2
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
Error14.8
Cost2244
\[\begin{array}{l} \mathbf{if}\;d \leq -2.3901732992931246 \cdot 10^{+81}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.644763038826746 \cdot 10^{-49}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;d \leq 1.3404554011445771 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \mathbf{elif}\;d \leq 1.2069815748150215 \cdot 10^{+69}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \end{array}\]
Alternative 2
Error18.8
Cost1674
\[\begin{array}{l} \mathbf{if}\;d \leq -2.6251436529546742 \cdot 10^{+85}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1.6406630229566118 \cdot 10^{+59}:\\ \;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\ \mathbf{elif}\;d \leq -1.418363775640226 \cdot 10^{-12} \lor \neg \left(d \leq 1.2863457966181983 \cdot 10^{-53}\right):\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \end{array}\]
Alternative 3
Error18.6
Cost1297
\[\begin{array}{l} \mathbf{if}\;d \leq -7.490156733069174 \cdot 10^{+71} \lor \neg \left(d \leq -1.7344613743200935 \cdot 10^{+59} \lor \neg \left(d \leq -2.8002525199011073 \cdot 10^{-10}\right) \land d \leq 1.928153543830285 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \end{array}\]
Alternative 4
Error20.3
Cost1988
\[\begin{array}{l} \mathbf{if}\;c \leq -5.012823408298066 \cdot 10^{-13}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 7.897694579240514 \cdot 10^{-58}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 2.707692421836616 \cdot 10^{+44}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c}\\ \mathbf{elif}\;c \leq 5.475526172947629 \cdot 10^{+56}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]
Alternative 5
Error20.5
Cost1297
\[\begin{array}{l} \mathbf{if}\;c \leq -2.648659214426478 \cdot 10^{-13} \lor \neg \left(c \leq 5512952.078642197 \lor \neg \left(c \leq 1.7115989933157516 \cdot 10^{+32}\right) \land c \leq 5.565175323815072 \cdot 10^{+54}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \end{array}\]
Alternative 6
Error23.2
Cost584
\[\begin{array}{l} \mathbf{if}\;d \leq -6.213553210147759 \cdot 10^{+71} \lor \neg \left(d \leq 2.6785472288895752 \cdot 10^{-06}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array}\]
Alternative 7
Error35.1
Cost834
\[\begin{array}{l} \mathbf{if}\;d \leq -2.520179551920492 \cdot 10^{+115}:\\ \;\;\;\;0\\ \mathbf{elif}\;d \leq 1.5347938031871036 \cdot 10^{+46}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 8
Error51.9
Cost64
\[0\]
Alternative 9
Error61.7
Cost64
\[1\]

Error

Derivation

  1. Split input into 3 regimes
  2. if d < -3.256398708752257e81 or 2.01390634755553049e69 < d

    1. Initial program 37.9

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

      \[\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 *-un-lft-identity_binary64_314737.9

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}\]
    6. Taylor expanded around 0 17.5

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

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

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

    if -3.256398708752257e81 < d < -8.23270870184497108e-48 or 1.8192329406445362e-149 < d < 2.01390634755553049e69

    1. Initial program 14.7

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

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

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

    if -8.23270870184497108e-48 < d < 1.8192329406445362e-149

    1. Initial program 21.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.2563987087522574 \cdot 10^{+81}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -8.232708701844971 \cdot 10^{-48}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{elif}\;d \leq 1.8192329406445362 \cdot 10^{-149}:\\ \;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\ \mathbf{elif}\;d \leq 2.0139063475555305 \cdot 10^{+69}:\\ \;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\ \end{array}\]

Reproduce

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