Complex division, real part

Percentage Accurate: 62.0% → 78.3%
Time: 10.0s
Alternatives: 8
Speedup: 1.1×

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 8 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: 62.0% accurate, 1.0× speedup?

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

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

Alternative 1: 78.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{b}{c} \cdot d\\ \mathbf{if}\;c \leq -2.9 \cdot 10^{+70}:\\ \;\;\;\;\frac{a + t\_0}{c}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-95}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+14}:\\ \;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \left(t\_0 - a \cdot \left(\frac{d}{c} \cdot \frac{d}{c}\right)\right)}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (* (/ b c) d)))
   (if (<= c -2.9e+70)
     (/ (+ a t_0) c)
     (if (<= c 3.6e-95)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c 1.25e+14)
         (/ (* a (+ c (* b (/ d a)))) (+ (* c c) (* d d)))
         (/ (+ a (- t_0 (* a (* (/ d c) (/ d c))))) c))))))
double code(double a, double b, double c, double d) {
	double t_0 = (b / c) * d;
	double tmp;
	if (c <= -2.9e+70) {
		tmp = (a + t_0) / c;
	} else if (c <= 3.6e-95) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.25e+14) {
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	} else {
		tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / 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) :: t_0
    real(8) :: tmp
    t_0 = (b / c) * d
    if (c <= (-2.9d+70)) then
        tmp = (a + t_0) / c
    else if (c <= 3.6d-95) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 1.25d+14) then
        tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d))
    else
        tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (b / c) * d;
	double tmp;
	if (c <= -2.9e+70) {
		tmp = (a + t_0) / c;
	} else if (c <= 3.6e-95) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.25e+14) {
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	} else {
		tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (b / c) * d
	tmp = 0
	if c <= -2.9e+70:
		tmp = (a + t_0) / c
	elif c <= 3.6e-95:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.25e+14:
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d))
	else:
		tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(b / c) * d)
	tmp = 0.0
	if (c <= -2.9e+70)
		tmp = Float64(Float64(a + t_0) / c);
	elseif (c <= 3.6e-95)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.25e+14)
		tmp = Float64(Float64(a * Float64(c + Float64(b * Float64(d / a)))) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = Float64(Float64(a + Float64(t_0 - Float64(a * Float64(Float64(d / c) * Float64(d / c))))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (b / c) * d;
	tmp = 0.0;
	if (c <= -2.9e+70)
		tmp = (a + t_0) / c;
	elseif (c <= 3.6e-95)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.25e+14)
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	else
		tmp = (a + (t_0 - (a * ((d / c) * (d / c))))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]}, If[LessEqual[c, -2.9e+70], N[(N[(a + t$95$0), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 3.6e-95], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.25e+14], N[(N[(a * N[(c + N[(b * N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(a + N[(t$95$0 - N[(a * N[(N[(d / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{b}{c} \cdot d\\
\mathbf{if}\;c \leq -2.9 \cdot 10^{+70}:\\
\;\;\;\;\frac{a + t\_0}{c}\\

\mathbf{elif}\;c \leq 3.6 \cdot 10^{-95}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

\mathbf{elif}\;c \leq 1.25 \cdot 10^{+14}:\\
\;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\

\mathbf{else}:\\
\;\;\;\;\frac{a + \left(t\_0 - a \cdot \left(\frac{d}{c} \cdot \frac{d}{c}\right)\right)}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -2.8999999999999998e70

    1. Initial program 36.0%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative85.9%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
    5. Simplified85.9%

      \[\leadsto \color{blue}{\frac{a + \frac{d \cdot b}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-*r/89.6%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
      2. *-commutative89.6%

        \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]
    7. Applied egg-rr89.6%

      \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]

    if -2.8999999999999998e70 < c < 3.6e-95

    1. Initial program 66.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. associate-/l*86.8%

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

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{d}} \]

    if 3.6e-95 < c < 1.25e14

    1. Initial program 94.6%

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

      \[\leadsto \frac{\color{blue}{a \cdot \left(c + \frac{b \cdot d}{a}\right)}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. associate-/l*94.7%

        \[\leadsto \frac{a \cdot \left(c + \color{blue}{b \cdot \frac{d}{a}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified94.7%

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

    if 1.25e14 < 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 68.6%

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

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

        \[\leadsto \frac{a + \left(\frac{b \cdot d}{c} + \color{blue}{\left(-\frac{a \cdot {d}^{2}}{{c}^{2}}\right)}\right)}{c} \]
      3. unsub-neg68.6%

        \[\leadsto \frac{a + \color{blue}{\left(\frac{b \cdot d}{c} - \frac{a \cdot {d}^{2}}{{c}^{2}}\right)}}{c} \]
      4. *-commutative68.6%

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

        \[\leadsto \frac{a + \left(\color{blue}{d \cdot \frac{b}{c}} - \frac{a \cdot {d}^{2}}{{c}^{2}}\right)}{c} \]
      6. associate-/l*74.6%

        \[\leadsto \frac{a + \left(d \cdot \frac{b}{c} - \color{blue}{a \cdot \frac{{d}^{2}}{{c}^{2}}}\right)}{c} \]
    5. Simplified74.6%

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

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

        \[\leadsto \frac{a + \left(d \cdot \frac{b}{c} - a \cdot \frac{d \cdot d}{\color{blue}{c \cdot c}}\right)}{c} \]
      3. times-frac81.8%

        \[\leadsto \frac{a + \left(d \cdot \frac{b}{c} - a \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{d}{c}\right)}\right)}{c} \]
    7. Applied egg-rr81.8%

      \[\leadsto \frac{a + \left(d \cdot \frac{b}{c} - a \cdot \color{blue}{\left(\frac{d}{c} \cdot \frac{d}{c}\right)}\right)}{c} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification87.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.9 \cdot 10^{+70}:\\ \;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{elif}\;c \leq 3.6 \cdot 10^{-95}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{+14}:\\ \;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \left(\frac{b}{c} \cdot d - a \cdot \left(\frac{d}{c} \cdot \frac{d}{c}\right)\right)}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 78.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{if}\;c \leq -1.25 \cdot 10^{+71}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 3.2 \cdot 10^{-95}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.06 \cdot 10^{+14}:\\ \;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ a (* (/ b c) d)) c)))
   (if (<= c -1.25e+71)
     t_0
     (if (<= c 3.2e-95)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c 1.06e+14)
         (/ (* a (+ c (* b (/ d a)))) (+ (* c c) (* d d)))
         t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (a + ((b / c) * d)) / c;
	double tmp;
	if (c <= -1.25e+71) {
		tmp = t_0;
	} else if (c <= 3.2e-95) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.06e+14) {
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (a + ((b / c) * d)) / c
    if (c <= (-1.25d+71)) then
        tmp = t_0
    else if (c <= 3.2d-95) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 1.06d+14) then
        tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a + ((b / c) * d)) / c;
	double tmp;
	if (c <= -1.25e+71) {
		tmp = t_0;
	} else if (c <= 3.2e-95) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.06e+14) {
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a + ((b / c) * d)) / c
	tmp = 0
	if c <= -1.25e+71:
		tmp = t_0
	elif c <= 3.2e-95:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.06e+14:
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a + Float64(Float64(b / c) * d)) / c)
	tmp = 0.0
	if (c <= -1.25e+71)
		tmp = t_0;
	elseif (c <= 3.2e-95)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.06e+14)
		tmp = Float64(Float64(a * Float64(c + Float64(b * Float64(d / a)))) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a + ((b / c) * d)) / c;
	tmp = 0.0;
	if (c <= -1.25e+71)
		tmp = t_0;
	elseif (c <= 3.2e-95)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.06e+14)
		tmp = (a * (c + (b * (d / a)))) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.25e+71], t$95$0, If[LessEqual[c, 3.2e-95], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.06e+14], N[(N[(a * N[(c + N[(b * N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 3.2 \cdot 10^{-95}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

\mathbf{elif}\;c \leq 1.06 \cdot 10^{+14}:\\
\;\;\;\;\frac{a \cdot \left(c + b \cdot \frac{d}{a}\right)}{c \cdot c + d \cdot d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.24999999999999993e71 or 1.06e14 < c

    1. Initial program 39.9%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative81.9%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
    5. Simplified81.9%

      \[\leadsto \color{blue}{\frac{a + \frac{d \cdot b}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-*r/85.6%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
      2. *-commutative85.6%

        \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]
    7. Applied egg-rr85.6%

      \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]

    if -1.24999999999999993e71 < c < 3.1999999999999997e-95

    1. Initial program 66.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. associate-/l*86.8%

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

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{d}} \]

    if 3.1999999999999997e-95 < c < 1.06e14

    1. Initial program 94.6%

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

      \[\leadsto \frac{\color{blue}{a \cdot \left(c + \frac{b \cdot d}{a}\right)}}{c \cdot c + d \cdot d} \]
    4. Step-by-step derivation
      1. associate-/l*94.7%

        \[\leadsto \frac{a \cdot \left(c + \color{blue}{b \cdot \frac{d}{a}}\right)}{c \cdot c + d \cdot d} \]
    5. Simplified94.7%

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

Alternative 3: 79.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{if}\;c \leq -1.28 \cdot 10^{+71}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;c \leq 5.1 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.28 \cdot 10^{+14}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (/ (+ a (* (/ b c) d)) c)))
   (if (<= c -1.28e+71)
     t_0
     (if (<= c 5.1e-99)
       (/ (+ b (* a (/ c d))) d)
       (if (<= c 1.28e+14) (/ (+ (* c a) (* b d)) (+ (* c c) (* d d))) t_0)))))
double code(double a, double b, double c, double d) {
	double t_0 = (a + ((b / c) * d)) / c;
	double tmp;
	if (c <= -1.28e+71) {
		tmp = t_0;
	} else if (c <= 5.1e-99) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.28e+14) {
		tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = (a + ((b / c) * d)) / c
    if (c <= (-1.28d+71)) then
        tmp = t_0
    else if (c <= 5.1d-99) then
        tmp = (b + (a * (c / d))) / d
    else if (c <= 1.28d+14) then
        tmp = ((c * a) + (b * d)) / ((c * c) + (d * d))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double t_0 = (a + ((b / c) * d)) / c;
	double tmp;
	if (c <= -1.28e+71) {
		tmp = t_0;
	} else if (c <= 5.1e-99) {
		tmp = (b + (a * (c / d))) / d;
	} else if (c <= 1.28e+14) {
		tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a + ((b / c) * d)) / c
	tmp = 0
	if c <= -1.28e+71:
		tmp = t_0
	elif c <= 5.1e-99:
		tmp = (b + (a * (c / d))) / d
	elif c <= 1.28e+14:
		tmp = ((c * a) + (b * d)) / ((c * c) + (d * d))
	else:
		tmp = t_0
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a + Float64(Float64(b / c) * d)) / c)
	tmp = 0.0
	if (c <= -1.28e+71)
		tmp = t_0;
	elseif (c <= 5.1e-99)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	elseif (c <= 1.28e+14)
		tmp = Float64(Float64(Float64(c * a) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a + ((b / c) * d)) / c;
	tmp = 0.0;
	if (c <= -1.28e+71)
		tmp = t_0;
	elseif (c <= 5.1e-99)
		tmp = (b + (a * (c / d))) / d;
	elseif (c <= 1.28e+14)
		tmp = ((c * a) + (b * d)) / ((c * c) + (d * d));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -1.28e+71], t$95$0, If[LessEqual[c, 5.1e-99], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 1.28e+14], N[(N[(N[(c * a), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{a + \frac{b}{c} \cdot d}{c}\\
\mathbf{if}\;c \leq -1.28 \cdot 10^{+71}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 5.1 \cdot 10^{-99}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.2800000000000001e71 or 1.28e14 < c

    1. Initial program 39.9%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative81.9%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
    5. Simplified81.9%

      \[\leadsto \color{blue}{\frac{a + \frac{d \cdot b}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-*r/85.6%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
      2. *-commutative85.6%

        \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]
    7. Applied egg-rr85.6%

      \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]

    if -1.2800000000000001e71 < c < 5.0999999999999999e-99

    1. Initial program 66.1%

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

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. associate-/l*86.8%

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

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{d}} \]

    if 5.0999999999999999e-99 < c < 1.28e14

    1. Initial program 94.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
  3. Recombined 3 regimes into one program.
  4. Final simplification87.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -1.28 \cdot 10^{+71}:\\ \;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{elif}\;c \leq 5.1 \cdot 10^{-99}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.28 \cdot 10^{+14}:\\ \;\;\;\;\frac{c \cdot a + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.9 \cdot 10^{+70} \lor \neg \left(c \leq 2.5 \cdot 10^{-79}\right):\\ \;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -2.9e+70) (not (<= c 2.5e-79)))
   (/ (+ a (* (/ b c) d)) c)
   (/ (+ b (* a (/ c d))) d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.9e+70) || !(c <= 2.5e-79)) {
		tmp = (a + ((b / c) * d)) / c;
	} else {
		tmp = (b + (a * (c / d))) / 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 ((c <= (-2.9d+70)) .or. (.not. (c <= 2.5d-79))) then
        tmp = (a + ((b / c) * d)) / c
    else
        tmp = (b + (a * (c / d))) / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.9e+70) || !(c <= 2.5e-79)) {
		tmp = (a + ((b / c) * d)) / c;
	} else {
		tmp = (b + (a * (c / d))) / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.9e+70) or not (c <= 2.5e-79):
		tmp = (a + ((b / c) * d)) / c
	else:
		tmp = (b + (a * (c / d))) / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.9e+70) || !(c <= 2.5e-79))
		tmp = Float64(Float64(a + Float64(Float64(b / c) * d)) / c);
	else
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -2.9e+70) || ~((c <= 2.5e-79)))
		tmp = (a + ((b / c) * d)) / c;
	else
		tmp = (b + (a * (c / d))) / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.9e+70], N[Not[LessEqual[c, 2.5e-79]], $MachinePrecision]], N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.9 \cdot 10^{+70} \lor \neg \left(c \leq 2.5 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.8999999999999998e70 or 2.5e-79 < c

    1. Initial program 47.8%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative78.6%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
    5. Simplified78.6%

      \[\leadsto \color{blue}{\frac{a + \frac{d \cdot b}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-*r/81.0%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
      2. *-commutative81.0%

        \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]
    7. Applied egg-rr81.0%

      \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]

    if -2.8999999999999998e70 < c < 2.5e-79

    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 d around inf 84.8%

      \[\leadsto \color{blue}{\frac{b + \frac{a \cdot c}{d}}{d}} \]
    4. Step-by-step derivation
      1. associate-/l*86.2%

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

      \[\leadsto \color{blue}{\frac{b + a \cdot \frac{c}{d}}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.6%

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

Alternative 5: 69.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -6 \cdot 10^{-19} \lor \neg \left(c \leq 1.3 \cdot 10^{-80}\right):\\ \;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -6e-19) (not (<= c 1.3e-80)))
   (/ (+ a (* (/ b c) d)) c)
   (/ b d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6e-19) || !(c <= 1.3e-80)) {
		tmp = (a + ((b / c) * d)) / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-6d-19)) .or. (.not. (c <= 1.3d-80))) then
        tmp = (a + ((b / c) * d)) / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -6e-19) || !(c <= 1.3e-80)) {
		tmp = (a + ((b / c) * d)) / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -6e-19) or not (c <= 1.3e-80):
		tmp = (a + ((b / c) * d)) / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -6e-19) || !(c <= 1.3e-80))
		tmp = Float64(Float64(a + Float64(Float64(b / c) * d)) / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -6e-19) || ~((c <= 1.3e-80)))
		tmp = (a + ((b / c) * d)) / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -6e-19], N[Not[LessEqual[c, 1.3e-80]], $MachinePrecision]], N[(N[(a + N[(N[(b / c), $MachinePrecision] * d), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -6 \cdot 10^{-19} \lor \neg \left(c \leq 1.3 \cdot 10^{-80}\right):\\
\;\;\;\;\frac{a + \frac{b}{c} \cdot d}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -5.99999999999999985e-19 or 1.3e-80 < c

    1. Initial program 50.4%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    4. Step-by-step derivation
      1. *-commutative74.0%

        \[\leadsto \frac{a + \frac{\color{blue}{d \cdot b}}{c}}{c} \]
    5. Simplified74.0%

      \[\leadsto \color{blue}{\frac{a + \frac{d \cdot b}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-*r/76.1%

        \[\leadsto \frac{a + \color{blue}{d \cdot \frac{b}{c}}}{c} \]
      2. *-commutative76.1%

        \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]
    7. Applied egg-rr76.1%

      \[\leadsto \frac{a + \color{blue}{\frac{b}{c} \cdot d}}{c} \]

    if -5.99999999999999985e-19 < c < 1.3e-80

    1. Initial program 67.5%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.9%

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

Alternative 6: 69.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.5 \cdot 10^{-21} \lor \neg \left(c \leq 1.85 \cdot 10^{-79}\right):\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -1.5e-21) (not (<= c 1.85e-79)))
   (/ (+ a (* b (/ d c))) c)
   (/ b d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -1.5e-21) || !(c <= 1.85e-79)) {
		tmp = (a + (b * (d / c))) / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-1.5d-21)) .or. (.not. (c <= 1.85d-79))) then
        tmp = (a + (b * (d / c))) / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -1.5e-21) || !(c <= 1.85e-79)) {
		tmp = (a + (b * (d / c))) / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -1.5e-21) or not (c <= 1.85e-79):
		tmp = (a + (b * (d / c))) / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -1.5e-21) || !(c <= 1.85e-79))
		tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -1.5e-21) || ~((c <= 1.85e-79)))
		tmp = (a + (b * (d / c))) / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -1.5e-21], N[Not[LessEqual[c, 1.85e-79]], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.5 \cdot 10^{-21} \lor \neg \left(c \leq 1.85 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -1.49999999999999996e-21 or 1.85000000000000009e-79 < c

    1. Initial program 50.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-inv50.3%

        \[\leadsto \color{blue}{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{c \cdot c + d \cdot d}} \]
      2. fma-define50.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(a, c, b \cdot d\right)} \cdot \frac{1}{c \cdot c + d \cdot d} \]
      3. add-sqr-sqrt50.3%

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

        \[\leadsto \mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\color{blue}{{\left(\sqrt{c \cdot c + d \cdot d}\right)}^{2}}} \]
      5. hypot-define50.3%

        \[\leadsto \mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{{\color{blue}{\left(\mathsf{hypot}\left(c, d\right)\right)}}^{2}} \]
    4. Applied egg-rr50.3%

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

      \[\leadsto \color{blue}{\frac{a + \frac{b \cdot d}{c}}{c}} \]
    6. Step-by-step derivation
      1. associate-/l*76.0%

        \[\leadsto \frac{a + \color{blue}{b \cdot \frac{d}{c}}}{c} \]
    7. Simplified76.0%

      \[\leadsto \color{blue}{\frac{a + b \cdot \frac{d}{c}}{c}} \]

    if -1.49999999999999996e-21 < c < 1.85000000000000009e-79

    1. Initial program 67.5%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.9%

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

