Complex division, imag part

Percentage Accurate: 63.2% → 84.4%
Time: 9.3s
Alternatives: 9
Speedup: 1.0×

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: 63.2% 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: 84.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{\frac{\frac{c \cdot c + d \cdot d}{c}}{\frac{a}{\frac{c}{d}} - b}}\\ \mathbf{if}\;c \leq -8.6 \cdot 10^{+155}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq -2.8 \cdot 10^{-32}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-70}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.16 \cdot 10^{+111}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b + d \cdot \left(a \cdot \frac{-1}{c}\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ -1.0 (/ (/ (+ (* c c) (* d d)) c) (- (/ a (/ c d)) b)))))
   (if (<= c -8.6e+155)
     (/ (- b (/ d (/ c a))) c)
     (if (<= c -2.8e-32)
       t_0
       (if (<= c 9.2e-70)
         (/ (- (/ (* c b) d) a) d)
         (if (<= c 1.16e+111) t_0 (/ (+ b (* d (* a (/ -1.0 c)))) c)))))))
double code(double a, double b, double c, double d) {
	double t_0 = -1.0 / ((((c * c) + (d * d)) / c) / ((a / (c / d)) - b));
	double tmp;
	if (c <= -8.6e+155) {
		tmp = (b - (d / (c / a))) / c;
	} else if (c <= -2.8e-32) {
		tmp = t_0;
	} else if (c <= 9.2e-70) {
		tmp = (((c * b) / d) - a) / d;
	} else if (c <= 1.16e+111) {
		tmp = t_0;
	} else {
		tmp = (b + (d * (a * (-1.0 / c)))) / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (-1.0d0) / ((((c * c) + (d * d)) / c) / ((a / (c / d)) - b))
    if (c <= (-8.6d+155)) then
        tmp = (b - (d / (c / a))) / c
    else if (c <= (-2.8d-32)) then
        tmp = t_0
    else if (c <= 9.2d-70) then
        tmp = (((c * b) / d) - a) / d
    else if (c <= 1.16d+111) then
        tmp = t_0
    else
        tmp = (b + (d * (a * ((-1.0d0) / c)))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = -1.0 / ((((c * c) + (d * d)) / c) / ((a / (c / d)) - b));
	double tmp;
	if (c <= -8.6e+155) {
		tmp = (b - (d / (c / a))) / c;
	} else if (c <= -2.8e-32) {
		tmp = t_0;
	} else if (c <= 9.2e-70) {
		tmp = (((c * b) / d) - a) / d;
	} else if (c <= 1.16e+111) {
		tmp = t_0;
	} else {
		tmp = (b + (d * (a * (-1.0 / c)))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = -1.0 / ((((c * c) + (d * d)) / c) / ((a / (c / d)) - b))
	tmp = 0
	if c <= -8.6e+155:
		tmp = (b - (d / (c / a))) / c
	elif c <= -2.8e-32:
		tmp = t_0
	elif c <= 9.2e-70:
		tmp = (((c * b) / d) - a) / d
	elif c <= 1.16e+111:
		tmp = t_0
	else:
		tmp = (b + (d * (a * (-1.0 / c)))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(-1.0 / Float64(Float64(Float64(Float64(c * c) + Float64(d * d)) / c) / Float64(Float64(a / Float64(c / d)) - b)))
	tmp = 0.0
	if (c <= -8.6e+155)
		tmp = Float64(Float64(b - Float64(d / Float64(c / a))) / c);
	elseif (c <= -2.8e-32)
		tmp = t_0;
	elseif (c <= 9.2e-70)
		tmp = Float64(Float64(Float64(Float64(c * b) / d) - a) / d);
	elseif (c <= 1.16e+111)
		tmp = t_0;
	else
		tmp = Float64(Float64(b + Float64(d * Float64(a * Float64(-1.0 / c)))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = -1.0 / ((((c * c) + (d * d)) / c) / ((a / (c / d)) - b));
	tmp = 0.0;
	if (c <= -8.6e+155)
		tmp = (b - (d / (c / a))) / c;
	elseif (c <= -2.8e-32)
		tmp = t_0;
	elseif (c <= 9.2e-70)
		tmp = (((c * b) / d) - a) / d;
	elseif (c <= 1.16e+111)
		tmp = t_0;
	else
		tmp = (b + (d * (a * (-1.0 / c)))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(-1.0 / N[(N[(N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(N[(a / N[(c / d), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -8.6e+155], N[(N[(b - N[(d / N[(c / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.8e-32], t$95$0, If[LessEqual[c, 9.2e-70], N[(N[(N[(N[(c * b), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.16e+111], t$95$0, N[(N[(b + N[(d * N[(a * N[(-1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -2.8 \cdot 10^{-32}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.16 \cdot 10^{+111}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 33.8%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6485.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified85.7%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6494.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr94.2%

      \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{1}{\frac{c}{a}}\right)\right), c\right) \]
      2. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d}{\frac{c}{a}}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \left(\frac{c}{a}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6494.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \mathsf{/.f64}\left(c, a\right)\right)\right), c\right) \]
    9. Applied egg-rr94.3%

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

    if -8.6000000000000005e155 < c < -2.7999999999999999e-32 or 9.20000000000000002e-70 < c < 1.16e111

    1. Initial program 74.1%

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

      \[\leadsto \mathsf{/.f64}\left(\color{blue}{\left(c \cdot \left(b + -1 \cdot \frac{a \cdot d}{c}\right)\right)}, \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \left(b + -1 \cdot \frac{a \cdot d}{c}\right)\right), \mathsf{+.f64}\left(\color{blue}{\mathsf{*.f64}\left(c, c\right)}, \mathsf{*.f64}\left(d, d\right)\right)\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \left(b - \frac{a \cdot d}{c}\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, \color{blue}{c}\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, \color{blue}{c}\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
      6. *-lowering-*.f6474.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(c, \mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right)\right) \]
    5. Simplified74.1%

      \[\leadsto \frac{\color{blue}{c \cdot \left(b - \frac{a \cdot d}{c}\right)}}{c \cdot c + d \cdot d} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{c \cdot c + d \cdot d}{c \cdot \left(b - \frac{a \cdot d}{c}\right)}}} \]
      2. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{c \cdot c + d \cdot d}{c \cdot \left(b - \frac{a \cdot d}{c}\right)}\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{c \cdot c + d \cdot d}{c \cdot \left(b - \frac{a \cdot d}{c}\right)}}\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \color{blue}{\left(\mathsf{neg}\left(\frac{c \cdot c + d \cdot d}{c \cdot \left(b - \frac{a \cdot d}{c}\right)}\right)\right)}\right) \]
      5. associate-/r*N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(\mathsf{neg}\left(\frac{\frac{c \cdot c + d \cdot d}{c}}{b - \frac{a \cdot d}{c}}\right)\right)\right) \]
      6. distribute-neg-frac2N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(\frac{\frac{c \cdot c + d \cdot d}{c}}{\color{blue}{\mathsf{neg}\left(\left(b - \frac{a \cdot d}{c}\right)\right)}}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\left(\frac{c \cdot c + d \cdot d}{c}\right), \color{blue}{\left(\mathsf{neg}\left(\left(b - \frac{a \cdot d}{c}\right)\right)\right)}\right)\right) \]
      8. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\left(c \cdot c + d \cdot d\right), c\right), \left(\mathsf{neg}\left(\color{blue}{\left(b - \frac{a \cdot d}{c}\right)}\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(c \cdot c\right), \left(d \cdot d\right)\right), c\right), \left(\mathsf{neg}\left(\left(\color{blue}{b} - \frac{a \cdot d}{c}\right)\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \left(d \cdot d\right)\right), c\right), \left(\mathsf{neg}\left(\left(b - \frac{a \cdot d}{c}\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(\mathsf{neg}\left(\left(b - \frac{a \cdot d}{c}\right)\right)\right)\right)\right) \]
      12. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(0 - \color{blue}{\left(b - \frac{a \cdot d}{c}\right)}\right)\right)\right) \]
      13. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(0 - \left(b + \color{blue}{\left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)}\right)\right)\right)\right) \]
      14. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(0 - \left(\left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right) + \color{blue}{b}\right)\right)\right)\right) \]
      15. associate--r+N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(\left(0 - \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right) - \color{blue}{b}\right)\right)\right) \]
      16. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right)\right) - b\right)\right)\right) \]
      17. remove-double-negN/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \left(\frac{a \cdot d}{c} - b\right)\right)\right) \]
      18. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{/.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(c, c\right), \mathsf{*.f64}\left(d, d\right)\right), c\right), \mathsf{\_.f64}\left(\left(\frac{a \cdot d}{c}\right), \color{blue}{b}\right)\right)\right) \]
    7. Applied egg-rr82.1%

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

    if -2.7999999999999999e-32 < c < 9.20000000000000002e-70

    1. Initial program 69.2%

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

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{-1 \cdot \frac{a}{d}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \left(\mathsf{neg}\left(\frac{a}{d}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} - \color{blue}{\frac{a}{d}} \]
      4. unpow2N/A

        \[\leadsto \frac{b \cdot c}{d \cdot d} - \frac{a}{d} \]
      5. associate-/r*N/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \frac{\color{blue}{a}}{d} \]
      6. div-subN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{\color{blue}{d}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{b \cdot c}{d} - a\right), \color{blue}{d}\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{b \cdot c}{d}\right), a\right), d\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot c\right), d\right), a\right), d\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(c \cdot b\right), d\right), a\right), d\right) \]
      11. *-lowering-*.f6492.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(c, b\right), d\right), a\right), d\right) \]
    5. Simplified92.7%

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

    if 1.16e111 < c

    1. Initial program 47.3%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6482.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified82.0%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{\frac{c}{a \cdot d}}\right)\right), c\right) \]
      2. associate-/r/N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{c} \cdot \left(a \cdot d\right)\right)\right), c\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\left(\frac{1}{c} \cdot a\right) \cdot d\right)\right), c\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\left(\frac{1}{c} \cdot a\right), d\right)\right), c\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{c}\right), a\right), d\right)\right), c\right) \]
      6. /-lowering-/.f6488.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, c\right), a\right), d\right)\right), c\right) \]
    7. Applied egg-rr88.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.6 \cdot 10^{+155}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq -2.8 \cdot 10^{-32}:\\ \;\;\;\;\frac{-1}{\frac{\frac{c \cdot c + d \cdot d}{c}}{\frac{a}{\frac{c}{d}} - b}}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-70}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.16 \cdot 10^{+111}:\\ \;\;\;\;\frac{-1}{\frac{\frac{c \cdot c + d \cdot d}{c}}{\frac{a}{\frac{c}{d}} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + d \cdot \left(a \cdot \frac{-1}{c}\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 81.7% accurate, 0.5× speedup?

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

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

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

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

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


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

    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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6481.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified81.4%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr87.1%

      \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{1}{\frac{c}{a}}\right)\right), c\right) \]
      2. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d}{\frac{c}{a}}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \left(\frac{c}{a}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \mathsf{/.f64}\left(c, a\right)\right)\right), c\right) \]
    9. Applied egg-rr87.2%

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

    if -7.9999999999999999e24 < c < 1.75000000000000006e-68

    1. Initial program 70.2%

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

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{-1 \cdot \frac{a}{d}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \left(\mathsf{neg}\left(\frac{a}{d}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} - \color{blue}{\frac{a}{d}} \]
      4. unpow2N/A

        \[\leadsto \frac{b \cdot c}{d \cdot d} - \frac{a}{d} \]
      5. associate-/r*N/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \frac{\color{blue}{a}}{d} \]
      6. div-subN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{\color{blue}{d}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{b \cdot c}{d} - a\right), \color{blue}{d}\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{b \cdot c}{d}\right), a\right), d\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot c\right), d\right), a\right), d\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(c \cdot b\right), d\right), a\right), d\right) \]
      11. *-lowering-*.f6488.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(c, b\right), d\right), a\right), d\right) \]
    5. Simplified88.2%

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

    if 1.75000000000000006e-68 < c < 2.1500000000000001e68

    1. Initial program 86.3%

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

    if 2.1500000000000001e68 < c

    1. Initial program 47.3%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6477.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified77.7%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{\frac{c}{a \cdot d}}\right)\right), c\right) \]
      2. associate-/r/N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{c} \cdot \left(a \cdot d\right)\right)\right), c\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\left(\frac{1}{c} \cdot a\right) \cdot d\right)\right), c\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\left(\frac{1}{c} \cdot a\right), d\right)\right), c\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{c}\right), a\right), d\right)\right), c\right) \]
      6. /-lowering-/.f6484.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, c\right), a\right), d\right)\right), c\right) \]
    7. Applied egg-rr84.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8 \cdot 10^{+24}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq 1.75 \cdot 10^{-68}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{elif}\;c \leq 2.15 \cdot 10^{+68}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + d \cdot \left(a \cdot \frac{-1}{c}\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 78.8% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.0999999999999999e25

    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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6481.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified81.4%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr87.1%

      \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{1}{\frac{c}{a}}\right)\right), c\right) \]
      2. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d}{\frac{c}{a}}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \left(\frac{c}{a}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \mathsf{/.f64}\left(c, a\right)\right)\right), c\right) \]
    9. Applied egg-rr87.2%

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

    if -2.0999999999999999e25 < c < 3.59999999999999978e-56

    1. Initial program 70.3%

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

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{-1 \cdot \frac{a}{d}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \left(\mathsf{neg}\left(\frac{a}{d}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} - \color{blue}{\frac{a}{d}} \]
      4. unpow2N/A

        \[\leadsto \frac{b \cdot c}{d \cdot d} - \frac{a}{d} \]
      5. associate-/r*N/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \frac{\color{blue}{a}}{d} \]
      6. div-subN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{\color{blue}{d}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{b \cdot c}{d} - a\right), \color{blue}{d}\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{b \cdot c}{d}\right), a\right), d\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot c\right), d\right), a\right), d\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(c \cdot b\right), d\right), a\right), d\right) \]
      11. *-lowering-*.f6486.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(c, b\right), d\right), a\right), d\right) \]
    5. Simplified86.9%

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

    if 3.59999999999999978e-56 < c

    1. Initial program 60.3%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6472.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified72.7%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{\frac{c}{a \cdot d}}\right)\right), c\right) \]
      2. associate-/r/N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{1}{c} \cdot \left(a \cdot d\right)\right)\right), c\right) \]
      3. associate-*r*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\left(\frac{1}{c} \cdot a\right) \cdot d\right)\right), c\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\left(\frac{1}{c} \cdot a\right), d\right)\right), c\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{c}\right), a\right), d\right)\right), c\right) \]
      6. /-lowering-/.f6477.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(1, c\right), a\right), d\right)\right), c\right) \]
    7. Applied egg-rr77.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.1 \cdot 10^{+25}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-56}:\\ \;\;\;\;\frac{\frac{c \cdot b}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + d \cdot \left(a \cdot \frac{-1}{c}\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.8% accurate, 0.8× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.1000000000000004e25

    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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6481.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified81.4%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr87.1%

      \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{1}{\frac{c}{a}}\right)\right), c\right) \]
      2. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d}{\frac{c}{a}}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \left(\frac{c}{a}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6487.2%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \mathsf{/.f64}\left(c, a\right)\right)\right), c\right) \]
    9. Applied egg-rr87.2%

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

    if -5.1000000000000004e25 < c < 4.1999999999999999e-57

    1. Initial program 70.3%

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

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

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \color{blue}{-1 \cdot \frac{a}{d}} \]
      2. mul-1-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} + \left(\mathsf{neg}\left(\frac{a}{d}\right)\right) \]
      3. unsub-negN/A

        \[\leadsto \frac{b \cdot c}{{d}^{2}} - \color{blue}{\frac{a}{d}} \]
      4. unpow2N/A

        \[\leadsto \frac{b \cdot c}{d \cdot d} - \frac{a}{d} \]
      5. associate-/r*N/A

        \[\leadsto \frac{\frac{b \cdot c}{d}}{d} - \frac{\color{blue}{a}}{d} \]
      6. div-subN/A

        \[\leadsto \frac{\frac{b \cdot c}{d} - a}{\color{blue}{d}} \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(\frac{b \cdot c}{d} - a\right), \color{blue}{d}\right) \]
      8. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\left(\frac{b \cdot c}{d}\right), a\right), d\right) \]
      9. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(b \cdot c\right), d\right), a\right), d\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\left(c \cdot b\right), d\right), a\right), d\right) \]
      11. *-lowering-*.f6486.9%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(c, b\right), d\right), a\right), d\right) \]
    5. Simplified86.9%

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

    if 4.1999999999999999e-57 < c

    1. Initial program 60.3%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6472.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified72.7%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6477.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr77.0%

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

