Complex division, real part

Percentage Accurate: 63.4% → 84.9%
Time: 10.5s
Alternatives: 11
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 11 alternatives:

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

Initial Program: 63.4% 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: 84.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;c \leq -2.05 \cdot 10^{-69}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;c \leq 1.25 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -6.2000000000000001e147 or 1.25000000000000001e154 < c

    1. Initial program 27.5%

      \[\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. /-lowering-/.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. associate-/l*N/A

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

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

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

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

    if -6.2000000000000001e147 < c < -2.04999999999999995e-69 or 1.2e-174 < c < 1.25000000000000001e154

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, b \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}\right) \]
      16. *-lowering-*.f6484.2

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

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

    if -2.04999999999999995e-69 < c < 1.2e-174

    1. Initial program 72.8%

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

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

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

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

Alternative 2: 82.0% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -2.35 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 6.6 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 31.4%

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

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

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

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

    if -5.4999999999999996e139 < d < -2.34999999999999996e-11 or 1.85000000000000009e-90 < d < 6.6000000000000003e140

    1. Initial program 83.1%

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

    if -2.34999999999999996e-11 < d < 1.85000000000000009e-90

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.6000000000000003e140 < d

    1. Initial program 31.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
      7. *-lowering-*.f6431.8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, b \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}\right) \]
      16. *-lowering-*.f6439.2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.5 \cdot 10^{+139}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -2.35 \cdot 10^{-11}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 1.85 \cdot 10^{-90}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{c}, \frac{b \cdot d}{c}, \frac{a}{c}\right)\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{+140}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 82.5% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -3 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.8 \cdot 10^{+140}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 31.4%

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

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

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

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

    if -1.5e139 < d < -3e-11 or 3.00000000000000024e-97 < d < 2.79999999999999983e140

    1. Initial program 83.1%

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

    if -3e-11 < d < 3.00000000000000024e-97

    1. Initial program 64.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 + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. /-lowering-/.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. associate-/l*N/A

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

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

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

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

    if 2.79999999999999983e140 < d

    1. Initial program 31.8%

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
      7. *-lowering-*.f6431.8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, b \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}\right) \]
      16. *-lowering-*.f6439.2

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+139}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -3 \cdot 10^{-11}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3 \cdot 10^{-97}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+140}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, \frac{a}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 65.8% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.7 \cdot 10^{-10}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 1.42 \cdot 10^{+141}:\\
\;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.70000000000000007e-10 or 1.42000000000000005e141 < d

    1. Initial program 51.6%

      \[\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. /-lowering-/.f6469.5

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Simplified69.5%

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

    if -1.70000000000000007e-10 < d < 9.6000000000000003e-112

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

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Simplified70.6%

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

    if 9.6000000000000003e-112 < d < 1.42000000000000005e141

    1. Initial program 76.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{d \cdot d + c \cdot c}} \cdot b \]
      7. accelerator-lowering-fma.f64N/A

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

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

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

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

Alternative 5: 78.1% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -1.95e-10 or 7.99999999999999957e49 < d

    1. Initial program 55.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, b \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}\right) \]
      16. *-lowering-*.f6458.4

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

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

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

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

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

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

    if -1.95e-10 < d < 7.99999999999999957e49

    1. Initial program 67.3%

      \[\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. /-lowering-/.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. associate-/l*N/A

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

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

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

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

Alternative 6: 77.6% accurate, 0.9× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.1999999999999998e-9 or 1.02000000000000002e52 < d

    1. Initial program 55.5%

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

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

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

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

    if -2.1999999999999998e-9 < d < 1.02000000000000002e52

    1. Initial program 67.3%

      \[\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. /-lowering-/.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. associate-/l*N/A

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

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

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

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

Alternative 7: 72.4% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.9 \cdot 10^{+28}:\\
\;\;\;\;\frac{a}{c}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.8999999999999999e28 or 1.2999999999999999e-37 < c

    1. Initial program 50.6%

      \[\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. /-lowering-/.f6464.7

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Simplified64.7%

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

    if -1.8999999999999999e28 < c < 1.2999999999999999e-37

    1. Initial program 75.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. /-lowering-/.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. accelerator-lowering-fma.f64N/A

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

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

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

Alternative 8: 64.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.54 \cdot 10^{+150}:\\
\;\;\;\;\frac{a}{c}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.54e150 or 9.20000000000000007e-38 < c

    1. Initial program 45.3%

      \[\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. /-lowering-/.f6469.4

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Simplified69.4%

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

    if -1.54e150 < c < -1.55000000000000008e-80

    1. Initial program 77.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\color{blue}{c \cdot c}} \]
      6. *-lowering-*.f6456.3

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

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

    if -1.55000000000000008e-80 < c < 9.20000000000000007e-38

    1. Initial program 74.3%

      \[\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. /-lowering-/.f6470.1

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Simplified70.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.54 \cdot 10^{+150}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{-80}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{c \cdot c}\\ \mathbf{elif}\;c \leq 9.2 \cdot 10^{-38}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 65.1% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.25 \cdot 10^{+59}:\\
\;\;\;\;\frac{a}{c}\\

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

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

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


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

    1. Initial program 48.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. /-lowering-/.f6465.6

        \[\leadsto \color{blue}{\frac{a}{c}} \]
    5. Simplified65.6%

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

    if -1.2499999999999999e59 < c < -6.7999999999999997e-87

    1. Initial program 83.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(a, \frac{c}{\mathsf{fma}\left(d, d, c \cdot c\right)}, b \cdot \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)}\right) \]
      16. *-lowering-*.f6489.9

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

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

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

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

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

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

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

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

        \[\leadsto c \cdot \frac{a}{\color{blue}{d \cdot d} + {c}^{2}} \]
      7. accelerator-lowering-fma.f64N/A

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

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

        \[\leadsto c \cdot \frac{a}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \]
    10. Simplified58.1%

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

    if -6.7999999999999997e-87 < c < 2.8e-38

    1. Initial program 74.3%

      \[\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. /-lowering-/.f6470.1

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Simplified70.1%

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

Alternative 10: 63.8% accurate, 1.6× speedup?

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

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

\mathbf{elif}\;d \leq 5.5 \cdot 10^{+53}:\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.1e-10 or 5.49999999999999975e53 < d

    1. Initial program 55.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. /-lowering-/.f6467.3

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

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

    if -2.1e-10 < d < 5.49999999999999975e53

    1. Initial program 66.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. /-lowering-/.f6462.8

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

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

Alternative 11: 42.7% 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 62.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}{c}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f6444.0

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

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

Developer Target 1: 99.3% 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 2024204 
(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))))