Complex division, imag part

Percentage Accurate: 61.7% → 80.8%
Time: 9.4s
Alternatives: 10
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 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 61.7% accurate, 1.0× speedup?

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

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

Alternative 1: 80.8% accurate, 0.5× speedup?

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

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

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

\mathbf{elif}\;d \leq 9.5 \cdot 10^{+90}:\\
\;\;\;\;\mathsf{fma}\left(-a, \frac{d}{t\_0}, \frac{c \cdot b}{t\_0}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -7.19999999999999948e-29

    1. Initial program 43.8%

      \[\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. lower-/.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. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(c, \frac{b}{d}, -1 \cdot a\right)}}{d} \]
      13. lower-/.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. lower-neg.f6475.8

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

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

    if -7.19999999999999948e-29 < d < 1.5e-100

    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 inf

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. lower-/.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. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
      5. lower-/.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. lower-*.f6488.2

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

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

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

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

        \[\leadsto \frac{b - \color{blue}{a \cdot \frac{d}{c}}}{c} \]
      4. lower-/.f6488.3

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

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

    if 1.5e-100 < d < 9.4999999999999994e90

    1. Initial program 83.6%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites85.7%

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

    if 9.4999999999999994e90 < d

    1. Initial program 48.7%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites51.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, \color{blue}{\mathsf{neg}\left(a\right)}\right)}{d} \]
      11. lower-neg.f6493.8

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 2: 65.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{if}\;c \leq -1.65 \cdot 10^{+162}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-216}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-66}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+45}:\\ \;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* b (/ c (fma c c (* d d))))))
   (if (<= c -1.65e+162)
     (/ b c)
     (if (<= c -4.5e-74)
       t_0
       (if (<= c 2.1e-216)
         (- (/ a d))
         (if (<= c 3.3e-66)
           (/ (- (* c b) (* d a)) (* d d))
           (if (<= c 1.5e+45)
             (* a (/ (- d) (fma d d (* c c))))
             (if (<= c 1.65e+136) t_0 (/ b c)))))))))
