Complex division, real part

Percentage Accurate: 61.0% → 84.2%
Time: 15.9s
Alternatives: 9
Speedup: 1.6×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 9 alternatives:

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

Initial Program: 61.0% 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: 84.2% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;d \leq -9.6 \cdot 10^{-141}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;d \leq 4.5 \cdot 10^{+104}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.99999999999999995e102 or 4.4999999999999998e104 < d

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

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

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

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

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

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

      if -1.99999999999999995e102 < d < -9.6000000000000004e-141 or 5.9999999999999998e-139 < d < 4.4999999999999998e104

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -9.6000000000000004e-141 < d < 5.9999999999999998e-139

      1. Initial program 75.0%

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -9.6 \cdot 10^{-141}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}, \frac{a \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\right)\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-139}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 4.5 \cdot 10^{+104}:\\ \;\;\;\;\mathsf{fma}\left(b, \frac{d}{\mathsf{fma}\left(d, d, c \cdot c\right)}, \frac{a \cdot c}{\mathsf{fma}\left(d, d, c \cdot c\right)}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 2: 83.2% accurate, 0.7× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ t_1 := \frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \mathbf{if}\;d \leq -1.5 \cdot 10^{+102}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-141}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq 7.6 \cdot 10^{-139}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+79}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
    (FPCore (a b c d)
     :precision binary64
     (let* ((t_0 (/ (fma a c (* d b)) (fma c c (* d d))))
            (t_1 (/ (fma c (* a (/ 1.0 d)) b) d)))
       (if (<= d -1.5e+102)
         t_1
         (if (<= d -2.6e-141)
           t_0
           (if (<= d 7.6e-139)
             (/ (fma b (/ d c) a) c)
             (if (<= d 2.1e+79) t_0 t_1))))))
    double code(double a, double b, double c, double d) {
    	double t_0 = fma(a, c, (d * b)) / fma(c, c, (d * d));
    	double t_1 = fma(c, (a * (1.0 / d)), b) / d;
    	double tmp;
    	if (d <= -1.5e+102) {
    		tmp = t_1;
    	} else if (d <= -2.6e-141) {
    		tmp = t_0;
    	} else if (d <= 7.6e-139) {
    		tmp = fma(b, (d / c), a) / c;
    	} else if (d <= 2.1e+79) {
    		tmp = t_0;
    	} else {
    		tmp = t_1;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	t_0 = Float64(fma(a, c, Float64(d * b)) / fma(c, c, Float64(d * d)))
    	t_1 = Float64(fma(c, Float64(a * Float64(1.0 / d)), b) / d)
    	tmp = 0.0
    	if (d <= -1.5e+102)
    		tmp = t_1;
    	elseif (d <= -2.6e-141)
    		tmp = t_0;
    	elseif (d <= 7.6e-139)
    		tmp = Float64(fma(b, Float64(d / c), a) / c);
    	elseif (d <= 2.1e+79)
    		tmp = t_0;
    	else
    		tmp = t_1;
    	end
    	return tmp
    end
    
    code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(c * c + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(c * N[(a * N[(1.0 / d), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -1.5e+102], t$95$1, If[LessEqual[d, -2.6e-141], t$95$0, If[LessEqual[d, 7.6e-139], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.1e+79], t$95$0, t$95$1]]]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\
    t_1 := \frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\
    \mathbf{if}\;d \leq -1.5 \cdot 10^{+102}:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;d \leq -2.6 \cdot 10^{-141}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;d \leq 7.6 \cdot 10^{-139}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
    
    \mathbf{elif}\;d \leq 2.1 \cdot 10^{+79}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if d < -1.4999999999999999e102 or 2.10000000000000008e79 < d

      1. Initial program 37.2%

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

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

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

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

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

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

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

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

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

        if -1.4999999999999999e102 < d < -2.60000000000000011e-141 or 7.60000000000000015e-139 < d < 2.10000000000000008e79

        1. Initial program 85.9%

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

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

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

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

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

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

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

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

        if -2.60000000000000011e-141 < d < 7.60000000000000015e-139

        1. Initial program 75.0%

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

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

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

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

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

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

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

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

        \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.5 \cdot 10^{+102}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq -2.6 \cdot 10^{-141}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{elif}\;d \leq 7.6 \cdot 10^{-139}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{+79}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \end{array} \]
      9. Add Preprocessing

      Alternative 3: 77.4% accurate, 0.7× speedup?

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

        1. Initial program 46.8%

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

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

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

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

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

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

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

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

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

          if -3e6 < d < 2.10000000000000003e-106

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

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

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

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

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

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

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

          if 2.10000000000000003e-106 < d < 1.40000000000000004e103

          1. Initial program 87.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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-106}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 1.4 \cdot 10^{+103}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a \cdot \frac{1}{d}, b\right)}{d}\\ \end{array} \]
          11. Add Preprocessing

          Alternative 4: 77.1% accurate, 0.8× speedup?

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

            1. Initial program 46.8%

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

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

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

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

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

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

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

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

            if -3e6 < d < 2.10000000000000003e-106

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

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

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

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

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

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

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

            if 2.10000000000000003e-106 < d < 1.45999999999999998e103

            1. Initial program 87.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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3000000:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-106}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 1.46 \cdot 10^{+103}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \]
            11. Add Preprocessing

            Alternative 5: 69.7% accurate, 0.8× speedup?

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

              1. Initial program 46.8%

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

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

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

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

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

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

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

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

              if -2.05e6 < d < 1.44999999999999997e-134

              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-/.f6468.9

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

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

              if 1.44999999999999997e-134 < d < 1.45999999999999998e103

              1. Initial program 89.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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2050000:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 1.46 \cdot 10^{+103}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(a, \frac{c}{d}, b\right)}{d}\\ \end{array} \]
              11. Add Preprocessing

              Alternative 6: 65.0% accurate, 0.8× speedup?

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

                1. Initial program 46.8%

                  \[\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-/.f6466.2

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

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

                if -2.75e6 < d < 1.44999999999999997e-134

                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-/.f6468.9

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

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

                if 1.44999999999999997e-134 < d < 7.49999999999999922e103

                1. Initial program 89.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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2750000:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-134}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{+103}:\\ \;\;\;\;b \cdot \frac{d}{\mathsf{fma}\left(c, c, d \cdot d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
                11. Add Preprocessing

                Alternative 7: 64.5% accurate, 0.8× speedup?

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

                  1. Initial program 46.8%

                    \[\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-/.f6466.2

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

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

                  if -2.75e6 < d < 1.5e-134

                  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-/.f6468.9

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

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

                  if 1.5e-134 < d < 2.3999999999999998e103

                  1. Initial program 89.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. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                Alternative 8: 62.5% accurate, 1.6× speedup?

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

                  1. Initial program 58.6%

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

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

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

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

                  if -2.75e6 < d < 6.20000000000000043e-107

                  1. Initial program 77.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-/.f6467.1

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

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

                Alternative 9: 42.7% 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 66.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-/.f6442.2

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

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