Average Error: 25.9 → 10.5
Time: 13.9s
Precision: binary64
Cost: 14024
\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{if}\;c \leq -1.25 \cdot 10^{+59}:\\ \;\;\;\;t_1 \cdot \left(\frac{a}{\frac{c}{d}} - b\right)\\ \mathbf{elif}\;c \leq -8 \cdot 10^{-185}:\\ \;\;\;\;t_1 \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{-121}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{+69}:\\ \;\;\;\;b \cdot \frac{c}{t_0} - \frac{a}{\frac{t_0}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \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 (+ (* c c) (* d d))) (t_1 (/ 1.0 (hypot c d))))
   (if (<= c -1.25e+59)
     (* t_1 (- (/ a (/ c d)) b))
     (if (<= c -8e-185)
       (* t_1 (/ (- (* c b) (* d a)) (hypot c d)))
       (if (<= c 6.4e-121)
         (- (* b (/ (/ c d) d)) (/ a d))
         (if (<= c 6.4e+69)
           (- (* b (/ c t_0)) (/ a (/ t_0 d)))
           (* (/ c (hypot c d)) (/ b (hypot c 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 t_0 = (c * c) + (d * d);
	double t_1 = 1.0 / hypot(c, d);
	double tmp;
	if (c <= -1.25e+59) {
		tmp = t_1 * ((a / (c / d)) - b);
	} else if (c <= -8e-185) {
		tmp = t_1 * (((c * b) - (d * a)) / hypot(c, d));
	} else if (c <= 6.4e-121) {
		tmp = (b * ((c / d) / d)) - (a / d);
	} else if (c <= 6.4e+69) {
		tmp = (b * (c / t_0)) - (a / (t_0 / d));
	} else {
		tmp = (c / hypot(c, d)) * (b / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (c * c) + (d * d);
	double t_1 = 1.0 / Math.hypot(c, d);
	double tmp;
	if (c <= -1.25e+59) {
		tmp = t_1 * ((a / (c / d)) - b);
	} else if (c <= -8e-185) {
		tmp = t_1 * (((c * b) - (d * a)) / Math.hypot(c, d));
	} else if (c <= 6.4e-121) {
		tmp = (b * ((c / d) / d)) - (a / d);
	} else if (c <= 6.4e+69) {
		tmp = (b * (c / t_0)) - (a / (t_0 / d));
	} else {
		tmp = (c / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
def code(a, b, c, d):
	t_0 = (c * c) + (d * d)
	t_1 = 1.0 / math.hypot(c, d)
	tmp = 0
	if c <= -1.25e+59:
		tmp = t_1 * ((a / (c / d)) - b)
	elif c <= -8e-185:
		tmp = t_1 * (((c * b) - (d * a)) / math.hypot(c, d))
	elif c <= 6.4e-121:
		tmp = (b * ((c / d) / d)) - (a / d)
	elif c <= 6.4e+69:
		tmp = (b * (c / t_0)) - (a / (t_0 / d))
	else:
		tmp = (c / math.hypot(c, d)) * (b / math.hypot(c, d))
	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(c * c) + Float64(d * d))
	t_1 = Float64(1.0 / hypot(c, d))
	tmp = 0.0
	if (c <= -1.25e+59)
		tmp = Float64(t_1 * Float64(Float64(a / Float64(c / d)) - b));
	elseif (c <= -8e-185)
		tmp = Float64(t_1 * Float64(Float64(Float64(c * b) - Float64(d * a)) / hypot(c, d)));
	elseif (c <= 6.4e-121)
		tmp = Float64(Float64(b * Float64(Float64(c / d) / d)) - Float64(a / d));
	elseif (c <= 6.4e+69)
		tmp = Float64(Float64(b * Float64(c / t_0)) - Float64(a / Float64(t_0 / d)));
	else
		tmp = Float64(Float64(c / hypot(c, d)) * Float64(b / hypot(c, d)));
	end
	return tmp
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
end
function tmp_2 = code(a, b, c, d)
	t_0 = (c * c) + (d * d);
	t_1 = 1.0 / hypot(c, d);
	tmp = 0.0;
	if (c <= -1.25e+59)
		tmp = t_1 * ((a / (c / d)) - b);
	elseif (c <= -8e-185)
		tmp = t_1 * (((c * b) - (d * a)) / hypot(c, d));
	elseif (c <= 6.4e-121)
		tmp = (b * ((c / d) / d)) - (a / d);
	elseif (c <= 6.4e+69)
		tmp = (b * (c / t_0)) - (a / (t_0 / d));
	else
		tmp = (c / hypot(c, d)) * (b / hypot(c, d));
	end
	tmp_2 = 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[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.25e+59], N[(t$95$1 * N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -8e-185], N[(t$95$1 * N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.4e-121], N[(N[(b * N[(N[(c / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6.4e+69], N[(N[(b * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision] - N[(a / N[(t$95$0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
t_1 := \frac{1}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+59}:\\
\;\;\;\;t_1 \cdot \left(\frac{a}{\frac{c}{d}} - b\right)\\

\mathbf{elif}\;c \leq -8 \cdot 10^{-185}:\\
\;\;\;\;t_1 \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\

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

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

\mathbf{else}:\\
\;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original25.9
Target0.4
Herbie10.5
\[\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 5 regimes
  2. if c < -1.2499999999999999e59

    1. Initial program 35.4

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Taylor expanded in c around -inf 14.4

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{a \cdot d}{c} + -1 \cdot b\right)} \]
    4. Simplified11.3

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(\frac{a}{\frac{c}{d}} + \left(-b\right)\right)} \]
      Proof

      [Start]14.4

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a \cdot d}{c} + -1 \cdot b\right) \]

      associate-/l* [=>]11.3

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\frac{a}{\frac{c}{d}}} + -1 \cdot b\right) \]

      mul-1-neg [=>]11.3

      \[ \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a}{\frac{c}{d}} + \color{blue}{\left(-b\right)}\right) \]

    if -1.2499999999999999e59 < c < -7.9999999999999999e-185

    1. Initial program 14.2

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}} \]

    if -7.9999999999999999e-185 < c < 6.40000000000000038e-121

    1. Initial program 22.6

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

      \[\leadsto \frac{\color{blue}{\left(b \cdot c - a \cdot d\right) + \left(\left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right) + \left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right)\right)}}{c \cdot c + d \cdot d} \]
    3. Simplified22.8

      \[\leadsto \frac{\color{blue}{\left(c \cdot b - a \cdot d\right) + 2 \cdot \left(2 \cdot \mathsf{fma}\left(-d, a, a \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
      Proof

      [Start]22.8

      \[ \frac{\left(b \cdot c - a \cdot d\right) + \left(\left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right) + \left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]

      *-commutative [=>]22.8

      \[ \frac{\left(\color{blue}{c \cdot b} - a \cdot d\right) + \left(\left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right) + \left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right)\right)}{c \cdot c + d \cdot d} \]

      count-2 [=>]22.8

      \[ \frac{\left(c \cdot b - a \cdot d\right) + \color{blue}{2 \cdot \left(\mathsf{fma}\left(-d, a, a \cdot d\right) + \mathsf{fma}\left(-d, a, a \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]

      count-2 [=>]22.8

      \[ \frac{\left(c \cdot b - a \cdot d\right) + 2 \cdot \color{blue}{\left(2 \cdot \mathsf{fma}\left(-d, a, a \cdot d\right)\right)}}{c \cdot c + d \cdot d} \]
    4. Taylor expanded in d around inf 9.1

      \[\leadsto \color{blue}{\left(4 \cdot \frac{a + -1 \cdot a}{d} + \frac{c \cdot b}{{d}^{2}}\right) - \frac{a}{d}} \]
    5. Simplified6.1

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

      [Start]9.1

      \[ \left(4 \cdot \frac{a + -1 \cdot a}{d} + \frac{c \cdot b}{{d}^{2}}\right) - \frac{a}{d} \]

      +-commutative [=>]9.1

      \[ \color{blue}{\left(\frac{c \cdot b}{{d}^{2}} + 4 \cdot \frac{a + -1 \cdot a}{d}\right)} - \frac{a}{d} \]

      associate--l+ [=>]9.1

      \[ \color{blue}{\frac{c \cdot b}{{d}^{2}} + \left(4 \cdot \frac{a + -1 \cdot a}{d} - \frac{a}{d}\right)} \]

      associate-*r/ [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \left(\color{blue}{\frac{4 \cdot \left(a + -1 \cdot a\right)}{d}} - \frac{a}{d}\right) \]

      div-sub [<=]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \color{blue}{\frac{4 \cdot \left(a + -1 \cdot a\right) - a}{d}} \]

      distribute-rgt1-in [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \frac{4 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot a\right)} - a}{d} \]

      metadata-eval [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \frac{4 \cdot \left(\color{blue}{0} \cdot a\right) - a}{d} \]

      mul0-lft [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \frac{4 \cdot \color{blue}{0} - a}{d} \]

      metadata-eval [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \frac{\color{blue}{0} - a}{d} \]

      neg-sub0 [<=]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \frac{\color{blue}{-a}}{d} \]

      distribute-frac-neg [=>]9.1

      \[ \frac{c \cdot b}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]

      sub-neg [<=]9.1

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

      associate-*l/ [<=]10.1

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

      *-commutative [=>]10.1

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

      unpow2 [=>]10.1

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

      associate-/r* [=>]6.1

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

    if 6.40000000000000038e-121 < c < 6.3999999999999997e69

    1. Initial program 15.7

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}} \]
    3. Taylor expanded in b around 0 15.7

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

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

      [Start]15.7

      \[ \frac{c \cdot b}{{d}^{2} + {c}^{2}} + -1 \cdot \frac{a \cdot d}{{d}^{2} + {c}^{2}} \]

      +-commutative [=>]15.7

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

      associate-/l* [=>]13.7

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

      associate-*r/ [=>]13.7

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

      mul-1-neg [=>]13.7

      \[ \frac{\color{blue}{-a}}{\frac{{d}^{2} + {c}^{2}}{d}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]

      +-commutative [=>]13.7

      \[ \frac{-a}{\frac{\color{blue}{{c}^{2} + {d}^{2}}}{d}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]

      unpow2 [=>]13.7

      \[ \frac{-a}{\frac{\color{blue}{c \cdot c} + {d}^{2}}{d}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]

      unpow2 [=>]13.7

      \[ \frac{-a}{\frac{c \cdot c + \color{blue}{d \cdot d}}{d}} + \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]

      associate-/l* [=>]14.1

      \[ \frac{-a}{\frac{c \cdot c + d \cdot d}{d}} + \color{blue}{\frac{c}{\frac{{d}^{2} + {c}^{2}}{b}}} \]

      associate-/r/ [=>]12.3

      \[ \frac{-a}{\frac{c \cdot c + d \cdot d}{d}} + \color{blue}{\frac{c}{{d}^{2} + {c}^{2}} \cdot b} \]

      +-commutative [=>]12.3

      \[ \frac{-a}{\frac{c \cdot c + d \cdot d}{d}} + \frac{c}{\color{blue}{{c}^{2} + {d}^{2}}} \cdot b \]

      unpow2 [=>]12.3

      \[ \frac{-a}{\frac{c \cdot c + d \cdot d}{d}} + \frac{c}{\color{blue}{c \cdot c} + {d}^{2}} \cdot b \]

      unpow2 [=>]12.3

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

    if 6.3999999999999997e69 < c

    1. Initial program 38.8

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

      \[\leadsto \color{blue}{\frac{c \cdot b}{{d}^{2} + {c}^{2}}} \]
    3. Simplified41.4

      \[\leadsto \color{blue}{\frac{c \cdot b}{d \cdot d + c \cdot c}} \]
      Proof

      [Start]41.4

      \[ \frac{c \cdot b}{{d}^{2} + {c}^{2}} \]

      unpow2 [=>]41.4

      \[ \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]

      unpow2 [=>]41.4

      \[ \frac{c \cdot b}{d \cdot d + \color{blue}{c \cdot c}} \]
    4. Applied egg-rr13.8

      \[\leadsto \color{blue}{\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification10.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.25 \cdot 10^{+59}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a}{\frac{c}{d}} - b\right)\\ \mathbf{elif}\;c \leq -8 \cdot 10^{-185}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{c \cdot b - d \cdot a}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{-121}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{+69}:\\ \;\;\;\;b \cdot \frac{c}{c \cdot c + d \cdot d} - \frac{a}{\frac{c \cdot c + d \cdot d}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error10.8
Cost13904
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := b \cdot \frac{c}{t_0} - \frac{a}{\frac{t_0}{d}}\\ \mathbf{if}\;c \leq -6.6 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a}{\frac{c}{d}} - b\right)\\ \mathbf{elif}\;c \leq -1.82 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.4 \cdot 10^{-121}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
Alternative 2
Error10.0
Cost7300
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := b \cdot \frac{c}{t_0} - \frac{a}{\frac{t_0}{d}}\\ \mathbf{if}\;c \leq -6 \cdot 10^{+108}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\frac{a}{\frac{c}{d}} - b\right)\\ \mathbf{elif}\;c \leq -1.36 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
Alternative 3
Error10.1
Cost2000
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := b \cdot \frac{c}{t_0} - \frac{a}{\frac{t_0}{d}}\\ \mathbf{if}\;c \leq -1.05 \cdot 10^{+106}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -1.1 \cdot 10^{-114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 5.9 \cdot 10^{-121}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]
Alternative 4
Error11.8
Cost1872
\[\begin{array}{l} t_0 := c \cdot c + d \cdot d\\ t_1 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -4.5 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-117}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{t_0}\\ \mathbf{elif}\;c \leq 2.25 \cdot 10^{-120}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+103}:\\ \;\;\;\;\frac{d \cdot a + \left(c \cdot b - a \cdot \left(d + d\right)\right)}{t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error15.7
Cost1496
\[\begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ t_1 := c \cdot c + d \cdot d\\ t_2 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -9.8 \cdot 10^{+41}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -1.5 \cdot 10^{-46}:\\ \;\;\;\;b \cdot \frac{c}{t_1}\\ \mathbf{elif}\;c \leq -5 \cdot 10^{-100}:\\ \;\;\;\;\frac{a \cdot \left(-d\right)}{t_1}\\ \mathbf{elif}\;c \leq 4.9 \cdot 10^{-49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 2 \cdot 10^{-18}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 5200:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error11.8
Cost1488
\[\begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -4.3 \cdot 10^{+45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -2.95 \cdot 10^{-114}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 8 \cdot 10^{-92}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{+102}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error16.0
Cost1234
\[\begin{array}{l} \mathbf{if}\;c \leq -2.3 \cdot 10^{-8} \lor \neg \left(c \leq -2.7 \cdot 10^{-44}\right) \land \left(c \leq -5.9 \cdot 10^{-102} \lor \neg \left(c \leq 5.2 \cdot 10^{-49}\right)\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \frac{\frac{c}{d}}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 8
Error15.0
Cost1232
\[\begin{array}{l} t_0 := \frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ t_1 := \frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \mathbf{if}\;c \leq -0.000175:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 2.4 \cdot 10^{-49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;c \leq 3 \cdot 10^{-20}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 53000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error15.1
Cost969
\[\begin{array}{l} \mathbf{if}\;d \leq -3.7 \cdot 10^{-47} \lor \neg \left(d \leq 1.8 \cdot 10^{+29}\right):\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 10
Error15.3
Cost968
\[\begin{array}{l} \mathbf{if}\;d \leq -1.75 \cdot 10^{-46}:\\ \;\;\;\;\frac{c}{\frac{d}{\frac{b}{d}}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 4.8 \cdot 10^{+29}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
Alternative 11
Error19.1
Cost841
\[\begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{-46} \lor \neg \left(d \leq 4.7 \cdot 10^{+29}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
Alternative 12
Error22.8
Cost521
\[\begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{-47} \lor \neg \left(d \leq 5.5 \cdot 10^{+29}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
Alternative 13
Error37.3
Cost192
\[\frac{b}{c} \]

Error

Reproduce

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