double code(double a, double b, double c, double d) {
	double t_0 = b * (c / fma(c, c, (d * d)));
	double tmp;
	if (c <= -1.65e+162) {
		tmp = b / c;
	} else if (c <= -4.5e-74) {
		tmp = t_0;
	} else if (c <= 2.1e-216) {
		tmp = -(a / d);
	} else if (c <= 3.3e-66) {
		tmp = ((c * b) - (d * a)) / (d * d);
	} else if (c <= 1.5e+45) {
		tmp = a * (-d / fma(d, d, (c * c)));
	} else if (c <= 1.65e+136) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(b * Float64(c / fma(c, c, Float64(d * d))))
	tmp = 0.0
	if (c <= -1.65e+162)
		tmp = Float64(b / c);
	elseif (c <= -4.5e-74)
		tmp = t_0;
	elseif (c <= 2.1e-216)
		tmp = Float64(-Float64(a / d));
	elseif (c <= 3.3e-66)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(d * d));
	elseif (c <= 1.5e+45)
		tmp = Float64(a * Float64(Float64(-d) / fma(d, d, Float64(c * c))));
	elseif (c <= 1.65e+136)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.65e+162], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.5e-74], t$95$0, If[LessEqual[c, 2.1e-216], (-N[(a / d), $MachinePrecision]), If[LessEqual[c, 3.3e-66], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.5e+45], N[(a * N[((-d) / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.65e+136], t$95$0, N[(b / c), $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\

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

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

\mathbf{elif}\;c \leq 1.5 \cdot 10^{+45}:\\
\;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\

\mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if c < -1.64999999999999994e162 or 1.64999999999999996e136 < c

    1. Initial program 24.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}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.1

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Applied rewrites72.1%

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

    if -1.64999999999999994e162 < c < -4.4999999999999999e-74 or 1.50000000000000005e45 < c < 1.64999999999999996e136

    1. Initial program 73.9%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites73.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto b \cdot \frac{c}{\mathsf{fma}\left(c, c, \color{blue}{d \cdot d}\right)} \]
      7. lower-*.f6470.4

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

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

    if -4.4999999999999999e-74 < c < 2.1000000000000002e-216

    1. Initial program 65.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. lower-/.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. lower-neg.f6483.8

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

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

    if 2.1000000000000002e-216 < c < 3.2999999999999999e-66

    1. Initial program 86.4%

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

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

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

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

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

    if 3.2999999999999999e-66 < c < 1.50000000000000005e45

    1. Initial program 80.9%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a \cdot d}{{c}^{2} + {d}^{2}}} \]
    4. 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. distribute-neg-frac2N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d \cdot a}{\mathsf{neg}\left(\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)\right)} \]
      11. lower-*.f6458.3

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \left(\mathsf{neg}\left(a\right)\right) \]
      11. lower-*.f6463.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.65 \cdot 10^{+162}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 2.1 \cdot 10^{-216}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 3.3 \cdot 10^{-66}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+45}:\\ \;\;\;\;a \cdot \frac{-d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 66.4% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{if}\;c \leq -1.65 \cdot 10^{+162}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 2.35 \cdot 10^{-45}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{+60}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* b (/ c (fma c c (* d d))))))
   (if (<= c -1.65e+162)
     (/ b c)
     (if (<= c -4.5e-74)
       t_0
       (if (<= c 2.35e-45)
         (- (/ a d))
         (if (<= c 1.05e+60)
           (/ (- (* c b) (* d a)) (* c c))
           (if (<= c 1.65e+136) t_0 (/ b c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = b * (c / fma(c, c, (d * d)));
	double tmp;
	if (c <= -1.65e+162) {
		tmp = b / c;
	} else if (c <= -4.5e-74) {
		tmp = t_0;
	} else if (c <= 2.35e-45) {
		tmp = -(a / d);
	} else if (c <= 1.05e+60) {
		tmp = ((c * b) - (d * a)) / (c * c);
	} else if (c <= 1.65e+136) {
		tmp = t_0;
	} else {
		tmp = b / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(b * Float64(c / fma(c, c, Float64(d * d))))
	tmp = 0.0
	if (c <= -1.65e+162)
		tmp = Float64(b / c);
	elseif (c <= -4.5e-74)
		tmp = t_0;
	elseif (c <= 2.35e-45)
		tmp = Float64(-Float64(a / d));
	elseif (c <= 1.05e+60)
		tmp = Float64(Float64(Float64(c * b) - Float64(d * a)) / Float64(c * c));
	elseif (c <= 1.65e+136)
		tmp = t_0;
	else
		tmp = Float64(b / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(b * N[(c / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.65e+162], N[(b / c), $MachinePrecision], If[LessEqual[c, -4.5e-74], t$95$0, If[LessEqual[c, 2.35e-45], (-N[(a / d), $MachinePrecision]), If[LessEqual[c, 1.05e+60], N[(N[(N[(c * b), $MachinePrecision] - N[(d * a), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.65e+136], t$95$0, N[(b / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\

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

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

\mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -1.64999999999999994e162 or 1.64999999999999996e136 < c

    1. Initial program 24.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}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.1

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Applied rewrites72.1%

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

    if -1.64999999999999994e162 < c < -4.4999999999999999e-74 or 1.0500000000000001e60 < c < 1.64999999999999996e136

    1. Initial program 75.0%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites74.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto b \cdot \frac{c}{\mathsf{fma}\left(c, c, \color{blue}{d \cdot d}\right)} \]
      7. lower-*.f6471.3

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

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

    if -4.4999999999999999e-74 < c < 2.3499999999999999e-45

    1. Initial program 71.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 \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. lower-/.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. lower-neg.f6474.3

        \[\leadsto \frac{a}{\color{blue}{-d}} \]
    5. Applied rewrites74.3%

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

    if 2.3499999999999999e-45 < c < 1.0500000000000001e60

    1. Initial program 87.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 \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. lower-*.f6465.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.65 \cdot 10^{+162}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;c \leq 2.35 \cdot 10^{-45}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;c \leq 1.05 \cdot 10^{+60}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c}\\ \mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\ \;\;\;\;b \cdot \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 80.5% accurate, 0.7× speedup?

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

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -7.19999999999999948e-29

    1. Initial program 43.8%

      \[\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. lower-/.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. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(c, \frac{b}{d}, -1 \cdot a\right)}}{d} \]
      13. lower-/.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. lower-neg.f6475.8

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

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

    if -7.19999999999999948e-29 < d < 1.5e-100

    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 inf

      \[\leadsto \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. lower-/.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. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
      5. lower-/.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. lower-*.f6488.2

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

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

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

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

        \[\leadsto \frac{b - \color{blue}{a \cdot \frac{d}{c}}}{c} \]
      4. lower-/.f6488.3

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

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

    if 1.5e-100 < d < 7.4e90

    1. Initial program 83.6%

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

    if 7.4e90 < d

    1. Initial program 48.7%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites51.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, \frac{c}{d}, \color{blue}{\mathsf{neg}\left(a\right)}\right)}{d} \]
      11. lower-neg.f6493.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.2 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\ \mathbf{elif}\;d \leq 1.5 \cdot 10^{-100}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{elif}\;d \leq 7.4 \cdot 10^{+90}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 66.8% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -4.5 \cdot 10^{-74}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 10^{-32}:\\
\;\;\;\;-\frac{a}{d}\\

\mathbf{elif}\;c \leq 1.65 \cdot 10^{+136}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.64999999999999994e162 or 1.64999999999999996e136 < c

    1. Initial program 24.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}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.1

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Applied rewrites72.1%

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

    if -1.64999999999999994e162 < c < -4.4999999999999999e-74 or 1.00000000000000006e-32 < c < 1.64999999999999996e136

    1. Initial program 77.0%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites76.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto b \cdot \frac{c}{\mathsf{fma}\left(c, c, \color{blue}{d \cdot d}\right)} \]
    9. Applied rewrites66.2%

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

    if -4.4999999999999999e-74 < c < 1.00000000000000006e-32

    1. Initial program 72.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. lower-/.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. lower-neg.f6473.0

        \[\leadsto \frac{a}{\color{blue}{-d}} \]
    5. Applied rewrites73.0%

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

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

Alternative 6: 73.2% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.99999999999999972e122 or 1.7e91 < d

    1. Initial program 35.6%

      \[\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. lower-/.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. lower-neg.f6475.2

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

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

    if -5.99999999999999972e122 < d < -7.19999999999999948e-29

    1. Initial program 73.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 \frac{b \cdot c - a \cdot d}{\color{blue}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

    if -7.19999999999999948e-29 < d < 1.7e91

    1. Initial program 73.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 \color{blue}{\frac{b + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. lower-/.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. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
      5. lower-/.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. lower-*.f6478.8

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6 \cdot 10^{+122}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{elif}\;d \leq -7.2 \cdot 10^{-29}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{+91}:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;-\frac{a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 78.1% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.19999999999999948e-29 or 4.4999999999999998e-29 < d

    1. Initial program 52.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. lower-/.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. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(c, \frac{b}{d}, -1 \cdot a\right)}}{d} \]
      13. lower-/.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. lower-neg.f6478.8

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

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

    if -7.19999999999999948e-29 < d < 4.4999999999999998e-29

    1. Initial program 70.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 + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. lower-/.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. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
      5. lower-/.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. lower-*.f6485.7

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

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

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

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

        \[\leadsto \frac{b - \color{blue}{a \cdot \frac{d}{c}}}{c} \]
      4. lower-/.f6485.8

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

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

Alternative 8: 77.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\
\mathbf{if}\;d \leq -7.2 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -7.19999999999999948e-29 or 4.4999999999999998e-29 < d

    1. Initial program 52.9%

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

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

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

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

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

        \[\leadsto \frac{b \cdot c - a \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      6. 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}} \]
      7. 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)} \]
      8. +-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}} \]
      9. lift-*.f64N/A

        \[\leadsto \left(\mathsf{neg}\left(\frac{\color{blue}{a \cdot d}}{c \cdot c + d \cdot d}\right)\right) + \frac{b \cdot c}{c \cdot c + d \cdot d} \]
      10. 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} \]
      11. 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} \]
      12. lower-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)} \]
    4. Applied rewrites56.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.19999999999999948e-29 < d < 4.4999999999999998e-29

    1. Initial program 70.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 + -1 \cdot \frac{a \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. lower-/.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. lower--.f64N/A

        \[\leadsto \frac{\color{blue}{b - \frac{a \cdot d}{c}}}{c} \]
      5. lower-/.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. lower-*.f6485.7

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

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

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

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

        \[\leadsto \frac{b - \color{blue}{a \cdot \frac{d}{c}}}{c} \]
      4. lower-/.f6485.8

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

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

Alternative 9: 63.5% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -8.5 \cdot 10^{-73}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\
\;\;\;\;-\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -8.4999999999999996e-73 or 3e59 < c

    1. Initial program 49.6%

      \[\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. lower-/.f6462.1

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    5. Applied rewrites62.1%

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

    if -8.4999999999999996e-73 < c < 3e59

    1. Initial program 73.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}} \]
    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. lower-/.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. lower-neg.f6469.0

        \[\leadsto \frac{a}{\color{blue}{-d}} \]
    5. Applied rewrites69.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -8.5 \cdot 10^{-73}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 3 \cdot 10^{+59}:\\ \;\;\;\;-\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 42.9% 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 60.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}{c}} \]
  4. Step-by-step derivation
    1. lower-/.f6441.5

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

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

Developer Target 1: 99.4% 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 2024216 
(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))))