Complex division, imag part

Percentage Accurate: 62.5% → 84.0%
Time: 9.8s
Alternatives: 9
Speedup: 1.5×

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.5% accurate, 1.0× speedup?

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

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

Alternative 1: 84.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\ t_1 := \mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c \cdot b}{t\_0}\right)\\ t_2 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \mathbf{if}\;c \leq -2.4 \cdot 10^{+82}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;c \leq -8.8 \cdot 10^{-91}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{+53}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma c c (* d d)))
        (t_1 (fma (- a) (/ d t_0) (/ (* c b) t_0)))
        (t_2 (/ (fma (- d) (/ a c) b) c)))
   (if (<= c -2.4e+82)
     t_2
     (if (<= c -8.8e-91)
       t_1
       (if (<= c 8.6e-164)
         (/ (- (* b (/ c d)) a) d)
         (if (<= c 2e+53) t_1 t_2))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(c, c, (d * d));
	double t_1 = fma(-a, (d / t_0), ((c * b) / t_0));
	double t_2 = fma(-d, (a / c), b) / c;
	double tmp;
	if (c <= -2.4e+82) {
		tmp = t_2;
	} else if (c <= -8.8e-91) {
		tmp = t_1;
	} else if (c <= 8.6e-164) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 2e+53) {
		tmp = t_1;
	} else {
		tmp = t_2;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(c, c, Float64(d * d))
	t_1 = fma(Float64(-a), Float64(d / t_0), Float64(Float64(c * b) / t_0))
	t_2 = Float64(fma(Float64(-d), Float64(a / c), b) / c)
	tmp = 0.0
	if (c <= -2.4e+82)
		tmp = t_2;
	elseif (c <= -8.8e-91)
		tmp = t_1;
	elseif (c <= 8.6e-164)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 2e+53)
		tmp = t_1;
	else
		tmp = t_2;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-a) * N[(d / t$95$0), $MachinePrecision] + N[(N[(c * b), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[((-d) * N[(a / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -2.4e+82], t$95$2, If[LessEqual[c, -8.8e-91], t$95$1, If[LessEqual[c, 8.6e-164], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2e+53], t$95$1, t$95$2]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(c, c, d \cdot d\right)\\
t_1 := \mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c \cdot b}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -2.4 \cdot 10^{+82}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;c \leq -8.8 \cdot 10^{-91}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;c \leq 2 \cdot 10^{+53}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.39999999999999998e82 or 2e53 < c

    1. Initial program 32.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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      2. mul-1-negN/A

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. *-lowering-*.f6479.0

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{neg}\left(d \cdot a\right)}{c} + b}}{c} \]
      5. distribute-lft-neg-inN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(d\right)}, \frac{a}{c}, b\right)}{c} \]
      9. /-lowering-/.f6482.7

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

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

    if -2.39999999999999998e82 < c < -8.8000000000000003e-91 or 8.5999999999999996e-164 < c < 2e53

    1. Initial program 79.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6484.3

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

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

    if -8.8000000000000003e-91 < c < 8.5999999999999996e-164

    1. Initial program 62.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6464.1

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{b \cdot \frac{c}{{d}^{2}}} + -1 \cdot \frac{a}{d} \]
      3. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \mathsf{fma}\left(b, \color{blue}{\frac{c}{{d}^{2}}}, -1 \cdot \frac{a}{d}\right) \]
      5. unpow2N/A

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)}\right) \]
      8. distribute-neg-frac2N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}}\right) \]
      12. neg-lowering-neg.f6484.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{-d}\right)} \]
    8. Step-by-step derivation
      1. distribute-frac-neg2N/A

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

        \[\leadsto \color{blue}{b \cdot \frac{c}{d \cdot d} - \frac{a}{d}} \]
      3. *-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{d} \]
      10. /-lowering-/.f6492.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.4 \cdot 10^{+82}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \mathbf{elif}\;c \leq -8.8 \cdot 10^{-91}:\\ \;\;\;\;\mathsf{fma}\left(-a, \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 2 \cdot 10^{+53}:\\ \;\;\;\;\mathsf{fma}\left(-a, \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 83.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ t_1 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \mathbf{if}\;c \leq -5.8 \cdot 10^{+81}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-87}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 3.65 \cdot 10^{+53}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (- (* c b) (* d a)) (+ (* d d) (* c c))))
        (t_1 (/ (fma (- d) (/ a c) b) c)))
   (if (<= c -5.8e+81)
     t_1
     (if (<= c -2.1e-87)
       t_0
       (if (<= c 8.6e-164)
         (/ (- (* b (/ c d)) a) d)
         (if (<= c 3.65e+53) t_0 t_1))))))
