Complex division, imag part

Percentage Accurate: 62.0% → 88.0%
Time: 11.2s
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: 62.0% 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: 88.0% accurate, 0.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -7.1 \cdot 10^{-71} \lor \neg \left(a \leq 1.3 \cdot 10^{-69}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{a}, -d\right)}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{a}{\mathsf{hypot}\left(d, c\right)}\\

\mathbf{else}:\\
\;\;\;\;b \cdot \left(\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{c}{\mathsf{hypot}\left(d, c\right)}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -7.10000000000000008e-71 or 1.3000000000000001e-69 < a

    1. Initial program 49.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.10000000000000008e-71 < a < 1.3000000000000001e-69

    1. Initial program 72.6%

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

      \[\leadsto \color{blue}{\frac{b \cdot c}{{c}^{2} + {d}^{2}}} \]
    4. Step-by-step derivation
      1. associate-/l*66.7%

        \[\leadsto \color{blue}{b \cdot \frac{c}{{c}^{2} + {d}^{2}}} \]
    5. Simplified66.7%

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

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

        \[\leadsto b \cdot \frac{1 \cdot c}{\color{blue}{c \cdot c} + {d}^{2}} \]
      3. pow266.7%

        \[\leadsto b \cdot \frac{1 \cdot c}{c \cdot c + \color{blue}{d \cdot d}} \]
      4. add-sqr-sqrt66.7%

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

        \[\leadsto b \cdot \color{blue}{\left(\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{c}{\sqrt{c \cdot c + d \cdot d}}\right)} \]
      6. +-commutative66.6%

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

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

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

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

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

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

Alternative 2: 82.1% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{+22}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-74}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.5 \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{else}:\\ \;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.5e+22)
   (/ (- b (* a (/ d c))) c)
   (if (<= c -9e-74)
     (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
     (if (<= c 4.2e-153)
       (/ (- (/ (* b c) d) a) d)
       (if (<= c 1.5e+75)
         (/ (fma b c (* d (- a))) (fma d d (* c c)))
         (* (- b (* d (/ a c))) (/ 1.0 c)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.5e+22) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= -9e-74) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 4.2e-153) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 1.5e+75) {
		tmp = fma(b, c, (d * -a)) / fma(d, d, (c * c));
	} else {
		tmp = (b - (d * (a / c))) * (1.0 / c);
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.5e+22)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= -9e-74)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 4.2e-153)
		tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d);
	elseif (c <= 1.5e+75)
		tmp = Float64(fma(b, c, Float64(d * Float64(-a))) / fma(d, d, Float64(c * c)));
	else
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) * Float64(1.0 / c));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.5e+22], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e-74], 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-153], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+75], N[(N[(b * c + N[(d * (-a)), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

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

\mathbf{elif}\;c \leq 1.5 \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{else}:\\
\;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -1.5e22

    1. Initial program 36.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5e22 < c < -8.9999999999999998e-74

    1. Initial program 99.7%

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

    if -8.9999999999999998e-74 < c < 4.20000000000000008e-153

    1. Initial program 65.0%

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

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

    if 4.20000000000000008e-153 < c < 1.5e75

    1. Initial program 80.5%

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

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

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

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

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

      \[\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 1.5e75 < c

    1. Initial program 39.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{+22}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-74}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 4.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.5 \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{else}:\\ \;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{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 -1.5 \cdot 10^{+22}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-72}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+73}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{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 -1.5e+22)
     (/ (- b (* a (/ d c))) c)
     (if (<= c -9e-72)
       t_0
       (if (<= c 1.12e-153)
         (/ (- (/ (* b c) d) a) d)
         (if (<= c 5.2e+73) t_0 (* (- b (* d (/ a c))) (/ 1.0 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 <= -1.5e+22) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= -9e-72) {
		tmp = t_0;
	} else if (c <= 1.12e-153) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 5.2e+73) {
		tmp = t_0;
	} else {
		tmp = (b - (d * (a / c))) * (1.0 / 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 <= (-1.5d+22)) then
        tmp = (b - (a * (d / c))) / c
    else if (c <= (-9d-72)) then
        tmp = t_0
    else if (c <= 1.12d-153) then
        tmp = (((b * c) / d) - a) / d
    else if (c <= 5.2d+73) then
        tmp = t_0
    else
        tmp = (b - (d * (a / c))) * (1.0d0 / 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 <= -1.5e+22) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= -9e-72) {
		tmp = t_0;
	} else if (c <= 1.12e-153) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 5.2e+73) {
		tmp = t_0;
	} else {
		tmp = (b - (d * (a / c))) * (1.0 / c);
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d))
	tmp = 0
	if c <= -1.5e+22:
		tmp = (b - (a * (d / c))) / c
	elif c <= -9e-72:
		tmp = t_0
	elif c <= 1.12e-153:
		tmp = (((b * c) / d) - a) / d
	elif c <= 5.2e+73:
		tmp = t_0
	else:
		tmp = (b - (d * (a / c))) * (1.0 / 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 <= -1.5e+22)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= -9e-72)
		tmp = t_0;
	elseif (c <= 1.12e-153)
		tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d);
	elseif (c <= 5.2e+73)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(d * Float64(a / c))) * Float64(1.0 / 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 <= -1.5e+22)
		tmp = (b - (a * (d / c))) / c;
	elseif (c <= -9e-72)
		tmp = t_0;
	elseif (c <= 1.12e-153)
		tmp = (((b * c) / d) - a) / d;
	elseif (c <= 5.2e+73)
		tmp = t_0;
	else
		tmp = (b - (d * (a / c))) * (1.0 / 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, -1.5e+22], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -9e-72], t$95$0, If[LessEqual[c, 1.12e-153], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 5.2e+73], t$95$0, N[(N[(b - N[(d * N[(a / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / c), $MachinePrecision]), $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 -1.5 \cdot 10^{+22}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

\mathbf{elif}\;c \leq -9 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.2 \cdot 10^{+73}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 36.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.5e22 < c < -9e-72 or 1.12000000000000005e-153 < c < 5.2000000000000001e73

    1. Initial program 86.3%

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

    if -9e-72 < c < 1.12000000000000005e-153

    1. Initial program 65.0%

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

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

    if 5.2000000000000001e73 < c

    1. Initial program 39.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{+22}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq -9 \cdot 10^{-72}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.12 \cdot 10^{-153}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 5.2 \cdot 10^{+73}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\left(b - d \cdot \frac{a}{c}\right) \cdot \frac{1}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 70.0% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.9 \cdot 10^{-26} \lor \neg \left(c \leq 7.8 \cdot 10^{-102}\right):\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.89999999999999986e-26 or 7.79999999999999999e-102 < c

    1. Initial program 50.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.89999999999999986e-26 < c < 7.79999999999999999e-102

    1. Initial program 71.8%

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

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

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

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

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

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

Alternative 5: 77.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.15 \cdot 10^{-65} \lor \neg \left(d \leq 1.05 \cdot 10^{+53}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.15e-65 or 1.0500000000000001e53 < d

    1. Initial program 46.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.15e-65 < d < 1.0500000000000001e53

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 69.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -8.2 \cdot 10^{-26}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 7.8 \cdot 10^{-102}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -8.2e-26)
   (/ (- b (* a (/ d c))) c)
   (if (<= c 7.8e-102) (/ a (- d)) (/ (- b (/ a (/ c d))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -8.2e-26) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 7.8e-102) {
		tmp = a / -d;
	} else {
		tmp = (b - (a / (c / d))) / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (c <= (-8.2d-26)) then
        tmp = (b - (a * (d / c))) / c
    else if (c <= 7.8d-102) then
        tmp = a / -d
    else
        tmp = (b - (a / (c / d))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -8.2e-26) {
		tmp = (b - (a * (d / c))) / c;
	} else if (c <= 7.8e-102) {
		tmp = a / -d;
	} else {
		tmp = (b - (a / (c / d))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -8.2e-26:
		tmp = (b - (a * (d / c))) / c
	elif c <= 7.8e-102:
		tmp = a / -d
	else:
		tmp = (b - (a / (c / d))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -8.2e-26)
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c);
	elseif (c <= 7.8e-102)
		tmp = Float64(a / Float64(-d));
	else
		tmp = Float64(Float64(b - Float64(a / Float64(c / d))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -8.2e-26)
		tmp = (b - (a * (d / c))) / c;
	elseif (c <= 7.8e-102)
		tmp = a / -d;
	else
		tmp = (b - (a / (c / d))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -8.2e-26], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 7.8e-102], N[(a / (-d)), $MachinePrecision], N[(N[(b - N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 48.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.1999999999999997e-26 < c < 7.79999999999999999e-102

    1. Initial program 71.8%

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

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

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

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

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

    if 7.79999999999999999e-102 < c

    1. Initial program 52.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.2 \cdot 10^{-26}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;c \leq 7.8 \cdot 10^{-102}:\\ \;\;\;\;\frac{a}{-d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a}{\frac{c}{d}}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.0% accurate, 0.8× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.15e-65

    1. Initial program 55.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.15e-65 < d < 3.8e52

    1. Initial program 69.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.8e52 < d

    1. Initial program 31.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 63.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -9.5 \cdot 10^{-35} \lor \neg \left(c \leq 0.0031\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -9.5000000000000003e-35 or 0.00309999999999999989 < c

    1. Initial program 48.0%

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

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

    if -9.5000000000000003e-35 < c < 0.00309999999999999989

    1. Initial program 72.3%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. 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} \]
    5. Simplified68.3%

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

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

Alternative 9: 43.3% 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 44.8%

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  4. Final simplification44.8%

    \[\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 2024050 
(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))))