Complex division, imag part

Percentage Accurate: 61.5% → 86.8%
Time: 10.6s
Alternatives: 10
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 10 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.5% 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: 86.8% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.32 \cdot 10^{+174}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-153} \lor \neg \left(c \leq 3.4 \cdot 10^{-136}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.32e+174)
   (/ (- b (* a (/ d c))) c)
   (if (or (<= c -3.1e-153) (not (<= c 3.4e-136)))
     (fma
      (/ c (hypot c d))
      (/ b (hypot c d))
      (* a (/ (- d) (pow (hypot c d) 2.0))))
     (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.32e+174) {
		tmp = (b - (a * (d / c))) / c;
	} else if ((c <= -3.1e-153) || !(c <= 3.4e-136)) {
		tmp = fma((c / hypot(c, d)), (b / hypot(c, d)), (a * (-d / pow(hypot(c, d), 2.0))));
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.32e+174)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif ((c <= -3.1e-153) || !(c <= 3.4e-136))
		tmp = fma(Float64(c / hypot(c, d)), Float64(b / hypot(c, d)), Float64(a * Float64(Float64(-d) / (hypot(c, d) ^ 2.0))));
	else
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.32e+174], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -3.1e-153], N[Not[LessEqual[c, 3.4e-136]], $MachinePrecision]], N[(N[(c / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] + N[(a * N[((-d) / N[Power[N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision], 2.0], $MachinePrecision]), $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 -1.32 \cdot 10^{+174}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

\mathbf{elif}\;c \leq -3.1 \cdot 10^{-153} \lor \neg \left(c \leq 3.4 \cdot 10^{-136}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.31999999999999999e174

    1. Initial program 32.2%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg70.6%

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

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-170.6%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in70.6%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg70.6%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in70.6%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg70.6%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg70.6%

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

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

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

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

    if -1.31999999999999999e174 < c < -3.09999999999999995e-153 or 3.4e-136 < c

    1. Initial program 67.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub67.9%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt67.9%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg73.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
      6. hypot-define73.4%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      7. hypot-define87.3%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*87.5%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right) \]
      9. add-sqr-sqrt87.5%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right) \]
      10. pow287.5%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}\right) \]
      11. hypot-define87.5%

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

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

    if -3.09999999999999995e-153 < c < 3.4e-136

    1. Initial program 73.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub68.1%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt68.1%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg66.4%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
      6. hypot-define66.4%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      7. hypot-define67.8%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*69.3%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right) \]
      9. add-sqr-sqrt69.3%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right) \]
      10. pow269.3%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}\right) \]
      11. hypot-define69.3%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in d around inf 93.7%

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

        \[\leadsto \frac{\color{blue}{b \cdot \frac{c}{d}} - a}{d} \]
    7. Simplified95.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.32 \cdot 10^{+174}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-153} \lor \neg \left(c \leq 3.4 \cdot 10^{-136}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, a \cdot \frac{-d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.3% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-136}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{+74}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -6.2e-47)
   (/ (- b (* a (/ d c))) c)
   (if (<= c 1.7e-136)
     (/ (- (* b (/ c d)) a) d)
     (if (<= c 1.7e+74)
       (/ (- (* c b) (* a d)) (+ (* c c) (* d d)))
       (/ (- b (/ a (/ c d))) c)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -6.2e-47) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 1.7e-136) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 1.7e+74) {
		tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b - (a / (c / d))) / 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 (c <= (-6.2d-47)) then
        tmp = (b - (a * (d / c))) / c
    else if (c <= 1.7d-136) then
        tmp = ((b * (c / d)) - a) / d
    else if (c <= 1.7d+74) then
        tmp = ((c * b) - (a * d)) / ((c * c) + (d * d))
    else
        tmp = (b - (a / (c / d))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -6.2e-47) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 1.7e-136) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 1.7e+74) {
		tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
	} else {
		tmp = (b - (a / (c / d))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -6.2e-47:
		tmp = (b - (a * (d / c))) / c
	elif c <= 1.7e-136:
		tmp = ((b * (c / d)) - a) / d
	elif c <= 1.7e+74:
		tmp = ((c * b) - (a * d)) / ((c * c) + (d * d))
	else:
		tmp = (b - (a / (c / d))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -6.2e-47)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= 1.7e-136)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 1.7e+74)
		tmp = Float64(Float64(Float64(c * b) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -6.2e-47)
		tmp = (b - (a * (d / c))) / c;
	elseif (c <= 1.7e-136)
		tmp = ((b * (c / d)) - a) / d;
	elseif (c <= 1.7e+74)
		tmp = ((c * b) - (a * d)) / ((c * c) + (d * d));
	else
		tmp = (b - (a / (c / d))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.2e-47], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.7e-136], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.7e+74], N[(N[(N[(c * b), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -6.1999999999999996e-47

    1. Initial program 53.1%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg71.7%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg71.7%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-171.7%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in71.7%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg71.7%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in71.7%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg71.7%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg71.7%

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

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

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

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

    if -6.1999999999999996e-47 < c < 1.7e-136

    1. Initial program 71.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub67.4%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt67.4%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg67.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
      6. hypot-define67.1%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      7. hypot-define69.8%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*71.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right) \]
      9. add-sqr-sqrt71.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right) \]
      10. pow271.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}\right) \]
      11. hypot-define71.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in d around inf 90.2%

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

        \[\leadsto \frac{\color{blue}{b \cdot \frac{c}{d}} - a}{d} \]
    7. Simplified90.8%

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

    if 1.7e-136 < c < 1.7e74

    1. Initial program 85.7%

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

    if 1.7e74 < c

    1. Initial program 49.8%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg83.9%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg83.9%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-183.9%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in83.9%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg83.9%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in83.9%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg83.9%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg83.9%

        \[\leadsto \frac{\color{blue}{b} + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      9. unsub-neg83.9%

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-num88.5%

        \[\leadsto \frac{b - a \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv88.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-136}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{+74}:\\ \;\;\;\;\frac{c \cdot b - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 60.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.75 \cdot 10^{+215}:\\ \;\;\;\;\frac{d}{c} \cdot \frac{a}{-c}\\ \mathbf{elif}\;c \leq -1.45 \cdot 10^{-64} \lor \neg \left(c \leq 8.4 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -2.75e+215)
   (* (/ d c) (/ a (- c)))
   (if (or (<= c -1.45e-64) (not (<= c 8.4e-57))) (/ b c) (/ a (- d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -2.75e+215) {
		tmp = (d / c) * (a / -c);
	} else if ((c <= -1.45e-64) || !(c <= 8.4e-57)) {
		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 <= (-2.75d+215)) then
        tmp = (d / c) * (a / -c)
    else if ((c <= (-1.45d-64)) .or. (.not. (c <= 8.4d-57))) 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 <= -2.75e+215) {
		tmp = (d / c) * (a / -c);
	} else if ((c <= -1.45e-64) || !(c <= 8.4e-57)) {
		tmp = b / c;
	} else {
		tmp = a / -d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -2.75e+215:
		tmp = (d / c) * (a / -c)
	elif (c <= -1.45e-64) or not (c <= 8.4e-57):
		tmp = b / c
	else:
		tmp = a / -d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -2.75e+215)
		tmp = Float64(Float64(d / c) * Float64(a / Float64(-c)));
	elseif ((c <= -1.45e-64) || !(c <= 8.4e-57))
		tmp = Float64(b / c);
	else
		tmp = Float64(a / Float64(-d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -2.75e+215)
		tmp = (d / c) * (a / -c);
	elseif ((c <= -1.45e-64) || ~((c <= 8.4e-57)))
		tmp = b / c;
	else
		tmp = a / -d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.75e+215], N[(N[(d / c), $MachinePrecision] * N[(a / (-c)), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[c, -1.45e-64], N[Not[LessEqual[c, 8.4e-57]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.75 \cdot 10^{+215}:\\
\;\;\;\;\frac{d}{c} \cdot \frac{a}{-c}\\

\mathbf{elif}\;c \leq -1.45 \cdot 10^{-64} \lor \neg \left(c \leq 8.4 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.75e215

    1. Initial program 45.7%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg62.0%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg62.0%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-162.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in62.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. distribute-lft-in62.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right) + -1 \cdot \frac{a \cdot d}{c}}}{c} \]
      6. neg-mul-162.0%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      7. mul-1-neg62.0%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      8. remove-double-neg62.0%

        \[\leadsto \frac{\color{blue}{b} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      9. associate-*r/62.0%

        \[\leadsto \frac{b + \color{blue}{\frac{-1 \cdot \left(a \cdot d\right)}{c}}}{c} \]
      10. associate-*r*62.0%

        \[\leadsto \frac{b + \frac{\color{blue}{\left(-1 \cdot a\right) \cdot d}}{c}}{c} \]
      11. neg-mul-162.0%

        \[\leadsto \frac{b + \frac{\color{blue}{\left(-a\right)} \cdot d}{c}}{c} \]
    5. Simplified62.0%

      \[\leadsto \color{blue}{\frac{b + \frac{\left(-a\right) \cdot d}{c}}{c}} \]
    6. Taylor expanded in d around inf 95.6%

      \[\leadsto \frac{\color{blue}{d \cdot \left(-1 \cdot \frac{a}{c} + \frac{b}{d}\right)}}{c} \]
    7. Step-by-step derivation
      1. +-commutative95.6%

        \[\leadsto \frac{d \cdot \color{blue}{\left(\frac{b}{d} + -1 \cdot \frac{a}{c}\right)}}{c} \]
      2. mul-1-neg95.6%

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

        \[\leadsto \frac{d \cdot \color{blue}{\left(\frac{b}{d} - \frac{a}{c}\right)}}{c} \]
    8. Simplified95.6%

      \[\leadsto \frac{\color{blue}{d \cdot \left(\frac{b}{d} - \frac{a}{c}\right)}}{c} \]
    9. Taylor expanded in d around inf 53.8%

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

        \[\leadsto \frac{\color{blue}{\frac{-1 \cdot \left(a \cdot d\right)}{c}}}{c} \]
      2. mul-1-neg53.8%

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

        \[\leadsto \frac{\frac{-\color{blue}{d \cdot a}}{c}}{c} \]
    11. Simplified53.8%

      \[\leadsto \frac{\color{blue}{\frac{-d \cdot a}{c}}}{c} \]
    12. Step-by-step derivation
      1. associate-/l/45.9%

        \[\leadsto \color{blue}{\frac{-d \cdot a}{c \cdot c}} \]
      2. distribute-lft-neg-in45.9%

        \[\leadsto \frac{\color{blue}{\left(-d\right) \cdot a}}{c \cdot c} \]
      3. times-frac83.4%

        \[\leadsto \color{blue}{\frac{-d}{c} \cdot \frac{a}{c}} \]
    13. Applied egg-rr83.4%

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

    if -2.75e215 < c < -1.4499999999999999e-64 or 8.3999999999999998e-57 < c

    1. Initial program 61.1%

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

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

    if -1.4499999999999999e-64 < c < 8.3999999999999998e-57

    1. Initial program 73.2%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified70.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.75 \cdot 10^{+215}:\\ \;\;\;\;\frac{d}{c} \cdot \frac{a}{-c}\\ \mathbf{elif}\;c \leq -1.45 \cdot 10^{-64} \lor \neg \left(c \leq 8.4 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 60.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.8 \cdot 10^{+215}:\\ \;\;\;\;\frac{a \cdot \frac{-d}{c}}{c}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -2.8e+215)
   (/ (* a (/ (- d) c)) c)
   (if (or (<= c -6e-65) (not (<= c 1.4e-56))) (/ b c) (/ a (- d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -2.8e+215) {
		tmp = (a * (-d / c)) / c;
	} else if ((c <= -6e-65) || !(c <= 1.4e-56)) {
		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 <= (-2.8d+215)) then
        tmp = (a * (-d / c)) / c
    else if ((c <= (-6d-65)) .or. (.not. (c <= 1.4d-56))) 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 <= -2.8e+215) {
		tmp = (a * (-d / c)) / c;
	} else if ((c <= -6e-65) || !(c <= 1.4e-56)) {
		tmp = b / c;
	} else {
		tmp = a / -d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -2.8e+215:
		tmp = (a * (-d / c)) / c
	elif (c <= -6e-65) or not (c <= 1.4e-56):
		tmp = b / c
	else:
		tmp = a / -d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -2.8e+215)
		tmp = Float64(Float64(a * Float64(Float64(-d) / c)) / c);
	elseif ((c <= -6e-65) || !(c <= 1.4e-56))
		tmp = Float64(b / c);
	else
		tmp = Float64(a / Float64(-d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -2.8e+215)
		tmp = (a * (-d / c)) / c;
	elseif ((c <= -6e-65) || ~((c <= 1.4e-56)))
		tmp = b / c;
	else
		tmp = a / -d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -2.8e+215], N[(N[(a * N[((-d) / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[Or[LessEqual[c, -6e-65], N[Not[LessEqual[c, 1.4e-56]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.8 \cdot 10^{+215}:\\
\;\;\;\;\frac{a \cdot \frac{-d}{c}}{c}\\

\mathbf{elif}\;c \leq -6 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.8e215

    1. Initial program 45.7%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg62.0%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg62.0%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-162.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in62.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. distribute-lft-in62.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right) + -1 \cdot \frac{a \cdot d}{c}}}{c} \]
      6. neg-mul-162.0%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      7. mul-1-neg62.0%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      8. remove-double-neg62.0%

        \[\leadsto \frac{\color{blue}{b} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      9. associate-*r/62.0%

        \[\leadsto \frac{b + \color{blue}{\frac{-1 \cdot \left(a \cdot d\right)}{c}}}{c} \]
      10. associate-*r*62.0%

        \[\leadsto \frac{b + \frac{\color{blue}{\left(-1 \cdot a\right) \cdot d}}{c}}{c} \]
      11. neg-mul-162.0%

        \[\leadsto \frac{b + \frac{\color{blue}{\left(-a\right)} \cdot d}{c}}{c} \]
    5. Simplified62.0%

      \[\leadsto \color{blue}{\frac{b + \frac{\left(-a\right) \cdot d}{c}}{c}} \]
    6. Taylor expanded in d around inf 95.6%

      \[\leadsto \frac{\color{blue}{d \cdot \left(-1 \cdot \frac{a}{c} + \frac{b}{d}\right)}}{c} \]
    7. Step-by-step derivation
      1. +-commutative95.6%

        \[\leadsto \frac{d \cdot \color{blue}{\left(\frac{b}{d} + -1 \cdot \frac{a}{c}\right)}}{c} \]
      2. mul-1-neg95.6%

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

        \[\leadsto \frac{d \cdot \color{blue}{\left(\frac{b}{d} - \frac{a}{c}\right)}}{c} \]
    8. Simplified95.6%

      \[\leadsto \frac{\color{blue}{d \cdot \left(\frac{b}{d} - \frac{a}{c}\right)}}{c} \]
    9. Taylor expanded in d around inf 53.8%

      \[\leadsto \frac{\color{blue}{-1 \cdot \frac{a \cdot d}{c}}}{c} \]
    10. Step-by-step derivation
      1. mul-1-neg53.8%

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

        \[\leadsto \frac{-\color{blue}{a \cdot \frac{d}{c}}}{c} \]
      3. distribute-rgt-neg-in83.5%

        \[\leadsto \frac{\color{blue}{a \cdot \left(-\frac{d}{c}\right)}}{c} \]
      4. distribute-neg-frac283.5%

        \[\leadsto \frac{a \cdot \color{blue}{\frac{d}{-c}}}{c} \]
    11. Simplified83.5%

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

    if -2.8e215 < c < -5.99999999999999996e-65 or 1.39999999999999997e-56 < c

    1. Initial program 61.1%

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

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

    if -5.99999999999999996e-65 < c < 1.39999999999999997e-56

    1. Initial program 73.2%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified70.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.8 \cdot 10^{+215}:\\ \;\;\;\;\frac{a \cdot \frac{-d}{c}}{c}\\ \mathbf{elif}\;c \leq -6 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 69.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.5 \cdot 10^{-96} \lor \neg \left(c \leq 2.3 \cdot 10^{-63}\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -4.5e-96) (not (<= c 2.3e-63)))
   (/ (- b (* a (/ d c))) c)
   (/ a (- d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.5e-96) || !(c <= 2.3e-63)) {
		tmp = (b - (a * (d / c))) / 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.5d-96)) .or. (.not. (c <= 2.3d-63))) then
        tmp = (b - (a * (d / c))) / 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.5e-96) || !(c <= 2.3e-63)) {
		tmp = (b - (a * (d / c))) / c;
	} else {
		tmp = a / -d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -4.5e-96) or not (c <= 2.3e-63):
		tmp = (b - (a * (d / c))) / c
	else:
		tmp = a / -d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -4.5e-96) || !(c <= 2.3e-63))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	else
		tmp = Float64(a / Float64(-d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -4.5e-96) || ~((c <= 2.3e-63)))
		tmp = (b - (a * (d / c))) / c;
	else
		tmp = a / -d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.5e-96], N[Not[LessEqual[c, 2.3e-63]], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.5 \cdot 10^{-96} \lor \neg \left(c \leq 2.3 \cdot 10^{-63}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.5e-96 or 2.3e-63 < c

    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 inf 74.4%

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

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

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-174.4%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in74.4%

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

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in74.4%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg74.4%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg74.4%

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

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

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

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

    if -4.5e-96 < c < 2.3e-63

    1. Initial program 71.9%

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

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

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

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

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

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

Alternative 6: 69.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -5.8 \cdot 10^{-96}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 4.9 \cdot 10^{-59}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -5.8e-96)
   (/ (- b (* a (/ d c))) c)
   (if (<= c 4.9e-59) (/ a (- d)) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -5.8e-96) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 4.9e-59) {
		tmp = a / -d;
	} else {
		tmp = (b - (a / (c / d))) / 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 (c <= (-5.8d-96)) then
        tmp = (b - (a * (d / c))) / c
    else if (c <= 4.9d-59) then
        tmp = a / -d
    else
        tmp = (b - (a / (c / d))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -5.8e-96) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 4.9e-59) {
		tmp = a / -d;
	} else {
		tmp = (b - (a / (c / d))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -5.8e-96:
		tmp = (b - (a * (d / c))) / c
	elif c <= 4.9e-59:
		tmp = a / -d
	else:
		tmp = (b - (a / (c / d))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -5.8e-96)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= 4.9e-59)
		tmp = Float64(a / Float64(-d));
	else
		tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -5.8e-96)
		tmp = (b - (a * (d / c))) / c;
	elseif (c <= 4.9e-59)
		tmp = a / -d;
	else
		tmp = (b - (a / (c / d))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -5.8e-96], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 4.9e-59], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5.8 \cdot 10^{-96}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

\mathbf{elif}\;c \leq 4.9 \cdot 10^{-59}:\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.79999999999999987e-96

    1. Initial program 56.3%

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

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

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg69.8%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-169.8%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in69.8%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg69.8%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in69.8%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg69.8%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg69.8%

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

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

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

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

    if -5.79999999999999987e-96 < c < 4.89999999999999977e-59

    1. Initial program 71.9%

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

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

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

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

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

    if 4.89999999999999977e-59 < c

    1. Initial program 64.7%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg80.0%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg80.0%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-180.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in80.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg80.0%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in80.0%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg80.0%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg80.0%

        \[\leadsto \frac{\color{blue}{b} + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      9. unsub-neg80.0%

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-num82.8%

        \[\leadsto \frac{b - a \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv82.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.8 \cdot 10^{-96}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 4.9 \cdot 10^{-59}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 76.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-58}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -6.2e-47)
   (/ (- b (* a (/ d c))) c)
   (if (<= c 1.6e-58) (/ (- (* b (/ c d)) a) d) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -6.2e-47) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 1.6e-58) {
		tmp = ((b * (c / d)) - a) / d;
	} else {
		tmp = (b - (a / (c / d))) / 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 (c <= (-6.2d-47)) then
        tmp = (b - (a * (d / c))) / c
    else if (c <= 1.6d-58) then
        tmp = ((b * (c / d)) - a) / d
    else
        tmp = (b - (a / (c / d))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -6.2e-47) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 1.6e-58) {
		tmp = ((b * (c / d)) - a) / d;
	} else {
		tmp = (b - (a / (c / d))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -6.2e-47:
		tmp = (b - (a * (d / c))) / c
	elif c <= 1.6e-58:
		tmp = ((b * (c / d)) - a) / d
	else:
		tmp = (b - (a / (c / d))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -6.2e-47)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= 1.6e-58)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	else
		tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -6.2e-47)
		tmp = (b - (a * (d / c))) / c;
	elseif (c <= 1.6e-58)
		tmp = ((b * (c / d)) - a) / d;
	else
		tmp = (b - (a / (c / d))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -6.2e-47], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.6e-58], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.1999999999999996e-47

    1. Initial program 53.1%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg71.7%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg71.7%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-171.7%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in71.7%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg71.7%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in71.7%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg71.7%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg71.7%

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

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

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

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

    if -6.1999999999999996e-47 < c < 1.6e-58

    1. Initial program 73.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub69.1%

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

        \[\leadsto \frac{\color{blue}{c \cdot b}}{c \cdot c + d \cdot d} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt69.1%

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

        \[\leadsto \color{blue}{\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}}} - \frac{a \cdot d}{c \cdot c + d \cdot d} \]
      5. fma-neg69.7%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\sqrt{c \cdot c + d \cdot d}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right)} \]
      6. hypot-define69.7%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, \frac{b}{\sqrt{c \cdot c + d \cdot d}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      7. hypot-define72.0%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\color{blue}{\mathsf{hypot}\left(c, d\right)}}, -\frac{a \cdot d}{c \cdot c + d \cdot d}\right) \]
      8. associate-/l*73.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right) \]
      9. add-sqr-sqrt73.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}}\right) \]
      10. pow273.9%

        \[\leadsto \mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}}\right) \]
      11. hypot-define73.9%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{c}{\mathsf{hypot}\left(c, d\right)}, \frac{b}{\mathsf{hypot}\left(c, d\right)}, -a \cdot \frac{d}{{\left(\mathsf{hypot}\left(c, d\right)\right)}^{2}}\right)} \]
    5. Taylor expanded in d around inf 88.2%

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

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

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

    if 1.6e-58 < c

    1. Initial program 64.7%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. remove-double-neg80.0%

        \[\leadsto \frac{\color{blue}{\left(-\left(-b\right)\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      2. mul-1-neg80.0%

        \[\leadsto \frac{\left(-\color{blue}{-1 \cdot b}\right) + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      3. neg-mul-180.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b\right)} + -1 \cdot \frac{a \cdot d}{c}}{c} \]
      4. distribute-lft-in80.0%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      5. mul-1-neg80.0%

        \[\leadsto \frac{\color{blue}{-\left(-1 \cdot b + \frac{a \cdot d}{c}\right)}}{c} \]
      6. distribute-neg-in80.0%

        \[\leadsto \frac{\color{blue}{\left(--1 \cdot b\right) + \left(-\frac{a \cdot d}{c}\right)}}{c} \]
      7. mul-1-neg80.0%

        \[\leadsto \frac{\left(-\color{blue}{\left(-b\right)}\right) + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      8. remove-double-neg80.0%

        \[\leadsto \frac{\color{blue}{b} + \left(-\frac{a \cdot d}{c}\right)}{c} \]
      9. unsub-neg80.0%

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-num82.8%

        \[\leadsto \frac{b - a \cdot \color{blue}{\frac{1}{\frac{c}{d}}}}{c} \]
      2. un-div-inv82.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.2 \cdot 10^{-47}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{-58}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 63.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{-d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -2.4e-65) (not (<= c 1.4e-56))) (/ b c) (/ a (- d))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.4e-65) || !(c <= 1.4e-56)) {
		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 <= (-2.4d-65)) .or. (.not. (c <= 1.4d-56))) 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 <= -2.4e-65) || !(c <= 1.4e-56)) {
		tmp = b / c;
	} else {
		tmp = a / -d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.4e-65) or not (c <= 1.4e-56):
		tmp = b / c
	else:
		tmp = a / -d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.4e-65) || !(c <= 1.4e-56))
		tmp = Float64(b / c);
	else
		tmp = Float64(a / Float64(-d));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -2.4e-65) || ~((c <= 1.4e-56)))
		tmp = b / c;
	else
		tmp = a / -d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e-65], N[Not[LessEqual[c, 1.4e-56]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(a / (-d)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{-65} \lor \neg \left(c \leq 1.4 \cdot 10^{-56}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.4000000000000002e-65 or 1.39999999999999997e-56 < c

    1. Initial program 58.7%

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

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

    if -2.4000000000000002e-65 < c < 1.39999999999999997e-56

    1. Initial program 73.2%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified70.2%

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

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

Alternative 9: 46.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.45 \cdot 10^{+117} \lor \neg \left(d \leq 7.2 \cdot 10^{+95}\right):\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -1.45e+117) (not (<= d 7.2e+95))) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -1.45e+117) || !(d <= 7.2e+95)) {
		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.45d+117)) .or. (.not. (d <= 7.2d+95))) 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.45e+117) || !(d <= 7.2e+95)) {
		tmp = a / d;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -1.45e+117) or not (d <= 7.2e+95):
		tmp = a / d
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -1.45e+117) || !(d <= 7.2e+95))
		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.45e+117) || ~((d <= 7.2e+95)))
		tmp = a / d;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.45e+117], N[Not[LessEqual[d, 7.2e+95]], $MachinePrecision]], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.45 \cdot 10^{+117} \lor \neg \left(d \leq 7.2 \cdot 10^{+95}\right):\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.45000000000000014e117 or 7.19999999999999955e95 < d

    1. Initial program 42.7%

      \[\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} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutative73.4%

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d}}{d}} - \frac{a}{d} \]
      6. div-sub82.7%

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

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

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

      \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{d} - a}{d}} \]
    6. Step-by-step derivation
      1. clear-num85.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{d}{c \cdot \frac{b}{d} - a}}} \]
      2. inv-pow85.1%

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

        \[\leadsto {\left(\frac{d}{\color{blue}{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}}\right)}^{-1} \]
      4. add-sqr-sqrt40.1%

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

        \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}\right)}\right)}^{-1} \]
      6. sqr-neg56.3%

        \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \sqrt{\color{blue}{a \cdot a}}\right)}\right)}^{-1} \]
      7. sqrt-unprod20.0%

        \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \color{blue}{\sqrt{a} \cdot \sqrt{a}}\right)}\right)}^{-1} \]
      8. add-sqr-sqrt42.7%

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, a\right)}}} \]
    9. Simplified42.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, a\right)}}} \]
    10. Taylor expanded in d around inf 30.8%

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

    if -1.45000000000000014e117 < d < 7.19999999999999955e95

    1. Initial program 74.6%

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

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

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

Alternative 10: 10.9% 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 64.9%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d}}{d}} - \frac{a}{d} \]
    6. div-sub49.9%

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

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

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

    \[\leadsto \color{blue}{\frac{c \cdot \frac{b}{d} - a}{d}} \]
  6. Step-by-step derivation
    1. clear-num50.3%

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

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

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

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

      \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}\right)}\right)}^{-1} \]
    6. sqr-neg30.9%

      \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \sqrt{\color{blue}{a \cdot a}}\right)}\right)}^{-1} \]
    7. sqrt-unprod10.8%

      \[\leadsto {\left(\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, \color{blue}{\sqrt{a} \cdot \sqrt{a}}\right)}\right)}^{-1} \]
    8. add-sqr-sqrt22.9%

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, a\right)}}} \]
  9. Simplified22.9%

    \[\leadsto \color{blue}{\frac{1}{\frac{d}{\mathsf{fma}\left(c, \frac{b}{d}, a\right)}}} \]
  10. Taylor expanded in d around inf 11.6%

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  11. Final simplification11.6%

    \[\leadsto \frac{a}{d} \]
  12. 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 2024059 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :alt
  (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))))