Complex division, imag part

Percentage Accurate: 61.9% → 83.1%
Time: 9.3s
Alternatives: 12
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 12 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.9% 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: 83.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{if}\;c \leq -4.15 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{d}{\frac{c}{a}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -4 \cdot 10^{-46}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-110}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+75}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
   (if (<= c -4.15e+80)
     (/ (- (/ d (/ c a)) b) (hypot c d))
     (if (<= c -4e-46)
       t_0
       (if (<= c 4.5e-110)
         (/ (- (/ (* b c) d) a) d)
         (if (<= c 8e+75) t_0 (/ (- b (* a (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -4.15e+80) {
		tmp = ((d / (c / a)) - b) / hypot(c, d);
	} else if (c <= -4e-46) {
		tmp = t_0;
	} else if (c <= 4.5e-110) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 8e+75) {
		tmp = t_0;
	} else {
		tmp = (b - (a * (d / c))) / c;
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	double tmp;
	if (c <= -4.15e+80) {
		tmp = ((d / (c / a)) - b) / Math.hypot(c, d);
	} else if (c <= -4e-46) {
		tmp = t_0;
	} else if (c <= 4.5e-110) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 8e+75) {
		tmp = t_0;
	} else {
		tmp = (b - (a * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -4.15e+80:
		tmp = ((d / (c / a)) - b) / math.hypot(c, d)
	elif c <= -4e-46:
		tmp = t_0
	elif c <= 4.5e-110:
		tmp = (((b * c) / d) - a) / d
	elif c <= 8e+75:
		tmp = t_0
	else:
		tmp = (b - (a * (d / c))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
	tmp = 0.0
	if (c <= -4.15e+80)
		tmp = Float64(Float64(Float64(d / Float64(c / a)) - b) / hypot(c, d));
	elseif (c <= -4e-46)
		tmp = t_0;
	elseif (c <= 4.5e-110)
		tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d);
	elseif (c <= 8e+75)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
	tmp = 0.0;
	if (c <= -4.15e+80)
		tmp = ((d / (c / a)) - b) / hypot(c, d);
	elseif (c <= -4e-46)
		tmp = t_0;
	elseif (c <= 4.5e-110)
		tmp = (((b * c) / d) - a) / d;
	elseif (c <= 8e+75)
		tmp = t_0;
	else
		tmp = (b - (a * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -4.15e+80], N[(N[(N[(d / N[(c / a), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], If[LessEqual[c, -4e-46], t$95$0, If[LessEqual[c, 4.5e-110], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+75], t$95$0, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -4.15 \cdot 10^{+80}:\\
\;\;\;\;\frac{\frac{d}{\frac{c}{a}} - b}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{elif}\;c \leq -4 \cdot 10^{-46}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 8 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -4.15000000000000002e80

    1. Initial program 28.5%

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

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

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac28.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{\left(a \cdot \frac{d}{c} - b\right)} \]
      5. *-commutative80.7%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\frac{d \cdot a}{c}} - b\right) \]
      7. associate-*r/82.7%

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

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

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

        \[\leadsto \frac{\color{blue}{d \cdot \frac{a}{c} - b}}{\mathsf{hypot}\left(c, d\right)} \]
      3. clear-num83.0%

        \[\leadsto \frac{d \cdot \color{blue}{\frac{1}{\frac{c}{a}}} - b}{\mathsf{hypot}\left(c, d\right)} \]
      4. un-div-inv83.0%

        \[\leadsto \frac{\color{blue}{\frac{d}{\frac{c}{a}}} - b}{\mathsf{hypot}\left(c, d\right)} \]
    9. Applied egg-rr83.0%

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

    if -4.15000000000000002e80 < c < -4.00000000000000009e-46 or 4.5000000000000001e-110 < c < 7.99999999999999941e75

    1. Initial program 87.8%

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

    if -4.00000000000000009e-46 < c < 4.5000000000000001e-110

    1. Initial program 66.3%

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

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

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

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

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

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

    if 7.99999999999999941e75 < c

    1. Initial program 27.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.15 \cdot 10^{+80}:\\ \;\;\;\;\frac{\frac{d}{\frac{c}{a}} - b}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{elif}\;c \leq -4 \cdot 10^{-46}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.5 \cdot 10^{-110}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+75}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 85.1% accurate, 0.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+238}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) 2e+238)
   (* (/ 1.0 (hypot c d)) (/ (fma b c (* a (- d))) (hypot c d)))
   (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= 2e+238) {
		tmp = (1.0 / hypot(c, d)) * (fma(b, c, (a * -d)) / hypot(c, d));
	} else {
		tmp = (b - (a * (d / c))) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) <= 2e+238)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(b, c, Float64(a * Float64(-d))) / hypot(c, d)));
	else
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+238], N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(b * c + N[(a * (-d)), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+238}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.0000000000000001e238

    1. Initial program 76.9%

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

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

        \[\leadsto \frac{1 \cdot \left(b \cdot c - a \cdot d\right)}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. times-frac76.9%

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

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

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

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

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

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

    if 2.0000000000000001e238 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 12.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+238}:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.1% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;c \leq -3.5 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 9.5 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -4.20000000000000023e97

    1. Initial program 27.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in a around 0 86.3%

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

    if -4.20000000000000023e97 < c < -3.5e-45 or 2.34999999999999996e-110 < c < 9.50000000000000061e75

    1. Initial program 85.6%

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

    if -3.5e-45 < c < 2.34999999999999996e-110

    1. Initial program 66.3%

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

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

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

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

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

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

    if 9.50000000000000061e75 < c

    1. Initial program 27.9%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.2 \cdot 10^{+97}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-45}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.35 \cdot 10^{-110}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 9.5 \cdot 10^{+75}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 75.7% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;c \leq 4.3 \cdot 10^{-66} \lor \neg \left(c \leq 1.05 \cdot 10^{+69}\right) \land c \leq 9 \cdot 10^{+117}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\

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


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

    1. Initial program 50.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in a around 0 79.2%

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

    if -7.49999999999999989e-25 < c < 4.30000000000000013e-66 or 1.05000000000000008e69 < c < 9e117

    1. Initial program 68.2%

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

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

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

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

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

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

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

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

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

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

    if 4.30000000000000013e-66 < c < 1.05000000000000008e69 or 9e117 < c

    1. Initial program 47.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{-25}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq 4.3 \cdot 10^{-66} \lor \neg \left(c \leq 1.05 \cdot 10^{+69}\right) \land c \leq 9 \cdot 10^{+117}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 75.7% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;c \leq 1.6 \cdot 10^{+71} \lor \neg \left(c \leq 2.8 \cdot 10^{+118}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


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

    1. Initial program 50.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in a around 0 79.2%

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

    if -1.22000000000000007e-23 < c < 4.80000000000000052e-66

    1. Initial program 69.8%

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

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

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

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

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

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

    if 4.80000000000000052e-66 < c < 1.60000000000000012e71 or 2.79999999999999986e118 < c

    1. Initial program 47.2%

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

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

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

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

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

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

    if 1.60000000000000012e71 < c < 2.79999999999999986e118

    1. Initial program 50.0%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.22 \cdot 10^{-23}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-66}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.6 \cdot 10^{+71} \lor \neg \left(c \leq 2.8 \cdot 10^{+118}\right):\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 69.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{-d}\\ t_1 := \frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{if}\;c \leq -3.5 \cdot 10^{-18}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 5.6 \cdot 10^{-103}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (- d))) (t_1 (/ (- b (* a (/ d c))) c)))
   (if (<= c -3.5e-18)
     t_1
     (if (<= c -4.9e-188)
       t_0
       (if (<= c -4.1e-223)
         (/ (* c (/ b d)) d)
         (if (<= c 5.6e-103) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double t_1 = (b - (a * (d / c))) / c;
	double tmp;
	if (c <= -3.5e-18) {
		tmp = t_1;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -4.1e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 5.6e-103) {
		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 = a / -d
    t_1 = (b - (a * (d / c))) / c
    if (c <= (-3.5d-18)) then
        tmp = t_1
    else if (c <= (-4.9d-188)) then
        tmp = t_0
    else if (c <= (-4.1d-223)) then
        tmp = (c * (b / d)) / d
    else if (c <= 5.6d-103) 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 = a / -d;
	double t_1 = (b - (a * (d / c))) / c;
	double tmp;
	if (c <= -3.5e-18) {
		tmp = t_1;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -4.1e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 5.6e-103) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = a / -d
	t_1 = (b - (a * (d / c))) / c
	tmp = 0
	if c <= -3.5e-18:
		tmp = t_1
	elif c <= -4.9e-188:
		tmp = t_0
	elif c <= -4.1e-223:
		tmp = (c * (b / d)) / d
	elif c <= 5.6e-103:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a, b, c, d)
	t_0 = Float64(a / Float64(-d))
	t_1 = Float64(Float64(b - Float64(a * Float64(d / c))) / c)
	tmp = 0.0
	if (c <= -3.5e-18)
		tmp = t_1;
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -4.1e-223)
		tmp = Float64(Float64(c * Float64(b / d)) / d);
	elseif (c <= 5.6e-103)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = a / -d;
	t_1 = (b - (a * (d / c))) / c;
	tmp = 0.0;
	if (c <= -3.5e-18)
		tmp = t_1;
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -4.1e-223)
		tmp = (c * (b / d)) / d;
	elseif (c <= 5.6e-103)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -3.5e-18], t$95$1, If[LessEqual[c, -4.9e-188], t$95$0, If[LessEqual[c, -4.1e-223], N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.6e-103], t$95$0, t$95$1]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.6 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.4999999999999999e-18 or 5.60000000000000046e-103 < c

    1. Initial program 50.0%

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

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

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

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

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

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

    if -3.4999999999999999e-18 < c < -4.90000000000000004e-188 or -4.10000000000000015e-223 < c < 5.60000000000000046e-103

    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 0 71.4%

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

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

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

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

    if -4.90000000000000004e-188 < c < -4.10000000000000015e-223

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    4. Taylor expanded in a around 0 99.6%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
    6. Simplified100.0%

      \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.5 \cdot 10^{-18}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 5.6 \cdot 10^{-103}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 68.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{-d}\\ \mathbf{if}\;c \leq -1.7 \cdot 10^{-18}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -3.3 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 6.6 \cdot 10^{-103}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (- d))))
   (if (<= c -1.7e-18)
     (/ (- b (/ (* a d) c)) c)
     (if (<= c -4.9e-188)
       t_0
       (if (<= c -3.3e-223)
         (/ (* c (/ b d)) d)
         (if (<= c 6.6e-103) t_0 (/ (- b (* a (/ d c))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -1.7e-18) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -3.3e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 6.6e-103) {
		tmp = t_0;
	} else {
		tmp = (b - (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) :: t_0
    real(8) :: tmp
    t_0 = a / -d
    if (c <= (-1.7d-18)) then
        tmp = (b - ((a * d) / c)) / c
    else if (c <= (-4.9d-188)) then
        tmp = t_0
    else if (c <= (-3.3d-223)) then
        tmp = (c * (b / d)) / d
    else if (c <= 6.6d-103) then
        tmp = t_0
    else
        tmp = (b - (a * (d / c))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -1.7e-18) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -3.3e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 6.6e-103) {
		tmp = t_0;
	} else {
		tmp = (b - (a * (d / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = a / -d
	tmp = 0
	if c <= -1.7e-18:
		tmp = (b - ((a * d) / c)) / c
	elif c <= -4.9e-188:
		tmp = t_0
	elif c <= -3.3e-223:
		tmp = (c * (b / d)) / d
	elif c <= 6.6e-103:
		tmp = t_0
	else:
		tmp = (b - (a * (d / c))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(a / Float64(-d))
	tmp = 0.0
	if (c <= -1.7e-18)
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -3.3e-223)
		tmp = Float64(Float64(c * Float64(b / d)) / d);
	elseif (c <= 6.6e-103)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = a / -d;
	tmp = 0.0;
	if (c <= -1.7e-18)
		tmp = (b - ((a * d) / c)) / c;
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -3.3e-223)
		tmp = (c * (b / d)) / d;
	elseif (c <= 6.6e-103)
		tmp = t_0;
	else
		tmp = (b - (a * (d / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[c, -1.7e-18], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -4.9e-188], t$95$0, If[LessEqual[c, -3.3e-223], N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 6.6e-103], t$95$0, N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq -3.3 \cdot 10^{-223}:\\
\;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\

\mathbf{elif}\;c \leq 6.6 \cdot 10^{-103}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 48.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{b - a \cdot \frac{d}{c}}{c}} \]
    6. Taylor expanded in a around 0 80.9%

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

    if -1.70000000000000001e-18 < c < -4.90000000000000004e-188 or -3.29999999999999994e-223 < c < 6.59999999999999979e-103

    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 0 71.4%

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

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

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

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

    if -4.90000000000000004e-188 < c < -3.29999999999999994e-223

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    4. Taylor expanded in a around 0 99.6%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
    6. Simplified100.0%

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

    if 6.59999999999999979e-103 < c

    1. Initial program 51.0%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.7 \cdot 10^{-18}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq -3.3 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 6.6 \cdot 10^{-103}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 64.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{-d}\\ \mathbf{if}\;c \leq -1.15 \cdot 10^{+17}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.26 \cdot 10^{-219}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d}\\ \mathbf{elif}\;c \leq 6000000:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (- d))))
   (if (<= c -1.15e+17)
     (/ b c)
     (if (<= c -4.9e-188)
       t_0
       (if (<= c -1.26e-219)
         (* (/ c d) (/ b d))
         (if (<= c 6000000.0) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -1.15e+17) {
		tmp = b / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -1.26e-219) {
		tmp = (c / d) * (b / d);
	} else if (c <= 6000000.0) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = a / -d
    if (c <= (-1.15d+17)) then
        tmp = b / c
    else if (c <= (-4.9d-188)) then
        tmp = t_0
    else if (c <= (-1.26d-219)) then
        tmp = (c / d) * (b / d)
    else if (c <= 6000000.0d0) then
        tmp = t_0
    else
        tmp = b / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -1.15e+17) {
		tmp = b / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -1.26e-219) {
		tmp = (c / d) * (b / d);
	} else if (c <= 6000000.0) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = a / -d
	tmp = 0
	if c <= -1.15e+17:
		tmp = b / c
	elif c <= -4.9e-188:
		tmp = t_0
	elif c <= -1.26e-219:
		tmp = (c / d) * (b / d)
	elif c <= 6000000.0:
		tmp = t_0
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(a / Float64(-d))
	tmp = 0.0
	if (c <= -1.15e+17)
		tmp = Float64(b / c);
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -1.26e-219)
		tmp = Float64(Float64(c / d) * Float64(b / d));
	elseif (c <= 6000000.0)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = a / -d;
	tmp = 0.0;
	if (c <= -1.15e+17)
		tmp = b / c;
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -1.26e-219)
		tmp = (c / d) * (b / d);
	elseif (c <= 6000000.0)
		tmp = t_0;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[c, -1.15e+17], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.9e-188], t$95$0, If[LessEqual[c, -1.26e-219], N[(N[(c / d), $MachinePrecision] * N[(b / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 6000000.0], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq -1.26 \cdot 10^{-219}:\\
\;\;\;\;\frac{c}{d} \cdot \frac{b}{d}\\

\mathbf{elif}\;c \leq 6000000:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.15e17 or 6e6 < c

    1. Initial program 43.5%

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

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

    if -1.15e17 < c < -4.90000000000000004e-188 or -1.26000000000000003e-219 < c < 6e6

    1. Initial program 69.8%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified65.7%

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

    if -4.90000000000000004e-188 < c < -1.26000000000000003e-219

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    4. Taylor expanded in a around 0 99.7%

      \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d}}}{d} \]
    5. Step-by-step derivation
      1. *-commutative99.7%

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

        \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
    6. Simplified100.0%

      \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
    7. Step-by-step derivation
      1. div-inv99.7%

        \[\leadsto \color{blue}{\left(c \cdot \frac{b}{d}\right) \cdot \frac{1}{d}} \]
      2. *-commutative99.7%

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

        \[\leadsto \color{blue}{\frac{b}{d} \cdot \left(c \cdot \frac{1}{d}\right)} \]
      4. div-inv100.0%

        \[\leadsto \frac{b}{d} \cdot \color{blue}{\frac{c}{d}} \]
    8. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{b}{d} \cdot \frac{c}{d}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.15 \cdot 10^{+17}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq -1.26 \cdot 10^{-219}:\\ \;\;\;\;\frac{c}{d} \cdot \frac{b}{d}\\ \mathbf{elif}\;c \leq 6000000:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.3% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a}{-d}\\ \mathbf{if}\;c \leq -8.6 \cdot 10^{+14}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 400000:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ a (- d))))
   (if (<= c -8.6e+14)
     (/ b c)
     (if (<= c -4.9e-188)
       t_0
       (if (<= c -4.1e-223)
         (/ (* c (/ b d)) d)
         (if (<= c 400000.0) t_0 (/ b c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -8.6e+14) {
		tmp = b / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -4.1e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 400000.0) {
		tmp = t_0;
	} 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) :: t_0
    real(8) :: tmp
    t_0 = a / -d
    if (c <= (-8.6d+14)) then
        tmp = b / c
    else if (c <= (-4.9d-188)) then
        tmp = t_0
    else if (c <= (-4.1d-223)) then
        tmp = (c * (b / d)) / d
    else if (c <= 400000.0d0) then
        tmp = t_0
    else
        tmp = b / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = a / -d;
	double tmp;
	if (c <= -8.6e+14) {
		tmp = b / c;
	} else if (c <= -4.9e-188) {
		tmp = t_0;
	} else if (c <= -4.1e-223) {
		tmp = (c * (b / d)) / d;
	} else if (c <= 400000.0) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = a / -d
	tmp = 0
	if c <= -8.6e+14:
		tmp = b / c
	elif c <= -4.9e-188:
		tmp = t_0
	elif c <= -4.1e-223:
		tmp = (c * (b / d)) / d
	elif c <= 400000.0:
		tmp = t_0
	else:
		tmp = b / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(a / Float64(-d))
	tmp = 0.0
	if (c <= -8.6e+14)
		tmp = Float64(b / c);
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -4.1e-223)
		tmp = Float64(Float64(c * Float64(b / d)) / d);
	elseif (c <= 400000.0)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = a / -d;
	tmp = 0.0;
	if (c <= -8.6e+14)
		tmp = b / c;
	elseif (c <= -4.9e-188)
		tmp = t_0;
	elseif (c <= -4.1e-223)
		tmp = (c * (b / d)) / d;
	elseif (c <= 400000.0)
		tmp = t_0;
	else
		tmp = b / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(a / (-d)), $MachinePrecision]}, If[LessEqual[c, -8.6e+14], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.9e-188], t$95$0, If[LessEqual[c, -4.1e-223], N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 400000.0], t$95$0, N[(b / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 400000:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -8.6e14 or 4e5 < c

    1. Initial program 43.5%

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

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

    if -8.6e14 < c < -4.90000000000000004e-188 or -4.10000000000000015e-223 < c < 4e5

    1. Initial program 69.6%

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

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    5. Simplified66.1%

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

    if -4.90000000000000004e-188 < c < -4.10000000000000015e-223

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\frac{-1 \cdot a + \frac{b \cdot c}{d}}{d}} \]
    4. Taylor expanded in a around 0 99.6%

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

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

        \[\leadsto \frac{\color{blue}{c \cdot \frac{b}{d}}}{d} \]
    6. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.6 \cdot 10^{+14}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.9 \cdot 10^{-188}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{elif}\;c \leq -4.1 \cdot 10^{-223}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d}}{d}\\ \mathbf{elif}\;c \leq 400000:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 65.5% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.95 \cdot 10^{+18} \lor \neg \left(c \leq 2600000\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.95e18 or 2.6e6 < c

    1. Initial program 43.5%

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

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

    if -1.95e18 < c < 2.6e6

    1. Initial program 71.1%

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

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

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

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

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

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

Alternative 11: 9.7% 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 58.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(\color{blue}{\frac{d \cdot a}{c}} - b\right) \]
    7. associate-*r/30.8%

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

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  9. Final simplification6.4%

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

Alternative 12: 42.6% accurate, 5.0× speedup?

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

\\
\frac{b}{c}
\end{array}
Derivation
  1. Initial program 58.4%

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

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  4. Final simplification41.9%

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

  :alt
  (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))

  (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))