Complex division, real part

Percentage Accurate: 61.6% → 80.1%
Time: 6.4s
Alternatives: 8
Speedup: 1.6×

Specification

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

\\
\frac{a \cdot c + b \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 8 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.6% accurate, 1.0× speedup?

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

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

Alternative 1: 80.1% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.10699999999999994e-4 or 1.85000000000000005e75 < d

    1. Initial program 55.2%

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

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

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

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

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

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

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

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

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

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

    if -1.10699999999999994e-4 < d < 9.50000000000000043e-64

    1. Initial program 70.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{a + \frac{-1 \cdot \frac{a \cdot {d}^{2}}{c} + b \cdot d}{c}}{c}} \]
    5. Applied rewrites91.6%

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

    if 9.50000000000000043e-64 < d < 1.85000000000000005e75

    1. Initial program 91.3%

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

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

Alternative 2: 79.5% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.10699999999999994e-4 or 1.85000000000000005e75 < d

    1. Initial program 55.2%

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

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

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

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

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

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

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

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

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

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

    if -1.10699999999999994e-4 < d < 9.50000000000000043e-64

    1. Initial program 70.1%

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

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

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

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

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

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

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

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

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

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

    if 9.50000000000000043e-64 < d < 1.85000000000000005e75

    1. Initial program 91.3%

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

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

Alternative 3: 64.1% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
\;\;\;\;\frac{t\_0}{c \cdot c}\\

