Complex division, real part

Percentage Accurate: 61.6% → 82.8%
Time: 7.0s
Alternatives: 11
Speedup: 1.6×

Specification

?
\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 11 alternatives:

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

Initial Program: 61.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
	return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d):
	return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d)
	return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
function tmp = code(a, b, c, d)
	tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 82.8% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;d \leq -1.75 \cdot 10^{-106}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 7.5 \cdot 10^{+67}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 45.2%

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

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

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

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

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

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

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

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

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

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

    if -7.49999999999999946e92 < d < -1.75e-106 or 1.44999999999999996e-112 < d < 7.5000000000000005e67

    1. Initial program 84.6%

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

    if -1.75e-106 < d < 1.44999999999999996e-112

    1. Initial program 70.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 + \left(-1 \cdot \frac{a \cdot {d}^{2}}{{c}^{2}} + \frac{b \cdot d}{c}\right)}{c}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

    if 7.5000000000000005e67 < d

    1. Initial program 23.4%

      \[\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-/.f6410.8

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}} \]
    9. Step-by-step derivation
      1. Applied rewrites82.2%

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+92}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-106}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-112}:\\ \;\;\;\;\frac{a - \frac{\mathsf{fma}\left(-b, d, \frac{\left(d \cdot d\right) \cdot a}{c}\right)}{c}}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{-1}{d} \cdot \left(-c\right), a, b\right)}{d}\\ \end{array} \]
    12. Add Preprocessing

    Alternative 2: 83.0% accurate, 0.6× speedup?

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

      1. Initial program 45.2%

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

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

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

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

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

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

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

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

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

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

      if -7.49999999999999946e92 < d < -1.75e-106 or 1.95000000000000011e-109 < d < 7.5000000000000005e67

      1. Initial program 84.6%

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

      if -1.75e-106 < d < 1.95000000000000011e-109

      1. Initial program 70.0%

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

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

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

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

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

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

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

      if 7.5000000000000005e67 < d

      1. Initial program 23.4%

        \[\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-/.f6410.8

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}} \]
      9. Step-by-step derivation
        1. Applied rewrites82.2%

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{+92}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-106}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{-109}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+67}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{-1}{d} \cdot \left(-c\right), a, b\right)}{d}\\ \end{array} \]
      12. Add Preprocessing

      Alternative 3: 63.5% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.35 \cdot 10^{+44}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-114}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-158}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+155}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot d\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (<= d -1.35e+44)
         (/ b d)
         (if (<= d -4e-114)
           (/ (fma c a (* b d)) (* d d))
           (if (<= d 1.05e-158)
             (/ a c)
             (if (<= d 2.8e+155) (* (/ b (fma c c (* d d))) d) (/ b d))))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (d <= -1.35e+44) {
      		tmp = b / d;
      	} else if (d <= -4e-114) {
      		tmp = fma(c, a, (b * d)) / (d * d);
      	} else if (d <= 1.05e-158) {
      		tmp = a / c;
      	} else if (d <= 2.8e+155) {
      		tmp = (b / fma(c, c, (d * d))) * d;
      	} else {
      		tmp = b / d;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (d <= -1.35e+44)
      		tmp = Float64(b / d);
      	elseif (d <= -4e-114)
      		tmp = Float64(fma(c, a, Float64(b * d)) / Float64(d * d));
      	elseif (d <= 1.05e-158)
      		tmp = Float64(a / c);
      	elseif (d <= 2.8e+155)
      		tmp = Float64(Float64(b / fma(c, c, Float64(d * d))) * d);
      	else
      		tmp = Float64(b / d);
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := If[LessEqual[d, -1.35e+44], N[(b / d), $MachinePrecision], If[LessEqual[d, -4e-114], N[(N[(c * a + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.05e-158], N[(a / c), $MachinePrecision], If[LessEqual[d, 2.8e+155], N[(N[(b / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision], N[(b / d), $MachinePrecision]]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -1.35 \cdot 10^{+44}:\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{elif}\;d \leq -4 \cdot 10^{-114}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\
      
      \mathbf{elif}\;d \leq 1.05 \cdot 10^{-158}:\\
      \;\;\;\;\frac{a}{c}\\
      
      \mathbf{elif}\;d \leq 2.8 \cdot 10^{+155}:\\
      \;\;\;\;\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot d\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b}{d}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 4 regimes
      2. if d < -1.35e44 or 2.80000000000000016e155 < d

        1. Initial program 38.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-/.f6477.6

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

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

        if -1.35e44 < d < -4.0000000000000002e-114

        1. Initial program 85.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 \frac{\color{blue}{a \cdot c}}{c \cdot c + d \cdot d} \]
        4. Step-by-step derivation
          1. *-commutativeN/A

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

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

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

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

            \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
          2. lower-*.f6429.5

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

          \[\leadsto \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
        9. Taylor expanded in c around 0

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

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

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

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

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

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

        if -4.0000000000000002e-114 < d < 1.04999999999999996e-158

        1. Initial program 70.1%

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

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

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

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

        if 1.04999999999999996e-158 < d < 2.80000000000000016e155

        1. Initial program 68.4%

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.35 \cdot 10^{+44}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-114}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-158}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 2.8 \cdot 10^{+155}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot d\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
      5. Add Preprocessing

      Alternative 4: 63.1% accurate, 0.7× speedup?

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

        1. Initial program 39.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-/.f6477.3

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

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

        if -1.69999999999999994e40 < d < -6.9999999999999997e-91

        1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -6.9999999999999997e-91 < d < 1.04999999999999996e-158

        1. Initial program 70.3%

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

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

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

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

        if 1.04999999999999996e-158 < d < 2.80000000000000016e155

        1. Initial program 68.4%

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

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

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

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

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

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

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

      Alternative 5: 64.3% accurate, 0.7× speedup?

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

        1. Initial program 30.7%

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

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

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

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

        if -2.3000000000000001e101 < d < -4.0000000000000002e-114 or 1.04999999999999996e-158 < d < 2.80000000000000016e155

        1. Initial program 75.7%

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

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

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

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

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

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

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

        if -4.0000000000000002e-114 < d < 1.04999999999999996e-158

        1. Initial program 70.1%

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

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

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

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

      Alternative 6: 77.2% accurate, 0.9× speedup?

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

        1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

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

        if -8.99999999999999999e-102 < d < 3.8000000000000002e-15

        1. Initial program 72.7%

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

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

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

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

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

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

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

        if 3.8000000000000002e-15 < d

        1. Initial program 36.0%

          \[\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-/.f6480.3

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

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

      Alternative 7: 76.4% accurate, 0.9× speedup?

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

        1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

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

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

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

        if -8.99999999999999999e-102 < d < 3.8000000000000002e-15

        1. Initial program 72.7%

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

          \[\leadsto \color{blue}{\frac{a + \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-/.f6486.2

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

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

        if 3.8000000000000002e-15 < d

        1. Initial program 36.0%

          \[\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-/.f6480.3

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

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

      Alternative 8: 77.6% accurate, 0.9× speedup?

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

        1. Initial program 48.9%

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

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

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

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

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

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

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

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

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

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

        if -1.84999999999999994e-34 < d < 3.8000000000000002e-15

        1. Initial program 74.4%

          \[\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-/.f6482.3

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

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

      Alternative 9: 72.1% accurate, 0.9× speedup?

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

        1. Initial program 39.3%

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

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

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

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

        if -2.6999999999999998e57 < c < 1.05e126

        1. Initial program 72.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-/.f6473.6

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

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

      Alternative 10: 64.4% accurate, 1.6× speedup?

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

        1. Initial program 44.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-/.f6469.0

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

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

        if -1.5999999999999999e40 < d < 9.5000000000000005e-15

        1. Initial program 75.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-/.f6461.1

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

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

      Alternative 11: 43.1% 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.6

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

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