Complex division, imag part

Percentage Accurate: 61.2% → 80.0%
Time: 12.6s
Alternatives: 7
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
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]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((b * c) - (a * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
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]
\begin{array}{l}

\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}

Alternative 1: 80.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{if}\;d \leq -3.25 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-47}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 460:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{d}{c} \cdot \frac{a}{c}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+77}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))))
   (if (<= d -3.25e+105)
     (- (/ c (* d (/ d b))) (/ a d))
     (if (<= d -2.5e-47)
       t_0
       (if (<= d 460.0)
         (fma -1.0 (* (/ d c) (/ a c)) (/ b c))
         (if (<= d 4.2e+77) t_0 (- (* (/ c d) (/ b d)) (/ a d))))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double tmp;
	if (d <= -3.25e+105) {
		tmp = (c / (d * (d / b))) - (a / d);
	} else if (d <= -2.5e-47) {
		tmp = t_0;
	} else if (d <= 460.0) {
		tmp = fma(-1.0, ((d / c) * (a / c)), (b / c));
	} else if (d <= 4.2e+77) {
		tmp = t_0;
	} else {
		tmp = ((c / d) * (b / d)) - (a / d);
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (d <= -3.25e+105)
		tmp = Float64(Float64(c / Float64(d * Float64(d / b))) - Float64(a / d));
	elseif (d <= -2.5e-47)
		tmp = t_0;
	elseif (d <= 460.0)
		tmp = fma(-1.0, Float64(Float64(d / c) * Float64(a / c)), Float64(b / c));
	elseif (d <= 4.2e+77)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(c / d) * Float64(b / d)) - Float64(a / d));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -3.25e+105], N[(N[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.5e-47], t$95$0, If[LessEqual[d, 460.0], N[(-1.0 * N[(N[(d / c), $MachinePrecision] * N[(a / c), $MachinePrecision]), $MachinePrecision] + N[(b / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 4.2e+77], t$95$0, N[(N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;d \leq -3.25 \cdot 10^{+105}:\\
\;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\

\mathbf{elif}\;d \leq -2.5 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 460:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{d}{c} \cdot \frac{a}{c}, \frac{b}{c}\right)\\

\mathbf{elif}\;d \leq 4.2 \cdot 10^{+77}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.25000000000000024e105

    1. Initial program 33.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 71.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative71.8%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. mul-1-neg71.8%

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]
      3. unsub-neg71.8%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}} \]
      4. *-commutative71.8%

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{d}^{2}} - \frac{a}{d} \]
      5. associate-/l*74.8%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}}} - \frac{a}{d} \]
    5. Simplified74.8%

      \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}} \]
    6. Step-by-step derivation
      1. pow274.8%

        \[\leadsto \frac{c}{\frac{\color{blue}{d \cdot d}}{b}} - \frac{a}{d} \]
      2. *-un-lft-identity74.8%

        \[\leadsto \frac{c}{\frac{d \cdot d}{\color{blue}{1 \cdot b}}} - \frac{a}{d} \]
      3. times-frac88.2%

        \[\leadsto \frac{c}{\color{blue}{\frac{d}{1} \cdot \frac{d}{b}}} - \frac{a}{d} \]
    7. Applied egg-rr88.2%

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

    if -3.25000000000000024e105 < d < -2.50000000000000006e-47 or 460 < d < 4.1999999999999997e77

    1. Initial program 86.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -2.50000000000000006e-47 < d < 460

    1. Initial program 65.6%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 83.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
    4. Step-by-step derivation
      1. fma-def83.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{a \cdot d}{{c}^{2}}, \frac{b}{c}\right)} \]
      2. associate-/l*83.1%

        \[\leadsto \mathsf{fma}\left(-1, \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}}, \frac{b}{c}\right) \]
    5. Simplified83.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{a}{\frac{{c}^{2}}{d}}, \frac{b}{c}\right)} \]
    6. Step-by-step derivation
      1. pow283.1%

        \[\leadsto \mathsf{fma}\left(-1, \frac{a}{\frac{\color{blue}{c \cdot c}}{d}}, \frac{b}{c}\right) \]
      2. *-un-lft-identity83.1%

        \[\leadsto \mathsf{fma}\left(-1, \frac{a}{\frac{c \cdot c}{\color{blue}{1 \cdot d}}}, \frac{b}{c}\right) \]
      3. times-frac88.4%

        \[\leadsto \mathsf{fma}\left(-1, \frac{a}{\color{blue}{\frac{c}{1} \cdot \frac{c}{d}}}, \frac{b}{c}\right) \]
    7. Applied egg-rr88.4%

      \[\leadsto \mathsf{fma}\left(-1, \frac{a}{\color{blue}{\frac{c}{1} \cdot \frac{c}{d}}}, \frac{b}{c}\right) \]
    8. Step-by-step derivation
      1. /-rgt-identity88.4%

        \[\leadsto \mathsf{fma}\left(-1, \frac{a}{\color{blue}{c} \cdot \frac{c}{d}}, \frac{b}{c}\right) \]
      2. *-un-lft-identity88.4%

        \[\leadsto \mathsf{fma}\left(-1, \frac{\color{blue}{1 \cdot a}}{c \cdot \frac{c}{d}}, \frac{b}{c}\right) \]
      3. *-commutative88.4%

        \[\leadsto \mathsf{fma}\left(-1, \frac{1 \cdot a}{\color{blue}{\frac{c}{d} \cdot c}}, \frac{b}{c}\right) \]
      4. times-frac89.2%

        \[\leadsto \mathsf{fma}\left(-1, \color{blue}{\frac{1}{\frac{c}{d}} \cdot \frac{a}{c}}, \frac{b}{c}\right) \]
      5. clear-num89.2%

        \[\leadsto \mathsf{fma}\left(-1, \color{blue}{\frac{d}{c}} \cdot \frac{a}{c}, \frac{b}{c}\right) \]
    9. Applied egg-rr89.2%

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

    if 4.1999999999999997e77 < d

    1. Initial program 38.1%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 70.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative70.1%

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]
      3. unsub-neg70.1%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{d}^{2}} - \frac{a}{d} \]
      5. associate-/l*74.9%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}}} - \frac{a}{d} \]
    5. Simplified74.9%

      \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}} \]
    6. Step-by-step derivation
      1. pow274.9%

        \[\leadsto \frac{c}{\frac{\color{blue}{d \cdot d}}{b}} - \frac{a}{d} \]
      2. associate-/l*70.1%

        \[\leadsto \color{blue}{\frac{c \cdot b}{d \cdot d}} - \frac{a}{d} \]
      3. times-frac78.7%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    7. Applied egg-rr78.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.25 \cdot 10^{+105}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq -2.5 \cdot 10^{-47}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 460:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{d}{c} \cdot \frac{a}{c}, \frac{b}{c}\right)\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{+77}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ t_1 := \frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \mathbf{if}\;c \leq -1.9 \cdot 10^{+89}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{-51}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{-114}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* c c) (* d d))))
        (t_1 (- (/ b c) (* d (/ (/ a c) c)))))
   (if (<= c -1.9e+89)
     t_1
     (if (<= c -1.7e-51)
       t_0
       (if (<= c 6.2e-114)
         (/ (- (* b (/ c d)) a) d)
         (if (<= c 3e+59) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = (b / c) - (d * ((a / c) / c));
	double tmp;
	if (c <= -1.9e+89) {
		tmp = t_1;
	} else if (c <= -1.7e-51) {
		tmp = t_0;
	} else if (c <= 6.2e-114) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 3e+59) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
    t_1 = (b / c) - (d * ((a / c) / c))
    if (c <= (-1.9d+89)) then
        tmp = t_1
    else if (c <= (-1.7d-51)) then
        tmp = t_0
    else if (c <= 6.2d-114) then
        tmp = ((b * (c / d)) - a) / d
    else if (c <= 3d+59) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	double t_1 = (b / c) - (d * ((a / c) / c));
	double tmp;
	if (c <= -1.9e+89) {
		tmp = t_1;
	} else if (c <= -1.7e-51) {
		tmp = t_0;
	} else if (c <= 6.2e-114) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 3e+59) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d))
	t_1 = (b / c) - (d * ((a / c) / c))
	tmp = 0
	if c <= -1.9e+89:
		tmp = t_1
	elif c <= -1.7e-51:
		tmp = t_0
	elif c <= 6.2e-114:
		tmp = ((b * (c / d)) - a) / d
	elif c <= 3e+59:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)))
	t_1 = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c)))
	tmp = 0.0
	if (c <= -1.9e+89)
		tmp = t_1;
	elseif (c <= -1.7e-51)
		tmp = t_0;
	elseif (c <= 6.2e-114)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 3e+59)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((c * b) - (d * a)) / ((c * c) + (d * d));
	t_1 = (b / c) - (d * ((a / c) / c));
	tmp = 0.0;
	if (c <= -1.9e+89)
		tmp = t_1;
	elseif (c <= -1.7e-51)
		tmp = t_0;
	elseif (c <= 6.2e-114)
		tmp = ((b * (c / d)) - a) / d;
	elseif (c <= 3e+59)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.9e+89], t$95$1, If[LessEqual[c, -1.7e-51], t$95$0, If[LessEqual[c, 6.2e-114], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3e+59], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\
t_1 := \frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -1.9 \cdot 10^{+89}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -1.7 \cdot 10^{-51}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.90000000000000012e89 or 3e59 < c

    1. Initial program 43.1%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 79.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
    4. Step-by-step derivation
      1. +-commutative79.4%

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

        \[\leadsto \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)} \]
      3. unsub-neg79.4%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}} \]
      4. associate-/l*78.0%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}} \]
      5. associate-/r/79.8%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{{c}^{2}} \cdot d} \]
    5. Simplified79.8%

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt35.2%

        \[\leadsto \frac{b}{c} - \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{{c}^{2}} \cdot d \]
      2. pow235.2%

        \[\leadsto \frac{b}{c} - \frac{\sqrt{a} \cdot \sqrt{a}}{\color{blue}{c \cdot c}} \cdot d \]
      3. times-frac37.7%

        \[\leadsto \frac{b}{c} - \color{blue}{\left(\frac{\sqrt{a}}{c} \cdot \frac{\sqrt{a}}{c}\right)} \cdot d \]
    7. Applied egg-rr37.7%

      \[\leadsto \frac{b}{c} - \color{blue}{\left(\frac{\sqrt{a}}{c} \cdot \frac{\sqrt{a}}{c}\right)} \cdot d \]
    8. Step-by-step derivation
      1. associate-*l/37.7%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\sqrt{a} \cdot \frac{\sqrt{a}}{c}}{c}} \cdot d \]
      2. associate-*r/37.7%

        \[\leadsto \frac{b}{c} - \frac{\color{blue}{\frac{\sqrt{a} \cdot \sqrt{a}}{c}}}{c} \cdot d \]
      3. rem-square-sqrt87.5%

        \[\leadsto \frac{b}{c} - \frac{\frac{\color{blue}{a}}{c}}{c} \cdot d \]
    9. Simplified87.5%

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

    if -1.90000000000000012e89 < c < -1.70000000000000001e-51 or 6.2e-114 < c < 3e59

    1. Initial program 83.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing

    if -1.70000000000000001e-51 < c < 6.2e-114

    1. Initial program 65.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 78.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative78.5%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. mul-1-neg78.5%

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]
      3. unsub-neg78.5%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}} \]
      4. *-commutative78.5%

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{d}^{2}} - \frac{a}{d} \]
      5. associate-/l*76.6%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}}} - \frac{a}{d} \]
    5. Simplified76.6%

      \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}} \]
    6. Step-by-step derivation
      1. pow276.6%

        \[\leadsto \frac{c}{\frac{\color{blue}{d \cdot d}}{b}} - \frac{a}{d} \]
      2. associate-/l*78.5%

        \[\leadsto \color{blue}{\frac{c \cdot b}{d \cdot d}} - \frac{a}{d} \]
      3. times-frac83.2%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    7. Applied egg-rr83.2%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    8. Step-by-step derivation
      1. associate-*r/85.2%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b}{d}} - \frac{a}{d} \]
      2. sub-div85.3%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b - a}{d}} \]
      3. *-commutative85.3%

        \[\leadsto \frac{\color{blue}{b \cdot \frac{c}{d}} - a}{d} \]
    9. Applied egg-rr85.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.9 \cdot 10^{+89}:\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{-51}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.2 \cdot 10^{-114}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 75.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{-51} \lor \neg \left(c \leq 6.2 \cdot 10^{-52}\right):\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -4.8e-51) (not (<= c 6.2e-52)))
   (- (/ b c) (* d (/ (/ a c) c)))
   (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.8e-51) || !(c <= 6.2e-52)) {
		tmp = (b / c) - (d * ((a / c) / c));
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-4.8d-51)) .or. (.not. (c <= 6.2d-52))) then
        tmp = (b / c) - (d * ((a / c) / c))
    else
        tmp = ((b * (c / d)) - a) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.8e-51) || !(c <= 6.2e-52)) {
		tmp = (b / c) - (d * ((a / c) / c));
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -4.8e-51) or not (c <= 6.2e-52):
		tmp = (b / c) - (d * ((a / c) / c))
	else:
		tmp = ((b * (c / d)) - a) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -4.8e-51) || !(c <= 6.2e-52))
		tmp = Float64(Float64(b / c) - Float64(d * Float64(Float64(a / c) / c)));
	else
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -4.8e-51) || ~((c <= 6.2e-52)))
		tmp = (b / c) - (d * ((a / c) / c));
	else
		tmp = ((b * (c / d)) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.8e-51], N[Not[LessEqual[c, 6.2e-52]], $MachinePrecision]], N[(N[(b / c), $MachinePrecision] - N[(d * N[(N[(a / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.8 \cdot 10^{-51} \lor \neg \left(c \leq 6.2 \cdot 10^{-52}\right):\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.8e-51 or 6.1999999999999998e-52 < c

    1. Initial program 54.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 76.8%

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2}} + \frac{b}{c}} \]
    4. Step-by-step derivation
      1. +-commutative76.8%

        \[\leadsto \color{blue}{\frac{b}{c} + -1 \cdot \frac{a \cdot d}{{c}^{2}}} \]
      2. mul-1-neg76.8%

        \[\leadsto \frac{b}{c} + \color{blue}{\left(-\frac{a \cdot d}{{c}^{2}}\right)} \]
      3. unsub-neg76.8%

        \[\leadsto \color{blue}{\frac{b}{c} - \frac{a \cdot d}{{c}^{2}}} \]
      4. associate-/l*75.8%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{\frac{{c}^{2}}{d}}} \]
      5. associate-/r/75.8%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{a}{{c}^{2}} \cdot d} \]
    5. Simplified75.8%

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt30.6%

        \[\leadsto \frac{b}{c} - \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{{c}^{2}} \cdot d \]
      2. pow230.6%

        \[\leadsto \frac{b}{c} - \frac{\sqrt{a} \cdot \sqrt{a}}{\color{blue}{c \cdot c}} \cdot d \]
      3. times-frac32.4%

        \[\leadsto \frac{b}{c} - \color{blue}{\left(\frac{\sqrt{a}}{c} \cdot \frac{\sqrt{a}}{c}\right)} \cdot d \]
    7. Applied egg-rr32.4%

      \[\leadsto \frac{b}{c} - \color{blue}{\left(\frac{\sqrt{a}}{c} \cdot \frac{\sqrt{a}}{c}\right)} \cdot d \]
    8. Step-by-step derivation
      1. associate-*l/32.4%

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{\sqrt{a} \cdot \frac{\sqrt{a}}{c}}{c}} \cdot d \]
      2. associate-*r/32.4%

        \[\leadsto \frac{b}{c} - \frac{\color{blue}{\frac{\sqrt{a} \cdot \sqrt{a}}{c}}}{c} \cdot d \]
      3. rem-square-sqrt81.2%

        \[\leadsto \frac{b}{c} - \frac{\frac{\color{blue}{a}}{c}}{c} \cdot d \]
    9. Simplified81.2%

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

    if -4.8e-51 < c < 6.1999999999999998e-52

    1. Initial program 68.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 77.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative77.3%

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]
      3. unsub-neg77.3%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}} \]
      4. *-commutative77.3%

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{d}^{2}} - \frac{a}{d} \]
      5. associate-/l*75.5%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}}} - \frac{a}{d} \]
    5. Simplified75.5%

      \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}} \]
    6. Step-by-step derivation
      1. pow275.5%

        \[\leadsto \frac{c}{\frac{\color{blue}{d \cdot d}}{b}} - \frac{a}{d} \]
      2. associate-/l*77.3%

        \[\leadsto \color{blue}{\frac{c \cdot b}{d \cdot d}} - \frac{a}{d} \]
      3. times-frac81.6%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    7. Applied egg-rr81.6%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    8. Step-by-step derivation
      1. associate-*r/83.5%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b}{d}} - \frac{a}{d} \]
      2. sub-div83.7%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b - a}{d}} \]
      3. *-commutative83.7%

        \[\leadsto \frac{\color{blue}{b \cdot \frac{c}{d}} - a}{d} \]
    9. Applied egg-rr83.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.8 \cdot 10^{-51} \lor \neg \left(c \leq 6.2 \cdot 10^{-52}\right):\\ \;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 69.5% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -7.2 \cdot 10^{-51} \lor \neg \left(c \leq 7 \cdot 10^{-48}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -7.2e-51) (not (<= c 7e-48)))
   (/ b c)
   (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -7.2e-51) || !(c <= 7e-48)) {
		tmp = b / c;
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-7.2d-51)) .or. (.not. (c <= 7d-48))) then
        tmp = b / c
    else
        tmp = ((b * (c / d)) - a) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -7.2e-51) || !(c <= 7e-48)) {
		tmp = b / c;
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -7.2e-51) or not (c <= 7e-48):
		tmp = b / c
	else:
		tmp = ((b * (c / d)) - a) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -7.2e-51) || !(c <= 7e-48))
		tmp = Float64(b / c);
	else
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -7.2e-51) || ~((c <= 7e-48)))
		tmp = b / c;
	else
		tmp = ((b * (c / d)) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -7.2e-51], N[Not[LessEqual[c, 7e-48]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -7.2 \cdot 10^{-51} \lor \neg \left(c \leq 7 \cdot 10^{-48}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -7.2000000000000001e-51 or 6.99999999999999982e-48 < c

    1. Initial program 54.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 67.8%

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

    if -7.2000000000000001e-51 < c < 6.99999999999999982e-48

    1. Initial program 68.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 77.3%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative77.3%

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{\left(-\frac{a}{d}\right)} \]
      3. unsub-neg77.3%

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} - \frac{a}{d}} \]
      4. *-commutative77.3%

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{d}^{2}} - \frac{a}{d} \]
      5. associate-/l*75.5%

        \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}}} - \frac{a}{d} \]
    5. Simplified75.5%

      \[\leadsto \color{blue}{\frac{c}{\frac{{d}^{2}}{b}} - \frac{a}{d}} \]
    6. Step-by-step derivation
      1. pow275.5%

        \[\leadsto \frac{c}{\frac{\color{blue}{d \cdot d}}{b}} - \frac{a}{d} \]
      2. associate-/l*77.3%

        \[\leadsto \color{blue}{\frac{c \cdot b}{d \cdot d}} - \frac{a}{d} \]
      3. times-frac81.6%

        \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    7. Applied egg-rr81.6%

      \[\leadsto \color{blue}{\frac{c}{d} \cdot \frac{b}{d}} - \frac{a}{d} \]
    8. Step-by-step derivation
      1. associate-*r/83.5%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b}{d}} - \frac{a}{d} \]
      2. sub-div83.7%

        \[\leadsto \color{blue}{\frac{\frac{c}{d} \cdot b - a}{d}} \]
      3. *-commutative83.7%

        \[\leadsto \frac{\color{blue}{b \cdot \frac{c}{d}} - a}{d} \]
    9. Applied egg-rr83.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.2 \cdot 10^{-51} \lor \neg \left(c \leq 7 \cdot 10^{-48}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 62.4% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.2 \cdot 10^{-51} \lor \neg \left(c \leq 5.5 \cdot 10^{-47}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -4.2e-51) (not (<= c 5.5e-47))) (/ b c) (/ (- a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.2e-51) || !(c <= 5.5e-47)) {
		tmp = b / c;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-4.2d-51)) .or. (.not. (c <= 5.5d-47))) then
        tmp = b / c
    else
        tmp = -a / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.2e-51) || !(c <= 5.5e-47)) {
		tmp = b / c;
	} else {
		tmp = -a / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -4.2e-51) or not (c <= 5.5e-47):
		tmp = b / c
	else:
		tmp = -a / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -4.2e-51) || !(c <= 5.5e-47))
		tmp = Float64(b / c);
	else
		tmp = Float64(Float64(-a) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -4.2e-51) || ~((c <= 5.5e-47)))
		tmp = b / c;
	else
		tmp = -a / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.2e-51], N[Not[LessEqual[c, 5.5e-47]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[((-a) / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.2 \cdot 10^{-51} \lor \neg \left(c \leq 5.5 \cdot 10^{-47}\right):\\
\;\;\;\;\frac{b}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{-a}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.20000000000000003e-51 or 5.5000000000000002e-47 < c

    1. Initial program 54.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 67.8%

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

    if -4.20000000000000003e-51 < c < 5.5000000000000002e-47

    1. Initial program 68.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 73.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. associate-*r/73.9%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-173.9%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified73.9%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.2 \cdot 10^{-51} \lor \neg \left(c \leq 5.5 \cdot 10^{-47}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 45.5% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.02 \cdot 10^{+118} \lor \neg \left(d \leq 1.25 \cdot 10^{+156}\right):\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -1.02e+118) (not (<= d 1.25e+156))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.02e+118) || !(d <= 1.25e+156)) {
		tmp = a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((d <= (-1.02d+118)) .or. (.not. (d <= 1.25d+156))) then
        tmp = a / d
    else
        tmp = b / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.02e+118) || !(d <= 1.25e+156)) {
		tmp = a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.02e+118) or not (d <= 1.25e+156):
		tmp = a / d
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.02e+118) || !(d <= 1.25e+156))
		tmp = Float64(a / d);
	else
		tmp = Float64(b / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -1.02e+118) || ~((d <= 1.25e+156)))
		tmp = a / d;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.02e+118], N[Not[LessEqual[d, 1.25e+156]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+118} \lor \neg \left(d \leq 1.25 \cdot 10^{+156}\right):\\
\;\;\;\;\frac{a}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.0199999999999999e118 or 1.24999999999999998e156 < d

    1. Initial program 32.1%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 0 73.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. associate-*r/73.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
      2. neg-mul-173.4%

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified73.4%

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
    6. Step-by-step derivation
      1. neg-sub073.4%

        \[\leadsto \frac{\color{blue}{0 - a}}{d} \]
      2. sub-neg73.4%

        \[\leadsto \frac{\color{blue}{0 + \left(-a\right)}}{d} \]
      3. add-sqr-sqrt32.5%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
      4. sqrt-unprod39.0%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
      5. sqr-neg39.0%

        \[\leadsto \frac{0 + \sqrt{\color{blue}{a \cdot a}}}{d} \]
      6. sqrt-unprod16.0%

        \[\leadsto \frac{0 + \color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
      7. add-sqr-sqrt29.7%

        \[\leadsto \frac{0 + \color{blue}{a}}{d} \]
    7. Applied egg-rr29.7%

      \[\leadsto \frac{\color{blue}{0 + a}}{d} \]
    8. Step-by-step derivation
      1. +-lft-identity29.7%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
    9. Simplified29.7%

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

    if -1.0199999999999999e118 < d < 1.24999999999999998e156

    1. Initial program 69.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around inf 56.7%

      \[\leadsto \color{blue}{\frac{b}{c}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.02 \cdot 10^{+118} \lor \neg \left(d \leq 1.25 \cdot 10^{+156}\right):\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 11.1% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{d} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
	return a / d;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = a / d
end function
public static double code(double a, double b, double c, double d) {
	return a / d;
}
def code(a, b, c, d):
	return a / d
function code(a, b, c, d)
	return Float64(a / d)
end
function tmp = code(a, b, c, d)
	tmp = a / d;
end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}

\\
\frac{a}{d}
\end{array}
Derivation
  1. Initial program 60.1%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Add Preprocessing
  3. Taylor expanded in c around 0 39.0%

    \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
  4. Step-by-step derivation
    1. associate-*r/39.0%

      \[\leadsto \color{blue}{\frac{-1 \cdot a}{d}} \]
    2. neg-mul-139.0%

      \[\leadsto \frac{\color{blue}{-a}}{d} \]
  5. Simplified39.0%

    \[\leadsto \color{blue}{\frac{-a}{d}} \]
  6. Step-by-step derivation
    1. neg-sub039.0%

      \[\leadsto \frac{\color{blue}{0 - a}}{d} \]
    2. sub-neg39.0%

      \[\leadsto \frac{\color{blue}{0 + \left(-a\right)}}{d} \]
    3. add-sqr-sqrt17.7%

      \[\leadsto \frac{0 + \color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
    4. sqrt-unprod21.6%

      \[\leadsto \frac{0 + \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
    5. sqr-neg21.6%

      \[\leadsto \frac{0 + \sqrt{\color{blue}{a \cdot a}}}{d} \]
    6. sqrt-unprod5.5%

      \[\leadsto \frac{0 + \color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
    7. add-sqr-sqrt10.0%

      \[\leadsto \frac{0 + \color{blue}{a}}{d} \]
  7. Applied egg-rr10.0%

    \[\leadsto \frac{\color{blue}{0 + a}}{d} \]
  8. Step-by-step derivation
    1. +-lft-identity10.0%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
  9. Simplified10.0%

    \[\leadsto \frac{\color{blue}{a}}{d} \]
  10. Final simplification10.0%

    \[\leadsto \frac{a}{d} \]
  11. Add Preprocessing

Developer target: 99.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \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} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\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}
\end{array}

Reproduce

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