\mathbf{elif}\;d \leq 4.4 \cdot 10^{+155}:\\
\;\;\;\;\frac{t\_0}{d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.10699999999999994e-4 or 4.4000000000000005e155 < d

    1. Initial program 53.5%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
    4. Step-by-step derivation
      1. lower-/.f6478.6

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites78.6%

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

    if -1.10699999999999994e-4 < d < 8.79999999999999939e-244

    1. Initial program 64.8%

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

      \[\leadsto \color{blue}{\frac{a}{c}} \]
    4. Step-by-step derivation
      1. lower-/.f6472.8

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Applied rewrites72.8%

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

    if 8.79999999999999939e-244 < d < 2.15000000000000007e-44

    1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{c}^{2}}} \]
    7. Step-by-step derivation
      1. Applied rewrites73.9%

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

      if 2.15000000000000007e-44 < d < 4.4000000000000005e155

      1. Initial program 79.7%

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

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

          \[\leadsto \color{blue}{\frac{a}{c}} \]
      5. Applied rewrites33.1%

        \[\leadsto \color{blue}{\frac{a}{c}} \]
      6. Taylor expanded in d around inf

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{d}^{2}}} \]
      10. Step-by-step derivation
        1. Applied rewrites65.9%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\ \mathbf{elif}\;d \leq 4.4 \cdot 10^{+155}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
      13. Add Preprocessing

      Alternative 4: 69.7% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (let* ((t_0 (/ (fma (/ a d) c b) d)))
         (if (<= d -0.0001107)
           t_0
           (if (<= d 8.8e-244)
             (/ a c)
             (if (<= d 2.15e-44) (/ (fma c a (* b d)) (* c c)) t_0)))))
      double code(double a, double b, double c, double d) {
      	double t_0 = fma((a / d), c, b) / d;
      	double tmp;
      	if (d <= -0.0001107) {
      		tmp = t_0;
      	} else if (d <= 8.8e-244) {
      		tmp = a / c;
      	} else if (d <= 2.15e-44) {
      		tmp = fma(c, a, (b * d)) / (c * c);
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	t_0 = Float64(fma(Float64(a / d), c, b) / d)
      	tmp = 0.0
      	if (d <= -0.0001107)
      		tmp = t_0;
      	elseif (d <= 8.8e-244)
      		tmp = Float64(a / c);
      	elseif (d <= 2.15e-44)
      		tmp = Float64(fma(c, a, Float64(b * d)) / Float64(c * c));
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.0001107], t$95$0, If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.15e-44], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
      \mathbf{if}\;d \leq -0.0001107:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if d < -1.10699999999999994e-4 or 2.15000000000000007e-44 < d

        1. Initial program 59.9%

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

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

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

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

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

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

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

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

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

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

        if -1.10699999999999994e-4 < d < 8.79999999999999939e-244

        1. Initial program 64.8%

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

          \[\leadsto \color{blue}{\frac{a}{c}} \]
        4. Step-by-step derivation
          1. lower-/.f6472.8

            \[\leadsto \color{blue}{\frac{a}{c}} \]
        5. Applied rewrites72.8%

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

        if 8.79999999999999939e-244 < d < 2.15000000000000007e-44

        1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{c}^{2}}} \]
        7. Step-by-step derivation
          1. Applied rewrites73.9%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 2.15 \cdot 10^{-44}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
        10. Add Preprocessing

        Alternative 5: 63.3% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
        (FPCore (a b c d)
         :precision binary64
         (if (<= d -0.0001107)
           (/ b d)
           (if (<= d 8.8e-244)
             (/ a c)
             (if (<= d 1.2e-42) (/ (fma c a (* b d)) (* c c)) (/ b d)))))
        double code(double a, double b, double c, double d) {
        	double tmp;
        	if (d <= -0.0001107) {
        		tmp = b / d;
        	} else if (d <= 8.8e-244) {
        		tmp = a / c;
        	} else if (d <= 1.2e-42) {
        		tmp = fma(c, a, (b * d)) / (c * c);
        	} else {
        		tmp = b / d;
        	}
        	return tmp;
        }
        
        function code(a, b, c, d)
        	tmp = 0.0
        	if (d <= -0.0001107)
        		tmp = Float64(b / d);
        	elseif (d <= 8.8e-244)
        		tmp = Float64(a / c);
        	elseif (d <= 1.2e-42)
        		tmp = Float64(fma(c, a, Float64(b * d)) / Float64(c * c));
        	else
        		tmp = Float64(b / d);
        	end
        	return tmp
        end
        
        code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 8.8e-244], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.2e-42], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;d \leq -0.0001107:\\
        \;\;\;\;\frac{b}{d}\\
        
        \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\
        \;\;\;\;\frac{a}{c}\\
        
        \mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
        \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\
        
        \mathbf{else}:\\
        \;\;\;\;\frac{b}{d}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d

          1. Initial program 59.9%

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

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

              \[\leadsto \color{blue}{\frac{b}{d}} \]
          5. Applied rewrites69.3%

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

          if -1.10699999999999994e-4 < d < 8.79999999999999939e-244

          1. Initial program 64.8%

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

            \[\leadsto \color{blue}{\frac{a}{c}} \]
          4. Step-by-step derivation
            1. lower-/.f6472.8

              \[\leadsto \color{blue}{\frac{a}{c}} \]
          5. Applied rewrites72.8%

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

          if 8.79999999999999939e-244 < d < 1.20000000000000001e-42

          1. Initial program 80.8%

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{{c}^{2}}} \]
          7. Step-by-step derivation
            1. Applied rewrites73.9%

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 8.8 \cdot 10^{-244}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
          10. Add Preprocessing

          Alternative 6: 77.0% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (a b c d)
           :precision binary64
           (let* ((t_0 (/ (fma (/ a d) c b) d)))
             (if (<= d -0.0001107) t_0 (if (<= d 1.2e-42) (/ (fma (/ b c) d a) c) t_0))))
          double code(double a, double b, double c, double d) {
          	double t_0 = fma((a / d), c, b) / d;
          	double tmp;
          	if (d <= -0.0001107) {
          		tmp = t_0;
          	} else if (d <= 1.2e-42) {
          		tmp = fma((b / c), d, a) / c;
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          function code(a, b, c, d)
          	t_0 = Float64(fma(Float64(a / d), c, b) / d)
          	tmp = 0.0
          	if (d <= -0.0001107)
          		tmp = t_0;
          	elseif (d <= 1.2e-42)
          		tmp = Float64(fma(Float64(b / c), d, a) / c);
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -0.0001107], t$95$0, If[LessEqual[d, 1.2e-42], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
          \mathbf{if}\;d \leq -0.0001107:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;d \leq 1.2 \cdot 10^{-42}:\\
          \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d < -1.10699999999999994e-4 or 1.20000000000000001e-42 < d

            1. Initial program 59.9%

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

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

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

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

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

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

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

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

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

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

            if -1.10699999999999994e-4 < d < 1.20000000000000001e-42

            1. Initial program 71.1%

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

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

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

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

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

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

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

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

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

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

          Alternative 7: 63.3% accurate, 1.6× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -0.0001107:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{-54}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
          (FPCore (a b c d)
           :precision binary64
           (if (<= d -0.0001107) (/ b d) (if (<= d 1.15e-54) (/ a c) (/ b d))))
          double code(double a, double b, double c, double d) {
          	double tmp;
          	if (d <= -0.0001107) {
          		tmp = b / d;
          	} else if (d <= 1.15e-54) {
          		tmp = a / c;
          	} else {
          		tmp = b / 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 (d <= (-0.0001107d0)) then
                  tmp = b / d
              else if (d <= 1.15d-54) then
                  tmp = a / c
              else
                  tmp = b / d
              end if
              code = tmp
          end function
          
          public static double code(double a, double b, double c, double d) {
          	double tmp;
          	if (d <= -0.0001107) {
          		tmp = b / d;
          	} else if (d <= 1.15e-54) {
          		tmp = a / c;
          	} else {
          		tmp = b / d;
          	}
          	return tmp;
          }
          
          def code(a, b, c, d):
          	tmp = 0
          	if d <= -0.0001107:
          		tmp = b / d
          	elif d <= 1.15e-54:
          		tmp = a / c
          	else:
          		tmp = b / d
          	return tmp
          
          function code(a, b, c, d)
          	tmp = 0.0
          	if (d <= -0.0001107)
          		tmp = Float64(b / d);
          	elseif (d <= 1.15e-54)
          		tmp = Float64(a / c);
          	else
          		tmp = Float64(b / d);
          	end
          	return tmp
          end
          
          function tmp_2 = code(a, b, c, d)
          	tmp = 0.0;
          	if (d <= -0.0001107)
          		tmp = b / d;
          	elseif (d <= 1.15e-54)
          		tmp = a / c;
          	else
          		tmp = b / d;
          	end
          	tmp_2 = tmp;
          end
          
          code[a_, b_, c_, d_] := If[LessEqual[d, -0.0001107], N[(b / d), $MachinePrecision], If[LessEqual[d, 1.15e-54], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d \leq -0.0001107:\\
          \;\;\;\;\frac{b}{d}\\
          
          \mathbf{elif}\;d \leq 1.15 \cdot 10^{-54}:\\
          \;\;\;\;\frac{a}{c}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{b}{d}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if d < -1.10699999999999994e-4 or 1.1499999999999999e-54 < d

            1. Initial program 60.2%

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

              \[\leadsto \color{blue}{\frac{b}{d}} \]
            4. Step-by-step derivation
              1. lower-/.f6468.9

                \[\leadsto \color{blue}{\frac{b}{d}} \]
            5. Applied rewrites68.9%

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

            if -1.10699999999999994e-4 < d < 1.1499999999999999e-54

            1. Initial program 70.9%

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

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

                \[\leadsto \color{blue}{\frac{a}{c}} \]
            5. Applied rewrites70.0%

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

          Alternative 8: 42.6% accurate, 3.2× speedup?

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

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

            \[\leadsto \color{blue}{\frac{a}{c}} \]
          4. Step-by-step derivation
            1. lower-/.f6442.5

              \[\leadsto \color{blue}{\frac{a}{c}} \]
          5. Applied rewrites42.5%

            \[\leadsto \color{blue}{\frac{a}{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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \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))
             (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
             (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
          double code(double a, double b, double c, double d) {
          	double tmp;
          	if (fabs(d) < fabs(c)) {
          		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
          	} else {
          		tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
              else
                  tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
          	} else {
          		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
          	}
          	return tmp;
          }
          
          def code(a, b, c, d):
          	tmp = 0
          	if math.fabs(d) < math.fabs(c):
          		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
          	else:
          		tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
          	else
          		tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c)));
          	else
          		tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
          
          
          \end{array}
          \end{array}
          

          Reproduce

          ?
          herbie shell --seed 2024235 
          (FPCore (a b c d)
            :name "Complex division, real part"
            :precision binary64
          
            :alt
            (! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
          
            (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))