Complex division, imag part

Percentage Accurate: 61.5% → 78.3%
Time: 8.9s
Alternatives: 9
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 9 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: 78.3% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 1.72 \cdot 10^{-69}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+45}:\\ \;\;\;\;\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 (* d (/ d b))) (/ a d))))
   (if (<= d -4.8e+91)
     t_0
     (if (<= d 1.72e-69)
       (- (/ b c) (/ (/ a (/ c d)) c))
       (if (<= d 1.9e+45) (/ (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 / (d * (d / b))) - (a / d);
	double tmp;
	if (d <= -4.8e+91) {
		tmp = t_0;
	} else if (d <= 1.72e-69) {
		tmp = (b / c) - ((a / (c / d)) / c);
	} else if (d <= 1.9e+45) {
		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(c / Float64(d * Float64(d / b))) - Float64(a / d))
	tmp = 0.0
	if (d <= -4.8e+91)
		tmp = t_0;
	elseif (d <= 1.72e-69)
		tmp = Float64(Float64(b / c) - Float64(Float64(a / Float64(c / d)) / c));
	elseif (d <= 1.9e+45)
		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[(c / N[(d * N[(d / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4.8e+91], t$95$0, If[LessEqual[d, 1.72e-69], N[(N[(b / c), $MachinePrecision] - N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e+45], 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}{d \cdot \frac{d}{b}} - \frac{a}{d}\\
\mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;d \leq 1.9 \cdot 10^{+45}:\\
\;\;\;\;\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 3 regimes
  2. if d < -4.79999999999999966e91 or 1.9000000000000001e45 < d

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.79999999999999966e91 < d < 1.72e-69

    1. Initial program 66.7%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity65.4%

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1 \cdot \left(\frac{a}{c} \cdot d\right)}{c}} \]
      3. *-un-lft-identity77.5%

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

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

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

    if 1.72e-69 < d < 1.9000000000000001e45

    1. Initial program 76.7%

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

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

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

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

        \[\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. Simplified76.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.8 \cdot 10^{+91}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 1.72 \cdot 10^{-69}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{+45}:\\ \;\;\;\;\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}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 78.4% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.0000000000000002e91 or 1.54999999999999998e44 < d

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.0000000000000002e91 < d < 4.5e-72

    1. Initial program 66.7%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity65.4%

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1 \cdot \left(\frac{a}{c} \cdot d\right)}{c}} \]
      3. *-un-lft-identity77.5%

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

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

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

    if 4.5e-72 < d < 1.54999999999999998e44

    1. Initial program 76.7%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification79.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{+91}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{-72}:\\ \;\;\;\;\frac{b}{c} - \frac{\frac{a}{\frac{c}{d}}}{c}\\ \mathbf{elif}\;d \leq 1.55 \cdot 10^{+44}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{d \cdot \frac{d}{b}} - \frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 69.2% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -0.000235 \lor \neg \left(c \leq -3.55 \cdot 10^{-168}\right) \land \left(c \leq -6.2 \cdot 10^{-202} \lor \neg \left(c \leq 360000000000\right)\right):\\
\;\;\;\;\frac{b}{c} - d \cdot \frac{\frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.34999999999999993e-4 or -3.55000000000000009e-168 < c < -6.2e-202 or 3.6e11 < c

    1. Initial program 47.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b}{c} - \frac{a}{{c}^{2}} \cdot d} \]
    6. Step-by-step derivation
      1. *-un-lft-identity64.7%

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

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

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

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

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

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

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

    if -2.34999999999999993e-4 < c < -3.55000000000000009e-168 or -6.2e-202 < c < 3.6e11

    1. Initial program 70.5%

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

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

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

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

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

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

Alternative 4: 73.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.9 \cdot 10^{+93} \lor \neg \left(d \leq 9 \cdot 10^{+43}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.8999999999999999e93 or 9e43 < d

    1. Initial program 41.3%

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

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

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

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

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

    if -1.8999999999999999e93 < d < 9e43

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1 \cdot \left(\frac{a}{c} \cdot d\right)}{c}} \]
      3. *-un-lft-identity73.8%

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

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

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

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

Alternative 5: 76.4% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.79999999999999966e91 or 5.20000000000000042e43 < d

    1. Initial program 41.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.79999999999999966e91 < d < 5.20000000000000042e43

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{c} - \color{blue}{\frac{1 \cdot \left(\frac{a}{c} \cdot d\right)}{c}} \]
      3. *-un-lft-identity74.3%

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

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

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

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

Alternative 6: 65.1% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{+44} \lor \neg \left(d \leq 3.1 \cdot 10^{+41}\right):\\
\;\;\;\;\frac{-a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.7e44 or 3.1e41 < d

    1. Initial program 44.1%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified68.6%

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

    if -1.7e44 < d < 3.1e41

    1. Initial program 68.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.9%

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

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

Alternative 7: 12.0% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.2 \cdot 10^{+108}:\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.20000000000000009e108

    1. Initial program 39.7%

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

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

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

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

        \[\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-identity39.7%

        \[\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-frac39.7%

        \[\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-def39.7%

        \[\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-sqrt24.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-unprod37.5%

        \[\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-neg37.5%

        \[\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-unprod12.7%

        \[\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-sqrt33.3%

        \[\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. *-commutative33.3%

        \[\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-def37.3%

        \[\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)}} \]
    4. Applied egg-rr37.3%

      \[\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)}} \]
    5. Taylor expanded in c around 0 32.0%

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

    if -1.20000000000000009e108 < d

    1. Initial program 61.3%

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

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

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

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

        \[\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-identity61.3%

        \[\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-frac61.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-def61.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-sqrt28.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-unprod42.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-neg42.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-unprod19.7%

        \[\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-sqrt34.1%

        \[\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. *-commutative34.1%

        \[\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-def41.7%

        \[\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)}} \]
    4. Applied egg-rr41.7%

      \[\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)}} \]
    5. Taylor expanded in c around inf 35.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+108}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 44.4% accurate, 3.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+114}:\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.05e114

    1. Initial program 40.5%

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

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

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

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

        \[\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-identity40.5%

        \[\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-frac40.5%

        \[\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-def40.5%

        \[\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-sqrt25.3%

        \[\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-unprod38.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-neg38.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-unprod12.9%

        \[\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-sqrt34.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. *-commutative34.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-def38.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)}} \]
    4. Applied egg-rr38.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)}} \]
    5. Taylor expanded in c around 0 32.7%

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

    if -1.05e114 < d

    1. Initial program 61.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+114}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 9.4% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
	return a / c;
}
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 / c
end function
public static double code(double a, double b, double c, double d) {
	return a / c;
}
def code(a, b, c, d):
	return a / c
function code(a, b, c, d)
	return Float64(a / c)
end
function tmp = code(a, b, c, d)
	tmp = a / c;
end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}

\\
\frac{a}{c}
\end{array}
Derivation
  1. Initial program 57.3%

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

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

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

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

      \[\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-identity57.3%

      \[\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-frac57.3%

      \[\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-def57.3%

      \[\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-sqrt28.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-unprod41.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-neg41.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-unprod18.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-sqrt34.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. *-commutative34.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-def40.9%

      \[\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)}} \]
  4. Applied egg-rr40.9%

    \[\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)}} \]
  5. Taylor expanded in c around inf 32.0%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  7. Final simplification10.2%

    \[\leadsto \frac{a}{c} \]
  8. Add Preprocessing

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 2024010 
(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))))