Alternative 5: 73.3% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a}{0 - d}\\
\mathbf{if}\;d \leq -2 \cdot 10^{+57}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.0000000000000001e57 or 1.06000000000000006e43 < d

    1. Initial program 47.7%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{a}{d}\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{\frac{a}{d}} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{a}{d}\right)}\right) \]
      4. /-lowering-/.f6470.5%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(a, \color{blue}{d}\right)\right) \]
    5. Simplified70.5%

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

    if -2.0000000000000001e57 < d < 1.06000000000000006e43

    1. Initial program 74.0%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6482.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified82.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+57}:\\ \;\;\;\;\frac{a}{0 - d}\\ \mathbf{elif}\;d \leq 1.06 \cdot 10^{+43}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{0 - d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 70.6% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;c \leq 1.5 \cdot 10^{-57}:\\
\;\;\;\;\frac{a}{0 - d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -3.6e14

    1. Initial program 54.4%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6479.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified79.5%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6485.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr85.1%

      \[\leadsto \frac{b - \color{blue}{d \cdot \frac{a}{c}}}{c} \]
    8. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{1}{\frac{c}{a}}\right)\right), c\right) \]
      2. un-div-invN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d}{\frac{c}{a}}\right)\right), c\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \left(\frac{c}{a}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6485.1%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(d, \mathsf{/.f64}\left(c, a\right)\right)\right), c\right) \]
    9. Applied egg-rr85.1%

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

    if -3.6e14 < c < 1.5e-57

    1. Initial program 69.5%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{a}{d}\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{\frac{a}{d}} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{a}{d}\right)}\right) \]
      4. /-lowering-/.f6471.7%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(a, \color{blue}{d}\right)\right) \]
    5. Simplified71.7%

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

    if 1.5e-57 < c

    1. Initial program 60.3%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6472.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified72.7%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6477.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr77.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.6 \cdot 10^{+14}:\\ \;\;\;\;\frac{b - \frac{d}{\frac{c}{a}}}{c}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{-57}:\\ \;\;\;\;\frac{a}{0 - d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 70.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{if}\;c \leq -4.2 \cdot 10^{+14}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 2 \cdot 10^{-56}:\\ \;\;\;\;\frac{a}{0 - 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 -4.2e+14) t_0 (if (<= c 2e-56) (/ a (- 0.0 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 <= -4.2e+14) {
		tmp = t_0;
	} else if (c <= 2e-56) {
		tmp = a / (0.0 - d);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (b - (d * (a / c))) / c
    if (c <= (-4.2d+14)) then
        tmp = t_0
    else if (c <= 2d-56) then
        tmp = a / (0.0d0 - d)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b - (d * (a / c))) / c;
	double tmp;
	if (c <= -4.2e+14) {
		tmp = t_0;
	} else if (c <= 2e-56) {
		tmp = a / (0.0 - d);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b - (d * (a / c))) / c
	tmp = 0
	if c <= -4.2e+14:
		tmp = t_0
	elif c <= 2e-56:
		tmp = a / (0.0 - 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 <= -4.2e+14)
		tmp = t_0;
	elseif (c <= 2e-56)
		tmp = Float64(a / Float64(0.0 - d));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b - (d * (a / c))) / c;
	tmp = 0.0;
	if (c <= -4.2e+14)
		tmp = t_0;
	elseif (c <= 2e-56)
		tmp = a / (0.0 - d);
	else
		tmp = t_0;
	end
	tmp_2 = 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, -4.2e+14], t$95$0, If[LessEqual[c, 2e-56], N[(a / N[(0.0 - d), $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 -4.2 \cdot 10^{+14}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 2 \cdot 10^{-56}:\\
\;\;\;\;\frac{a}{0 - d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.2e14 or 2.0000000000000001e-56 < c

    1. Initial program 57.5%

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

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + -1 \cdot \frac{a \cdot d}{c}\right), \color{blue}{c}\right) \]
      2. mul-1-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b + \left(\mathsf{neg}\left(\frac{a \cdot d}{c}\right)\right)\right), c\right) \]
      3. unsub-negN/A

        \[\leadsto \mathsf{/.f64}\left(\left(b - \frac{a \cdot d}{c}\right), c\right) \]
      4. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{a \cdot d}{c}\right)\right), c\right) \]
      5. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\left(a \cdot d\right), c\right)\right), c\right) \]
      6. *-lowering-*.f6476.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{/.f64}\left(\mathsf{*.f64}\left(a, d\right), c\right)\right), c\right) \]
    5. Simplified76.0%

      \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(\frac{d \cdot a}{c}\right)\right), c\right) \]
      2. associate-/l*N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \left(d \cdot \frac{a}{c}\right)\right), c\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \left(\frac{a}{c}\right)\right)\right), c\right) \]
      4. /-lowering-/.f6480.8%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{\_.f64}\left(b, \mathsf{*.f64}\left(d, \mathsf{/.f64}\left(a, c\right)\right)\right), c\right) \]
    7. Applied egg-rr80.8%

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

    if -4.2e14 < c < 2.0000000000000001e-56

    1. Initial program 69.5%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{a}{d}\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{\frac{a}{d}} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{a}{d}\right)}\right) \]
      4. /-lowering-/.f6471.7%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(a, \color{blue}{d}\right)\right) \]
    5. Simplified71.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.2 \cdot 10^{+14}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{-56}:\\ \;\;\;\;\frac{a}{0 - d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - d \cdot \frac{a}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 63.9% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.1 \cdot 10^{+18}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;c \leq 3.6 \cdot 10^{-56}:\\
\;\;\;\;\frac{a}{0 - d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.1e18 or 3.59999999999999978e-56 < c

    1. Initial program 56.9%

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

      \[\leadsto \color{blue}{\frac{b}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6467.6%

        \[\leadsto \mathsf{/.f64}\left(b, \color{blue}{c}\right) \]
    5. Simplified67.6%

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

    if -1.1e18 < c < 3.59999999999999978e-56

    1. Initial program 70.1%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d}} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \mathsf{neg}\left(\frac{a}{d}\right) \]
      2. neg-sub0N/A

        \[\leadsto 0 - \color{blue}{\frac{a}{d}} \]
      3. --lowering--.f64N/A

        \[\leadsto \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{a}{d}\right)}\right) \]
      4. /-lowering-/.f6471.4%

        \[\leadsto \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(a, \color{blue}{d}\right)\right) \]
    5. Simplified71.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.1 \cdot 10^{+18}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-56}:\\ \;\;\;\;\frac{a}{0 - d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 42.8% 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 62.5%

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

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f6446.0%

      \[\leadsto \mathsf{/.f64}\left(b, \color{blue}{c}\right) \]
  5. Simplified46.0%

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  6. 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 2024192 
(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))))