Complex division, real part

Percentage Accurate: 61.4% → 80.4%
Time: 10.5s
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.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: 80.4% accurate, 0.7× 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 4.25 \cdot 10^{-106}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+60}:\\ \;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (fma a (/ c d) b) d)))
   (if (<= d -7e-29)
     t_0
     (if (<= d 4.25e-106)
       (/ (fma b (/ d c) a) c)
       (if (<= d 2.9e+60) (/ (+ (* a c) (* d b)) (+ (* c c) (* d 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 <= 4.25e-106) {
		tmp = fma(b, (d / c), a) / c;
	} else if (d <= 2.9e+60) {
		tmp = ((a * c) + (d * b)) / ((c * c) + (d * 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 <= 4.25e-106)
		tmp = Float64(fma(b, Float64(d / c), a) / c);
	elseif (d <= 2.9e+60)
		tmp = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -7e-29], t$95$0, If[LessEqual[d, 4.25e-106], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.9e+60], N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -6.9999999999999995e-29 or 2.9e60 < 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. 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.0

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

      \[\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 < 2.9e60

    1. Initial program 94.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification85.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 4.25 \cdot 10^{-106}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.9 \cdot 10^{+60}:\\ \;\;\;\;\frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 66.5% accurate, 0.7× speedup?

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -2.1e82 or 7.5000000000000003e130 < 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 -2.1e82 < d < -3.6999999999999997e-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. +-commutativeN/A

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

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

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

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

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

        \[\leadsto \frac{\mathsf{fma}\left(d, b, \color{blue}{c \cdot a}\right)}{d \cdot d} \]
      8. 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.6999999999999997e-29 < d < 2.05000000000000017e-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 2.05000000000000017e-120 < d < 7.5000000000000003e130

    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. Applied rewrites67.2%

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

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

    Alternative 3: 65.7% accurate, 0.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+130}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (if (<= d -8e-22)
       (/ b d)
       (if (<= d 2.05e-120)
         (/ a c)
         (if (<= d 7.5e+130) (* b (/ d (fma c c (* d d)))) (/ b d)))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (d <= -8e-22) {
    		tmp = b / d;
    	} else if (d <= 2.05e-120) {
    		tmp = a / c;
    	} else if (d <= 7.5e+130) {
    		tmp = b * (d / fma(c, c, (d * d)));
    	} else {
    		tmp = b / d;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (d <= -8e-22)
    		tmp = Float64(b / d);
    	elseif (d <= 2.05e-120)
    		tmp = Float64(a / c);
    	elseif (d <= 7.5e+130)
    		tmp = Float64(b * Float64(d / fma(c, c, Float64(d * d))));
    	else
    		tmp = Float64(b / d);
    	end
    	return tmp
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[d, -8e-22], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], If[LessEqual[d, 7.5e+130], N[(b * N[(d / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\
    \;\;\;\;\frac{b}{d}\\
    
    \mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
    \;\;\;\;\frac{a}{c}\\
    
    \mathbf{elif}\;d \leq 7.5 \cdot 10^{+130}:\\
    \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{b}{d}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d < -8.0000000000000004e-22 or 7.5000000000000003e130 < 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 -8.0000000000000004e-22 < d < 2.05000000000000017e-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 2.05000000000000017e-120 < d < 7.5000000000000003e130

      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. Applied rewrites67.2%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+130}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
      9. Add Preprocessing

      Alternative 4: 65.2% accurate, 0.8× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 5.5 \cdot 10^{-109}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+92}:\\ \;\;\;\;d \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (<= d -8e-22)
         (/ b d)
         (if (<= d 5.5e-109)
           (/ a c)
           (if (<= d 5.6e+92) (* d (/ b (fma c c (* d d)))) (/ b d)))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (d <= -8e-22) {
      		tmp = b / d;
      	} else if (d <= 5.5e-109) {
      		tmp = a / c;
      	} else if (d <= 5.6e+92) {
      		tmp = d * (b / fma(c, c, (d * d)));
      	} else {
      		tmp = b / d;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (d <= -8e-22)
      		tmp = Float64(b / d);
      	elseif (d <= 5.5e-109)
      		tmp = Float64(a / c);
      	elseif (d <= 5.6e+92)
      		tmp = Float64(d * Float64(b / fma(c, c, Float64(d * d))));
      	else
      		tmp = Float64(b / d);
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := If[LessEqual[d, -8e-22], N[(b / d), $MachinePrecision], If[LessEqual[d, 5.5e-109], N[(a / c), $MachinePrecision], If[LessEqual[d, 5.6e+92], N[(d * N[(b / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b / d), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{elif}\;d \leq 5.5 \cdot 10^{-109}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;d \leq 5.6 \cdot 10^{+92}:\\
      \;\;\;\;d \cdot \frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b}{d}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if d < -8.0000000000000004e-22 or 5.60000000000000001e92 < 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 -8.0000000000000004e-22 < d < 5.5000000000000003e-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 5.5000000000000003e-109 < d < 5.60000000000000001e92

        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. Applied rewrites64.3%

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

        Alternative 5: 77.3% accurate, 0.9× 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{else}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\ \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) (/ b (fma (/ c d) c 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 {
        		tmp = b / fma((c / d), c, 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);
        	else
        		tmp = Float64(b / fma(Float64(c / d), c, 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], N[(b / N[(N[(c / d), $MachinePrecision] * c + d), $MachinePrecision]), $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{else}:\\
        \;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 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

          1. Initial program 56.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 \color{blue}{\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
            2. clear-numN/A

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

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

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

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

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

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

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

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

              \[\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 rewrites56.1%

            \[\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}{\color{blue}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
            2. 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)}}} \]
            3. 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)}}} \]
            4. *-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)}} \]
            5. 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)}} \]
            6. 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)} \]
            7. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(d, d \cdot \frac{1}{\mathsf{fma}\left(c, a, d \cdot b\right)}, \frac{c \cdot c}{\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-*.f6481.5

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

            \[\leadsto \color{blue}{\frac{b}{d + \frac{c \cdot c}{d}}} \]
          10. Step-by-step derivation
            1. Applied rewrites82.8%

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

          Alternative 6: 69.4% accurate, 0.9× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.7 \cdot 10^{-29}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\ \end{array} \end{array} \]
          (FPCore (a b c d)
           :precision binary64
           (if (<= d -3.7e-29)
             (/ (fma a (/ c d) b) d)
             (if (<= d 2.05e-120) (/ a c) (/ b (fma (/ c d) c d)))))
          double code(double a, double b, double c, double d) {
          	double tmp;
          	if (d <= -3.7e-29) {
          		tmp = fma(a, (c / d), b) / d;
          	} else if (d <= 2.05e-120) {
          		tmp = a / c;
          	} else {
          		tmp = b / fma((c / d), c, d);
          	}
          	return tmp;
          }
          
          function code(a, b, c, d)
          	tmp = 0.0
          	if (d <= -3.7e-29)
          		tmp = Float64(fma(a, Float64(c / d), b) / d);
          	elseif (d <= 2.05e-120)
          		tmp = Float64(a / c);
          	else
          		tmp = Float64(b / fma(Float64(c / d), c, d));
          	end
          	return tmp
          end
          
          code[a_, b_, c_, d_] := If[LessEqual[d, -3.7e-29], N[(N[(a * N[(c / d), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.05e-120], N[(a / c), $MachinePrecision], N[(b / N[(N[(c / d), $MachinePrecision] * c + d), $MachinePrecision]), $MachinePrecision]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;d \leq -3.7 \cdot 10^{-29}:\\
          \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\
          
          \mathbf{elif}\;d \leq 2.05 \cdot 10^{-120}:\\
          \;\;\;\;\frac{a}{c}\\
          
          \mathbf{else}:\\
          \;\;\;\;\frac{b}{\mathsf{fma}\left(\frac{c}{d}, c, d\right)}\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 3 regimes
          2. if d < -3.6999999999999997e-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 -3.6999999999999997e-29 < d < 2.05000000000000017e-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 2.05000000000000017e-120 < d

            1. Initial program 61.4%

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

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

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

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

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

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

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

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

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

                \[\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 rewrites61.4%

              \[\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}{\color{blue}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
              2. 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)}}} \]
              3. 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)}}} \]
              4. *-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)}} \]
              5. 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)}} \]
              6. 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)} \]
              7. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(d, d \cdot \frac{1}{\mathsf{fma}\left(c, a, d \cdot b\right)}, \frac{c \cdot c}{\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-*.f6476.0

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

              \[\leadsto \color{blue}{\frac{b}{d + \frac{c \cdot c}{d}}} \]
            10. Step-by-step derivation
              1. Applied rewrites77.0%

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

            Alternative 7: 67.7% accurate, 0.9× speedup?

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

              1. Initial program 56.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 \color{blue}{\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}} \]
                2. clear-numN/A

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

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

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

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

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

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

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

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

                  \[\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 rewrites56.9%

                \[\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}{\color{blue}{\frac{\mathsf{fma}\left(c, c, d \cdot d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}} \]
                2. 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)}}} \]
                3. 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)}}} \]
                4. *-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)}} \]
                5. 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)}} \]
                6. 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)} \]
                7. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(d, d \cdot \frac{1}{\mathsf{fma}\left(c, a, d \cdot b\right)}, \frac{c \cdot c}{\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-*.f6466.4

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

                \[\leadsto \color{blue}{\frac{b}{d + \frac{c \cdot c}{d}}} \]
              10. Step-by-step derivation
                1. Applied rewrites70.4%

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

                if -3.20000000000000021e-137 < d < 2.05000000000000017e-120

                1. Initial program 68.1%

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

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

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

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

              Alternative 8: 62.8% accurate, 1.6× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -8 \cdot 10^{-22}:\\ \;\;\;\;\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 -8e-22) (/ 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 <= -8e-22) {
              		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 <= (-8d-22)) 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 <= -8e-22) {
              		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 <= -8e-22:
              		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 <= -8e-22)
              		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 <= -8e-22)
              		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, -8e-22], 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 -8 \cdot 10^{-22}:\\
              \;\;\;\;\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 < -8.0000000000000004e-22 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 -8.0000000000000004e-22 < 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 9: 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))))