Complex division, imag part

Percentage Accurate: 61.0% → 81.3%
Time: 7.2s
Alternatives: 7
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 7 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.0% 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: 81.3% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\ \mathbf{if}\;c \leq -3.8 \cdot 10^{+72}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-80}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+112}:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{t\_0}{b}\right)}^{-1}, c, \left(-d\right) \cdot \frac{a}{t\_0}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-b}{{c}^{3}}, d, \frac{\frac{-a}{c}}{c}\right), d, \frac{b}{c}\right)\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (fma d d (* c c))))
   (if (<= c -3.8e+72)
     (/ (- b (/ (* a d) c)) c)
     (if (<= c -2.5e-121)
       (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))
       (if (<= c 1.2e-80)
         (/ (- (/ (* b c) d) a) d)
         (if (<= c 1.5e+112)
           (fma (pow (/ t_0 b) -1.0) c (* (- d) (/ a t_0)))
           (fma
            (fma (/ (- b) (pow c 3.0)) d (/ (/ (- a) c) c))
            d
            (/ b c))))))))
double code(double a, double b, double c, double d) {
	double t_0 = fma(d, d, (c * c));
	double tmp;
	if (c <= -3.8e+72) {
		tmp = (b - ((a * d) / c)) / c;
	} else if (c <= -2.5e-121) {
		tmp = ((b * c) - (a * d)) / ((c * c) + (d * d));
	} else if (c <= 1.2e-80) {
		tmp = (((b * c) / d) - a) / d;
	} else if (c <= 1.5e+112) {
		tmp = fma(pow((t_0 / b), -1.0), c, (-d * (a / t_0)));
	} else {
		tmp = fma(fma((-b / pow(c, 3.0)), d, ((-a / c) / c)), d, (b / c));
	}
	return tmp;
}
function code(a, b, c, d)
	t_0 = fma(d, d, Float64(c * c))
	tmp = 0.0
	if (c <= -3.8e+72)
		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
	elseif (c <= -2.5e-121)
		tmp = Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (c <= 1.2e-80)
		tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d);
	elseif (c <= 1.5e+112)
		tmp = fma((Float64(t_0 / b) ^ -1.0), c, Float64(Float64(-d) * Float64(a / t_0)));
	else
		tmp = fma(fma(Float64(Float64(-b) / (c ^ 3.0)), d, Float64(Float64(Float64(-a) / c) / c)), d, Float64(b / c));
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -3.8e+72], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, -2.5e-121], 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.2e-80], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.5e+112], N[(N[Power[N[(t$95$0 / b), $MachinePrecision], -1.0], $MachinePrecision] * c + N[((-d) * N[(a / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[((-b) / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] * d + N[(N[((-a) / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * d + N[(b / c), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

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

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

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

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


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

    1. Initial program 35.5%

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

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

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

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

    if -3.80000000000000006e72 < c < -2.49999999999999995e-121

    1. Initial program 80.4%

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

    if -2.49999999999999995e-121 < c < 1.2e-80

    1. Initial program 61.2%

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d}} - a}{d} \]
      10. lower-*.f6494.6

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

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

    if 1.2e-80 < c < 1.4999999999999999e112

    1. Initial program 79.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.4999999999999999e112 < c

    1. Initial program 27.5%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot \left(c \cdot c + d \cdot d\right) - \frac{c \cdot c + d \cdot d}{b \cdot c} \cdot \left(a \cdot d\right)}{\frac{c \cdot c + d \cdot d}{b \cdot c} \cdot \left(c \cdot c + d \cdot d\right)}} \]
    4. Applied rewrites2.3%

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{a}{{c}^{2}} + d \cdot \left(\frac{b}{{c}^{3}} - 2 \cdot \frac{b}{{c}^{3}}\right), d, \frac{b}{c}\right)} \]
    7. Applied rewrites81.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.8 \cdot 10^{+72}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \mathbf{elif}\;c \leq -2.5 \cdot 10^{-121}:\\ \;\;\;\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-80}:\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{elif}\;c \leq 1.5 \cdot 10^{+112}:\\ \;\;\;\;\mathsf{fma}\left({\left(\frac{\mathsf{fma}\left(d, d, c \cdot c\right)}{b}\right)}^{-1}, c, \left(-d\right) \cdot \frac{a}{\mathsf{fma}\left(d, d, c \cdot c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{-b}{{c}^{3}}, d, \frac{\frac{-a}{c}}{c}\right), d, \frac{b}{c}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.4% accurate, 0.5× speedup?

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

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

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

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

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


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

    1. Initial program 39.6%

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

      \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \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. lower--.f64N/A

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

        \[\leadsto \frac{\color{blue}{\frac{b \cdot c}{d}} - a}{d} \]
      10. lower-*.f6479.8

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

      \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
    6. Step-by-step derivation
      1. Applied rewrites82.5%

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

      if -5.6999999999999998e-9 < d < 1.8999999999999999e-126

      1. Initial program 63.5%

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

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

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

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

      if 1.8999999999999999e-126 < d < 1.4e125

      1. Initial program 77.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 3: 78.3% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{-9} \lor \neg \left(d \leq 7.8 \cdot 10^{+27}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (or (<= d -5.7e-9) (not (<= d 7.8e+27)))
       (/ (fma (/ c d) b (- a)) d)
       (/ (- b (/ (* a d) c)) c)))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if ((d <= -5.7e-9) || !(d <= 7.8e+27)) {
    		tmp = fma((c / d), b, -a) / d;
    	} else {
    		tmp = (b - ((a * d) / c)) / c;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if ((d <= -5.7e-9) || !(d <= 7.8e+27))
    		tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d);
    	else
    		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
    	end
    	return tmp
    end
    
    code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.7e-9], N[Not[LessEqual[d, 7.8e+27]], $MachinePrecision]], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -5.7 \cdot 10^{-9} \lor \neg \left(d \leq 7.8 \cdot 10^{+27}\right):\\
    \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if d < -5.6999999999999998e-9 or 7.7999999999999997e27 < d

      1. Initial program 43.7%

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

        \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \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. lower--.f64N/A

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{b \cdot c}{d} - a}{d}} \]
      6. Step-by-step derivation
        1. Applied rewrites80.5%

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

        if -5.6999999999999998e-9 < d < 7.7999999999999997e27

        1. Initial program 66.9%

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{b - \frac{a \cdot d}{c}}{c}} \]
      7. Recombined 2 regimes into one program.
      8. Final simplification82.6%

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

      Alternative 4: 76.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -5.7 \cdot 10^{-9} \lor \neg \left(d \leq 7.8 \cdot 10^{+27}\right):\\ \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -5.7e-9) (not (<= d 7.8e+27)))
         (/ (- (/ (* b c) d) a) d)
         (/ (- b (/ (* a d) c)) c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -5.7e-9) || !(d <= 7.8e+27)) {
      		tmp = (((b * c) / d) - a) / d;
      	} else {
      		tmp = (b - ((a * d) / c)) / c;
      	}
      	return tmp;
      }
      
      real(8) function code(a, b, c, d)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: c
          real(8), intent (in) :: d
          real(8) :: tmp
          if ((d <= (-5.7d-9)) .or. (.not. (d <= 7.8d+27))) then
              tmp = (((b * c) / d) - a) / d
          else
              tmp = (b - ((a * d) / c)) / c
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -5.7e-9) || !(d <= 7.8e+27)) {
      		tmp = (((b * c) / d) - a) / d;
      	} else {
      		tmp = (b - ((a * d) / c)) / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if (d <= -5.7e-9) or not (d <= 7.8e+27):
      		tmp = (((b * c) / d) - a) / d
      	else:
      		tmp = (b - ((a * d) / c)) / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -5.7e-9) || !(d <= 7.8e+27))
      		tmp = Float64(Float64(Float64(Float64(b * c) / d) - a) / d);
      	else
      		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if ((d <= -5.7e-9) || ~((d <= 7.8e+27)))
      		tmp = (((b * c) / d) - a) / d;
      	else
      		tmp = (b - ((a * d) / c)) / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -5.7e-9], N[Not[LessEqual[d, 7.8e+27]], $MachinePrecision]], N[(N[(N[(N[(b * c), $MachinePrecision] / d), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -5.7 \cdot 10^{-9} \lor \neg \left(d \leq 7.8 \cdot 10^{+27}\right):\\
      \;\;\;\;\frac{\frac{b \cdot c}{d} - a}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -5.6999999999999998e-9 or 7.7999999999999997e27 < d

        1. Initial program 43.7%

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

          \[\leadsto \color{blue}{-1 \cdot \frac{a}{d} + \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. lower--.f64N/A

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

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

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

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

        if -5.6999999999999998e-9 < d < 7.7999999999999997e27

        1. Initial program 66.9%

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

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

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

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

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

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

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

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

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

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

      Alternative 5: 73.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -950000 \lor \neg \left(d \leq 2.8 \cdot 10^{+44}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -950000.0) (not (<= d 2.8e+44)))
         (/ (- a) d)
         (/ (- b (/ (* a d) c)) c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -950000.0) || !(d <= 2.8e+44)) {
      		tmp = -a / d;
      	} else {
      		tmp = (b - ((a * d) / c)) / c;
      	}
      	return tmp;
      }
      
      real(8) function code(a, b, c, d)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: c
          real(8), intent (in) :: d
          real(8) :: tmp
          if ((d <= (-950000.0d0)) .or. (.not. (d <= 2.8d+44))) then
              tmp = -a / d
          else
              tmp = (b - ((a * d) / c)) / c
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -950000.0) || !(d <= 2.8e+44)) {
      		tmp = -a / d;
      	} else {
      		tmp = (b - ((a * d) / c)) / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if (d <= -950000.0) or not (d <= 2.8e+44):
      		tmp = -a / d
      	else:
      		tmp = (b - ((a * d) / c)) / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -950000.0) || !(d <= 2.8e+44))
      		tmp = Float64(Float64(-a) / d);
      	else
      		tmp = Float64(Float64(b - Float64(Float64(a * d) / c)) / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if ((d <= -950000.0) || ~((d <= 2.8e+44)))
      		tmp = -a / d;
      	else
      		tmp = (b - ((a * d) / c)) / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -950000.0], N[Not[LessEqual[d, 2.8e+44]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(N[(a * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -950000 \lor \neg \left(d \leq 2.8 \cdot 10^{+44}\right):\\
      \;\;\;\;\frac{-a}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b - \frac{a \cdot d}{c}}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -9.5e5 or 2.8000000000000001e44 < d

        1. Initial program 42.4%

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

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

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

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

        if -9.5e5 < d < 2.8000000000000001e44

        1. Initial program 67.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. lower-*.f6483.5

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

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

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

      Alternative 6: 64.0% accurate, 1.5× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{-12} \lor \neg \left(d \leq 3 \cdot 10^{+34}\right):\\ \;\;\;\;\frac{-a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -1.5e-12) (not (<= d 3e+34))) (/ (- a) d) (/ b c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -1.5e-12) || !(d <= 3e+34)) {
      		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 <= (-1.5d-12)) .or. (.not. (d <= 3d+34))) 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 <= -1.5e-12) || !(d <= 3e+34)) {
      		tmp = -a / d;
      	} else {
      		tmp = b / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if (d <= -1.5e-12) or not (d <= 3e+34):
      		tmp = -a / d
      	else:
      		tmp = b / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -1.5e-12) || !(d <= 3e+34))
      		tmp = Float64(Float64(-a) / d);
      	else
      		tmp = Float64(b / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if ((d <= -1.5e-12) || ~((d <= 3e+34)))
      		tmp = -a / d;
      	else
      		tmp = b / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.5e-12], N[Not[LessEqual[d, 3e+34]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -1.5 \cdot 10^{-12} \lor \neg \left(d \leq 3 \cdot 10^{+34}\right):\\
      \;\;\;\;\frac{-a}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -1.5000000000000001e-12 or 3.00000000000000018e34 < d

        1. Initial program 43.3%

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

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

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

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

        if -1.5000000000000001e-12 < d < 3.00000000000000018e34

        1. Initial program 67.2%

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

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

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

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

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

      Alternative 7: 43.1% 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 55.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-/.f6446.3

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

        \[\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 2024315 
      (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))))