Alternative 7: 63.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -3.2 \cdot 10^{-21} \lor \neg \left(c \leq 14500000000\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -3.2e-21) (not (<= c 14500000000.0))) (/ a c) (/ b d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -3.2e-21) || !(c <= 14500000000.0)) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if ((c <= (-3.2d-21)) .or. (.not. (c <= 14500000000.0d0))) then
        tmp = a / c
    else
        tmp = b / d
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -3.2e-21) || !(c <= 14500000000.0)) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -3.2e-21) or not (c <= 14500000000.0):
		tmp = a / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -3.2e-21) || !(c <= 14500000000.0))
		tmp = Float64(a / c);
	else
		tmp = Float64(b / d);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if ((c <= -3.2e-21) || ~((c <= 14500000000.0)))
		tmp = a / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -3.2e-21], N[Not[LessEqual[c, 14500000000.0]], $MachinePrecision]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.2 \cdot 10^{-21} \lor \neg \left(c \leq 14500000000\right):\\
\;\;\;\;\frac{a}{c}\\

\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.2000000000000002e-21 or 1.45e10 < c

    1. Initial program 44.0%

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

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

    if -3.2000000000000002e-21 < c < 1.45e10

    1. Initial program 71.4%

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

      \[\leadsto \color{blue}{\frac{b}{d}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.8%

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

Alternative 8: 43.0% accurate, 5.0× 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 57.6%

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

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

Developer Target 1: 99.4% accurate, 0.1× 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 2024180 
(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))))