Complex division, real part

Percentage Accurate: 61.7% → 83.6%
Time: 5.8s
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.7% accurate, 1.0× speedup?

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

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

Alternative 1: 83.6% accurate, 0.6× speedup?

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

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

\mathbf{elif}\;d \leq -1.5 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;d \leq 1.15 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9.80000000000000035e128 or 1.1499999999999999e89 < d

    1. Initial program 33.2%

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

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

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

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

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

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

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

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

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

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

    if -9.80000000000000035e128 < d < -1.5000000000000002e-101 or 3.9999999999999999e-131 < d < 1.1499999999999999e89

    1. Initial program 79.8%

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

    if -1.5000000000000002e-101 < d < 3.9999999999999999e-131

    1. Initial program 70.5%

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.8 \cdot 10^{+128}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq -1.5 \cdot 10^{-101}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{elif}\;d \leq 4 \cdot 10^{-131}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{+89}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \end{array} \]
    9. Add Preprocessing

    Alternative 2: 77.2% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3 \cdot 10^{-34}:\\ \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-51}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, 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 (<= c -3e-34)
       (/ (fma b (/ d c) a) c)
       (if (<= c 1.25e-51) (/ (fma (/ c d) a b) d) (/ (fma (/ b c) d a) c))))
    double code(double a, double b, double c, double d) {
    	double tmp;
    	if (c <= -3e-34) {
    		tmp = fma(b, (d / c), a) / c;
    	} else if (c <= 1.25e-51) {
    		tmp = fma((c / d), a, b) / d;
    	} else {
    		tmp = fma((b / c), d, a) / c;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	tmp = 0.0
    	if (c <= -3e-34)
    		tmp = Float64(fma(b, Float64(d / c), a) / c);
    	elseif (c <= 1.25e-51)
    		tmp = Float64(fma(Float64(c / d), a, b) / d);
    	else
    		tmp = Float64(fma(Float64(b / c), d, a) / c);
    	end
    	return tmp
    end
    
    code[a_, b_, c_, d_] := If[LessEqual[c, -3e-34], N[(N[(b * N[(d / c), $MachinePrecision] + a), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1.25e-51], N[(N[(N[(c / d), $MachinePrecision] * a + b), $MachinePrecision] / d), $MachinePrecision], N[(N[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    \mathbf{if}\;c \leq -3 \cdot 10^{-34}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(b, \frac{d}{c}, a\right)}{c}\\
    
    \mathbf{elif}\;c \leq 1.25 \cdot 10^{-51}:\\
    \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, 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 3 regimes
    2. if c < -3e-34

      1. Initial program 51.2%

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

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

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

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

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

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

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

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

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

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

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

        if -3e-34 < c < 1.25000000000000001e-51

        1. Initial program 75.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. *-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-/.f6431.2

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

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

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

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

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

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

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

        if 1.25000000000000001e-51 < c

        1. Initial program 55.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. *-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-/.f6480.7

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

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

      Alternative 3: 76.3% accurate, 0.9× speedup?

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

        1. Initial program 51.2%

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

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

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

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

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

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

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

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

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

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

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

          if -3e-34 < c < 1.25000000000000001e-51

          1. Initial program 75.1%

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

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

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

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

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

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

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

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

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

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

          if 1.25000000000000001e-51 < c

          1. Initial program 55.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. *-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-/.f6480.7

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

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

        Alternative 4: 76.1% accurate, 0.9× speedup?

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

          1. Initial program 53.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. *-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-/.f6478.5

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

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

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

            if -3e-34 < c < 1.25000000000000001e-51

            1. Initial program 75.1%

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

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

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

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

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

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

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

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

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

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

          Alternative 5: 72.1% accurate, 0.9× speedup?

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

            1. Initial program 45.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-/.f6474.4

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

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

            if -5.25000000000000025e39 < d < 2.05000000000000001e124

            1. Initial program 73.3%

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

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

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

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

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

            Alternative 6: 64.0% accurate, 0.9× speedup?

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

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

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

              if -2.00000000000000001e41 < d < -1.4000000000000001e-61

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

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

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

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

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

                  \[\leadsto \frac{d \cdot b}{\color{blue}{d \cdot d}} \]
                2. lower-*.f6441.1

                  \[\leadsto \frac{d \cdot b}{\color{blue}{d \cdot d}} \]
              8. Applied rewrites41.1%

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

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

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

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

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

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

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

              if -1.4000000000000001e-61 < d < 1.75e91

              1. Initial program 73.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-/.f6463.1

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2 \cdot 10^{+41}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.4 \cdot 10^{-61}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\ \mathbf{elif}\;d \leq 1.75 \cdot 10^{+91}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
            5. Add Preprocessing

            Alternative 7: 63.5% accurate, 0.9× speedup?

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

              1. Initial program 33.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-/.f6479.4

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

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

              if -2.8499999999999999e163 < d < -1.6e-57

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

                  \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
                2. lower-*.f6461.1

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

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

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

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

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

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

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

              if -1.6e-57 < d < 1.75e91

              1. Initial program 73.9%

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

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

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

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

              \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.85 \cdot 10^{+163}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq -1.6 \cdot 10^{-57}:\\ \;\;\;\;\frac{b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\ \mathbf{elif}\;d \leq 1.75 \cdot 10^{+91}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
            5. Add Preprocessing

            Alternative 8: 63.1% accurate, 1.6× speedup?

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

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

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

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

              if -3.65e-38 < c < 1.21999999999999998e-51

              1. Initial program 74.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-/.f6469.6

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

                \[\leadsto \color{blue}{\frac{b}{d}} \]
            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 63.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-/.f6442.7

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

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

            Developer Target 1: 99.2% 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 2024249 
            (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))))