double code(double a, double b, double c, double d) {
	double t_0 = ((c * b) - (d * a)) / ((d * d) + (c * c));
	double t_1 = fma(-d, (a / c), b) / c;
	double tmp;
	if (c <= -5.8e+81) {
		tmp = t_1;
	} else if (c <= -2.1e-87) {
		tmp = t_0;
	} else if (c <= 8.6e-164) {
		tmp = ((b * (c / d)) - a) / d;
	} else if (c <= 3.65e+53) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(Float64(d * d) + Float64(c * c)))
	t_1 = Float64(fma(Float64(-d), Float64(a / c), b) / c)
	tmp = 0.0
	if (c <= -5.8e+81)
		tmp = t_1;
	elseif (c <= -2.1e-87)
		tmp = t_0;
	elseif (c <= 8.6e-164)
		tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d);
	elseif (c <= 3.65e+53)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(N[(d * d), $MachinePrecision] + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-d) * N[(a / c), $MachinePrecision] + b), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -5.8e+81], t$95$1, If[LessEqual[c, -2.1e-87], t$95$0, If[LessEqual[c, 8.6e-164], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 3.65e+53], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
t_1 := \frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\
\mathbf{if}\;c \leq -5.8 \cdot 10^{+81}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq -2.1 \cdot 10^{-87}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 3.65 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.7999999999999999e81 or 3.65000000000000008e53 < c

    1. Initial program 32.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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      2. mul-1-negN/A

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. *-lowering-*.f6479.0

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{neg}\left(d \cdot a\right)}{c} + b}}{c} \]
      5. distribute-lft-neg-inN/A

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(d\right)}, \frac{a}{c}, b\right)}{c} \]
      9. /-lowering-/.f6482.7

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

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

    if -5.7999999999999999e81 < c < -2.10000000000000007e-87 or 8.5999999999999996e-164 < c < 3.65000000000000008e53

    1. Initial program 79.0%

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

    if -2.10000000000000007e-87 < c < 8.5999999999999996e-164

    1. Initial program 62.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6464.1

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{b \cdot \frac{c}{{d}^{2}}} + -1 \cdot \frac{a}{d} \]
      3. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \mathsf{fma}\left(b, \color{blue}{\frac{c}{{d}^{2}}}, -1 \cdot \frac{a}{d}\right) \]
      5. unpow2N/A

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)}\right) \]
      8. distribute-neg-frac2N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}}\right) \]
      12. neg-lowering-neg.f6484.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{-d}\right)} \]
    8. Step-by-step derivation
      1. distribute-frac-neg2N/A

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

        \[\leadsto \color{blue}{b \cdot \frac{c}{d \cdot d} - \frac{a}{d}} \]
      3. *-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{d} \]
      10. /-lowering-/.f6492.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.8 \cdot 10^{+81}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \mathbf{elif}\;c \leq -2.1 \cdot 10^{-87}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;c \leq 8.6 \cdot 10^{-164}:\\ \;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 3.65 \cdot 10^{+53}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-d, \frac{a}{c}, b\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 66.1% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -1.55 \cdot 10^{-80}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.1 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -5.5000000000000002e123 or 5.1000000000000003e92 < c

    1. Initial program 25.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}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f6477.5

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Simplified77.5%

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

    if -5.5000000000000002e123 < c < -1.55000000000000008e-80 or 4.8e-31 < c < 5.1000000000000003e92

    1. Initial program 80.2%

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c}} \]
      2. *-lowering-*.f6461.4

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

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

    if -1.55000000000000008e-80 < c < 4.8e-31

    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 c around 0

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

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

        \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
      3. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
      6. neg-lowering-neg.f6465.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+123}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{-80}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c}\\ \mathbf{elif}\;c \leq 4.8 \cdot 10^{-31}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;c \leq 5.1 \cdot 10^{+92}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 73.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-a}{d}\\ \mathbf{if}\;d \leq -1.3 \cdot 10^{+150}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -0.48:\\ \;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+51}:\\ \;\;\;\;\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) d)))
   (if (<= d -1.3e+150)
     t_0
     (if (<= d -0.48)
       (* a (/ (- d) (fma c c (* d d))))
       (if (<= d 2.15e+51) (/ (- b (/ (* d a) c)) c) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = -a / d;
	double tmp;
	if (d <= -1.3e+150) {
		tmp = t_0;
	} else if (d <= -0.48) {
		tmp = a * (-d / fma(c, c, (d * d)));
	} else if (d <= 2.15e+51) {
		tmp = (b - ((d * a) / c)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(Float64(-a) / d)
	tmp = 0.0
	if (d <= -1.3e+150)
		tmp = t_0;
	elseif (d <= -0.48)
		tmp = Float64(a * Float64(Float64(-d) / fma(c, c, Float64(d * d))));
	elseif (d <= 2.15e+51)
		tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c);
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[((-a) / d), $MachinePrecision]}, If[LessEqual[d, -1.3e+150], t$95$0, If[LessEqual[d, -0.48], N[(a * N[((-d) / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.15e+51], 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}{d}\\
\mathbf{if}\;d \leq -1.3 \cdot 10^{+150}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq -0.48:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.30000000000000003e150 or 2.1499999999999999e51 < d

    1. Initial program 32.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 \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
      2. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
      3. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
      6. neg-lowering-neg.f6468.8

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

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

    if -1.30000000000000003e150 < d < -0.47999999999999998

    1. Initial program 64.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6481.8

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{neg}\left(\frac{a \cdot d}{{c}^{2} + {d}^{2}}\right)} \]
      3. associate-/l*N/A

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

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

        \[\leadsto \mathsf{neg}\left(a \cdot \color{blue}{\frac{d}{{c}^{2} + {d}^{2}}}\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{neg}\left(a \cdot \frac{d}{\color{blue}{c \cdot c} + {d}^{2}}\right) \]
      7. accelerator-lowering-fma.f64N/A

        \[\leadsto \mathsf{neg}\left(a \cdot \frac{d}{\color{blue}{\mathsf{fma}\left(c, c, {d}^{2}\right)}}\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{neg}\left(a \cdot \frac{d}{\mathsf{fma}\left(c, c, \color{blue}{d \cdot d}\right)}\right) \]
      9. *-lowering-*.f6465.7

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

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

    if -0.47999999999999998 < d < 2.1499999999999999e51

    1. Initial program 64.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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      2. mul-1-negN/A

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. *-lowering-*.f6480.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+150}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -0.48:\\ \;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{+51}:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.65 \cdot 10^{-9}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\

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

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


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

    1. Initial program 47.9%

      \[\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 \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. mul-1-negN/A

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
      8. sub-negN/A

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

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

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

        \[\leadsto \frac{c \cdot \frac{b}{d} + \color{blue}{-1 \cdot a}}{d} \]
      12. accelerator-lowering-fma.f64N/A

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

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

        \[\leadsto \frac{\mathsf{fma}\left(c, \frac{b}{d}, \color{blue}{\mathsf{neg}\left(a\right)}\right)}{d} \]
      15. neg-lowering-neg.f6477.3

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

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

    if -1.65000000000000009e-9 < d < 3.2999999999999998e49

    1. Initial program 64.2%

      \[\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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      2. mul-1-negN/A

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. *-lowering-*.f6481.0

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

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

    if 3.2999999999999998e49 < d

    1. Initial program 35.4%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6444.2

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{b \cdot \frac{c}{{d}^{2}}} + -1 \cdot \frac{a}{d} \]
      3. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \mathsf{fma}\left(b, \color{blue}{\frac{c}{{d}^{2}}}, -1 \cdot \frac{a}{d}\right) \]
      5. unpow2N/A

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)}\right) \]
      8. distribute-neg-frac2N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}}\right) \]
      12. neg-lowering-neg.f6475.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{-d}\right)} \]
    8. Step-by-step derivation
      1. distribute-frac-neg2N/A

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

        \[\leadsto \color{blue}{b \cdot \frac{c}{d \cdot d} - \frac{a}{d}} \]
      3. *-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{d} \]
      10. /-lowering-/.f6480.8

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

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

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

