Complex division, real part

Percentage Accurate: 62.0% → 85.9%
Time: 8.1s
Alternatives: 8
Speedup: 1.3×

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

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) INFINITY)
   (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d)))
   (+ (/ b d) (/ (/ c d) (/ d a)))))
double code(double a, double b, double c, double d) {
	double tmp;
	if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
	} else {
		tmp = (b / d) + ((c / d) / (d / a));
	}
	return tmp;
}
function code(a, b, c, d)
	tmp = 0.0
	if (Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)));
	else
		tmp = Float64(Float64(b / d) + Float64(Float64(c / d) / Float64(d / a)));
	end
	return tmp
end
code[a_, b_, c_, d_] := If[LessEqual[N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], 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], N[(N[(b / d), $MachinePrecision] + N[(N[(c / d), $MachinePrecision] / N[(d / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\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{else}:\\
\;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0

    1. Initial program 78.7%

      \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \]
    2. Step-by-step derivation
      1. *-un-lft-identity78.7%

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

        \[\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-frac78.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-def78.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-def78.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-def95.8%

        \[\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)}} \]
    3. Applied egg-rr95.8%

      \[\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 +inf.0 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d)))

    1. Initial program 0.0%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow249.7%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac57.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{c}{d}}{\frac{d}{a}}\\ \end{array} \]

Alternative 2: 80.8% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -5.5 \cdot 10^{+84}:\\
\;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\

\mathbf{elif}\;c \leq -3.25 \cdot 10^{-201}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;c \leq 1.02 \cdot 10^{+95}:\\
\;\;\;\;t_0\\

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


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

    1. Initial program 45.4%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow290.0%

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

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

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

    if -5.5000000000000004e84 < c < -3.24999999999999987e-201 or 2.2999999999999999e-25 < c < 1.0200000000000001e95

    1. Initial program 80.8%

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

    if -3.24999999999999987e-201 < c < 2.2999999999999999e-25

    1. Initial program 70.0%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow285.5%

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

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

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

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

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

    if 1.0200000000000001e95 < c

    1. Initial program 36.3%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac78.2%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c} \cdot \color{blue}{\frac{1}{\frac{c}{d}}} \]
      3. un-div-inv78.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -5.5 \cdot 10^{+84}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{elif}\;c \leq -3.25 \cdot 10^{-201}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;c \leq 2.3 \cdot 10^{-25}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 1.02 \cdot 10^{+95}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]

Alternative 3: 75.7% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -0.35:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -0.34999999999999998 or 4e53 < c

    1. Initial program 51.2%

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

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

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac81.9%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
      2. clear-num81.9%

        \[\leadsto \frac{a}{c} + \frac{b}{c} \cdot \color{blue}{\frac{1}{\frac{c}{d}}} \]
      3. un-div-inv82.0%

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

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

    if -0.34999999999999998 < c < 1.1999999999999999e-24

    1. Initial program 73.4%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow281.9%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac85.9%

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

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

    if 1.1999999999999999e-24 < c < 3.4000000000000001e24

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow280.8%

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1 \cdot b}{\frac{c}{d} \cdot c}} \]
      3. *-un-lft-identity80.8%

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

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

    if 3.4000000000000001e24 < c < 4e53

    1. Initial program 77.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -0.35:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \mathbf{elif}\;c \leq 1.2 \cdot 10^{-24}:\\ \;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\ \mathbf{elif}\;c \leq 3.4 \cdot 10^{+24}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq 4 \cdot 10^{+53}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]

Alternative 4: 76.6% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
t_0 := \frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{-8}:\\
\;\;\;\;t_0\\

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

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

