Complex division, real part

Percentage Accurate: 60.6% → 80.8%
Time: 6.4s
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: 60.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: 80.8% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;d \leq -2.7 \cdot 10^{-131}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 9.2 \cdot 10^{+47}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 45.1%

      \[\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} + \frac{a \cdot c}{{d}^{2}}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

      if -1.2e75 < d < -2.70000000000000021e-131 or 2.39999999999999994e-144 < d < 9.1999999999999994e47

      1. Initial program 82.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\left(\frac{c}{{c}^{2} + {d}^{2}} + \frac{b \cdot d}{a \cdot \left({c}^{2} + {d}^{2}\right)}\right) \cdot a} \]
      7. Applied rewrites86.4%

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

      if -2.70000000000000021e-131 < d < 2.39999999999999994e-144

      1. Initial program 73.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if 9.1999999999999994e47 < d

      1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.2 \cdot 10^{+75}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -2.7 \cdot 10^{-131}:\\ \;\;\;\;\mathsf{fma}\left(\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{d}{a}, \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \cdot a\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 9.2 \cdot 10^{+47}:\\ \;\;\;\;\mathsf{fma}\left(\frac{b}{\mathsf{fma}\left(c, c, d \cdot d\right)}, \frac{d}{a}, \frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)}\right) \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 2: 82.5% accurate, 0.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

        if -2.2500000000000001e105 < d < -5.5000000000000003e-137 or 1.69999999999999992e-143 < d < 1.7499999999999999e75

        1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -5.5000000000000003e-137 < d < 1.69999999999999992e-143

        1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 1.7499999999999999e75 < d

        1. Initial program 36.8%

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.25 \cdot 10^{+105}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-143}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 1.75 \cdot 10^{+75}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
      9. Add Preprocessing

      Alternative 3: 82.4% accurate, 0.7× speedup?

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

        1. Initial program 40.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\frac{\color{blue}{c \cdot a}}{d} + b}{d} \]
          4. associate-*l/N/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-/.f6490.9

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

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

        if -2.2500000000000001e105 < d < -5.5000000000000003e-137 or 1.69999999999999992e-143 < d < 1.7499999999999999e75

        1. Initial program 83.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -5.5000000000000003e-137 < d < 1.69999999999999992e-143

        1. Initial program 72.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 1.7499999999999999e75 < d

        1. Initial program 36.8%

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.25 \cdot 10^{+105}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{elif}\;d \leq -5.5 \cdot 10^{-137}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-143}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 1.75 \cdot 10^{+75}:\\ \;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
      5. Add Preprocessing

      Alternative 4: 63.3% accurate, 0.7× speedup?

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

        1. Initial program 41.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-/.f6479.6

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

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

        if -1.4500000000000001e102 < d < -4.00000000000000026e-158

        1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -4.00000000000000026e-158 < d < 2.39999999999999994e-144

        1. Initial program 74.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-/.f6478.8

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

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

        if 2.39999999999999994e-144 < d < 4.00000000000000004e55

        1. Initial program 81.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \color{blue}{\frac{a \cdot c}{{c}^{2} + {d}^{2}}} \]
        6. 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-*.f6465.7

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.45 \cdot 10^{+102}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -4 \cdot 10^{-158}:\\ \;\;\;\;\frac{b}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot d\\ \mathbf{elif}\;d \leq 2.4 \cdot 10^{-144}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{+55}:\\ \;\;\;\;\frac{c}{\mathsf{fma}\left(c, c, d \cdot d\right)} \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
      5. Add Preprocessing

      Alternative 5: 69.1% accurate, 0.8× speedup?

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

        1. Initial program 52.4%

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

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

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

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

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

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

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

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

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

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

        if -2.6000000000000002e50 < d < -4.00000000000000026e-158

        1. Initial program 81.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -4.00000000000000026e-158 < d < 3.19999999999999987e-22

        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 c around inf

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

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

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

      Alternative 6: 76.9% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+72} \lor \neg \left(d \leq 2.3 \cdot 10^{+50}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -1.3e+72) (not (<= d 2.3e+50)))
         (/ (fma (/ a d) c b) d)
         (/ (fma (/ b c) d a) c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -1.3e+72) || !(d <= 2.3e+50)) {
      		tmp = fma((a / d), c, b) / d;
      	} else {
      		tmp = fma((b / c), d, a) / c;
      	}
      	return tmp;
      }
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -1.3e+72) || !(d <= 2.3e+50))
      		tmp = Float64(fma(Float64(a / d), c, b) / d);
      	else
      		tmp = Float64(fma(Float64(b / c), d, a) / c);
      	end
      	return tmp
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.3e+72], N[Not[LessEqual[d, 2.3e+50]], $MachinePrecision]], N[(N[(N[(a / d), $MachinePrecision] * c + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -1.3 \cdot 10^{+72} \lor \neg \left(d \leq 2.3 \cdot 10^{+50}\right):\\
      \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -1.29999999999999991e72 or 2.29999999999999997e50 < d

        1. Initial program 43.8%

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

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

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

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

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

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

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

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

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

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

        if -1.29999999999999991e72 < d < 2.29999999999999997e50

        1. Initial program 78.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-/.f6476.3

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.3 \cdot 10^{+72} \lor \neg \left(d \leq 2.3 \cdot 10^{+50}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \end{array} \]
      5. Add Preprocessing

      Alternative 7: 77.5% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+72}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\ \;\;\;\;\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 -2e+72)
         (/ (fma (/ c d) a b) d)
         (if (<= d 2.3e+50) (/ (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 <= -2e+72) {
      		tmp = fma((c / d), a, b) / d;
      	} else if (d <= 2.3e+50) {
      		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 <= -2e+72)
      		tmp = Float64(fma(Float64(c / d), a, b) / d);
      	elseif (d <= 2.3e+50)
      		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, -2e+72], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.3e+50], 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 -2 \cdot 10^{+72}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
      
      \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\
      \;\;\;\;\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 < -1.99999999999999989e72

        1. Initial program 45.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\frac{\color{blue}{c \cdot a}}{d} + b}{d} \]
          4. associate-*l/N/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-/.f6489.8

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

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

        if -1.99999999999999989e72 < d < 2.29999999999999997e50

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 2.29999999999999997e50 < d

        1. Initial program 42.6%

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+72}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\ \;\;\;\;\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} \]
      5. Add Preprocessing

      Alternative 8: 76.6% accurate, 0.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+72}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\ \;\;\;\;\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 -2e+72)
         (/ (fma (/ c d) a b) d)
         (if (<= d 2.3e+50) (/ (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 <= -2e+72) {
      		tmp = fma((c / d), a, b) / d;
      	} else if (d <= 2.3e+50) {
      		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 <= -2e+72)
      		tmp = Float64(fma(Float64(c / d), a, b) / d);
      	elseif (d <= 2.3e+50)
      		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, -2e+72], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 2.3e+50], 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 -2 \cdot 10^{+72}:\\
      \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\
      
      \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\
      \;\;\;\;\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 < -1.99999999999999989e72

        1. Initial program 45.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\frac{\color{blue}{c \cdot a}}{d} + b}{d} \]
          4. associate-*l/N/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-/.f6489.8

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

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

        if -1.99999999999999989e72 < d < 2.29999999999999997e50

        1. Initial program 78.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-/.f6476.3

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

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

        if 2.29999999999999997e50 < d

        1. Initial program 42.6%

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+72}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+50}:\\ \;\;\;\;\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} \]
      5. Add Preprocessing

      Alternative 9: 63.9% accurate, 0.9× speedup?

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

        1. Initial program 42.9%

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

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

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

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

        if -1.4500000000000001e102 < d < -4.00000000000000026e-158

        1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -4.00000000000000026e-158 < d < 5.0000000000000004e43

        1. Initial program 76.4%

          \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
        2. Add Preprocessing
        3. Taylor expanded in 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}} \]
      3. Recombined 3 regimes into one program.
      4. Add Preprocessing

      Alternative 10: 64.2% accurate, 1.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.22 \cdot 10^{+70} \lor \neg \left(d \leq 5 \cdot 10^{+43}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (or (<= d -1.22e+70) (not (<= d 5e+43))) (/ b d) (/ a c)))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -1.22e+70) || !(d <= 5e+43)) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	return tmp;
      }
      
      real(8) function code(a, b, c, d)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: c
          real(8), intent (in) :: d
          real(8) :: tmp
          if ((d <= (-1.22d+70)) .or. (.not. (d <= 5d+43))) then
              tmp = b / d
          else
              tmp = a / c
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if ((d <= -1.22e+70) || !(d <= 5e+43)) {
      		tmp = b / d;
      	} else {
      		tmp = a / c;
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if (d <= -1.22e+70) or not (d <= 5e+43):
      		tmp = b / d
      	else:
      		tmp = a / c
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if ((d <= -1.22e+70) || !(d <= 5e+43))
      		tmp = Float64(b / d);
      	else
      		tmp = Float64(a / c);
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if ((d <= -1.22e+70) || ~((d <= 5e+43)))
      		tmp = b / d;
      	else
      		tmp = a / c;
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.22e+70], N[Not[LessEqual[d, 5e+43]], $MachinePrecision]], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;d \leq -1.22 \cdot 10^{+70} \lor \neg \left(d \leq 5 \cdot 10^{+43}\right):\\
      \;\;\;\;\frac{b}{d}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{a}{c}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if d < -1.22e70 or 5.0000000000000004e43 < d

        1. Initial program 45.0%

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

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

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

        if -1.22e70 < d < 5.0000000000000004e43

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

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

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

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

      Alternative 11: 42.8% 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 65.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-/.f6441.7

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

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

      Developer Target 1: 99.3% accurate, 0.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|d\right| < \left|c\right|:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\ \end{array} \end{array} \]
      (FPCore (a b c d)
       :precision binary64
       (if (< (fabs d) (fabs c))
         (/ (+ a (* b (/ d c))) (+ c (* d (/ d c))))
         (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
      double code(double a, double b, double c, double d) {
      	double tmp;
      	if (fabs(d) < fabs(c)) {
      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
      	} else {
      		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
      	}
      	return tmp;
      }
      
      real(8) function code(a, b, c, d)
          real(8), intent (in) :: a
          real(8), intent (in) :: b
          real(8), intent (in) :: c
          real(8), intent (in) :: d
          real(8) :: tmp
          if (abs(d) < abs(c)) then
              tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
          else
              tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
          end if
          code = tmp
      end function
      
      public static double code(double a, double b, double c, double d) {
      	double tmp;
      	if (Math.abs(d) < Math.abs(c)) {
      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
      	} else {
      		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
      	}
      	return tmp;
      }
      
      def code(a, b, c, d):
      	tmp = 0
      	if math.fabs(d) < math.fabs(c):
      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
      	else:
      		tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
      	return tmp
      
      function code(a, b, c, d)
      	tmp = 0.0
      	if (abs(d) < abs(c))
      		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c))));
      	else
      		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d))));
      	end
      	return tmp
      end
      
      function tmp_2 = code(a, b, c, d)
      	tmp = 0.0;
      	if (abs(d) < abs(c))
      		tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
      	else
      		tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
      	end
      	tmp_2 = tmp;
      end
      
      code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;\left|d\right| < \left|c\right|:\\
      \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
      
      
      \end{array}
      \end{array}
      

      Reproduce

      ?
      herbie shell --seed 2024322 
      (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))))