Average Error: 26.5 → 5.7
Time: 17.1s
Precision: binary64
Cost: 67344
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := \frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)}\\ t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ t_2 := \frac{1}{\mathsf{hypot}\left(d, c\right)}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -4.939221699676908 \cdot 10^{+146}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.926004778278525 \cdot 10^{+141}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}, t_2, t_0 \cdot \frac{-1}{\mathsf{hypot}\left(d, c\right)}\right) + \mathsf{fma}\left(\frac{d \cdot \left(-a\right)}{\mathsf{hypot}\left(d, c\right)}, t_2, t_2 \cdot t_0\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (* d a) (hypot d c)))
        (t_1 (- (/ (* (/ (- b) d) c) (- d)) (/ a d)))
        (t_2 (/ 1.0 (hypot d c))))
   (if (<= d -2.5355883399872014e+249)
     t_1
     (if (<= d -9.766740365443902e+235)
       (/ (- b (* d (/ a c))) c)
       (if (<= d -4.939221699676908e+146)
         (- (* c (/ (/ b d) d)) (/ a d))
         (if (<= d 2.926004778278525e+141)
           (+
            (fma (* b (/ c (hypot d c))) t_2 (* t_0 (/ -1.0 (hypot d c))))
            (fma (/ (* d (- a)) (hypot d c)) t_2 (* t_2 t_0)))
           t_1))))))
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 t_0 = (d * a) / hypot(d, c);
	double t_1 = (((-b / d) * c) / -d) - (a / d);
	double t_2 = 1.0 / hypot(d, c);
	double tmp;
	if (d <= -2.5355883399872014e+249) {
		tmp = t_1;
	} else if (d <= -9.766740365443902e+235) {
		tmp = (b - (d * (a / c))) / c;
	} else if (d <= -4.939221699676908e+146) {
		tmp = (c * ((b / d) / d)) - (a / d);
	} else if (d <= 2.926004778278525e+141) {
		tmp = fma((b * (c / hypot(d, c))), t_2, (t_0 * (-1.0 / hypot(d, c)))) + fma(((d * -a) / hypot(d, c)), t_2, (t_2 * t_0));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function code(a, b, c, d)
	t_0 = Float64(Float64(d * a) / hypot(d, c))
	t_1 = Float64(Float64(Float64(Float64(Float64(-b) / d) * c) / Float64(-d)) - Float64(a / d))
	t_2 = Float64(1.0 / hypot(d, c))
	tmp = 0.0
	if (d <= -2.5355883399872014e+249)
		tmp = t_1;
	elseif (d <= -9.766740365443902e+235)
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) / c);
	elseif (d <= -4.939221699676908e+146)
		tmp = Float64(Float64(c * Float64(Float64(b / d) / d)) - Float64(a / d));
	elseif (d <= 2.926004778278525e+141)
		tmp = Float64(fma(Float64(b * Float64(c / hypot(d, c))), t_2, Float64(t_0 * Float64(-1.0 / hypot(d, c)))) + fma(Float64(Float64(d * Float64(-a)) / hypot(d, c)), t_2, Float64(t_2 * t_0)));
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * a), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(N[((-b) / d), $MachinePrecision] * c), $MachinePrecision] / (-d)), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -2.5355883399872014e+249], t$95$1, If[LessEqual[d, -9.766740365443902e+235], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, -4.939221699676908e+146], N[(N[(c * N[(N[(b / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.926004778278525e+141], N[(N[(N[(b * N[(c / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2 + N[(t$95$0 * N[(-1.0 / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(d * (-a)), $MachinePrecision] / N[Sqrt[d ^ 2 + c ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$2 + N[(t$95$2 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)}\\
t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\
t_2 := \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\

\mathbf{elif}\;d \leq -4.939221699676908 \cdot 10^{+146}:\\
\;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\

\mathbf{elif}\;d \leq 2.926004778278525 \cdot 10^{+141}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}, t_2, t_0 \cdot \frac{-1}{\mathsf{hypot}\left(d, c\right)}\right) + \mathsf{fma}\left(\frac{d \cdot \left(-a\right)}{\mathsf{hypot}\left(d, c\right)}, t_2, t_2 \cdot t_0\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original26.5
Target0.5
Herbie5.7
\[\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} \]

Derivation

  1. Split input into 4 regimes
  2. if d < -2.5355883399872014e249 or 2.9260047782785248e141 < d

    1. Initial program 42.5

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified42.5

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(d, -a, b \cdot c\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 d (neg.f64 a) (*.f64 b c)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 d (neg.f64 a)) (*.f64 b c))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 a) d)) (*.f64 b c)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 b c) (*.f64 (neg.f64 a) d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 b c) (*.f64 a d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Taylor expanded in d around inf 15.2

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}} \]
    4. Simplified9.3

      \[\leadsto \color{blue}{c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}} \]
      Proof
      (-.f64 (*.f64 c (/.f64 (/.f64 b d) d)) (/.f64 a d)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 c (Rewrite<= associate-/r*_binary64 (/.f64 b (*.f64 d d)))) (/.f64 a d)): 32 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 c (/.f64 b (Rewrite<= unpow2_binary64 (pow.f64 d 2)))) (/.f64 a d)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 c b) (pow.f64 d 2))) (/.f64 a d)): 24 points increase in error, 8 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (*.f64 c b) (pow.f64 d 2)) (neg.f64 (/.f64 a d)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 (*.f64 c b) (pow.f64 d 2)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 a d)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 a d)) (/.f64 (*.f64 c b) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr7.2

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

    if -2.5355883399872014e249 < d < -9.76674036544390209e235

    1. Initial program 43.2

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
    3. Simplified55.9

      \[\leadsto \color{blue}{\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}} \]
      Proof
      (-.f64 (/.f64 b c) (*.f64 d (/.f64 (/.f64 a c) c))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b c) (*.f64 d (Rewrite<= associate-/r*_binary64 (/.f64 a (*.f64 c c))))): 25 points increase in error, 9 points decrease in error
      (-.f64 (/.f64 b c) (*.f64 d (/.f64 a (Rewrite<= unpow2_binary64 (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b c) (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 a (pow.f64 c 2)) d))): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 b c) (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 a d) (pow.f64 c 2)))): 34 points increase in error, 6 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 b c) (neg.f64 (/.f64 (*.f64 a d) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 b c) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 (*.f64 a d) (pow.f64 c 2))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 a d) (pow.f64 c 2))) (/.f64 b c))): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr55.1

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

    if -9.76674036544390209e235 < d < -4.9392216996769081e146

    1. Initial program 47.7

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Simplified47.7

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(d, -a, b \cdot c\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
      Proof
      (/.f64 (fma.f64 d (neg.f64 a) (*.f64 b c)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 d (neg.f64 a)) (*.f64 b c))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 a) d)) (*.f64 b c)) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 b c) (*.f64 (neg.f64 a) d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 b c) (*.f64 a d))) (fma.f64 c c (*.f64 d d))): 0 points increase in error, 0 points decrease in error
      (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 c c) (*.f64 d d)))): 1 points increase in error, 0 points decrease in error
    3. Taylor expanded in d around inf 19.9

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{c \cdot b}{{d}^{2}}} \]
    4. Simplified13.1

      \[\leadsto \color{blue}{c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}} \]
      Proof
      (-.f64 (*.f64 c (/.f64 (/.f64 b d) d)) (/.f64 a d)): 0 points increase in error, 0 points decrease in error
      (-.f64 (*.f64 c (Rewrite<= associate-/r*_binary64 (/.f64 b (*.f64 d d)))) (/.f64 a d)): 32 points increase in error, 6 points decrease in error
      (-.f64 (*.f64 c (/.f64 b (Rewrite<= unpow2_binary64 (pow.f64 d 2)))) (/.f64 a d)): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 c b) (pow.f64 d 2))) (/.f64 a d)): 24 points increase in error, 8 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (/.f64 (*.f64 c b) (pow.f64 d 2)) (neg.f64 (/.f64 a d)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 (*.f64 c b) (pow.f64 d 2)) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (/.f64 a d)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 (/.f64 a d)) (/.f64 (*.f64 c b) (pow.f64 d 2)))): 0 points increase in error, 0 points decrease in error

    if -4.9392216996769081e146 < d < 2.9260047782785248e141

    1. Initial program 19.6

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Applied egg-rr7.7

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\frac{a \cdot d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    3. Applied egg-rr3.6

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(d, c\right)} \cdot b, \frac{1}{\mathsf{hypot}\left(d, c\right)}, -\frac{a \cdot d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\right) + \mathsf{fma}\left(-\frac{a \cdot d}{\mathsf{hypot}\left(d, c\right)}, \frac{1}{\mathsf{hypot}\left(d, c\right)}, \frac{a \cdot d}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification5.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;\frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -4.939221699676908 \cdot 10^{+146}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.926004778278525 \cdot 10^{+141}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}, \frac{1}{\mathsf{hypot}\left(d, c\right)}, \frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{-1}{\mathsf{hypot}\left(d, c\right)}\right) + \mathsf{fma}\left(\frac{d \cdot \left(-a\right)}{\mathsf{hypot}\left(d, c\right)}, \frac{1}{\mathsf{hypot}\left(d, c\right)}, \frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \end{array} \]

