Complex division, imag part

Percentage Accurate: 61.7% → 81.9%
Time: 10.0s
Alternatives: 9
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 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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 81.9% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;c \leq -2.7 \cdot 10^{+65}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-75}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-156}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 4.6 \cdot 10^{+67}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- b (* d (/ a c))) c)))
   (if (<= c -2.7e+65)
     t_0
     (if (<= c -2.4e-75)
       (/ (fma b c (* d (- a))) (fma d d (* c c)))
       (if (<= c 3.9e-156)
         (/ (- (* c (/ b d)) a) d)
         (if (<= c 4.6e+67)
           (/ (- (* c b) (* d a)) (+ (* c c) (* d d)))
           t_0))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b - (d * (a / c))) / c;
	double tmp;
	if (c <= -2.7e+65) {
		tmp = t_0;
	} else if (c <= -2.4e-75) {
		tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
	} else if (c <= 3.9e-156) {
		tmp = ((c * (b / d)) - a) / d;
	} else if (c <= 4.6e+67) {
		tmp = ((c * b) - (d * a)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(b - Float64(d * Float64(a / c))) / c)
	tmp = 0.0
	if (c <= -2.7e+65)
		tmp = t_0;
	elseif (c <= -2.4e-75)
		tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c)));
	elseif (c <= 3.9e-156)
		tmp = Float64(Float64(Float64(c * Float64(b / d)) - a) / d);
	elseif (c <= 4.6e+67)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.7e+65], t$95$0, If[LessEqual[c, -2.4e-75], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 3.9e-156], N[(N[(N[(c * N[(b / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 4.6e+67], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\
\mathbf{if}\;c \leq -2.7 \cdot 10^{+65}:\\
\;\;\;\;t\_0\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.70000000000000019e65 or 4.5999999999999997e67 < c

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.70000000000000019e65 < c < -2.40000000000000019e-75

    1. Initial program 88.6%

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

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

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

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

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

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

    if -2.40000000000000019e-75 < c < 3.9000000000000001e-156

    1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.9000000000000001e-156 < c < 4.5999999999999997e67

    1. Initial program 80.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.7 \cdot 10^{+65}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -2.4 \cdot 10^{-75}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, c, d \cdot \left(-a\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 3.9 \cdot 10^{-156}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 4.6 \cdot 10^{+67}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.9% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;c \leq -4.2 \cdot 10^{-75}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.4 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.6e62 or 1.4e68 < c

    1. Initial program 40.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.6e62 < c < -4.2000000000000002e-75 or 2.3e-154 < c < 1.4e68

    1. Initial program 83.5%

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

    if -4.2000000000000002e-75 < c < 2.3e-154

    1. Initial program 58.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{+62}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq -4.2 \cdot 10^{-75}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.3 \cdot 10^{-154}:\\ \;\;\;\;\frac{c \cdot \frac{b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.4 \cdot 10^{+68}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 77.4% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -5 \cdot 10^{-8} \lor \neg \left(c \leq 1.4 \cdot 10^{-30}\right):\\
\;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.9999999999999998e-8 or 1.39999999999999994e-30 < c

    1. Initial program 49.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.9999999999999998e-8 < c < 1.39999999999999994e-30

    1. Initial program 67.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 78.5% accurate, 0.8× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -6.2e-8 or 5.89999999999999979e-30 < c

    1. Initial program 49.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.2e-8 < c < 5.89999999999999979e-30

    1. Initial program 67.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-\frac{a + -1 \cdot \frac{b \cdot c}{d}}{d}} \]
      2. distribute-neg-frac284.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{d} \]
      11. *-commutative84.4%

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

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

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

Alternative 5: 72.7% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.79999999999999985e36 or 9.0000000000000005e87 < d

    1. Initial program 42.6%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 71.0%

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    7. Simplified71.0%

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

    if -4.79999999999999985e36 < d < 9.0000000000000005e87

    1. Initial program 68.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 71.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.55 \cdot 10^{+131} \lor \neg \left(d \leq 4.6 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.55000000000000008e131 or 4.6000000000000003e87 < d

    1. Initial program 37.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 78.4%

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    7. Simplified78.4%

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

    if -1.55000000000000008e131 < d < 4.6000000000000003e87

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 62.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.5 \cdot 10^{-42} \lor \neg \left(d \leq 1.85 \cdot 10^{+87}\right):\\
\;\;\;\;\frac{a}{-d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.5e-42 or 1.85000000000000001e87 < d

    1. Initial program 45.4%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 68.3%

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

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

        \[\leadsto \frac{\color{blue}{-a}}{d} \]
    7. Simplified68.3%

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

    if -4.5e-42 < d < 1.85000000000000001e87

    1. Initial program 68.4%

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

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

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

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

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

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

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

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

Alternative 8: 43.4% accurate, 1.9× speedup?

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

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

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


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

    1. Initial program 39.3%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in c around 0 81.7%

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

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

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

      \[\leadsto \color{blue}{\frac{-a}{d}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt40.5%

        \[\leadsto \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
      2. sqrt-unprod47.4%

        \[\leadsto \frac{\color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
      3. sqr-neg47.4%

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

        \[\leadsto \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
      5. add-sqr-sqrt35.0%

        \[\leadsto \frac{\color{blue}{a}}{d} \]
      6. *-un-lft-identity35.0%

        \[\leadsto \color{blue}{1 \cdot \frac{a}{d}} \]
    9. Applied egg-rr35.0%

      \[\leadsto \color{blue}{1 \cdot \frac{a}{d}} \]
    10. Step-by-step derivation
      1. *-lft-identity35.0%

        \[\leadsto \color{blue}{\frac{a}{d}} \]
    11. Simplified35.0%

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

    if -3.00000000000000007e133 < d

    1. Initial program 60.2%

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

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

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

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

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

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

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

Alternative 9: 11.7% accurate, 5.0× speedup?

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, c, a \cdot \left(-d\right)\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in c around 0 43.5%

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

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

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

    \[\leadsto \color{blue}{\frac{-a}{d}} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt21.5%

      \[\leadsto \frac{\color{blue}{\sqrt{-a} \cdot \sqrt{-a}}}{d} \]
    2. sqrt-unprod23.7%

      \[\leadsto \frac{\color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}}{d} \]
    3. sqr-neg23.7%

      \[\leadsto \frac{\sqrt{\color{blue}{a \cdot a}}}{d} \]
    4. sqrt-unprod4.9%

      \[\leadsto \frac{\color{blue}{\sqrt{a} \cdot \sqrt{a}}}{d} \]
    5. add-sqr-sqrt13.4%

      \[\leadsto \frac{\color{blue}{a}}{d} \]
    6. *-un-lft-identity13.4%

      \[\leadsto \color{blue}{1 \cdot \frac{a}{d}} \]
  9. Applied egg-rr13.4%

    \[\leadsto \color{blue}{1 \cdot \frac{a}{d}} \]
  10. Step-by-step derivation
    1. *-lft-identity13.4%

      \[\leadsto \color{blue}{\frac{a}{d}} \]
  11. Simplified13.4%

    \[\leadsto \color{blue}{\frac{a}{d}} \]
  12. Add Preprocessing

Developer Target 1: 99.3% accurate, 0.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024188 
(FPCore (a b c d)
  :name "Complex division, imag part"
  :precision binary64

  :alt
  (! :herbie-platform default (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))))