Alternative 6: 77.6% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b \cdot \frac{c}{d} - a}{d}\\ \mathbf{if}\;d \leq -2.1 \cdot 10^{-9}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8 \cdot 10^{+49}:\\ \;\;\;\;\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 (/ (- (* b (/ c d)) a) d)))
   (if (<= d -2.1e-9) t_0 (if (<= d 8e+49) (/ (- b (/ (* d a) c)) c) t_0))))
double code(double a, double b, double c, double d) {
	double t_0 = ((b * (c / d)) - a) / d;
	double tmp;
	if (d <= -2.1e-9) {
		tmp = t_0;
	} else if (d <= 8e+49) {
		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 = ((b * (c / d)) - a) / d
    if (d <= (-2.1d-9)) then
        tmp = t_0
    else if (d <= 8d+49) 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 = ((b * (c / d)) - a) / d;
	double tmp;
	if (d <= -2.1e-9) {
		tmp = t_0;
	} else if (d <= 8e+49) {
		tmp = (b - ((d * a) / c)) / c;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = ((b * (c / d)) - a) / d
	tmp = 0
	if d <= -2.1e-9:
		tmp = t_0
	elif d <= 8e+49:
		tmp = (b - ((d * a) / c)) / c
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(Float64(b * Float64(c / d)) - a) / d)
	tmp = 0.0
	if (d <= -2.1e-9)
		tmp = t_0;
	elseif (d <= 8e+49)
		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 = ((b * (c / d)) - a) / d;
	tmp = 0.0;
	if (d <= -2.1e-9)
		tmp = t_0;
	elseif (d <= 8e+49)
		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[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -2.1e-9], t$95$0, If[LessEqual[d, 8e+49], 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{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{if}\;d \leq -2.1 \cdot 10^{-9}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq 8 \cdot 10^{+49}:\\
\;\;\;\;\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.10000000000000019e-9 or 7.99999999999999957e49 < d

    1. Initial program 42.3%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-subN/A

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

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

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

        \[\leadsto \left(\mathsf{neg}\left(\color{blue}{a \cdot \frac{d}{c \cdot c + d \cdot d}}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      5. distribute-lft-neg-inN/A

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{neg}\left(a\right), \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(c, c, d \cdot d\right)}}\right) \]
      15. *-lowering-*.f6451.4

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

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

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{{d}^{2}} + -1 \cdot \frac{a}{d}} \]
      2. associate-/l*N/A

        \[\leadsto \color{blue}{b \cdot \frac{c}{{d}^{2}}} + -1 \cdot \frac{a}{d} \]
      3. accelerator-lowering-fma.f64N/A

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

        \[\leadsto \mathsf{fma}\left(b, \color{blue}{\frac{c}{{d}^{2}}}, -1 \cdot \frac{a}{d}\right) \]
      5. unpow2N/A

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)}\right) \]
      8. distribute-neg-frac2N/A

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

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

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

        \[\leadsto \mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}}\right) \]
      12. neg-lowering-neg.f6471.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(b, \frac{c}{d \cdot d}, \frac{a}{-d}\right)} \]
    8. Step-by-step derivation
      1. distribute-frac-neg2N/A

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

        \[\leadsto \color{blue}{b \cdot \frac{c}{d \cdot d} - \frac{a}{d}} \]
      3. *-commutativeN/A

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{c}{d} \cdot b} - a}{d} \]
      10. /-lowering-/.f6478.4

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

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

    if -2.10000000000000019e-9 < d < 7.99999999999999957e49

    1. Initial program 64.2%

      \[\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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
      2. mul-1-negN/A

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

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

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

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

        \[\leadsto \frac{b - \frac{\color{blue}{d \cdot a}}{c}}{c} \]
      7. *-lowering-*.f6481.0

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

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

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

Alternative 7: 64.9% accurate, 0.9× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.80000000000000007e82 or 5.8000000000000001e-31 < c

    1. Initial program 37.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-/.f6469.2

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Simplified69.2%

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

    if -1.80000000000000007e82 < c < -1.7499999999999999e-91

    1. Initial program 83.2%

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

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

        \[\leadsto \color{blue}{\frac{b \cdot c}{{c}^{2} + {d}^{2}}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{c \cdot b}}{{c}^{2} + {d}^{2}} \]
      3. *-lowering-*.f64N/A

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

        \[\leadsto \frac{c \cdot b}{\color{blue}{{d}^{2} + {c}^{2}}} \]
      5. unpow2N/A

        \[\leadsto \frac{c \cdot b}{\color{blue}{d \cdot d} + {c}^{2}} \]
      6. accelerator-lowering-fma.f64N/A

        \[\leadsto \frac{c \cdot b}{\color{blue}{\mathsf{fma}\left(d, d, {c}^{2}\right)}} \]
      7. unpow2N/A

        \[\leadsto \frac{c \cdot b}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \]
      8. *-lowering-*.f6459.6

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

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

    if -1.7499999999999999e-91 < c < 5.8000000000000001e-31

    1. Initial program 64.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 \color{blue}{\mathsf{neg}\left(\frac{a}{d}\right)} \]
      2. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
      3. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
      6. neg-lowering-neg.f6466.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.8 \cdot 10^{+82}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -1.75 \cdot 10^{-91}:\\ \;\;\;\;\frac{c \cdot b}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 5.8 \cdot 10^{-31}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 64.2% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3500000:\\
\;\;\;\;\frac{b}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.5e6 or 2.59999999999999995e-31 < c

    1. Initial program 43.5%

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

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

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Simplified67.3%

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

    if -3.5e6 < c < 2.59999999999999995e-31

    1. Initial program 67.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}} \]
    4. Step-by-step derivation
      1. mul-1-negN/A

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

        \[\leadsto \color{blue}{\frac{a}{\mathsf{neg}\left(d\right)}} \]
      3. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{-1 \cdot d}} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \color{blue}{\frac{a}{-1 \cdot d}} \]
      5. mul-1-negN/A

        \[\leadsto \frac{a}{\color{blue}{\mathsf{neg}\left(d\right)}} \]
      6. neg-lowering-neg.f6461.6

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

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

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

Alternative 9: 43.0% accurate, 3.2× 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 54.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-/.f6445.0

      \[\leadsto \color{blue}{\frac{b}{c}} \]
  5. Simplified45.0%

    \[\leadsto \color{blue}{\frac{b}{c}} \]
  6. Add Preprocessing

Developer Target 1: 99.3% accurate, 0.6× 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 2024204 
(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))))