Complex division, imag part

Percentage Accurate: 61.3% → 81.6%
Time: 8.9s
Alternatives: 10
Speedup: 1.8×

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.3% 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: 81.6% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -7.8 \cdot 10^{+150}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-131}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+133}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c (/ b d)) a) d)))
   (if (<= d -7.8e+150)
     t_0
     (if (<= d -7.5e-131)
       (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
       (if (<= d 4.1e-25)
         (- (/ b c) (/ (* a (/ d c)) c))
         (if (<= d 1.2e+133)
           (/ (fma b c (* d (- a))) (fma c c (* d d)))
           t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * (b / d)) - a) / d;
	double tmp;
	if (d <= -7.8e+150) {
		tmp = t_0;
	} else if (d <= -7.5e-131) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else if (d <= 4.1e-25) {
		tmp = (b / c) - ((a * (d / c)) / c);
	} else if (d <= 1.2e+133) {
		tmp = fma(b, c, (d * -a)) / fma(c, c, (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * Float64(b / d)) - a) / d)
	tmp = 0.0
	if (d <= -7.8e+150)
		tmp = t_0;
	elseif (d <= -7.5e-131)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 4.1e-25)
		tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c));
	elseif (d <= 1.2e+133)
		tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(c, c, Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7.8e+150], t$95$0, If[LessEqual[d, -7.5e-131], 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, 4.1e-25], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.2e+133], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;d \leq 1.2 \cdot 10^{+133}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -7.79999999999999981e150 or 1.1999999999999999e133 < d

    1. Initial program 27.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.79999999999999981e150 < d < -7.49999999999999964e-131

    1. Initial program 81.9%

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

    if -7.49999999999999964e-131 < d < 4.09999999999999987e-25

    1. Initial program 63.1%

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{a}{c}\right)} + \frac{b}{c} \]
    5. Step-by-step derivation
      1. associate-*r/86.8%

        \[\leadsto -1 \cdot \color{blue}{\frac{\frac{d}{c} \cdot a}{c}} + \frac{b}{c} \]
    6. Applied egg-rr86.8%

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

    if 4.09999999999999987e-25 < d < 1.1999999999999999e133

    1. Initial program 79.5%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-neg79.6%

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(b, c, -a \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. distribute-lft-neg-out79.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification85.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.8 \cdot 10^{+150}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -7.5 \cdot 10^{-131}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 4.1 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{+133}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]

Alternative 2: 81.6% accurate, 0.6× 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{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{if}\;d \leq -1.9 \cdot 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-130}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 3.85 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+132}:\\ \;\;\;\;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 (/ (- (* c (/ b d)) a) d)))
   (if (<= d -1.9e+151)
     t_1
     (if (<= d -1.45e-130)
       t_0
       (if (<= d 3.85e-25)
         (- (/ b c) (/ (* a (/ d c)) c))
         (if (<= d 2.8e+132) 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 = ((c * (b / d)) - a) / d;
	double tmp;
	if (d <= -1.9e+151) {
		tmp = t_1;
	} else if (d <= -1.45e-130) {
		tmp = t_0;
	} else if (d <= 3.85e-25) {
		tmp = (b / c) - ((a * (d / c)) / c);
	} else if (d <= 2.8e+132) {
		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 = ((c * (b / d)) - a) / d
    if (d <= (-1.9d+151)) then
        tmp = t_1
    else if (d <= (-1.45d-130)) then
        tmp = t_0
    else if (d <= 3.85d-25) then
        tmp = (b / c) - ((a * (d / c)) / c)
    else if (d <= 2.8d+132) 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 = ((c * (b / d)) - a) / d;
	double tmp;
	if (d <= -1.9e+151) {
		tmp = t_1;
	} else if (d <= -1.45e-130) {
		tmp = t_0;
	} else if (d <= 3.85e-25) {
		tmp = (b / c) - ((a * (d / c)) / c);
	} else if (d <= 2.8e+132) {
		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 = ((c * (b / d)) - a) / d
	tmp = 0
	if d <= -1.9e+151:
		tmp = t_1
	elif d <= -1.45e-130:
		tmp = t_0
	elif d <= 3.85e-25:
		tmp = (b / c) - ((a * (d / c)) / c)
	elif d <= 2.8e+132:
		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(Float64(c * Float64(b / d)) - a) / d)
	tmp = 0.0
	if (d <= -1.9e+151)
		tmp = t_1;
	elseif (d <= -1.45e-130)
		tmp = t_0;
	elseif (d <= 3.85e-25)
		tmp = Float64(Float64(b / c) - Float64(Float64(a * Float64(d / c)) / c));
	elseif (d <= 2.8e+132)
		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 = ((c * (b / d)) - a) / d;
	tmp = 0.0;
	if (d <= -1.9e+151)
		tmp = t_1;
	elseif (d <= -1.45e-130)
		tmp = t_0;
	elseif (d <= 3.85e-25)
		tmp = (b / c) - ((a * (d / c)) / c);
	elseif (d <= 2.8e+132)
		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[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.9e+151], t$95$1, If[LessEqual[d, -1.45e-130], t$95$0, If[LessEqual[d, 3.85e-25], N[(N[(b / c), $MachinePrecision] - N[(N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.8e+132], 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{c \cdot \frac{b}{d} - a}{d}\\
\mathbf{if}\;d \leq -1.9 \cdot 10^{+151}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -1.45 \cdot 10^{-130}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 2.8 \cdot 10^{+132}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.9e151 or 2.7999999999999999e132 < d

    1. Initial program 27.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9e151 < d < -1.45e-130 or 3.8500000000000001e-25 < d < 2.7999999999999999e132

    1. Initial program 80.7%

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

    if -1.45e-130 < d < 3.8500000000000001e-25

    1. Initial program 63.1%

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{a}{c}\right)} + \frac{b}{c} \]
    5. Step-by-step derivation
      1. associate-*r/86.8%

        \[\leadsto -1 \cdot \color{blue}{\frac{\frac{d}{c} \cdot a}{c}} + \frac{b}{c} \]
    6. Applied egg-rr86.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.9 \cdot 10^{+151}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-130}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.85 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+132}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]

Alternative 3: 76.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.3 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.21999999999999998e73 or 5.2999999999999997e-25 < d

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.21999999999999998e73 < d < 5.2999999999999997e-25

    1. Initial program 67.5%

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{a}{c}\right)} + \frac{b}{c} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.3 \cdot 10^{-25}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{d}{c} \cdot \frac{a}{c}\\ \end{array} \]

Alternative 4: 77.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.2 \cdot 10^{-25}\right):\\
\;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.21999999999999998e73 or 5.2e-25 < d

    1. Initial program 50.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.21999999999999998e73 < d < 5.2e-25

    1. Initial program 67.5%

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

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

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

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

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{a}{c}\right)} + \frac{b}{c} \]
    5. Step-by-step derivation
      1. associate-*r/81.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.22 \cdot 10^{+73} \lor \neg \left(d \leq 5.2 \cdot 10^{-25}\right):\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c} - \frac{a \cdot \frac{d}{c}}{c}\\ \end{array} \]

