Complex division, real part

Percentage Accurate: 61.5% → 84.8%
Time: 9.4s
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: 61.5% 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.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot c + b \cdot d\\ \mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{t\_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (let* ((t_0 (+ (* a c) (* b d))))
   (if (<= (/ t_0 (+ (* c c) (* d d))) INFINITY)
     (/ (/ t_0 (hypot c d)) (hypot c d))
     (* (/ d (hypot c d)) (/ b (hypot c d))))))
double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= ((double) INFINITY)) {
		tmp = (t_0 / hypot(c, d)) / hypot(c, d);
	} else {
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double t_0 = (a * c) + (b * d);
	double tmp;
	if ((t_0 / ((c * c) + (d * d))) <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 / Math.hypot(c, d)) / Math.hypot(c, d);
	} else {
		tmp = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	t_0 = (a * c) + (b * d)
	tmp = 0
	if (t_0 / ((c * c) + (d * d))) <= math.inf:
		tmp = (t_0 / math.hypot(c, d)) / math.hypot(c, d)
	else:
		tmp = (d / math.hypot(c, d)) * (b / math.hypot(c, d))
	return tmp
function code(a, b, c, d)
	t_0 = Float64(Float64(a * c) + Float64(b * d))
	tmp = 0.0
	if (Float64(t_0 / Float64(Float64(c * c) + Float64(d * d))) <= Inf)
		tmp = Float64(Float64(t_0 / hypot(c, d)) / hypot(c, d));
	else
		tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	t_0 = (a * c) + (b * d);
	tmp = 0.0;
	if ((t_0 / ((c * c) + (d * d))) <= Inf)
		tmp = (t_0 / hypot(c, d)) / hypot(c, d);
	else
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(t$95$0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
\mathbf{if}\;\frac{t\_0}{c \cdot c + d \cdot d} \leq \infty:\\
\;\;\;\;\frac{\frac{t\_0}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\


\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 76.7%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity76.8%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/76.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      13. hypot-def93.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-rr93.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. Step-by-step derivation
      1. associate-*l/93.4%

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

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

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

        \[\leadsto \frac{\frac{\color{blue}{a \cdot c + b \cdot d}}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \]
      2. +-commutative93.4%

        \[\leadsto \frac{\frac{\color{blue}{b \cdot d + a \cdot c}}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} \]
    8. Applied egg-rr93.4%

      \[\leadsto \frac{\frac{\color{blue}{b \cdot d + a \cdot c}}{\mathsf{hypot}\left(c, 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. Add Preprocessing
    3. Taylor expanded in a around 0 1.2%

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. hypot-udef1.2%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{c \cdot c + d \cdot d}} \]
      4. hypot-udef1.2%

        \[\leadsto \frac{d \cdot b}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
      5. times-frac65.2%

        \[\leadsto \color{blue}{\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}} \]
    5. Applied egg-rr65.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq \infty:\\ \;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 80.0% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{+130}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+23}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \end{array} \]
(FPCore (a b c d)
 :precision binary64
 (if (<= d -3.4e+130)
   (+ (/ b d) (/ (/ 1.0 (/ (/ d c) a)) d))
   (if (<= d -3.4e-105)
     (/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
     (if (<= d 3.2e+23)
       (* (/ 1.0 c) (+ a (/ b (/ c d))))
       (* (/ d (hypot c d)) (/ b (hypot c d)))))))
double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3.4e+130) {
		tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
	} else if (d <= -3.4e-105) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 3.2e+23) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else {
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	}
	return tmp;
}
public static double code(double a, double b, double c, double d) {
	double tmp;
	if (d <= -3.4e+130) {
		tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
	} else if (d <= -3.4e-105) {
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	} else if (d <= 3.2e+23) {
		tmp = (1.0 / c) * (a + (b / (c / d)));
	} else {
		tmp = (d / Math.hypot(c, d)) * (b / Math.hypot(c, d));
	}
	return tmp;
}
def code(a, b, c, d):
	tmp = 0
	if d <= -3.4e+130:
		tmp = (b / d) + ((1.0 / ((d / c) / a)) / d)
	elif d <= -3.4e-105:
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
	elif d <= 3.2e+23:
		tmp = (1.0 / c) * (a + (b / (c / d)))
	else:
		tmp = (d / math.hypot(c, d)) * (b / math.hypot(c, d))
	return tmp
function code(a, b, c, d)
	tmp = 0.0
	if (d <= -3.4e+130)
		tmp = Float64(Float64(b / d) + Float64(Float64(1.0 / Float64(Float64(d / c) / a)) / d));
	elseif (d <= -3.4e-105)
		tmp = Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)));
	elseif (d <= 3.2e+23)
		tmp = Float64(Float64(1.0 / c) * Float64(a + Float64(b / Float64(c / d))));
	else
		tmp = Float64(Float64(d / hypot(c, d)) * Float64(b / hypot(c, d)));
	end
	return tmp
