Complex division, imag part

Percentage Accurate: 61.2% → 79.5%
Time: 6.8s
Alternatives: 11
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 11 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.2% accurate, 1.0× speedup?

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

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

Alternative 1: 79.5% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-1}{\mathsf{fma}\left(d, {a}^{-1}, c \cdot \frac{c}{\mathsf{fma}\left(b, -c, a \cdot d\right)}\right)}\\ \mathbf{if}\;c \leq -1.7 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -6.5 \cdot 10^{+28}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-145}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-77}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+136}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ -1.0 (fma d (pow a -1.0) (* c (/ c (fma b (- c) (* a d))))))))
   (if (<= c -1.7e+138)
     (/ b c)
     (if (<= c -6.5e+28)
       t_0
       (if (<= c -1.05e-145)
         (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
         (if (<= c 2.2e-77)
           (/ (fma b (/ c d) (- a)) d)
           (if (<= c 8e+136) t_0 (/ (- b (/ (* a d) c)) c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = -1.0 / fma(d, pow(a, -1.0), (c * (c / fma(b, -c, (a * d)))));
	double tmp;
	if (c <= -1.7e+138) {
		tmp = b / c;
	} else if (c <= -6.5e+28) {
		tmp = t_0;
	} else if (c <= -1.05e-145) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 2.2e-77) {
		tmp = fma(b, (c / d), -a) / d;
	} else if (c <= 8e+136) {
		tmp = t_0;
	} else {
		tmp = (b - ((a * d) / c)) / c;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = Float64(-1.0 / fma(d, (a ^ -1.0), Float64(c * Float64(c / fma(b, Float64(-c), Float64(a * d))))))
	tmp = 0.0
	if (c <= -1.7e+138)
		tmp = Float64(b / c);
	elseif (c <= -6.5e+28)
		tmp = t_0;
	elseif (c <= -1.05e-145)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 2.2e-77)
		tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d);
	elseif (c <= 8e+136)
		tmp = t_0;
	else
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(-1.0 / N[(d * N[Power[a, -1.0], $MachinePrecision] + N[(c * N[(c / N[(b * (-c) + N[(a * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.7e+138], N[(b / c), $MachinePrecision], If[LessEqual[c, -6.5e+28], t$95$0, If[LessEqual[c, -1.05e-145], N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 2.2e-77], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 8e+136], t$95$0, N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;c \leq -6.5 \cdot 10^{+28}:\\
\;\;\;\;t\_0\\

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

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

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

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


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

    1. Initial program 43.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-/.f6487.5

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

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

    if -1.70000000000000006e138 < c < -6.5000000000000001e28 or 2.20000000000000007e-77 < c < 8.00000000000000047e136

    1. Initial program 64.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites64.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-1}{\mathsf{fma}\left(d, \color{blue}{\frac{1}{a}}, c \cdot \frac{c}{\mathsf{fma}\left(b, -c, a \cdot d\right)}\right)} \]
    7. Step-by-step derivation
      1. lower-/.f6488.0

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

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

    if -6.5000000000000001e28 < c < -1.04999999999999996e-145

    1. Initial program 90.4%

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

    if -1.04999999999999996e-145 < c < 2.20000000000000007e-77

    1. Initial program 69.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\mathsf{fma}\left(d, \frac{d}{\mathsf{fma}\left(b, -c, a \cdot d\right)}, c \cdot \frac{c}{\color{blue}{b \cdot \left(-c\right)} + a \cdot d}\right)} \]
      18. lower-fma.f6483.7

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

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

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

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

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

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

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

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

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

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

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

    if 8.00000000000000047e136 < c

    1. Initial program 33.8%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.7 \cdot 10^{+138}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq -6.5 \cdot 10^{+28}:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(d, {a}^{-1}, c \cdot \frac{c}{\mathsf{fma}\left(b, -c, a \cdot d\right)}\right)}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-145}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{-77}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+136}:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(d, {a}^{-1}, c \cdot \frac{c}{\mathsf{fma}\left(b, -c, a \cdot d\right)}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 84.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(b, -c, a \cdot d\right)\\ \mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{-1}{\mathsf{fma}\left(d, \frac{d}{t\_0}, c \cdot \frac{c}{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 b (- c) (* a d))))
   (if (<= (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) INFINITY)
     (/ -1.0 (fma d (/ d t_0) (* c (/ c t_0))))
     (/ (fma b (/ c d) (- a)) d))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(b, -c, (a * d));
	double tmp;
	if ((((b * c) - (a * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = -1.0 / fma(d, (d / t_0), (c * (c / t_0)));
	} else {
		tmp = fma(b, (c / d), -a) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(b, Float64(-c), Float64(a * d))
	tmp = 0.0
	if (Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(-1.0 / fma(d, Float64(d / t_0), Float64(c * Float64(c / 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[(b * (-c) + N[(a * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(-1.0 / N[(d * N[(d / t$95$0), $MachinePrecision] + N[(c * N[(c / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(b, -c, a \cdot d\right)\\
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{-1}{\mathsf{fma}\left(d, \frac{d}{t\_0}, c \cdot \frac{c}{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 2 regimes
  2. if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0

    1. Initial program 78.2%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites78.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites0.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\mathsf{fma}\left(d, \frac{d}{\mathsf{fma}\left(b, -c, a \cdot d\right)}, c \cdot \frac{c}{\color{blue}{b \cdot \left(-c\right)} + a \cdot d}\right)} \]
      18. lower-fma.f642.8

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 65.3% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -1.1 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_1}{d \cdot d}\\

\mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\
\;\;\;\;\frac{b}{c}\\

\mathbf{elif}\;d \leq 1.85 \cdot 10^{-88}:\\
\;\;\;\;\frac{t\_1}{c \cdot c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -4.2999999999999997e121 or 4.4999999999999999e139 < d

    1. Initial program 37.9%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Taylor expanded in c around 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.f6481.0

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

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

    if -4.2999999999999997e121 < d < -1.09999999999999993e-15

    1. Initial program 96.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 \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.0

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

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

    if -1.09999999999999993e-15 < d < 3.65e-186

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

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

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

    if 3.65e-186 < d < 1.8499999999999999e-88

    1. Initial program 87.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 \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-*.f6473.2

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

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

    if 1.8499999999999999e-88 < d < 4.4999999999999999e139

    1. Initial program 68.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.3 \cdot 10^{+121}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -1.1 \cdot 10^{-15}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{d \cdot d}\\ \mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{-88}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 65.7% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\
\;\;\;\;\frac{b}{c}\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.49999999999999992e78 or 4.4999999999999999e139 < d

    1. Initial program 45.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.f6480.9

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

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

    if -2.49999999999999992e78 < d < -9.99999999999999995e-91 or 1.8499999999999999e-88 < d < 4.4999999999999999e139

    1. Initial program 74.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999995e-91 < d < 3.65e-186

    1. Initial program 60.7%

      \[\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-/.f6473.0

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

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

    if 3.65e-186 < d < 1.8499999999999999e-88

    1. Initial program 87.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 \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-*.f6473.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{+78}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 3.65 \cdot 10^{-186}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{-88}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 76.2% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;c \leq -8.6 \cdot 10^{+46}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 1.7 \cdot 10^{+16}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -4.30000000000000035e125 or 1.7e16 < c

    1. Initial program 48.4%

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

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

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

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

    if -4.30000000000000035e125 < c < -8.60000000000000009e46 or -1.04999999999999996e-145 < c < 1.7e16

    1. Initial program 65.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites65.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -8.60000000000000009e46 < c < -1.04999999999999996e-145

    1. Initial program 90.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.3 \cdot 10^{+125}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -8.6 \cdot 10^{+46}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{elif}\;c \leq -1.05 \cdot 10^{-145}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{+16}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 65.1% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.49999999999999992e78 or 4.4999999999999999e139 < d

    1. Initial program 45.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.f6480.9

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

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

    if -2.49999999999999992e78 < d < -9.99999999999999995e-91 or 4.19999999999999982e-145 < d < 4.4999999999999999e139

    1. Initial program 78.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999995e-91 < d < 4.19999999999999982e-145

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{+78}:\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-90}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 4.2 \cdot 10^{-145}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+139}:\\ \;\;\;\;\left(-a\right) \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-a}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 71.9% accurate, 0.8× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -2.09999999999999985e131 or 7.60000000000000029e136 < c

    1. Initial program 39.7%

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

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

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

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

    if -2.09999999999999985e131 < c < 1.7e16

    1. Initial program 72.0%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.7e16 < c < 7.60000000000000029e136

    1. Initial program 79.3%

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

      \[\leadsto \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-*.f6469.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.1 \cdot 10^{+131}:\\ \;\;\;\;\frac{b}{c}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{+16}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \mathbf{elif}\;c \leq 7.6 \cdot 10^{+136}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 74.3% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -4.3 \cdot 10^{+125} \lor \neg \left(c \leq 1.7 \cdot 10^{+16}\right):\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \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 (or (<= c -4.3e+125) (not (<= c 1.7e+16)))
   (/ (- b (/ (* a d) c)) c)
   (/ (fma b (/ c d) (- a)) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -4.3e+125) || !(c <= 1.7e+16)) {
		tmp = (b - ((a * d) / c)) / c;
	} else {
		tmp = fma(b, (c / d), -a) / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -4.3e+125) || !(c <= 1.7e+16))
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	else
		tmp = Float64(fma(b, Float64(c / d), Float64(-a)) / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -4.3e+125], N[Not[LessEqual[c, 1.7e+16]], $MachinePrecision]], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b * N[(c / d), $MachinePrecision] + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.3 \cdot 10^{+125} \lor \neg \left(c \leq 1.7 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -4.30000000000000035e125 or 1.7e16 < c

    1. Initial program 48.4%

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

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

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

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

    if -4.30000000000000035e125 < c < 1.7e16

    1. Initial program 71.8%

      \[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Applied rewrites71.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-1}{\mathsf{fma}\left(d, \frac{d}{\mathsf{fma}\left(b, -c, a \cdot d\right)}, c \cdot \frac{c}{\color{blue}{b \cdot \left(-c\right)} + a \cdot d}\right)} \]
      18. lower-fma.f6482.2

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -4.3 \cdot 10^{+125} \lor \neg \left(c \leq 1.7 \cdot 10^{+16}\right):\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{c}{d}, -a\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 61.7% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.6 \cdot 10^{+123} \lor \neg \left(c \leq 7.1 \cdot 10^{+16}\right):\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.59999999999999998e123 or 7.1e16 < c

    1. Initial program 47.9%

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

      \[\leadsto \color{blue}{\frac{b}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6470.7

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

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

    if -3.59999999999999998e123 < c < 7.1e16

    1. Initial program 72.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.f6460.1

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

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

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

Alternative 10: 44.4% accurate, 1.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.6 \cdot 10^{+82} \lor \neg \left(d \leq 6.4 \cdot 10^{+173}\right):\\
\;\;\;\;\frac{a}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.5999999999999998e82 or 6.4000000000000005e173 < d

    1. Initial program 45.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a}{-d}} \]
    6. Step-by-step derivation
      1. Applied rewrites36.7%

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

      if -2.5999999999999998e82 < d < 6.4000000000000005e173

      1. Initial program 70.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-/.f6447.5

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

        \[\leadsto \color{blue}{\frac{b}{c}} \]
    7. Recombined 2 regimes into one program.
    8. Final simplification44.4%

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

    Alternative 11: 10.4% accurate, 3.2× speedup?

    \[\begin{array}{l} \\ \frac{a}{d} \end{array} \]
    (FPCore (a b c d) :precision binary64 (/ a d))
    double code(double a, double b, double c, double d) {
    	return a / d;
    }
    
    real(8) function code(a, b, c, d)
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8), intent (in) :: c
        real(8), intent (in) :: d
        code = a / d
    end function
    
    public static double code(double a, double b, double c, double d) {
    	return a / d;
    }
    
    def code(a, b, c, d):
    	return a / d
    
    function code(a, b, c, d)
    	return Float64(a / d)
    end
    
    function tmp = code(a, b, c, d)
    	tmp = a / d;
    end
    
    code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{a}{d}
    \end{array}
    
    Derivation
    1. Initial program 63.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.f6443.2

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

      \[\leadsto \color{blue}{\frac{a}{-d}} \]
    6. Step-by-step derivation
      1. Applied rewrites12.9%

        \[\leadsto \color{blue}{\frac{a}{d}} \]
      2. Final simplification12.9%

        \[\leadsto \frac{a}{d} \]
      3. Add Preprocessing

      Developer Target 1: 99.2% 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 2024305 
      (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))))