Complex division, real part

Percentage Accurate: 61.3% → 83.6%
Time: 5.6s
Alternatives: 9
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 9 alternatives:

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

Initial Program: 61.3% 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: 83.6% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -1.12 \cdot 10^{-110}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 2.3 \cdot 10^{+86}:\\
\;\;\;\;t\_0\\

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


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

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

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

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

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

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

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

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

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

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

    if -1.34999999999999999e75 < d < -1.11999999999999998e-110 or 1.64999999999999991e-78 < d < 2.2999999999999999e86

    1. Initial program 81.0%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      3. lower-fma.f6481.0

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

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

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

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

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

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

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

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

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

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

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

    if -1.11999999999999998e-110 < d < 1.64999999999999991e-78

    1. Initial program 66.1%

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

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

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

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    6. 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. *-commutativeN/A

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

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

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

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

    if 2.2999999999999999e86 < d

    1. Initial program 38.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      3. lower-fma.f6438.3

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

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

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

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

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

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

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

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

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

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

Alternative 2: 76.1% accurate, 0.7× speedup?

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

    if -2.2000000000000001e74 < d < -2.3e-6

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

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

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

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

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

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

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

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

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

    if -2.3e-6 < d < -2.8e-108

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.8e-108 < d < 4.1000000000000003e84

    1. Initial program 69.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{a \cdot c + b \cdot d}{\color{blue}{c \cdot c + d \cdot d}} \]
      2. lift-*.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    6. 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. *-commutativeN/A

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

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

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

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

    if 4.1000000000000003e84 < d

    1. Initial program 38.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      3. lower-fma.f6438.3

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

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

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

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

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

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

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

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

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

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

Alternative 3: 75.2% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -2.3 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\

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


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

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

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

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

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

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

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

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

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

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

    if -2.2000000000000001e74 < d < -2.3e-6 or -6.39999999999999962e-105 < d < 4.1000000000000003e84

    1. Initial program 68.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. *-commutativeN/A

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

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

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

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

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

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

    if -2.3e-6 < d < -6.39999999999999962e-105

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.1000000000000003e84 < d

    1. Initial program 38.3%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{c \cdot c} + d \cdot d} \]
      3. lower-fma.f6438.3

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

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

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

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

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

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

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

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

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

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

Alternative 4: 75.4% accurate, 0.7× speedup?

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

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

\mathbf{elif}\;d \leq -2.3 \cdot 10^{-6}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 4.1 \cdot 10^{+84}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.2000000000000001e74 or 4.1000000000000003e84 < d

    1. Initial program 43.1%

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

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

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

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

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

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

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

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

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

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

    if -2.2000000000000001e74 < d < -2.3e-6 or -6.39999999999999962e-105 < d < 4.1000000000000003e84

    1. Initial program 68.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. *-commutativeN/A

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

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

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

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

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

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

    if -2.3e-6 < d < -6.39999999999999962e-105

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\mathsf{fma}\left(d, d, \color{blue}{c \cdot c}\right)} \cdot b \]
    7. Applied rewrites84.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. Add Preprocessing

Alternative 5: 68.8% accurate, 0.7× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.2000000000000001e74 or 1.25000000000000005e-26 < d

    1. Initial program 48.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. *-commutativeN/A

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

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

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

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

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

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

    if -2.2000000000000001e74 < d < -6.9999999999999994e-5 or -4.8000000000000002e-114 < d < 1.25000000000000005e-26

    1. Initial program 65.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-/.f6473.8

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

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

    if -6.9999999999999994e-5 < d < -4.8000000000000002e-114

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 63.6% accurate, 0.8× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.2000000000000001e74 or 1.25000000000000005e-26 < d

    1. Initial program 48.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-/.f6472.0

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

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

    if -2.2000000000000001e74 < d < -6.9999999999999994e-5 or -4.8000000000000002e-114 < d < 1.25000000000000005e-26

    1. Initial program 65.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-/.f6473.8

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

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

    if -6.9999999999999994e-5 < d < -4.8000000000000002e-114

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 63.4% accurate, 0.8× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.2000000000000001e74 or 1.25000000000000005e-26 < d

    1. Initial program 48.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-/.f6472.0

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

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

    if -2.2000000000000001e74 < d < -6.9999999999999994e-5 or -4.8000000000000002e-114 < d < 1.25000000000000005e-26

    1. Initial program 65.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-/.f6473.8

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

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

    if -6.9999999999999994e-5 < d < -4.8000000000000002e-114

    1. Initial program 99.6%

      \[\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 62.5% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.8 \cdot 10^{-108} \lor \neg \left(d \leq 1.25 \cdot 10^{-26}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= d -2.8e-108) (not (<= d 1.25e-26))) (/ b d) (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -2.8e-108) || !(d <= 1.25e-26)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((d <= (-2.8d-108)) .or. (.not. (d <= 1.25d-26))) then
        tmp = b / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((d <= -2.8e-108) || !(d <= 1.25e-26)) {
		tmp = b / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (d <= -2.8e-108) or not (d <= 1.25e-26):
		tmp = b / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((d <= -2.8e-108) || !(d <= 1.25e-26))
		tmp = Float64(b / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((d <= -2.8e-108) || ~((d <= 1.25e-26)))
		tmp = b / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.8e-108], N[Not[LessEqual[d, 1.25e-26]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.8 \cdot 10^{-108} \lor \neg \left(d \leq 1.25 \cdot 10^{-26}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.8e-108 or 1.25000000000000005e-26 < d

    1. Initial program 55.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. lower-/.f6465.5

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

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

    if -2.8e-108 < d < 1.25000000000000005e-26

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

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

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

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

Alternative 9: 42.4% 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 60.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. lower-/.f6440.7

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

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