Alternatives

Alternative 1
Error8.1
Cost33816
\[\begin{array}{l} t_0 := \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, \frac{d \cdot \left(-a\right)}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -3.5729780386512144 \cdot 10^{+121}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-174}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.2241809059768097 \cdot 10^{-149}:\\ \;\;\;\;\frac{b}{c} + \frac{d}{\frac{c}{a}} \cdot \frac{-1}{c}\\ \mathbf{elif}\;d \leq 2.926004778278525 \cdot 10^{+141}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error12.4
Cost14552
\[\begin{array}{l} t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;d \leq -4.939221699676908 \cdot 10^{+146}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -76127214.12311965:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.9168056692032655 \cdot 10^{-159}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;d \leq 2.424138041514158 \cdot 10^{+124}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error14.6
Cost1620
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.9704135634555555 \cdot 10^{-81}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.424138041514158 \cdot 10^{+124}:\\ \;\;\;\;\frac{b \cdot c - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error16.1
Cost1360
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ t_1 := \frac{\frac{-b}{d} \cdot c}{-d} - \frac{a}{d}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error16.6
Cost1232
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;c \cdot \frac{\frac{b}{d}}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 6
Error19.7
Cost1104
\[\begin{array}{l} t_0 := \frac{-a}{d}\\ t_1 := \frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.7248893549882116 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 4.970989366873508 \cdot 10^{+61}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error17.3
Cost1104
\[\begin{array}{l} t_0 := \frac{\frac{b \cdot c}{d} - a}{d}\\ t_1 := \frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error17.4
Cost1104
\[\begin{array}{l} t_0 := \frac{\frac{b \cdot c}{d} - a}{d}\\ t_1 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error17.1
Cost1104
\[\begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;d \leq -2.5355883399872014 \cdot 10^{+249}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -9.766740365443902 \cdot 10^{+235}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -4.516151575779809 \cdot 10^{+29}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \end{array} \]
Alternative 10
Error23.1
Cost520
\[\begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -1.7248893549882116 \cdot 10^{+32}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 2.001975080593576 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error37.1
Cost192
\[\frac{b}{c} \]

Error

Reproduce

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