Alternative 5: 72.4% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.4 \cdot 10^{+49} \lor \neg \left(c \leq 8.2 \cdot 10^{+116}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.4e49 or 8.1999999999999996e116 < c

    1. Initial program 39.7%

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

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

    if -2.4e49 < c < 8.1999999999999996e116

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+49} \lor \neg \left(c \leq 8.2 \cdot 10^{+116}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \end{array} \]

Alternative 6: 73.1% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+50} \lor \neg \left(c \leq 10^{+117}\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 -2.4e+50) (not (<= c 1e+117)))
   (/ b c)
   (/ (- (* b (/ c d)) a) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.4e+50) || !(c <= 1e+117)) {
		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 <= (-2.4d+50)) .or. (.not. (c <= 1d+117))) 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 <= -2.4e+50) || !(c <= 1e+117)) {
		tmp = b / c;
	} else {
		tmp = ((b * (c / d)) - a) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.4e+50) or not (c <= 1e+117):
		tmp = b / c
	else:
		tmp = ((b * (c / d)) - a) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.4e+50) || !(c <= 1e+117))
		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 <= -2.4e+50) || ~((c <= 1e+117)))
		tmp = b / c;
	else
		tmp = ((b * (c / d)) - a) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.4e+50], N[Not[LessEqual[c, 1e+117]], $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 -2.4 \cdot 10^{+50} \lor \neg \left(c \leq 10^{+117}\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 < -2.4000000000000002e50 or 1.00000000000000005e117 < c

    1. Initial program 39.7%

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

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

    if -2.4000000000000002e50 < c < 1.00000000000000005e117

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+50} \lor \neg \left(c \leq 10^{+117}\right):\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]

Alternative 7: 63.7% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{+18} \lor \neg \left(d \leq 15800\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.2e18 or 15800 < d

    1. Initial program 50.1%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    4. Simplified63.1%

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

    if -3.2e18 < d < 15800

    1. Initial program 68.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.2 \cdot 10^{+18} \lor \neg \left(d \leq 15800\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]

Alternative 8: 44.7% accurate, 2.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+203}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{elif}\;d \leq 1.4 \cdot 10^{+178}:\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.55e203

    1. Initial program 28.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-neg28.2%

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

        \[\leadsto \frac{\mathsf{fma}\left(b, c, -\color{blue}{d \cdot a}\right)}{c \cdot c + d \cdot d} \]
      3. distribute-rgt-neg-out28.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.55e203 < d < 1.39999999999999997e178

    1. Initial program 67.5%

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

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

    if 1.39999999999999997e178 < d

    1. Initial program 23.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-neg23.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(b, c, -\color{blue}{d \cdot a}\right)}{c \cdot c + d \cdot d} \]
      3. distribute-rgt-neg-out23.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      5. *-un-lft-identity23.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+203}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+178}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]

Alternative 9: 43.7% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq 2 \cdot 10^{+178}:\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 2.0000000000000001e178

    1. Initial program 63.5%

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

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

    if 2.0000000000000001e178 < d

    1. Initial program 23.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. fma-neg23.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(b, c, -\color{blue}{d \cdot a}\right)}{c \cdot c + d \cdot d} \]
      3. distribute-rgt-neg-out23.9%

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

        \[\leadsto \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      5. *-un-lft-identity23.9%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 2 \cdot 10^{+178}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{d}\\ \end{array} \]

Alternative 10: 11.0% 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 58.9%

    \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
  2. Step-by-step derivation
    1. fma-neg58.9%

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

      \[\leadsto \frac{\mathsf{fma}\left(b, c, -\color{blue}{d \cdot a}\right)}{c \cdot c + d \cdot d} \]
    3. distribute-rgt-neg-out58.9%

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

      \[\leadsto \frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
    5. *-un-lft-identity58.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  5. Final simplification8.8%

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

Developer target: 99.4% 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 2023330 
(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))))