\mathbf{elif}\;c \leq 2.2 \cdot 10^{+52}:\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if c < -6.59999999999999954e-8 or 2.2e52 < c

    1. Initial program 52.1%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow274.0%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac81.4%

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

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

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

        \[\leadsto \frac{a}{c} + \frac{b}{c} \cdot \color{blue}{\frac{1}{\frac{c}{d}}} \]
      3. un-div-inv81.5%

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

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

    if -6.59999999999999954e-8 < c < 1.90000000000000006e-23

    1. Initial program 73.4%

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

      \[\leadsto \color{blue}{\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}} \]
    3. Step-by-step derivation
      1. unpow281.9%

        \[\leadsto \frac{b}{d} + \frac{c \cdot a}{\color{blue}{d \cdot d}} \]
      2. times-frac85.9%

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

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

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

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

    if 1.90000000000000006e-23 < c < 2.20000000000000002e24

    1. Initial program 99.8%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow280.8%

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

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

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{1 \cdot b}{\frac{c}{d} \cdot c}} \]
      3. *-un-lft-identity80.8%

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

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

    if 2.20000000000000002e24 < c < 2.2e52

    1. Initial program 71.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -6.6 \cdot 10^{-8}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \mathbf{elif}\;c \leq 1.9 \cdot 10^{-23}:\\ \;\;\;\;\frac{b}{d} + \frac{a \cdot \frac{c}{d}}{d}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+24}:\\ \;\;\;\;\frac{a}{c} + \frac{b}{c \cdot \frac{c}{d}}\\ \mathbf{elif}\;c \leq 2.2 \cdot 10^{+52}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]

Alternative 5: 70.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.1 \cdot 10^{-35} \lor \neg \left(d \leq 3.9 \cdot 10^{+118}\right):\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -4.10000000000000026e-35 or 3.9e118 < d

    1. Initial program 54.5%

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

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

    if -4.10000000000000026e-35 < d < 3.9e118

    1. Initial program 73.8%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow270.7%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac76.8%

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

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

        \[\leadsto \frac{a}{c} + \color{blue}{\frac{b}{c} \cdot \frac{d}{c}} \]
      2. clear-num76.8%

        \[\leadsto \frac{a}{c} + \frac{b}{c} \cdot \color{blue}{\frac{1}{\frac{c}{d}}} \]
      3. un-div-inv76.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.1 \cdot 10^{-35} \lor \neg \left(d \leq 3.9 \cdot 10^{+118}\right):\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c} + \frac{\frac{b}{c}}{\frac{c}{d}}\\ \end{array} \]

Alternative 6: 70.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.2 \cdot 10^{-35}:\\
\;\;\;\;\frac{b}{d}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -5.20000000000000009e-35 or 6.5999999999999996e117 < d

    1. Initial program 54.5%

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

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

    if -5.20000000000000009e-35 < d < 6.5999999999999996e117

    1. Initial program 73.8%

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

      \[\leadsto \color{blue}{\frac{a}{c} + \frac{d \cdot b}{{c}^{2}}} \]
    3. Step-by-step derivation
      1. unpow270.7%

        \[\leadsto \frac{a}{c} + \frac{d \cdot b}{\color{blue}{c \cdot c}} \]
      2. times-frac76.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5.2 \cdot 10^{-35}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{elif}\;d \leq 6.6 \cdot 10^{+117}:\\ \;\;\;\;\frac{a}{c} + \frac{d}{c} \cdot \frac{b}{c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d}\\ \end{array} \]

Alternative 7: 63.0% accurate, 1.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.7 \cdot 10^{+80}:\\
\;\;\;\;\frac{a}{c}\\

\mathbf{elif}\;c \leq 1.7 \cdot 10^{-23} \lor \neg \left(c \leq 3.8 \cdot 10^{+24}\right) \land c \leq 2.65 \cdot 10^{+53}:\\
\;\;\;\;\frac{b}{d}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.69999999999999996e80 or 1.7e-23 < c < 3.80000000000000015e24 or 2.6500000000000001e53 < c

    1. Initial program 51.8%

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

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

    if -3.69999999999999996e80 < c < 1.7e-23 or 3.80000000000000015e24 < c < 2.6500000000000001e53

    1. Initial program 73.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;c \leq -3.7 \cdot 10^{+80}:\\ \;\;\;\;\frac{a}{c}\\ \mathbf{elif}\;c \leq 1.7 \cdot 10^{-23} \lor \neg \left(c \leq 3.8 \cdot 10^{+24}\right) \land c \leq 2.65 \cdot 10^{+53}:\\ \;\;\;\;\frac{b}{d}\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{c}\\ \end{array} \]

Alternative 8: 42.6% 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 64.5%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  3. Final simplification41.6%

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

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

  :herbie-target
  (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))))