Complex division, real part

Percentage Accurate: 61.4% → 84.5%
Time: 9.3s
Alternatives: 8
Speedup: 0.8×

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: 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: 84.5% accurate, 0.0× speedup?

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

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

\mathbf{elif}\;c \leq -2.55 \cdot 10^{-64}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;c \leq 5.5 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 43.8%

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

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

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

      \[\leadsto \color{blue}{\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}} \]
    6. Step-by-step derivation
      1. *-un-lft-identity88.7%

        \[\leadsto \frac{a}{c} + b \cdot \frac{\color{blue}{1 \cdot d}}{{c}^{2}} \]
      2. pow288.7%

        \[\leadsto \frac{a}{c} + b \cdot \frac{1 \cdot d}{\color{blue}{c \cdot c}} \]
      3. times-frac91.7%

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c}} \cdot \frac{d}{c} \]
      3. clear-num92.4%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1}{\frac{c}{b}}} \cdot \frac{d}{c} \]
      4. clear-num92.4%

        \[\leadsto \frac{a}{c} + \frac{1}{\frac{c}{b}} \cdot \color{blue}{\frac{1}{\frac{c}{d}}} \]
      5. frac-times92.4%

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1 \cdot 1}{\frac{c}{b} \cdot \frac{c}{d}}} \]
      6. metadata-eval92.4%

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

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

    if -5.0000000000000002e206 < c < -2.54999999999999992e-64 or 4.5e-95 < c < 5.5000000000000003e119

    1. Initial program 68.4%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity68.4%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a \cdot c + b \cdot d\right)}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt68.4%

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define68.5%

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

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

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

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

    if -2.54999999999999992e-64 < c < 4.5e-95

    1. Initial program 66.4%

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

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

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

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

    if 5.5000000000000003e119 < c

    1. Initial program 34.0%

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

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

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

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

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

Alternative 2: 82.3% accurate, 0.4× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{b + a \cdot \frac{c}{d}}{d}\\
t_1 := \frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -7 \cdot 10^{+59}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\