end
function tmp_2 = code(a, b, c, d)
	tmp = 0.0;
	if (d <= -3.4e+130)
		tmp = (b / d) + ((1.0 / ((d / c) / a)) / d);
	elseif (d <= -3.4e-105)
		tmp = ((a * c) + (b * d)) / ((c * c) + (d * d));
	elseif (d <= 3.2e+23)
		tmp = (1.0 / c) * (a + (b / (c / d)));
	else
		tmp = (d / hypot(c, d)) * (b / hypot(c, d));
	end
	tmp_2 = tmp;
end
code[a_, b_, c_, d_] := If[LessEqual[d, -3.4e+130], N[(N[(b / d), $MachinePrecision] + N[(N[(1.0 / N[(N[(d / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.4e-105], N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.2e+23], N[(N[(1.0 / c), $MachinePrecision] * N[(a + N[(b / N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(b / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.4000000000000001e130

    1. Initial program 41.1%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/82.0%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*88.4%

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\frac{1}{\frac{d}{\color{blue}{c \cdot a}}}}{d} \]
      3. associate-/r*88.5%

        \[\leadsto \frac{b}{d} + \frac{\frac{1}{\color{blue}{\frac{\frac{d}{c}}{a}}}}{d} \]
    11. Simplified88.5%

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

    if -3.4000000000000001e130 < d < -3.39999999999999992e-105

    1. Initial program 81.6%

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

    if -3.39999999999999992e-105 < d < 3.2e23

    1. Initial program 70.7%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef70.7%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity70.7%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/70.7%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      13. hypot-def85.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)}} \]
    4. Applied egg-rr85.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)}} \]
    5. Taylor expanded in c around inf 49.3%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \color{blue}{\frac{b}{\frac{c}{d}}}\right) \]
    7. Simplified50.2%

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

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

    if 3.2e23 < d

    1. Initial program 46.3%

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

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

        \[\leadsto \frac{\color{blue}{d \cdot b}}{c \cdot c + d \cdot d} \]
      2. add-sqr-sqrt41.7%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}} \]
      3. hypot-udef41.7%

        \[\leadsto \frac{d \cdot b}{\color{blue}{\mathsf{hypot}\left(c, d\right)} \cdot \sqrt{c \cdot c + d \cdot d}} \]
      4. hypot-udef41.7%

        \[\leadsto \frac{d \cdot b}{\mathsf{hypot}\left(c, d\right) \cdot \color{blue}{\mathsf{hypot}\left(c, d\right)}} \]
      5. times-frac81.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{+130}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\ \mathbf{elif}\;d \leq -3.4 \cdot 10^{-105}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{+23}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{b}{\mathsf{hypot}\left(c, d\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 80.5% accurate, 0.6× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.4000000000000001e130

    1. Initial program 41.1%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/82.0%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*88.4%

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

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

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

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\frac{1}{\frac{d}{\color{blue}{c \cdot a}}}}{d} \]
      3. associate-/r*88.5%

        \[\leadsto \frac{b}{d} + \frac{\frac{1}{\color{blue}{\frac{\frac{d}{c}}{a}}}}{d} \]
    11. Simplified88.5%

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

    if -3.4000000000000001e130 < d < -9.4999999999999999e-107

    1. Initial program 81.6%

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

    if -9.4999999999999999e-107 < d < 6.19999999999999941e23

    1. Initial program 70.7%

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{d \cdot d + c \cdot c}} \]
      2. fma-udef70.7%

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity70.7%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/70.7%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\sqrt{\color{blue}{c \cdot c + d \cdot d}}} \]
      13. hypot-def85.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)}} \]
    4. Applied egg-rr85.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)}} \]
    5. Taylor expanded in c around inf 49.3%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \color{blue}{\frac{b}{\frac{c}{d}}}\right) \]
    7. Simplified50.2%

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

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

    if 6.19999999999999941e23 < d

    1. Initial program 46.3%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*74.8%

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{e^{\mathsf{log1p}\left(\frac{a \cdot c}{d}\right)} - 1}}{d} \]
      3. associate-/l*70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(\color{blue}{\frac{a}{\frac{d}{c}}}\right)} - 1}{d} \]
      4. div-inv70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(\color{blue}{a \cdot \frac{1}{\frac{d}{c}}}\right)} - 1}{d} \]
      5. clear-num70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(a \cdot \color{blue}{\frac{c}{d}}\right)} - 1}{d} \]
    9. Applied egg-rr70.8%

      \[\leadsto \frac{b}{d} + \frac{\color{blue}{e^{\mathsf{log1p}\left(a \cdot \frac{c}{d}\right)} - 1}}{d} \]
    10. Step-by-step derivation
      1. expm1-def76.0%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(a \cdot \frac{c}{d}\right)\right)}}{d} \]
      2. expm1-log1p78.5%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{a \cdot \frac{c}{d}}}{d} \]
      3. associate-*r/74.8%

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

        \[\leadsto \frac{b}{d} + \frac{\frac{\color{blue}{c \cdot a}}{d}}{d} \]
      5. associate-*r/78.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.4 \cdot 10^{+130}:\\ \;\;\;\;\frac{b}{d} + \frac{\frac{1}{\frac{\frac{d}{c}}{a}}}{d}\\ \mathbf{elif}\;d \leq -9.5 \cdot 10^{-107}:\\ \;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\ \mathbf{elif}\;d \leq 6.2 \cdot 10^{+23}:\\ \;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{b}{d} + \frac{c \cdot \frac{a}{d}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 72.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.3 \cdot 10^{+38} \lor \neg \left(d \leq 8.6 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{b}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.2999999999999999e38 or 8.5999999999999997e23 < d

    1. Initial program 49.8%

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

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

    if -3.2999999999999999e38 < d < 8.5999999999999997e23

    1. Initial program 73.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity73.6%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/73.6%

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

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

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

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

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

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

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

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

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

        \[\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-rr87.1%

      \[\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 44.2%

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

        \[\leadsto \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \left(a + \color{blue}{\frac{b}{\frac{c}{d}}}\right) \]
    7. Simplified44.9%

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

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

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

Alternative 5: 77.8% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.0115 \lor \neg \left(d \leq 5 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{c} \cdot \left(a + \frac{b}{\frac{c}{d}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -0.0115 or 5.00000000000000045e24 < d

    1. Initial program 52.6%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/75.3%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*76.6%

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

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

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

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

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

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

    if -0.0115 < d < 5.00000000000000045e24

    1. Initial program 72.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity72.6%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/72.6%

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

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

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

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

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

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

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

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

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

        \[\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.9%

      \[\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 44.8%

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

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

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

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

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

Alternative 6: 77.9% accurate, 0.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -8.00000000000000065e-5

    1. Initial program 57.7%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/74.3%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*78.1%

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

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

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

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

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

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

    if -8.00000000000000065e-5 < d < 1.25000000000000011e24

    1. Initial program 72.6%

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

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

        \[\leadsto \frac{a \cdot c + b \cdot d}{\color{blue}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      3. *-un-lft-identity72.6%

        \[\leadsto \color{blue}{1 \cdot \frac{a \cdot c + b \cdot d}{\mathsf{fma}\left(d, d, c \cdot c\right)}} \]
      4. associate-*r/72.6%

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

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

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

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

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

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

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

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

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

        \[\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.9%

      \[\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 44.8%

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

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

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

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

    if 1.25000000000000011e24 < d

    1. Initial program 46.3%

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a}{\frac{{d}^{2}}{c}}} \]
      2. associate-/r/76.5%

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

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

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

        \[\leadsto \frac{b}{d} + \color{blue}{\frac{a \cdot c}{d \cdot d}} \]
      3. associate-/r*74.8%

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

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

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

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{e^{\mathsf{log1p}\left(\frac{a \cdot c}{d}\right)} - 1}}{d} \]
      3. associate-/l*70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(\color{blue}{\frac{a}{\frac{d}{c}}}\right)} - 1}{d} \]
      4. div-inv70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(\color{blue}{a \cdot \frac{1}{\frac{d}{c}}}\right)} - 1}{d} \]
      5. clear-num70.8%

        \[\leadsto \frac{b}{d} + \frac{e^{\mathsf{log1p}\left(a \cdot \color{blue}{\frac{c}{d}}\right)} - 1}{d} \]
    9. Applied egg-rr70.8%

      \[\leadsto \frac{b}{d} + \frac{\color{blue}{e^{\mathsf{log1p}\left(a \cdot \frac{c}{d}\right)} - 1}}{d} \]
    10. Step-by-step derivation
      1. expm1-def76.0%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(a \cdot \frac{c}{d}\right)\right)}}{d} \]
      2. expm1-log1p78.5%

        \[\leadsto \frac{b}{d} + \frac{\color{blue}{a \cdot \frac{c}{d}}}{d} \]
      3. associate-*r/74.8%

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

        \[\leadsto \frac{b}{d} + \frac{\frac{\color{blue}{c \cdot a}}{d}}{d} \]
      5. associate-*r/78.5%

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

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

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

Alternative 7: 62.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;c \leq -3.8 \cdot 10^{+59} \lor \neg \left(c \leq 2.7 \cdot 10^{+18}\right):\\
\;\;\;\;\frac{a}{c}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if c < -3.8000000000000001e59 or 2.7e18 < c

    1. Initial program 43.6%

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

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

    if -3.8000000000000001e59 < c < 2.7e18

    1. Initial program 75.9%

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

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

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

Alternative 8: 42.7% 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 62.7%

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

    \[\leadsto \color{blue}{\frac{a}{c}} \]
  4. Final simplification42.2%

    \[\leadsto \frac{a}{c} \]
  5. Add Preprocessing

Developer target: 99.3% 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 2024027 
(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))))