Complex division, real part

Percentage Accurate: 61.4% → 80.1%
Time: 7.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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 80.1% accurate, 0.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -9.9999999999999995e-8 or 2.3e154 < d

    1. Initial program 34.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      if -9.9999999999999995e-8 < d < 2.20000000000000021e-112

      1. Initial program 67.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-/.f6468.8

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

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

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

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

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

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

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

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

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

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

      if 2.20000000000000021e-112 < d < 2.3e154

      1. Initial program 80.9%

        \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
      2. Add Preprocessing
    7. Recombined 3 regimes into one program.
    8. Final simplification84.9%

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{-7}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{-112}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{c}{d}, \frac{a}{d}, \frac{b}{d}\right)\\ \end{array} \]
    9. Add Preprocessing

    Alternative 2: 80.2% accurate, 0.7× speedup?

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

      1. Initial program 41.4%

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

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

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

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

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

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

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

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

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

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

      if -9.9999999999999995e-8 < d < 2.20000000000000021e-112

      1. Initial program 67.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-/.f6468.8

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

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

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

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

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

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

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

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

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

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

      if 2.20000000000000021e-112 < d < 2.3e154

      1. Initial program 80.9%

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

      if 2.3e154 < d

      1. Initial program 23.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-/.f6424.7

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{-7}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{a}{d}, c, b\right)}{d}\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{-112}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{c}\\ \mathbf{elif}\;d \leq 2.3 \cdot 10^{+154}:\\ \;\;\;\;\frac{b \cdot d + a \cdot c}{d \cdot d + c \cdot c}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, a, b\right)}{d}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 3: 61.0% accurate, 0.8× speedup?

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

      1. Initial program 46.7%

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

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

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

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

      if -7.5e102 < c < -3.09999999999999989e-226

      1. Initial program 61.3%

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

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

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

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

      if -3.09999999999999989e-226 < c < 1.1800000000000001e-20

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7.5 \cdot 10^{+102}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq -3.1 \cdot 10^{-226}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;c \leq 1.18 \cdot 10^{-20}:\\ \;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]
    5. Add Preprocessing

    Alternative 4: 63.8% accurate, 0.8× speedup?

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

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

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

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

      if -7.5e102 < c < 5.00000000000000015e-140

      1. Initial program 68.5%

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

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

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

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

      if 5.00000000000000015e-140 < c < 1.99999999999999989e49

      1. Initial program 79.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-/.f6429.7

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 5: 77.0% accurate, 0.9× speedup?

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

      1. Initial program 43.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 + \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-/.f6485.5

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

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

      if -4.40000000000000015e102 < c < 7.9999999999999999e46

      1. Initial program 70.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-/.f6423.2

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

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

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

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

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

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

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

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

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

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

    Alternative 6: 76.2% accurate, 0.9× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\mathsf{fma}\left(\frac{b}{c}, d, a\right)}{c}\\ \mathbf{if}\;c \leq -4.4 \cdot 10^{+102}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 8 \cdot 10^{+46}:\\ \;\;\;\;\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 c) d a) c)))
       (if (<= c -4.4e+102) t_0 (if (<= c 8e+46) (/ (fma (/ a d) c b) d) t_0))))
    double code(double a, double b, double c, double d) {
    	double t_0 = fma((b / c), d, a) / c;
    	double tmp;
    	if (c <= -4.4e+102) {
    		tmp = t_0;
    	} else if (c <= 8e+46) {
    		tmp = fma((a / d), c, b) / d;
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    function code(a, b, c, d)
    	t_0 = Float64(fma(Float64(b / c), d, a) / c)
    	tmp = 0.0
    	if (c <= -4.4e+102)
    		tmp = t_0;
    	elseif (c <= 8e+46)
    		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[(N[(b / c), $MachinePrecision] * d + a), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.4e+102], t$95$0, If[LessEqual[c, 8e+46], 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(\frac{b}{c}, d, a\right)}{c}\\
    \mathbf{if}\;c \leq -4.4 \cdot 10^{+102}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;c \leq 8 \cdot 10^{+46}:\\
    \;\;\;\;\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 < -4.40000000000000015e102 or 7.9999999999999999e46 < c

      1. Initial program 43.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 + \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-/.f6485.5

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

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

      if -4.40000000000000015e102 < c < 7.9999999999999999e46

      1. Initial program 70.9%

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

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

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

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

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

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

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

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

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

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

    Alternative 7: 70.7% accurate, 0.9× speedup?

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

      1. Initial program 41.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-/.f6481.0

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

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

      if -7.5e102 < c < 6.4999999999999994e132

      1. Initial program 69.7%

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

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

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

    Alternative 8: 62.8% accurate, 1.6× speedup?

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

      1. Initial program 46.7%

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

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

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

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

      if -7.5e102 < c < 7.79999999999999996e-22

      1. Initial program 70.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-/.f6456.4

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

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

    Alternative 9: 43.8% accurate, 3.2× speedup?

    \[\begin{array}{l} \\ \frac{a}{c} \end{array} \]
    (FPCore (a b c d) :precision binary64 (/ a c))
    double code(double a, double b, double c, double d) {
    	return a / c;
    }
    
    real(8) function code(a, b, c, d)
        real(8), intent (in) :: a
        real(8), intent (in) :: b
        real(8), intent (in) :: c
        real(8), intent (in) :: d
        code = a / c
    end function
    
    public static double code(double a, double b, double c, double d) {
    	return a / c;
    }
    
    def code(a, b, c, d):
    	return a / c
    
    function code(a, b, c, d)
    	return Float64(a / c)
    end
    
    function tmp = code(a, b, c, d)
    	tmp = a / c;
    end
    
    code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
    
    \begin{array}{l}
    
    \\
    \frac{a}{c}
    \end{array}
    
    Derivation
    1. Initial program 59.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-/.f6445.0

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

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