\mathbf{elif}\;c \leq -1.7 \cdot 10^{+27}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq -3.5 \cdot 10^{-64}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;c \leq 6.5 \cdot 10^{-79}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;c \leq 1.45 \cdot 10^{+119}:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 56.4%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right)} \cdot \frac{1}{c}}{c} \]
      3. associate-*l*85.7%

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

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

    if -7e59 < c < -1.7e27 or -3.5000000000000003e-64 < c < 6.5000000000000003e-79

    1. Initial program 63.6%

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

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

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

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

    if -1.7e27 < c < -3.5000000000000003e-64 or 6.5000000000000003e-79 < c < 1.45000000000000004e119

    1. Initial program 73.8%

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

    if 1.45000000000000004e119 < c

    1. Initial program 34.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -7 \cdot 10^{+59}:\\ \;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\ \mathbf{elif}\;c \leq -1.7 \cdot 10^{+27}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq -3.5 \cdot 10^{-64}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 6.5 \cdot 10^{-79}:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.45 \cdot 10^{+119}:\\ \;\;\;\;\frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 70.2% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -53000000 \lor \neg \left(d \leq -1.65 \cdot 10^{-9}\right) \land \left(d \leq -1.3 \cdot 10^{-41} \lor \neg \left(d \leq 1.15 \cdot 10^{+149}\right)\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.3e7 or -1.65000000000000009e-9 < d < -1.3e-41 or 1.1499999999999999e149 < d

    1. Initial program 48.1%

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

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

    if -5.3e7 < d < -1.65000000000000009e-9 or -1.3e-41 < d < 1.1499999999999999e149

    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 78.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -53000000 \lor \neg \left(d \leq -1.65 \cdot 10^{-9}\right) \land \left(d \leq -1.3 \cdot 10^{-41} \lor \neg \left(d \leq 1.15 \cdot 10^{+149}\right)\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 63.4% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -2.45 \cdot 10^{+61} \lor \neg \left(c \leq -1.4 \cdot 10^{-45}\right) \land \left(c \leq -1.65 \cdot 10^{-64} \lor \neg \left(c \leq 1.45 \cdot 10^{+66}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (or (<= c -2.45e+61)
         (and (not (<= c -1.4e-45))
              (or (<= c -1.65e-64) (not (<= c 1.45e+66)))))
   (/ a c)
   (/ b d)))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((c <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66)))) {
		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 <= (-2.45d+61)) .or. (.not. (c <= (-1.4d-45))) .and. (c <= (-1.65d-64)) .or. (.not. (c <= 1.45d+66))) 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 <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66)))) {
		tmp = a / c;
	} else {
		tmp = b / d;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if (c <= -2.45e+61) or (not (c <= -1.4e-45) and ((c <= -1.65e-64) or not (c <= 1.45e+66))):
		tmp = a / c
	else:
		tmp = b / d
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if ((c <= -2.45e+61) || (!(c <= -1.4e-45) && ((c <= -1.65e-64) || !(c <= 1.45e+66))))
		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 <= -2.45e+61) || (~((c <= -1.4e-45)) && ((c <= -1.65e-64) || ~((c <= 1.45e+66)))))
		tmp = a / c;
	else
		tmp = b / d;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -2.45e+61], And[N[Not[LessEqual[c, -1.4e-45]], $MachinePrecision], Or[LessEqual[c, -1.65e-64], N[Not[LessEqual[c, 1.45e+66]], $MachinePrecision]]]], N[(a / c), $MachinePrecision], N[(b / d), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -2.45 \cdot 10^{+61} \lor \neg \left(c \leq -1.4 \cdot 10^{-45}\right) \land \left(c \leq -1.65 \cdot 10^{-64} \lor \neg \left(c \leq 1.45 \cdot 10^{+66}\right)\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -2.45000000000000013e61 or -1.4000000000000001e-45 < c < -1.65e-64 or 1.44999999999999993e66 < c

    1. Initial program 52.2%

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

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

    if -2.45000000000000013e61 < c < -1.4000000000000001e-45 or -1.65e-64 < c < 1.44999999999999993e66

    1. Initial program 64.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -2.45 \cdot 10^{+61} \lor \neg \left(c \leq -1.4 \cdot 10^{-45}\right) \land \left(c \leq -1.65 \cdot 10^{-64} \lor \neg \left(c \leq 1.45 \cdot 10^{+66}\right)\right):\\ \;\;\;\;\frac{a}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 77.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.65 \cdot 10^{+69}:\\ \;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\ \mathbf{elif}\;c \leq 1050000:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.65e+69)
   (/ (+ a (* d (* b (/ 1.0 c)))) c)
   (if (<= c 1050000.0) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.65e+69) {
		tmp = (a + (d * (b * (1.0 / c)))) / c;
	} else if (c <= 1050000.0) {
		tmp = (b + (a * (c / d))) / d;
	} else {
		tmp = (a + (d * (b / 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) :: tmp
    if (c <= (-1.65d+69)) then
        tmp = (a + (d * (b * (1.0d0 / c)))) / c
    else if (c <= 1050000.0d0) then
        tmp = (b + (a * (c / d))) / d
    else
        tmp = (a + (d * (b / c))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.65e+69) {
		tmp = (a + (d * (b * (1.0 / c)))) / c;
	} else if (c <= 1050000.0) {
		tmp = (b + (a * (c / d))) / d;
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -1.65e+69:
		tmp = (a + (d * (b * (1.0 / c)))) / c
	elif c <= 1050000.0:
		tmp = (b + (a * (c / d))) / d
	else:
		tmp = (a + (d * (b / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.65e+69)
		tmp = Float64(Float64(a + Float64(d * Float64(b * Float64(1.0 / c)))) / c);
	elseif (c <= 1050000.0)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -1.65e+69)
		tmp = (a + (d * (b * (1.0 / c)))) / c;
	elseif (c <= 1050000.0)
		tmp = (b + (a * (c / d))) / d;
	else
		tmp = (a + (d * (b / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.65e+69], N[(N[(a + N[(d * N[(b * N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 1050000.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.65 \cdot 10^{+69}:\\
\;\;\;\;\frac{a + d \cdot \left(b \cdot \frac{1}{c}\right)}{c}\\

\mathbf{elif}\;c \leq 1050000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.6499999999999999e69

    1. Initial program 56.4%

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

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

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

        \[\leadsto \frac{a + \color{blue}{\left(d \cdot b\right)} \cdot \frac{1}{c}}{c} \]
      3. associate-*l*85.7%

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

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

    if -1.6499999999999999e69 < c < 1.05e6

    1. Initial program 66.6%

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

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

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

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

    if 1.05e6 < c

    1. Initial program 47.5%

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

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

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

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

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

Alternative 6: 77.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;c \leq -1.12 \cdot 10^{+66}:\\ \;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\ \mathbf{elif}\;c \leq 5000:\\ \;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a + d \cdot \frac{b}{c}}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= c -1.12e+66)
   (/ (+ a (/ d (/ c b))) c)
   (if (<= c 5000.0) (/ (+ b (* a (/ c d))) d) (/ (+ a (* d (/ b c))) c))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.12e+66) {
		tmp = (a + (d / (c / b))) / c;
	} else if (c <= 5000.0) {
		tmp = (b + (a * (c / d))) / d;
	} else {
		tmp = (a + (d * (b / 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) :: tmp
    if (c <= (-1.12d+66)) then
        tmp = (a + (d / (c / b))) / c
    else if (c <= 5000.0d0) then
        tmp = (b + (a * (c / d))) / d
    else
        tmp = (a + (d * (b / c))) / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (c <= -1.12e+66) {
		tmp = (a + (d / (c / b))) / c;
	} else if (c <= 5000.0) {
		tmp = (b + (a * (c / d))) / d;
	} else {
		tmp = (a + (d * (b / c))) / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if c <= -1.12e+66:
		tmp = (a + (d / (c / b))) / c
	elif c <= 5000.0:
		tmp = (b + (a * (c / d))) / d
	else:
		tmp = (a + (d * (b / c))) / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (c <= -1.12e+66)
		tmp = Float64(Float64(a + Float64(d / Float64(c / b))) / c);
	elseif (c <= 5000.0)
		tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d);
	else
		tmp = Float64(Float64(a + Float64(d * Float64(b / c))) / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (c <= -1.12e+66)
		tmp = (a + (d / (c / b))) / c;
	elseif (c <= 5000.0)
		tmp = (b + (a * (c / d))) / d;
	else
		tmp = (a + (d * (b / c))) / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[c, -1.12e+66], N[(N[(a + N[(d / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 5000.0], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], N[(N[(a + N[(d * N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;c \leq -1.12 \cdot 10^{+66}:\\
\;\;\;\;\frac{a + \frac{d}{\frac{c}{b}}}{c}\\

\mathbf{elif}\;c \leq 5000:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if c < -1.12e66

    1. Initial program 56.4%

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

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

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

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

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

        \[\leadsto \frac{a + d \cdot \color{blue}{\frac{1}{\frac{c}{b}}}}{c} \]
      2. un-div-inv85.7%

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

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

    if -1.12e66 < c < 5e3

    1. Initial program 66.6%

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

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

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

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

    if 5e3 < c

    1. Initial program 47.5%

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

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

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

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

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

Alternative 7: 43.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{+194}:\\ \;\;\;\;\frac{a}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \end{array} \]
(FPCore (a b c d) :precision binary64 (if (<= d -2.5e+194) (/ a d) (/ a c)))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.5e+194) {
		tmp = a / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
real(8) function code(a, b, c, d)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8), intent (in) :: d
    real(8) :: tmp
    if (d <= (-2.5d+194)) then
        tmp = a / d
    else
        tmp = a / c
    end if
    code = tmp
end function
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -2.5e+194) {
		tmp = a / d;
	} else {
		tmp = a / c;
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -2.5e+194:
		tmp = a / d
	else:
		tmp = a / c
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -2.5e+194)
		tmp = Float64(a / d);
	else
		tmp = Float64(a / c);
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -2.5e+194)
		tmp = a / d;
	else
		tmp = a / c;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -2.5e+194], N[(a / d), $MachinePrecision], N[(a / c), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{+194}:\\
\;\;\;\;\frac{a}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.49999999999999994e194

    1. Initial program 38.6%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. *-un-lft-identity38.6%

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

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

        \[\leadsto \color{blue}{\frac{1}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}} \]
      4. hypot-define38.6%

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \color{blue}{a} \]
    6. Taylor expanded in c around 0 30.6%

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

    if -2.49999999999999994e194 < d

    1. Initial program 61.7%

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

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

Alternative 8: 43.1% 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 59.0%

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

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

Developer target: 99.2% 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 2024085 
(FPCore (a b c d)
  :name "Complex division, real part"
  :precision binary64

  :alt
  (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))))