Complex division, real part

Percentage Accurate: 61.4% → 85.0%
Time: 10.0s
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: 61.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: 85.0% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 2.00000000000000013e294

    1. Initial program 78.9%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{c \cdot c + d \cdot d}{a \cdot c + b \cdot d}}} \]
      9. lower-/.f6478.8

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
    4. Applied rewrites78.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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{a \cdot c + \color{blue}{b \cdot d}}} \]
      4. lift-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)}}} \]
      5. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 41.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. 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. lower-fma.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 0.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. 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. associate-/l*N/A

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 2 \cdot 10^{+294}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(c, c \cdot \frac{1}{\mathsf{fma}\left(c, a, b \cdot d\right)}, d \cdot \frac{d}{\mathsf{fma}\left(c, a, b \cdot d\right)}\right)}\\ \mathbf{elif}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.5% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -6.9999999999999995e-29

    1. Initial program 43.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. 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. lower-fma.f64N/A

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

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

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

    if -6.9999999999999995e-29 < d < 4.2499999999999999e-106

    1. Initial program 69.2%

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

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

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

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

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

    if 4.2499999999999999e-106 < d < 3.99999999999999978e58

    1. Initial program 94.4%

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

    if 3.99999999999999978e58 < d

    1. Initial program 42.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 4.25 \cdot 10^{-106}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{+58}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 66.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.9 \cdot 10^{+82}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{d \cdot d}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\ \;\;\;\;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.9e+82)
   (/ b d)
   (if (<= d -3.4e-29)
     (/ (fma d b (* a c)) (* d d))
     (if (<= d 5.1e-120)
       (/ a c)
       (if (<= d 1.32e+131) (* b (/ d (fma d d (* c c)))) (/ b d))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -1.9e+82) {
		tmp = b / d;
	} else if (d <= -3.4e-29) {
		tmp = fma(d, b, (a * c)) / (d * d);
	} else if (d <= 5.1e-120) {
		tmp = a / c;
	} else if (d <= 1.32e+131) {
		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.9e+82)
		tmp = Float64(b / d);
	elseif (d <= -3.4e-29)
		tmp = Float64(fma(d, b, Float64(a * c)) / Float64(d * d));
	elseif (d <= 5.1e-120)
		tmp = Float64(a / c);
	elseif (d <= 1.32e+131)
		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.9e+82], N[(b / d), $MachinePrecision], If[LessEqual[d, -3.4e-29], N[(N[(d * b + N[(a * c), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.1e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.32e+131], 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.9 \cdot 10^{+82}:\\
\;\;\;\;\frac{b}{d}\\

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

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

\mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\
\;\;\;\;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 4 regimes
  2. if d < -1.90000000000000017e82 or 1.32e131 < d

    1. Initial program 30.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-/.f6476.9

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

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

    if -1.90000000000000017e82 < d < -3.39999999999999972e-29

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d}} \]
      2. lower-*.f6469.8

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.39999999999999972e-29 < d < 5.0999999999999998e-120

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

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

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

    if 5.0999999999999998e-120 < d < 1.32e131

    1. Initial program 75.2%

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

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.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. lower-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. lower-*.f6458.1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{d \cdot d} + c \cdot c} \cdot b \]
      16. lift-fma.f6467.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.9 \cdot 10^{+82}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, a \cdot c\right)}{d \cdot d}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 78.2% accurate, 0.7× speedup?

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

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

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\
\;\;\;\;\frac{b}{d + \frac{c \cdot c}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -6.9999999999999995e-29

    1. Initial program 43.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. 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. lower-fma.f64N/A

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

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

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

    if -6.9999999999999995e-29 < d < 2.09999999999999991e-36

    1. Initial program 73.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. 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. associate-/l*N/A

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

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

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

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

    if 2.09999999999999991e-36 < d < 7.49999999999999967e79

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{a \cdot c + \color{blue}{b \cdot d}}} \]
      4. lift-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)}}} \]
      5. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      5. lower-*.f6484.0

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
    9. Applied rewrites84.0%

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

    if 7.49999999999999967e79 < d

    1. Initial program 44.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. associate-/l*N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-36}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\ \;\;\;\;\frac{b}{d + \frac{c \cdot c}{d}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-36}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\ \;\;\;\;\frac{b}{d + \frac{c \cdot c}{d}}\\ \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 -7e-29)
     t_0
     (if (<= d 2.1e-36)
       (/ (fma b (/ d c) a) c)
       (if (<= d 7.5e+79) (/ b (+ d (/ (* c c) d))) 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 <= -7e-29) {
		tmp = t_0;
	} else if (d <= 2.1e-36) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 7.5e+79) {
		tmp = b / (d + ((c * c) / d));
	} 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 <= -7e-29)
		tmp = t_0;
	elseif (d <= 2.1e-36)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 7.5e+79)
		tmp = Float64(b / Float64(d + Float64(Float64(c * c) / d)));
	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, -7e-29], t$95$0, If[LessEqual[d, 2.1e-36], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.5e+79], N[(b / N[(d + N[(N[(c * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $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 -7 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\
\;\;\;\;\frac{b}{d + \frac{c \cdot c}{d}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.9999999999999995e-29 or 7.49999999999999967e79 < d

    1. Initial program 43.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. 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. lower-fma.f64N/A

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

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

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

    if -6.9999999999999995e-29 < d < 2.09999999999999991e-36

    1. Initial program 73.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. 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. associate-/l*N/A

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

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

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

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

    if 2.09999999999999991e-36 < d < 7.49999999999999967e79

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \frac{1}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{a \cdot c + \color{blue}{b \cdot d}}} \]
      4. lift-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)}}} \]
      5. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
      5. lower-*.f6484.0

        \[\leadsto \frac{b}{d + \frac{\color{blue}{c \cdot c}}{d}} \]
    9. Applied rewrites84.0%

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

Alternative 6: 78.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{if}\;d \leq -7 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-36}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a (/ c d) b) d)))
   (if (<= d -7e-29)
     t_0
     (if (<= d 2.1e-36)
       (/ (fma b (/ d c) a) c)
       (if (<= d 7.5e+79) (* b (/ d (fma d d (* c 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 <= -7e-29) {
		tmp = t_0;
	} else if (d <= 2.1e-36) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 7.5e+79) {
		tmp = b * (d / fma(d, d, (c * 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 <= -7e-29)
		tmp = t_0;
	elseif (d <= 2.1e-36)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 7.5e+79)
		tmp = Float64(b * Float64(d / fma(d, d, Float64(c * c))));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7e-29], t$95$0, If[LessEqual[d, 2.1e-36], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 7.5e+79], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -7 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.9999999999999995e-29 or 7.49999999999999967e79 < d

    1. Initial program 43.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. 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. lower-fma.f64N/A

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

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

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

    if -6.9999999999999995e-29 < d < 2.09999999999999991e-36

    1. Initial program 73.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. 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. associate-/l*N/A

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

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

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

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

    if 2.09999999999999991e-36 < d < 7.49999999999999967e79

    1. Initial program 86.2%

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

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.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. lower-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. lower-*.f6474.8

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{d \cdot d} + c \cdot c} \cdot b \]
      16. lift-fma.f6483.8

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

      \[\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 simplification83.3%

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

Alternative 7: 70.1% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{if}\;d \leq -3.4 \cdot 10^{-29}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+79}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a (/ c d) b) d)))
   (if (<= d -3.4e-29)
     t_0
     (if (<= d 5.1e-120)
       (/ a c)
       (if (<= d 7.5e+79) (* b (/ d (fma d d (* c 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 <= -3.4e-29) {
		tmp = t_0;
	} else if (d <= 5.1e-120) {
		tmp = a / c;
	} else if (d <= 7.5e+79) {
		tmp = b * (d / fma(d, d, (c * 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 <= -3.4e-29)
		tmp = t_0;
	elseif (d <= 5.1e-120)
		tmp = Float64(a / c);
	elseif (d <= 7.5e+79)
		tmp = Float64(b * Float64(d / fma(d, d, Float64(c * c))));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -3.4e-29], t$95$0, If[LessEqual[d, 5.1e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 7.5e+79], N[(b * N[(d / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -3.4 \cdot 10^{-29}:\\
\;\;\;\;t\_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -3.39999999999999972e-29 or 7.49999999999999967e79 < d

    1. Initial program 43.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. 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. lower-fma.f64N/A

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

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

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

    if -3.39999999999999972e-29 < d < 5.0999999999999998e-120

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

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

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

    if 5.0999999999999998e-120 < d < 7.49999999999999967e79

    1. Initial program 82.2%

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

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.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. lower-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. lower-*.f6463.9

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{d \cdot d} + c \cdot c} \cdot b \]
      16. lift-fma.f6470.3

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

      \[\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 simplification76.5%

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

Alternative 8: 65.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3 \cdot 10^{-20}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\ \;\;\;\;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 -3e-20)
   (/ b d)
   (if (<= d 5.1e-120)
     (/ a c)
     (if (<= d 1.32e+131) (* b (/ d (fma d d (* c c)))) (/ b d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3e-20) {
		tmp = b / d;
	} else if (d <= 5.1e-120) {
		tmp = a / c;
	} else if (d <= 1.32e+131) {
		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 <= -3e-20)
		tmp = Float64(b / d);
	elseif (d <= 5.1e-120)
		tmp = Float64(a / c);
	elseif (d <= 1.32e+131)
		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, -3e-20], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.1e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.32e+131], 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 -3 \cdot 10^{-20}:\\
\;\;\;\;\frac{b}{d}\\

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

\mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\
\;\;\;\;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 < -3.00000000000000029e-20 or 1.32e131 < d

    1. Initial program 40.4%

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

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites72.0%

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

    if -3.00000000000000029e-20 < d < 5.0999999999999998e-120

    1. Initial program 71.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-/.f6471.9

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

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

    if 5.0999999999999998e-120 < d < 1.32e131

    1. Initial program 75.2%

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

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.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. lower-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. lower-*.f6458.1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{d \cdot d} + c \cdot c} \cdot b \]
      16. lift-fma.f6467.2

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

      \[\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 simplification70.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3 \cdot 10^{-20}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 5.1 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.32 \cdot 10^{+131}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 65.2% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3 \cdot 10^{-20}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 6.2 \cdot 10^{-109}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{+92}:\\ \;\;\;\;d \cdot \frac{b}{\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 -3e-20)
   (/ b d)
   (if (<= d 6.2e-109)
     (/ a c)
     (if (<= d 1.15e+92) (* d (/ b (fma d d (* c c)))) (/ b d)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3e-20) {
		tmp = b / d;
	} else if (d <= 6.2e-109) {
		tmp = a / c;
	} else if (d <= 1.15e+92) {
		tmp = d * (b / fma(d, d, (c * c)));
	} else {
		tmp = b / d;
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -3e-20)
		tmp = Float64(b / d);
	elseif (d <= 6.2e-109)
		tmp = Float64(a / c);
	elseif (d <= 1.15e+92)
		tmp = Float64(d * Float64(b / fma(d, d, Float64(c * c))));
	else
		tmp = Float64(b / d);
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[d, -3e-20], N[(b / d), $MachinePrecision], If[LessEqual[d, 6.2e-109], N[(a / c), $MachinePrecision], If[LessEqual[d, 1.15e+92], N[(d * N[(b / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;d \leq 1.15 \cdot 10^{+92}:\\
\;\;\;\;d \cdot \frac{b}{\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 < -3.00000000000000029e-20 or 1.14999999999999999e92 < d

    1. Initial program 42.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-/.f6471.7

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites71.7%

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

    if -3.00000000000000029e-20 < d < 6.1999999999999999e-109

    1. Initial program 69.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-/.f6471.0

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

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

    if 6.1999999999999999e-109 < d < 1.14999999999999999e92

    1. Initial program 83.2%

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

        \[\leadsto \color{blue}{\frac{b \cdot d}{{c}^{2} + {d}^{2}}} \]
      2. lower-*.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. lower-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. lower-*.f6464.0

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \frac{b}{\color{blue}{d \cdot d} + c \cdot c} \]
      14. lift-fma.f6464.3

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

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

Alternative 10: 62.8% accurate, 1.6× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.00000000000000029e-20 or 5.0999999999999998e-120 < 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-/.f6462.8

        \[\leadsto \color{blue}{\frac{b}{d}} \]
    5. Applied rewrites62.8%

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

    if -3.00000000000000029e-20 < d < 5.0999999999999998e-120

    1. Initial program 71.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-/.f6471.9

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

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

Alternative 11: 42.9% 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 59.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-/.f6438.3

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

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