Complex division, imag part

Percentage Accurate: 62.3% → 80.5%
Time: 8.9s
Alternatives: 9
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 62.3% accurate, 1.0× speedup?

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

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

Alternative 1: 80.5% accurate, 0.4× speedup?

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

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

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

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

\mathbf{elif}\;d \leq 0.0102:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -3e74

    1. Initial program 53.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3e74 < d < -2.39999999999999998e54

    1. Initial program 17.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999998e54 < d < -1.25000000000000008e-153

    1. Initial program 86.4%

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

    if -1.25000000000000008e-153 < d < 0.010200000000000001

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

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

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

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

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

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

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

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

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

    if 0.010200000000000001 < d

    1. Initial program 58.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3 \cdot 10^{+74}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{b}{d}, -a\right)}{d}\\ \mathbf{elif}\;d \leq -2.4 \cdot 10^{+54}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{c}, \frac{d \cdot \left(d \cdot d\right)}{c \cdot c} - d, \mathsf{fma}\left(\frac{d \cdot d}{c \cdot c}, -b, b\right)\right)}{c}\\ \mathbf{elif}\;d \leq -1.25 \cdot 10^{-153}:\\ \;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;d \leq 0.0102:\\ \;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{b}{d}, \frac{a}{-d}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.4% accurate, 0.6× speedup?

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

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

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

\mathbf{elif}\;d \leq 0.0102:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -9.5000000000000003e29

    1. Initial program 53.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} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5000000000000003e29 < d < -1.25000000000000008e-153

    1. Initial program 84.7%

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

    if -1.25000000000000008e-153 < d < 0.010200000000000001

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

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

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

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

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

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

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

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

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

    if 0.010200000000000001 < d

    1. Initial program 58.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 80.5% accurate, 0.8× speedup?

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

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

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

\mathbf{elif}\;d \leq 0.0102:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9.5000000000000003e29 or 0.010200000000000001 < d

    1. Initial program 56.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} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.5000000000000003e29 < d < -1.25000000000000008e-153

    1. Initial program 84.7%

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

    if -1.25000000000000008e-153 < d < 0.010200000000000001

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

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

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

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

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

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

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

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

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

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

Alternative 4: 73.4% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 0.0102:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.7499999999999999e28 or 5.6e142 < d

    1. Initial program 43.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.f6475.1

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

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

    if -3.7499999999999999e28 < d < 0.010200000000000001

    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 inf

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

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

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

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

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

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

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

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

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

    if 0.010200000000000001 < d < 5.6e142

    1. Initial program 91.1%

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

      \[\leadsto \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-*.f6479.8

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

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

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

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

        \[\leadsto \frac{c \cdot b - \color{blue}{d \cdot a}}{d \cdot d} \]
      4. cancel-sign-sub-invN/A

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

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

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

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

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

Alternative 5: 64.5% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 0.00039:\\
\;\;\;\;\frac{b}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8e22 or 5.6e142 < d

    1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

    if -8e22 < d < 3.89999999999999993e-4

    1. Initial program 72.0%

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

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

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

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

    if 3.89999999999999993e-4 < d < 5.6e142

    1. Initial program 91.1%

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

      \[\leadsto \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-*.f6479.8

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

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

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

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

        \[\leadsto \frac{c \cdot b - \color{blue}{d \cdot a}}{d \cdot d} \]
      4. cancel-sign-sub-invN/A

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

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

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

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

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

Alternative 6: 64.5% accurate, 0.8× speedup?

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

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

\mathbf{elif}\;d \leq 0.00039:\\
\;\;\;\;\frac{b}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8e22 or 5.6e142 < d

    1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

    if -8e22 < d < 3.89999999999999993e-4

    1. Initial program 72.0%

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

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

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

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

    if 3.89999999999999993e-4 < d < 5.6e142

    1. Initial program 91.1%

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

      \[\leadsto \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-*.f6479.8

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

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

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

Alternative 7: 78.5% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;d \leq 0.0102:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.6e-24 or 0.010200000000000001 < d

    1. Initial program 58.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} + \frac{b \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.6e-24 < d < 0.010200000000000001

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

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

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

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

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

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

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

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

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

Alternative 8: 63.8% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;d \leq 0.00145:\\
\;\;\;\;\frac{b}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -8e22 or 0.00145 < d

    1. Initial program 56.9%

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

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

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

    if -8e22 < d < 0.00145

    1. Initial program 72.0%

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

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

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

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

Alternative 9: 42.0% accurate, 3.2× speedup?

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

\\
\frac{b}{c}
\end{array}
Derivation
  1. Initial program 64.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-/.f6440.0

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

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

Developer Target 1: 99.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (< (fabs d) (fabs c))
   (/ (- b (* a (/ d c))) (+ c (* d (/ d c))))
   (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (fabs(d) < fabs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (abs(d) < abs(c)) then
        tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
    else
        tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (Math.abs(d) < Math.abs(c)) {
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	} else {
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if math.fabs(d) < math.fabs(c):
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
	else:
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (abs(d) < abs(c))
		tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
	else
		tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (abs(d) < abs(c))
		tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
	else
		tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\

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


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024207 
(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))))