Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.1% → 79.9%
Time: 26.6s
Alternatives: 16
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (*
  (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
  (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
double code(double d, double h, double l, double M, double D) {
	return (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    code = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m * d_1) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end function
public static double code(double d, double h, double l, double M, double D) {
	return (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
def code(d, h, l, M, D):
	return (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
function code(d, h, l, M, D)
	return Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
end
function tmp = code(d, h, l, M, D)
	tmp = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
end
code[d_, h_, l_, M_, D_] := N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)
\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 16 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: 66.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (*
  (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
  (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
double code(double d, double h, double l, double M, double D) {
	return (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    code = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m * d_1) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end function
public static double code(double d, double h, double l, double M, double D) {
	return (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
}
def code(d, h, l, M, D):
	return (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
function code(d, h, l, M, D)
	return Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
end
function tmp = code(d, h, l, M, D)
	tmp = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
end
code[d_, h_, l_, M_, D_] := N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)
\end{array}

Alternative 1: 79.9% accurate, 0.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \sqrt{-d}\\ t_1 := \sqrt{\frac{d}{\ell}} \cdot \left(\frac{t_0}{\sqrt{-h}} \cdot \left(1 + h \cdot \frac{{\left(M_m \cdot \frac{D_m}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right)\\ \mathbf{if}\;h \leq -3.8 \cdot 10^{+194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;h \leq -1.45 \cdot 10^{-190}:\\ \;\;\;\;\frac{t_0}{\sqrt{-\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D_m}{2} \cdot \frac{M_m}{d}\right)}^{2}\right)\right)\right)\\ \mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (sqrt (- d)))
        (t_1
         (*
          (sqrt (/ d l))
          (*
           (/ t_0 (sqrt (- h)))
           (+ 1.0 (* h (/ (pow (* M_m (/ D_m (/ d 0.5))) 2.0) (/ l -0.5))))))))
   (if (<= h -3.8e+194)
     t_1
     (if (<= h -1.45e-190)
       (*
        (/ t_0 (sqrt (- l)))
        (*
         (sqrt (/ d h))
         (+ 1.0 (* (/ h l) (* -0.5 (pow (* (/ D_m 2.0) (/ M_m d)) 2.0))))))
       (if (<= h -1e-310)
         t_1
         (*
          (+ 1.0 (* (pow (* (/ M_m d) (* D_m 0.5)) 2.0) (* -0.5 (/ h l))))
          (/ d (* (sqrt h) (sqrt l)))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = sqrt(-d);
	double t_1 = sqrt((d / l)) * ((t_0 / sqrt(-h)) * (1.0 + (h * (pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))));
	double tmp;
	if (h <= -3.8e+194) {
		tmp = t_1;
	} else if (h <= -1.45e-190) {
		tmp = (t_0 / sqrt(-l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * pow(((D_m / 2.0) * (M_m / d)), 2.0)))));
	} else if (h <= -1e-310) {
		tmp = t_1;
	} else {
		tmp = (1.0 + (pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sqrt(-d)
    t_1 = sqrt((d / l)) * ((t_0 / sqrt(-h)) * (1.0d0 + (h * (((m_m * (d_m / (d / 0.5d0))) ** 2.0d0) / (l / (-0.5d0))))))
    if (h <= (-3.8d+194)) then
        tmp = t_1
    else if (h <= (-1.45d-190)) then
        tmp = (t_0 / sqrt(-l)) * (sqrt((d / h)) * (1.0d0 + ((h / l) * ((-0.5d0) * (((d_m / 2.0d0) * (m_m / d)) ** 2.0d0)))))
    else if (h <= (-1d-310)) then
        tmp = t_1
    else
        tmp = (1.0d0 + ((((m_m / d) * (d_m * 0.5d0)) ** 2.0d0) * ((-0.5d0) * (h / l)))) * (d / (sqrt(h) * sqrt(l)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = Math.sqrt(-d);
	double t_1 = Math.sqrt((d / l)) * ((t_0 / Math.sqrt(-h)) * (1.0 + (h * (Math.pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))));
	double tmp;
	if (h <= -3.8e+194) {
		tmp = t_1;
	} else if (h <= -1.45e-190) {
		tmp = (t_0 / Math.sqrt(-l)) * (Math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * Math.pow(((D_m / 2.0) * (M_m / d)), 2.0)))));
	} else if (h <= -1e-310) {
		tmp = t_1;
	} else {
		tmp = (1.0 + (Math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = math.sqrt(-d)
	t_1 = math.sqrt((d / l)) * ((t_0 / math.sqrt(-h)) * (1.0 + (h * (math.pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))))
	tmp = 0
	if h <= -3.8e+194:
		tmp = t_1
	elif h <= -1.45e-190:
		tmp = (t_0 / math.sqrt(-l)) * (math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * math.pow(((D_m / 2.0) * (M_m / d)), 2.0)))))
	elif h <= -1e-310:
		tmp = t_1
	else:
		tmp = (1.0 + (math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (math.sqrt(h) * math.sqrt(l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = sqrt(Float64(-d))
	t_1 = Float64(sqrt(Float64(d / l)) * Float64(Float64(t_0 / sqrt(Float64(-h))) * Float64(1.0 + Float64(h * Float64((Float64(M_m * Float64(D_m / Float64(d / 0.5))) ^ 2.0) / Float64(l / -0.5))))))
	tmp = 0.0
	if (h <= -3.8e+194)
		tmp = t_1;
	elseif (h <= -1.45e-190)
		tmp = Float64(Float64(t_0 / sqrt(Float64(-l))) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(D_m / 2.0) * Float64(M_m / d)) ^ 2.0))))));
	elseif (h <= -1e-310)
		tmp = t_1;
	else
		tmp = Float64(Float64(1.0 + Float64((Float64(Float64(M_m / d) * Float64(D_m * 0.5)) ^ 2.0) * Float64(-0.5 * Float64(h / l)))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = sqrt(-d);
	t_1 = sqrt((d / l)) * ((t_0 / sqrt(-h)) * (1.0 + (h * (((M_m * (D_m / (d / 0.5))) ^ 2.0) / (l / -0.5)))));
	tmp = 0.0;
	if (h <= -3.8e+194)
		tmp = t_1;
	elseif (h <= -1.45e-190)
		tmp = (t_0 / sqrt(-l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * (((D_m / 2.0) * (M_m / d)) ^ 2.0)))));
	elseif (h <= -1e-310)
		tmp = t_1;
	else
		tmp = (1.0 + ((((M_m / d) * (D_m * 0.5)) ^ 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[(-d)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(t$95$0 / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(h * N[(N[Power[N[(M$95$m * N[(D$95$m / N[(d / 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[h, -3.8e+194], t$95$1, If[LessEqual[h, -1.45e-190], N[(N[(t$95$0 / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(D$95$m / 2.0), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, -1e-310], t$95$1, N[(N[(1.0 + N[(N[Power[N[(N[(M$95$m / d), $MachinePrecision] * N[(D$95$m * 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{-d}\\
t_1 := \sqrt{\frac{d}{\ell}} \cdot \left(\frac{t_0}{\sqrt{-h}} \cdot \left(1 + h \cdot \frac{{\left(M_m \cdot \frac{D_m}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right)\\
\mathbf{if}\;h \leq -3.8 \cdot 10^{+194}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;h \leq -1.45 \cdot 10^{-190}:\\
\;\;\;\;\frac{t_0}{\sqrt{-\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D_m}{2} \cdot \frac{M_m}{d}\right)}^{2}\right)\right)\right)\\

\mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -3.7999999999999999e194 or -1.4500000000000001e-190 < h < -9.999999999999969e-311

    1. Initial program 57.3%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified57.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*l/62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)}{\ell}}\right)\right) \]
      2. associate-/l*62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h}{\frac{\ell}{{\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5}}}\right)\right) \]
      3. *-commutative62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{\color{blue}{-0.5 \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}}}\right)\right) \]
      4. div-inv62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{-0.5 \cdot {\left(\color{blue}{\left(D \cdot \frac{1}{2}\right)} \cdot \frac{M}{d}\right)}^{2}}}\right)\right) \]
      5. metadata-eval62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{-0.5 \cdot {\left(\left(D \cdot \color{blue}{0.5}\right) \cdot \frac{M}{d}\right)}^{2}}}\right)\right) \]
    4. Applied egg-rr62.7%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h}{\frac{\ell}{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}}}\right)\right) \]
    5. Step-by-step derivation
      1. associate-/l*62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h \cdot \left(-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right)}{\ell}}\right)\right) \]
      2. *-commutative62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{\color{blue}{\left(-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right) \cdot h}}{\ell}\right)\right) \]
      3. associate-*l/62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell} \cdot h}\right)\right) \]
      4. *-commutative62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{h \cdot \frac{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell}}\right)\right) \]
      5. *-commutative62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{\color{blue}{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot -0.5}}{\ell}\right)\right) \]
      6. associate-/l*62.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \color{blue}{\frac{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\frac{\ell}{-0.5}}}\right)\right) \]
      7. associate-*r/62.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(\frac{\left(D \cdot 0.5\right) \cdot M}{d}\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      8. associate-*l/62.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(\frac{D \cdot 0.5}{d} \cdot M\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      9. *-commutative62.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(M \cdot \frac{D \cdot 0.5}{d}\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      10. associate-/l*62.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \color{blue}{\frac{D}{\frac{d}{0.5}}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    6. Simplified62.8%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}}\right)\right) \]
    7. Step-by-step derivation
      1. frac-2neg62.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\color{blue}{\frac{-d}{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      2. sqrt-div86.4%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    8. Applied egg-rr86.4%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]

    if -3.7999999999999999e194 < h < -1.4500000000000001e-190

    1. Initial program 69.3%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified67.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right)} \]
    3. Step-by-step derivation
      1. frac-2neg67.2%

        \[\leadsto \sqrt{\color{blue}{\frac{-d}{-\ell}}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \]
      2. sqrt-div81.4%

        \[\leadsto \color{blue}{\frac{\sqrt{-d}}{\sqrt{-\ell}}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \]
    4. Applied egg-rr81.4%

      \[\leadsto \color{blue}{\frac{\sqrt{-d}}{\sqrt{-\ell}}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \]

    if -9.999999999999969e-311 < h

    1. Initial program 69.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified69.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr71.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \]
    4. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      2. distribute-rgt1-in82.2%

        \[\leadsto \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right) + 1\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. +-commutative82.2%

        \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -3.8 \cdot 10^{+194}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right)\\ \mathbf{elif}\;h \leq -1.45 \cdot 10^{-190}:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}\right)\right)\right)\\ \mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 2: 77.0% accurate, 0.4× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M_m \cdot D_m}{d \cdot 2}\right)}^{2}\right)\right) \leq 2 \cdot 10^{+191}:\\ \;\;\;\;\left(1 - 0.5 \cdot {\left(\left(D_m \cdot 0.5\right) \cdot \left(\frac{M_m}{d} \cdot \sqrt{\frac{h}{\ell}}\right)\right)}^{2}\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<=
      (*
       (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
       (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M_m D_m) (* d 2.0)) 2.0)))))
      2e+191)
   (*
    (- 1.0 (* 0.5 (pow (* (* D_m 0.5) (* (/ M_m d) (sqrt (/ h l)))) 2.0)))
    (* (sqrt (/ d l)) (sqrt (/ d h))))
   (fabs (/ d (sqrt (* h l))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (((pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((M_m * D_m) / (d * 2.0)), 2.0))))) <= 2e+191) {
		tmp = (1.0 - (0.5 * pow(((D_m * 0.5) * ((M_m / d) * sqrt((h / l)))), 2.0))) * (sqrt((d / l)) * sqrt((d / h)));
	} else {
		tmp = fabs((d / sqrt((h * l))));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (((((d / h) ** 0.5d0) * ((d / l) ** 0.5d0)) * (1.0d0 - ((h / l) * (0.5d0 * (((m_m * d_m) / (d * 2.0d0)) ** 2.0d0))))) <= 2d+191) then
        tmp = (1.0d0 - (0.5d0 * (((d_m * 0.5d0) * ((m_m / d) * sqrt((h / l)))) ** 2.0d0))) * (sqrt((d / l)) * sqrt((d / h)))
    else
        tmp = abs((d / sqrt((h * l))))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (((Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((M_m * D_m) / (d * 2.0)), 2.0))))) <= 2e+191) {
		tmp = (1.0 - (0.5 * Math.pow(((D_m * 0.5) * ((M_m / d) * Math.sqrt((h / l)))), 2.0))) * (Math.sqrt((d / l)) * Math.sqrt((d / h)));
	} else {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if ((math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((M_m * D_m) / (d * 2.0)), 2.0))))) <= 2e+191:
		tmp = (1.0 - (0.5 * math.pow(((D_m * 0.5) * ((M_m / d) * math.sqrt((h / l)))), 2.0))) * (math.sqrt((d / l)) * math.sqrt((d / h)))
	else:
		tmp = math.fabs((d / math.sqrt((h * l))))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M_m * D_m) / Float64(d * 2.0)) ^ 2.0))))) <= 2e+191)
		tmp = Float64(Float64(1.0 - Float64(0.5 * (Float64(Float64(D_m * 0.5) * Float64(Float64(M_m / d) * sqrt(Float64(h / l)))) ^ 2.0))) * Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))));
	else
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (((((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((M_m * D_m) / (d * 2.0)) ^ 2.0))))) <= 2e+191)
		tmp = (1.0 - (0.5 * (((D_m * 0.5) * ((M_m / d) * sqrt((h / l)))) ^ 2.0))) * (sqrt((d / l)) * sqrt((d / h)));
	else
		tmp = abs((d / sqrt((h * l))));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2e+191], N[(N[(1.0 - N[(0.5 * N[Power[N[(N[(D$95$m * 0.5), $MachinePrecision] * N[(N[(M$95$m / d), $MachinePrecision] * N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M_m \cdot D_m}{d \cdot 2}\right)}^{2}\right)\right) \leq 2 \cdot 10^{+191}:\\
\;\;\;\;\left(1 - 0.5 \cdot {\left(\left(D_m \cdot 0.5\right) \cdot \left(\frac{M_m}{d} \cdot \sqrt{\frac{h}{\ell}}\right)\right)}^{2}\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 2.00000000000000015e191

    1. Initial program 87.5%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified87.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Step-by-step derivation
      1. add-sqr-sqrt87.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(\sqrt{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}} \cdot \sqrt{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}}\right)}\right) \]
      2. pow287.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{{\left(\sqrt{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}}\right)}^{2}}\right) \]
      3. sqrt-prod87.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\color{blue}{\left(\sqrt{{\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2}} \cdot \sqrt{\frac{h}{\ell}}\right)}}^{2}\right) \]
      4. unpow287.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\sqrt{\color{blue}{\frac{M}{\frac{d \cdot 2}{D}} \cdot \frac{M}{\frac{d \cdot 2}{D}}}} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      5. sqrt-prod50.0%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\color{blue}{\left(\sqrt{\frac{M}{\frac{d \cdot 2}{D}}} \cdot \sqrt{\frac{M}{\frac{d \cdot 2}{D}}}\right)} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      6. add-sqr-sqrt88.2%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\color{blue}{\frac{M}{\frac{d \cdot 2}{D}}} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      7. associate-/l*88.2%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\frac{M}{\color{blue}{\frac{d}{\frac{D}{2}}}} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      8. associate-/r/87.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\color{blue}{\left(\frac{M}{d} \cdot \frac{D}{2}\right)} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      9. *-commutative87.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\color{blue}{\left(\frac{D}{2} \cdot \frac{M}{d}\right)} \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      10. div-inv87.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\left(\color{blue}{\left(D \cdot \frac{1}{2}\right)} \cdot \frac{M}{d}\right) \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
      11. metadata-eval87.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\left(\left(\left(D \cdot \color{blue}{0.5}\right) \cdot \frac{M}{d}\right) \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \]
    4. Applied egg-rr87.5%

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{{\left(\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right) \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}}\right) \]
    5. Step-by-step derivation
      1. associate-*l*87.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot {\color{blue}{\left(\left(D \cdot 0.5\right) \cdot \left(\frac{M}{d} \cdot \sqrt{\frac{h}{\ell}}\right)\right)}}^{2}\right) \]
    6. Simplified87.5%

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{{\left(\left(D \cdot 0.5\right) \cdot \left(\frac{M}{d} \cdot \sqrt{\frac{h}{\ell}}\right)\right)}^{2}}\right) \]

    if 2.00000000000000015e191 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 23.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified23.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 24.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt23.1%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod31.9%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow231.9%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod26.3%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv26.3%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt26.3%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square26.3%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div31.9%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow231.9%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod23.1%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt60.9%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr60.9%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right) \leq 2 \cdot 10^{+191}:\\ \;\;\;\;\left(1 - 0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \left(\frac{M}{d} \cdot \sqrt{\frac{h}{\ell}}\right)\right)}^{2}\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \]

Alternative 3: 75.5% accurate, 0.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M_m \cdot D_m}{d \cdot 2}\right)}^{2}\right)\right)\\ \mathbf{if}\;t_0 \leq 2 \cdot 10^{+191}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M_m D_m) (* d 2.0)) 2.0)))))))
   (if (<= t_0 2e+191) t_0 (fabs (/ d (sqrt (* h l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((M_m * D_m) / (d * 2.0)), 2.0))));
	double tmp;
	if (t_0 <= 2e+191) {
		tmp = t_0;
	} else {
		tmp = fabs((d / sqrt((h * l))));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (((d / h) ** 0.5d0) * ((d / l) ** 0.5d0)) * (1.0d0 - ((h / l) * (0.5d0 * (((m_m * d_m) / (d * 2.0d0)) ** 2.0d0))))
    if (t_0 <= 2d+191) then
        tmp = t_0
    else
        tmp = abs((d / sqrt((h * l))))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((M_m * D_m) / (d * 2.0)), 2.0))));
	double tmp;
	if (t_0 <= 2e+191) {
		tmp = t_0;
	} else {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((M_m * D_m) / (d * 2.0)), 2.0))))
	tmp = 0
	if t_0 <= 2e+191:
		tmp = t_0
	else:
		tmp = math.fabs((d / math.sqrt((h * l))))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M_m * D_m) / Float64(d * 2.0)) ^ 2.0)))))
	tmp = 0.0
	if (t_0 <= 2e+191)
		tmp = t_0;
	else
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((M_m * D_m) / (d * 2.0)) ^ 2.0))));
	tmp = 0.0;
	if (t_0 <= 2e+191)
		tmp = t_0;
	else
		tmp = abs((d / sqrt((h * l))));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+191], t$95$0, N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M_m \cdot D_m}{d \cdot 2}\right)}^{2}\right)\right)\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{+191}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 2.00000000000000015e191

    1. Initial program 87.5%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]

    if 2.00000000000000015e191 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 23.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified23.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 24.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt23.1%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod31.9%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow231.9%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod26.3%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv26.3%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt26.3%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square26.3%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div31.9%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow231.9%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod23.1%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt60.9%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr60.9%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right) \leq 2 \cdot 10^{+191}:\\ \;\;\;\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \]

Alternative 4: 74.7% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;\ell \leq -7.2 \cdot 10^{+144}:\\ \;\;\;\;t_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-306}:\\ \;\;\;\;t_0 \cdot \left(\left(1 + h \cdot \frac{{\left(M_m \cdot \frac{D_m}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (sqrt (/ d l))))
   (if (<= l -7.2e+144)
     (* t_0 (/ (sqrt (- d)) (sqrt (- h))))
     (if (<= l 6.8e-306)
       (*
        t_0
        (*
         (+ 1.0 (* h (/ (pow (* M_m (/ D_m (/ d 0.5))) 2.0) (/ l -0.5))))
         (sqrt (/ d h))))
       (*
        (+ 1.0 (* (pow (* (/ M_m d) (* D_m 0.5)) 2.0) (* -0.5 (/ h l))))
        (/ d (* (sqrt h) (sqrt l))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = sqrt((d / l));
	double tmp;
	if (l <= -7.2e+144) {
		tmp = t_0 * (sqrt(-d) / sqrt(-h));
	} else if (l <= 6.8e-306) {
		tmp = t_0 * ((1.0 + (h * (pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))) * sqrt((d / h)));
	} else {
		tmp = (1.0 + (pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((d / l))
    if (l <= (-7.2d+144)) then
        tmp = t_0 * (sqrt(-d) / sqrt(-h))
    else if (l <= 6.8d-306) then
        tmp = t_0 * ((1.0d0 + (h * (((m_m * (d_m / (d / 0.5d0))) ** 2.0d0) / (l / (-0.5d0))))) * sqrt((d / h)))
    else
        tmp = (1.0d0 + ((((m_m / d) * (d_m * 0.5d0)) ** 2.0d0) * ((-0.5d0) * (h / l)))) * (d / (sqrt(h) * sqrt(l)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = Math.sqrt((d / l));
	double tmp;
	if (l <= -7.2e+144) {
		tmp = t_0 * (Math.sqrt(-d) / Math.sqrt(-h));
	} else if (l <= 6.8e-306) {
		tmp = t_0 * ((1.0 + (h * (Math.pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))) * Math.sqrt((d / h)));
	} else {
		tmp = (1.0 + (Math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = math.sqrt((d / l))
	tmp = 0
	if l <= -7.2e+144:
		tmp = t_0 * (math.sqrt(-d) / math.sqrt(-h))
	elif l <= 6.8e-306:
		tmp = t_0 * ((1.0 + (h * (math.pow((M_m * (D_m / (d / 0.5))), 2.0) / (l / -0.5)))) * math.sqrt((d / h)))
	else:
		tmp = (1.0 + (math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (math.sqrt(h) * math.sqrt(l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = sqrt(Float64(d / l))
	tmp = 0.0
	if (l <= -7.2e+144)
		tmp = Float64(t_0 * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))));
	elseif (l <= 6.8e-306)
		tmp = Float64(t_0 * Float64(Float64(1.0 + Float64(h * Float64((Float64(M_m * Float64(D_m / Float64(d / 0.5))) ^ 2.0) / Float64(l / -0.5)))) * sqrt(Float64(d / h))));
	else
		tmp = Float64(Float64(1.0 + Float64((Float64(Float64(M_m / d) * Float64(D_m * 0.5)) ^ 2.0) * Float64(-0.5 * Float64(h / l)))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = sqrt((d / l));
	tmp = 0.0;
	if (l <= -7.2e+144)
		tmp = t_0 * (sqrt(-d) / sqrt(-h));
	elseif (l <= 6.8e-306)
		tmp = t_0 * ((1.0 + (h * (((M_m * (D_m / (d / 0.5))) ^ 2.0) / (l / -0.5)))) * sqrt((d / h)));
	else
		tmp = (1.0 + ((((M_m / d) * (D_m * 0.5)) ^ 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -7.2e+144], N[(t$95$0 * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.8e-306], N[(t$95$0 * N[(N[(1.0 + N[(h * N[(N[Power[N[(M$95$m * N[(D$95$m / N[(d / 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / N[(l / -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[Power[N[(N[(M$95$m / d), $MachinePrecision] * N[(D$95$m * 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;\ell \leq -7.2 \cdot 10^{+144}:\\
\;\;\;\;t_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\

\mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-306}:\\
\;\;\;\;t_0 \cdot \left(\left(1 + h \cdot \frac{{\left(M_m \cdot \frac{D_m}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right) \cdot \sqrt{\frac{d}{h}}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.1999999999999995e144

    1. Initial program 51.2%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified49.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 5.3%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div5.3%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval5.3%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv5.3%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr5.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div51.8%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr51.8%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified51.8%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    10. Step-by-step derivation
      1. frac-2neg52.1%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\color{blue}{\frac{-d}{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      2. sqrt-div63.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    11. Applied egg-rr62.7%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \]

    if -7.1999999999999995e144 < l < 6.7999999999999996e-306

    1. Initial program 70.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified68.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)\right)\right)} \]
    3. Step-by-step derivation
      1. associate-*l/70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h \cdot \left({\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5\right)}{\ell}}\right)\right) \]
      2. associate-/l*70.4%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h}{\frac{\ell}{{\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2} \cdot -0.5}}}\right)\right) \]
      3. *-commutative70.4%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{\color{blue}{-0.5 \cdot {\left(\frac{D}{2} \cdot \frac{M}{d}\right)}^{2}}}}\right)\right) \]
      4. div-inv70.4%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{-0.5 \cdot {\left(\color{blue}{\left(D \cdot \frac{1}{2}\right)} \cdot \frac{M}{d}\right)}^{2}}}\right)\right) \]
      5. metadata-eval70.4%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\frac{\ell}{-0.5 \cdot {\left(\left(D \cdot \color{blue}{0.5}\right) \cdot \frac{M}{d}\right)}^{2}}}\right)\right) \]
    4. Applied egg-rr70.4%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h}{\frac{\ell}{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}}}\right)\right) \]
    5. Step-by-step derivation
      1. associate-/l*70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{h \cdot \left(-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right)}{\ell}}\right)\right) \]
      2. *-commutative70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{\color{blue}{\left(-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right) \cdot h}}{\ell}\right)\right) \]
      3. associate-*l/70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{\frac{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell} \cdot h}\right)\right) \]
      4. *-commutative70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{h \cdot \frac{-0.5 \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell}}\right)\right) \]
      5. *-commutative70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{\color{blue}{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot -0.5}}{\ell}\right)\right) \]
      6. associate-/l*70.5%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \color{blue}{\frac{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\frac{\ell}{-0.5}}}\right)\right) \]
      7. associate-*r/72.3%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(\frac{\left(D \cdot 0.5\right) \cdot M}{d}\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      8. associate-*l/72.3%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(\frac{D \cdot 0.5}{d} \cdot M\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      9. *-commutative72.3%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\color{blue}{\left(M \cdot \frac{D \cdot 0.5}{d}\right)}}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      10. associate-/l*72.3%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \color{blue}{\frac{D}{\frac{d}{0.5}}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    6. Simplified72.3%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \color{blue}{h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}}\right)\right) \]

    if 6.7999999999999996e-306 < l

    1. Initial program 69.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified69.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr71.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \]
    4. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      2. distribute-rgt1-in82.2%

        \[\leadsto \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right) + 1\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. +-commutative82.2%

        \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.2 \cdot 10^{+144}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-306}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 5: 61.3% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{-105}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \mathsf{fma}\left(h, {\left(\frac{M_m}{2} \cdot \frac{D_m}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}, 1\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -1.35e-105)
   (* (sqrt (/ d l)) (/ (sqrt (- d)) (sqrt (- h))))
   (if (<= l -1e-309)
     (* d (log (exp (pow (* h l) -0.5))))
     (if (<= l 6e+37)
       (*
        (/ d (sqrt (* h l)))
        (fma h (* (pow (* (/ M_m 2.0) (/ D_m d)) 2.0) (/ -0.5 l)) 1.0))
       (* d (/ (sqrt (/ 1.0 h)) (sqrt l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -1.35e-105) {
		tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h));
	} else if (l <= -1e-309) {
		tmp = d * log(exp(pow((h * l), -0.5)));
	} else if (l <= 6e+37) {
		tmp = (d / sqrt((h * l))) * fma(h, (pow(((M_m / 2.0) * (D_m / d)), 2.0) * (-0.5 / l)), 1.0);
	} else {
		tmp = d * (sqrt((1.0 / h)) / sqrt(l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -1.35e-105)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))));
	elseif (l <= -1e-309)
		tmp = Float64(d * log(exp((Float64(h * l) ^ -0.5))));
	elseif (l <= 6e+37)
		tmp = Float64(Float64(d / sqrt(Float64(h * l))) * fma(h, Float64((Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0) * Float64(-0.5 / l)), 1.0));
	else
		tmp = Float64(d * Float64(sqrt(Float64(1.0 / h)) / sqrt(l)));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -1.35e-105], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1e-309], N[(d * N[Log[N[Exp[N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6e+37], N[(N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(h * N[(N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.35 \cdot 10^{-105}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\
\;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\

\mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \mathsf{fma}\left(h, {\left(\frac{M_m}{2} \cdot \frac{D_m}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}, 1\right)\\

\mathbf{else}:\\
\;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.34999999999999996e-105

    1. Initial program 63.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified63.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 4.8%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div4.8%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval4.8%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv4.8%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr4.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div48.2%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative48.2%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    10. Step-by-step derivation
      1. frac-2neg64.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\color{blue}{\frac{-d}{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      2. sqrt-div76.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    11. Applied egg-rr58.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \]

    if -1.34999999999999996e-105 < l < -1.000000000000002e-309

    1. Initial program 66.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 23.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-log-exp45.4%

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{h \cdot \ell}}}\right)} \]
      2. inv-pow45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}}\right) \]
      3. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(-1\right)}}}}\right) \]
      4. sqrt-pow145.4%

        \[\leadsto d \cdot \log \left(e^{\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}}}\right) \]
      5. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}}\right) \]
      6. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}}\right) \]
    5. Applied egg-rr45.4%

      \[\leadsto d \cdot \color{blue}{\log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)} \]

    if -1.000000000000002e-309 < l < 6.00000000000000043e37

    1. Initial program 72.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified72.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Step-by-step derivation
      1. expm1-log1p-u72.6%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)}\right) \]
      2. expm1-udef72.6%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)} - 1\right)}\right) \]
      3. *-commutative72.6%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2}}\right)} - 1\right)\right) \]
      4. associate-/l*72.6%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\left(\frac{M}{\color{blue}{\frac{d}{\frac{D}{2}}}}\right)}^{2}\right)} - 1\right)\right) \]
      5. associate-/r/71.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\color{blue}{\left(\frac{M}{d} \cdot \frac{D}{2}\right)}}^{2}\right)} - 1\right)\right) \]
      6. *-commutative71.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\color{blue}{\left(\frac{D}{2} \cdot \frac{M}{d}\right)}}^{2}\right)} - 1\right)\right) \]
      7. div-inv71.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\left(\color{blue}{\left(D \cdot \frac{1}{2}\right)} \cdot \frac{M}{d}\right)}^{2}\right)} - 1\right)\right) \]
      8. metadata-eval71.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\left(\left(D \cdot \color{blue}{0.5}\right) \cdot \frac{M}{d}\right)}^{2}\right)} - 1\right)\right) \]
    4. Applied egg-rr71.1%

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right)} - 1\right)}\right) \]
    5. Step-by-step derivation
      1. expm1-def71.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{h}{\ell} \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right)\right)}\right) \]
      2. expm1-log1p71.3%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(\frac{h}{\ell} \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}\right)}\right) \]
      3. associate-*l/73.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\frac{h \cdot {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell}}\right) \]
      4. *-commutative73.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \frac{\color{blue}{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot h}}{\ell}\right) \]
      5. associate-*l/73.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(\frac{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell} \cdot h\right)}\right) \]
      6. *-commutative73.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2}}{\ell}\right)}\right) \]
      7. associate-*r/75.4%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{\left(D \cdot 0.5\right) \cdot M}{d}\right)}}^{2}}{\ell}\right)\right) \]
      8. associate-*l/73.9%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D \cdot 0.5}{d} \cdot M\right)}}^{2}}{\ell}\right)\right) \]
      9. *-commutative73.9%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(M \cdot \frac{D \cdot 0.5}{d}\right)}}^{2}}{\ell}\right)\right) \]
      10. associate-/l*73.9%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(M \cdot \color{blue}{\frac{D}{\frac{d}{0.5}}}\right)}^{2}}{\ell}\right)\right) \]
    6. Simplified73.9%

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\ell}\right)}\right) \]
    7. Applied egg-rr62.5%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}} + \frac{d}{\sqrt{h \cdot \ell}} \cdot \left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\right)} \]
    8. Step-by-step derivation
      1. *-commutative62.5%

        \[\leadsto \frac{d}{\sqrt{h \cdot \ell}} + \color{blue}{\left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h \cdot \ell}}} \]
      2. distribute-rgt1-in85.1%

        \[\leadsto \color{blue}{\left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right) + 1\right) \cdot \frac{d}{\sqrt{h \cdot \ell}}} \]
      3. *-commutative85.1%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right) + 1\right)} \]
      4. fma-def85.1%

        \[\leadsto \frac{d}{\sqrt{h \cdot \ell}} \cdot \color{blue}{\mathsf{fma}\left(h, {\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}, 1\right)} \]
    9. Simplified85.1%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}} \cdot \mathsf{fma}\left(h, {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}, 1\right)} \]

    if 6.00000000000000043e37 < l

    1. Initial program 65.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.6%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 50.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
      2. sqrt-div66.3%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}} \]
    5. Applied egg-rr66.3%

      \[\leadsto d \cdot \color{blue}{\frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification64.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.35 \cdot 10^{-105}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \mathsf{fma}\left(h, {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}, 1\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\ \end{array} \]

Alternative 6: 64.4% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -6.4 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -6.4e-106)
   (* (sqrt (/ d l)) (/ (sqrt (- d)) (sqrt (- h))))
   (if (<= l -1e-309)
     (* d (log (exp (pow (* h l) -0.5))))
     (*
      (+ 1.0 (* (pow (* (/ M_m d) (* D_m 0.5)) 2.0) (* -0.5 (/ h l))))
      (/ d (* (sqrt h) (sqrt l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -6.4e-106) {
		tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h));
	} else if (l <= -1e-309) {
		tmp = d * log(exp(pow((h * l), -0.5)));
	} else {
		tmp = (1.0 + (pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (l <= (-6.4d-106)) then
        tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h))
    else if (l <= (-1d-309)) then
        tmp = d * log(exp(((h * l) ** (-0.5d0))))
    else
        tmp = (1.0d0 + ((((m_m / d) * (d_m * 0.5d0)) ** 2.0d0) * ((-0.5d0) * (h / l)))) * (d / (sqrt(h) * sqrt(l)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -6.4e-106) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt(-d) / Math.sqrt(-h));
	} else if (l <= -1e-309) {
		tmp = d * Math.log(Math.exp(Math.pow((h * l), -0.5)));
	} else {
		tmp = (1.0 + (Math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= -6.4e-106:
		tmp = math.sqrt((d / l)) * (math.sqrt(-d) / math.sqrt(-h))
	elif l <= -1e-309:
		tmp = d * math.log(math.exp(math.pow((h * l), -0.5)))
	else:
		tmp = (1.0 + (math.pow(((M_m / d) * (D_m * 0.5)), 2.0) * (-0.5 * (h / l)))) * (d / (math.sqrt(h) * math.sqrt(l)))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -6.4e-106)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))));
	elseif (l <= -1e-309)
		tmp = Float64(d * log(exp((Float64(h * l) ^ -0.5))));
	else
		tmp = Float64(Float64(1.0 + Float64((Float64(Float64(M_m / d) * Float64(D_m * 0.5)) ^ 2.0) * Float64(-0.5 * Float64(h / l)))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (l <= -6.4e-106)
		tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h));
	elseif (l <= -1e-309)
		tmp = d * log(exp(((h * l) ^ -0.5)));
	else
		tmp = (1.0 + ((((M_m / d) * (D_m * 0.5)) ^ 2.0) * (-0.5 * (h / l)))) * (d / (sqrt(h) * sqrt(l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -6.4e-106], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1e-309], N[(d * N[Log[N[Exp[N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[Power[N[(N[(M$95$m / d), $MachinePrecision] * N[(D$95$m * 0.5), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6.4 \cdot 10^{-106}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\
\;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 + {\left(\frac{M_m}{d} \cdot \left(D_m \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.4e-106

    1. Initial program 63.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified63.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 4.8%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div4.8%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval4.8%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv4.8%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr4.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div48.2%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative48.2%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    10. Step-by-step derivation
      1. frac-2neg64.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\color{blue}{\frac{-d}{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      2. sqrt-div76.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    11. Applied egg-rr58.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \]

    if -6.4e-106 < l < -1.000000000000002e-309

    1. Initial program 66.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 23.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-log-exp45.4%

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{h \cdot \ell}}}\right)} \]
      2. inv-pow45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}}\right) \]
      3. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(-1\right)}}}}\right) \]
      4. sqrt-pow145.4%

        \[\leadsto d \cdot \log \left(e^{\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}}}\right) \]
      5. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}}\right) \]
      6. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}}\right) \]
    5. Applied egg-rr45.4%

      \[\leadsto d \cdot \color{blue}{\log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)} \]

    if -1.000000000000002e-309 < l

    1. Initial program 69.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified69.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr71.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \]
    4. Step-by-step derivation
      1. *-commutative71.3%

        \[\leadsto \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} + \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      2. distribute-rgt1-in82.2%

        \[\leadsto \color{blue}{\left({\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right) + 1\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. +-commutative82.2%

        \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)} \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \]
    5. Simplified82.2%

      \[\leadsto \color{blue}{\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.4 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + {\left(\frac{M}{d} \cdot \left(D \cdot 0.5\right)\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 7: 61.3% accurate, 1.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D_m \cdot \frac{M_m \cdot 0.5}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -5.8e-106)
   (* (sqrt (/ d l)) (/ (sqrt (- d)) (sqrt (- h))))
   (if (<= l -1e-309)
     (* d (log (exp (pow (* h l) -0.5))))
     (if (<= l 6e+37)
       (*
        (/ d (sqrt (* h l)))
        (+ 1.0 (* h (* (/ -0.5 l) (pow (* D_m (/ (* M_m 0.5) d)) 2.0)))))
       (* d (/ (sqrt (/ 1.0 h)) (sqrt l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -5.8e-106) {
		tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h));
	} else if (l <= -1e-309) {
		tmp = d * log(exp(pow((h * l), -0.5)));
	} else if (l <= 6e+37) {
		tmp = (d / sqrt((h * l))) * (1.0 + (h * ((-0.5 / l) * pow((D_m * ((M_m * 0.5) / d)), 2.0))));
	} else {
		tmp = d * (sqrt((1.0 / h)) / sqrt(l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (l <= (-5.8d-106)) then
        tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h))
    else if (l <= (-1d-309)) then
        tmp = d * log(exp(((h * l) ** (-0.5d0))))
    else if (l <= 6d+37) then
        tmp = (d / sqrt((h * l))) * (1.0d0 + (h * (((-0.5d0) / l) * ((d_m * ((m_m * 0.5d0) / d)) ** 2.0d0))))
    else
        tmp = d * (sqrt((1.0d0 / h)) / sqrt(l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -5.8e-106) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt(-d) / Math.sqrt(-h));
	} else if (l <= -1e-309) {
		tmp = d * Math.log(Math.exp(Math.pow((h * l), -0.5)));
	} else if (l <= 6e+37) {
		tmp = (d / Math.sqrt((h * l))) * (1.0 + (h * ((-0.5 / l) * Math.pow((D_m * ((M_m * 0.5) / d)), 2.0))));
	} else {
		tmp = d * (Math.sqrt((1.0 / h)) / Math.sqrt(l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= -5.8e-106:
		tmp = math.sqrt((d / l)) * (math.sqrt(-d) / math.sqrt(-h))
	elif l <= -1e-309:
		tmp = d * math.log(math.exp(math.pow((h * l), -0.5)))
	elif l <= 6e+37:
		tmp = (d / math.sqrt((h * l))) * (1.0 + (h * ((-0.5 / l) * math.pow((D_m * ((M_m * 0.5) / d)), 2.0))))
	else:
		tmp = d * (math.sqrt((1.0 / h)) / math.sqrt(l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -5.8e-106)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))));
	elseif (l <= -1e-309)
		tmp = Float64(d * log(exp((Float64(h * l) ^ -0.5))));
	elseif (l <= 6e+37)
		tmp = Float64(Float64(d / sqrt(Float64(h * l))) * Float64(1.0 + Float64(h * Float64(Float64(-0.5 / l) * (Float64(D_m * Float64(Float64(M_m * 0.5) / d)) ^ 2.0)))));
	else
		tmp = Float64(d * Float64(sqrt(Float64(1.0 / h)) / sqrt(l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (l <= -5.8e-106)
		tmp = sqrt((d / l)) * (sqrt(-d) / sqrt(-h));
	elseif (l <= -1e-309)
		tmp = d * log(exp(((h * l) ^ -0.5)));
	elseif (l <= 6e+37)
		tmp = (d / sqrt((h * l))) * (1.0 + (h * ((-0.5 / l) * ((D_m * ((M_m * 0.5) / d)) ^ 2.0))));
	else
		tmp = d * (sqrt((1.0 / h)) / sqrt(l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -5.8e-106], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1e-309], N[(d * N[Log[N[Exp[N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6e+37], N[(N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(h * N[(N[(-0.5 / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.8 \cdot 10^{-106}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\
\;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\

\mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D_m \cdot \frac{M_m \cdot 0.5}{d}\right)}^{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.8000000000000001e-106

    1. Initial program 63.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified63.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 4.8%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div4.8%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval4.8%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv4.8%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr4.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div48.2%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative48.2%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified48.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    10. Step-by-step derivation
      1. frac-2neg64.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\color{blue}{\frac{-d}{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
      2. sqrt-div76.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \cdot \left(1 + h \cdot \frac{{\left(M \cdot \frac{D}{\frac{d}{0.5}}\right)}^{2}}{\frac{\ell}{-0.5}}\right)\right) \]
    11. Applied egg-rr58.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\frac{\sqrt{-d}}{\sqrt{-h}}} \]

    if -5.8000000000000001e-106 < l < -1.000000000000002e-309

    1. Initial program 66.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 23.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-log-exp45.4%

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{h \cdot \ell}}}\right)} \]
      2. inv-pow45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}}\right) \]
      3. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(-1\right)}}}}\right) \]
      4. sqrt-pow145.4%

        \[\leadsto d \cdot \log \left(e^{\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}}}\right) \]
      5. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\left(\frac{\color{blue}{-1}}{2}\right)}}\right) \]
      6. metadata-eval45.4%

        \[\leadsto d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}}\right) \]
    5. Applied egg-rr45.4%

      \[\leadsto d \cdot \color{blue}{\log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)} \]

    if -1.000000000000002e-309 < l < 6.00000000000000043e37

    1. Initial program 72.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified72.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr15.6%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Applied egg-rr85.1%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right) + 1\right)} \]

    if 6.00000000000000043e37 < l

    1. Initial program 65.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.6%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 50.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
      2. sqrt-div66.3%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}} \]
    5. Applied egg-rr66.3%

      \[\leadsto d \cdot \color{blue}{\frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification64.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\ \mathbf{elif}\;\ell \leq 6 \cdot 10^{+37}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D \cdot \frac{M \cdot 0.5}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\ \end{array} \]

Alternative 8: 60.1% accurate, 1.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \frac{d}{\sqrt{h \cdot \ell}}\\ \mathbf{if}\;h \leq -7.5 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\left|t_0\right|\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D_m \cdot \frac{M_m \cdot 0.5}{d}\right)}^{2}\right)\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (/ d (sqrt (* h l)))))
   (if (<= h -7.5e+146)
     (* (sqrt (/ d l)) (sqrt (/ d h)))
     (if (<= h -1e-310)
       (fabs t_0)
       (*
        t_0
        (+ 1.0 (* h (* (/ -0.5 l) (pow (* D_m (/ (* M_m 0.5) d)) 2.0)))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = d / sqrt((h * l));
	double tmp;
	if (h <= -7.5e+146) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (h <= -1e-310) {
		tmp = fabs(t_0);
	} else {
		tmp = t_0 * (1.0 + (h * ((-0.5 / l) * pow((D_m * ((M_m * 0.5) / d)), 2.0))));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d / sqrt((h * l))
    if (h <= (-7.5d+146)) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else if (h <= (-1d-310)) then
        tmp = abs(t_0)
    else
        tmp = t_0 * (1.0d0 + (h * (((-0.5d0) / l) * ((d_m * ((m_m * 0.5d0) / d)) ** 2.0d0))))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = d / Math.sqrt((h * l));
	double tmp;
	if (h <= -7.5e+146) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (h <= -1e-310) {
		tmp = Math.abs(t_0);
	} else {
		tmp = t_0 * (1.0 + (h * ((-0.5 / l) * Math.pow((D_m * ((M_m * 0.5) / d)), 2.0))));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = d / math.sqrt((h * l))
	tmp = 0
	if h <= -7.5e+146:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif h <= -1e-310:
		tmp = math.fabs(t_0)
	else:
		tmp = t_0 * (1.0 + (h * ((-0.5 / l) * math.pow((D_m * ((M_m * 0.5) / d)), 2.0))))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = Float64(d / sqrt(Float64(h * l)))
	tmp = 0.0
	if (h <= -7.5e+146)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (h <= -1e-310)
		tmp = abs(t_0);
	else
		tmp = Float64(t_0 * Float64(1.0 + Float64(h * Float64(Float64(-0.5 / l) * (Float64(D_m * Float64(Float64(M_m * 0.5) / d)) ^ 2.0)))));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = d / sqrt((h * l));
	tmp = 0.0;
	if (h <= -7.5e+146)
		tmp = sqrt((d / l)) * sqrt((d / h));
	elseif (h <= -1e-310)
		tmp = abs(t_0);
	else
		tmp = t_0 * (1.0 + (h * ((-0.5 / l) * ((D_m * ((M_m * 0.5) / d)) ^ 2.0))));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[h, -7.5e+146], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[h, -1e-310], N[Abs[t$95$0], $MachinePrecision], N[(t$95$0 * N[(1.0 + N[(h * N[(N[(-0.5 / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \frac{d}{\sqrt{h \cdot \ell}}\\
\mathbf{if}\;h \leq -7.5 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

\mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\left|t_0\right|\\

\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D_m \cdot \frac{M_m \cdot 0.5}{d}\right)}^{2}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -7.49999999999999983e146

    1. Initial program 59.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified59.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 6.9%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div6.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval6.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv6.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr6.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div42.1%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr42.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative42.1%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified42.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]

    if -7.49999999999999983e146 < h < -9.999999999999969e-311

    1. Initial program 66.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 12.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod30.9%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow230.9%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod27.2%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv27.3%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt27.3%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square27.3%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div30.9%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow230.9%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod0.0%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt53.0%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr53.0%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]

    if -9.999999999999969e-311 < h

    1. Initial program 69.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified69.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr24.0%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Applied egg-rr72.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(h \cdot \left({\left(D \cdot \frac{0.5 \cdot M}{d}\right)}^{2} \cdot \frac{-0.5}{\ell}\right) + 1\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -7.5 \cdot 10^{+146}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;h \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + h \cdot \left(\frac{-0.5}{\ell} \cdot {\left(D \cdot \frac{M \cdot 0.5}{d}\right)}^{2}\right)\right)\\ \end{array} \]

Alternative 9: 45.8% accurate, 1.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;\ell \leq -5.1 \cdot 10^{+168}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-257}:\\ \;\;\;\;\left|\frac{d}{t_0}\right|\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\ \mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= l -5.1e+168)
     (* (sqrt (/ d l)) (sqrt (/ d h)))
     (if (<= l -1.5e-257)
       (fabs (/ d t_0))
       (if (<= l -1e-309)
         (/ d (+ 1.0 (+ t_0 -1.0)))
         (if (<= l 7.6e-180)
           (* (- d) (sqrt (/ 1.0 (* h l))))
           (/ d (* (sqrt h) (sqrt l)))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (l <= -5.1e+168) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (l <= -1.5e-257) {
		tmp = fabs((d / t_0));
	} else if (l <= -1e-309) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 7.6e-180) {
		tmp = -d * sqrt((1.0 / (h * l)));
	} else {
		tmp = d / (sqrt(h) * sqrt(l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (l <= (-5.1d+168)) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else if (l <= (-1.5d-257)) then
        tmp = abs((d / t_0))
    else if (l <= (-1d-309)) then
        tmp = d / (1.0d0 + (t_0 + (-1.0d0)))
    else if (l <= 7.6d-180) then
        tmp = -d * sqrt((1.0d0 / (h * l)))
    else
        tmp = d / (sqrt(h) * sqrt(l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (l <= -5.1e+168) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (l <= -1.5e-257) {
		tmp = Math.abs((d / t_0));
	} else if (l <= -1e-309) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 7.6e-180) {
		tmp = -d * Math.sqrt((1.0 / (h * l)));
	} else {
		tmp = d / (Math.sqrt(h) * Math.sqrt(l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if l <= -5.1e+168:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif l <= -1.5e-257:
		tmp = math.fabs((d / t_0))
	elif l <= -1e-309:
		tmp = d / (1.0 + (t_0 + -1.0))
	elif l <= 7.6e-180:
		tmp = -d * math.sqrt((1.0 / (h * l)))
	else:
		tmp = d / (math.sqrt(h) * math.sqrt(l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (l <= -5.1e+168)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (l <= -1.5e-257)
		tmp = abs(Float64(d / t_0));
	elseif (l <= -1e-309)
		tmp = Float64(d / Float64(1.0 + Float64(t_0 + -1.0)));
	elseif (l <= 7.6e-180)
		tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(h * l))));
	else
		tmp = Float64(d / Float64(sqrt(h) * sqrt(l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (l <= -5.1e+168)
		tmp = sqrt((d / l)) * sqrt((d / h));
	elseif (l <= -1.5e-257)
		tmp = abs((d / t_0));
	elseif (l <= -1e-309)
		tmp = d / (1.0 + (t_0 + -1.0));
	elseif (l <= 7.6e-180)
		tmp = -d * sqrt((1.0 / (h * l)));
	else
		tmp = d / (sqrt(h) * sqrt(l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -5.1e+168], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1.5e-257], N[Abs[N[(d / t$95$0), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, -1e-309], N[(d / N[(1.0 + N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.6e-180], N[((-d) * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;\ell \leq -5.1 \cdot 10^{+168}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

\mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-257}:\\
\;\;\;\;\left|\frac{d}{t_0}\right|\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\

\mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if l < -5.10000000000000025e168

    1. Initial program 53.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified52.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 5.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div5.5%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval5.5%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv5.5%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr5.5%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}} \]
      2. sqrt-prod0.0%

        \[\leadsto \frac{\sqrt{d} \cdot \sqrt{d}}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      3. times-frac0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}} \]
      4. sqrt-div0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}} \]
      5. sqrt-div54.3%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    7. Applied egg-rr54.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} \]
    8. Step-by-step derivation
      1. *-commutative54.3%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
    9. Simplified54.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]

    if -5.10000000000000025e168 < l < -1.5e-257

    1. Initial program 66.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.0%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 7.6%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod28.7%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow228.7%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod23.3%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv23.3%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt23.3%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square23.3%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div28.7%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow228.7%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod0.0%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt48.3%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr48.3%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]

    if -1.5e-257 < l < -1.000000000000002e-309

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u47.9%

        \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    7. Applied egg-rr47.9%

      \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-udef69.7%

        \[\leadsto \frac{d}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)} - 1}} \]
      2. expm1-log1p69.7%

        \[\leadsto \frac{d}{e^{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}\right)} - 1} \]
      3. log1p-udef69.7%

        \[\leadsto \frac{d}{e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)}} - 1} \]
      4. add-exp-log69.7%

        \[\leadsto \frac{d}{\color{blue}{\left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)} - 1} \]
      5. associate--l+69.7%

        \[\leadsto \frac{d}{\color{blue}{1 + \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right) - 1\right)}} \]
      6. expm1-log1p69.7%

        \[\leadsto \frac{d}{1 + \left(\color{blue}{\sqrt{h \cdot \ell}} - 1\right)} \]
    9. Applied egg-rr69.7%

      \[\leadsto \frac{d}{\color{blue}{1 + \left(\sqrt{h \cdot \ell} - 1\right)}} \]

    if -1.000000000000002e-309 < l < 7.59999999999999999e-180

    1. Initial program 81.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified81.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr4.1%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. associate-*r*45.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg45.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    6. Simplified45.9%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 7.59999999999999999e-180 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div51.0%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval51.0%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv51.1%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr51.1%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. sqrt-prod62.4%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      2. *-commutative62.4%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
    7. Applied egg-rr62.4%

      \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification54.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.1 \cdot 10^{+168}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -1.5 \cdot 10^{-257}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\ \mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 10: 46.0% accurate, 1.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;\ell \leq -1.8 \cdot 10^{-259}:\\ \;\;\;\;\left|\frac{d}{t_0}\right|\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= l -1.8e-259)
     (fabs (/ d t_0))
     (if (<= l -1e-309)
       (/ d (+ 1.0 (+ t_0 -1.0)))
       (if (<= l 1.26e-179)
         (* (- d) (sqrt (/ 1.0 (* h l))))
         (/ d (* (sqrt h) (sqrt l))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (l <= -1.8e-259) {
		tmp = fabs((d / t_0));
	} else if (l <= -1e-309) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 1.26e-179) {
		tmp = -d * sqrt((1.0 / (h * l)));
	} else {
		tmp = d / (sqrt(h) * sqrt(l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (l <= (-1.8d-259)) then
        tmp = abs((d / t_0))
    else if (l <= (-1d-309)) then
        tmp = d / (1.0d0 + (t_0 + (-1.0d0)))
    else if (l <= 1.26d-179) then
        tmp = -d * sqrt((1.0d0 / (h * l)))
    else
        tmp = d / (sqrt(h) * sqrt(l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (l <= -1.8e-259) {
		tmp = Math.abs((d / t_0));
	} else if (l <= -1e-309) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 1.26e-179) {
		tmp = -d * Math.sqrt((1.0 / (h * l)));
	} else {
		tmp = d / (Math.sqrt(h) * Math.sqrt(l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if l <= -1.8e-259:
		tmp = math.fabs((d / t_0))
	elif l <= -1e-309:
		tmp = d / (1.0 + (t_0 + -1.0))
	elif l <= 1.26e-179:
		tmp = -d * math.sqrt((1.0 / (h * l)))
	else:
		tmp = d / (math.sqrt(h) * math.sqrt(l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (l <= -1.8e-259)
		tmp = abs(Float64(d / t_0));
	elseif (l <= -1e-309)
		tmp = Float64(d / Float64(1.0 + Float64(t_0 + -1.0)));
	elseif (l <= 1.26e-179)
		tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(h * l))));
	else
		tmp = Float64(d / Float64(sqrt(h) * sqrt(l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (l <= -1.8e-259)
		tmp = abs((d / t_0));
	elseif (l <= -1e-309)
		tmp = d / (1.0 + (t_0 + -1.0));
	elseif (l <= 1.26e-179)
		tmp = -d * sqrt((1.0 / (h * l)));
	else
		tmp = d / (sqrt(h) * sqrt(l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.8e-259], N[Abs[N[(d / t$95$0), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, -1e-309], N[(d / N[(1.0 + N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.26e-179], N[((-d) * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;\ell \leq -1.8 \cdot 10^{-259}:\\
\;\;\;\;\left|\frac{d}{t_0}\right|\\

\mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\

\mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.7999999999999999e-259

    1. Initial program 62.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified62.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 7.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod26.8%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow226.8%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod22.9%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv22.9%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt22.9%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square22.9%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div26.8%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow226.8%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod0.0%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt45.9%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr45.9%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]

    if -1.7999999999999999e-259 < l < -1.000000000000002e-309

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u47.9%

        \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    7. Applied egg-rr47.9%

      \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-udef69.7%

        \[\leadsto \frac{d}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)} - 1}} \]
      2. expm1-log1p69.7%

        \[\leadsto \frac{d}{e^{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}\right)} - 1} \]
      3. log1p-udef69.7%

        \[\leadsto \frac{d}{e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)}} - 1} \]
      4. add-exp-log69.7%

        \[\leadsto \frac{d}{\color{blue}{\left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)} - 1} \]
      5. associate--l+69.7%

        \[\leadsto \frac{d}{\color{blue}{1 + \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right) - 1\right)}} \]
      6. expm1-log1p69.7%

        \[\leadsto \frac{d}{1 + \left(\color{blue}{\sqrt{h \cdot \ell}} - 1\right)} \]
    9. Applied egg-rr69.7%

      \[\leadsto \frac{d}{\color{blue}{1 + \left(\sqrt{h \cdot \ell} - 1\right)}} \]

    if -1.000000000000002e-309 < l < 1.2599999999999999e-179

    1. Initial program 81.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified81.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr4.1%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. associate-*r*45.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg45.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    6. Simplified45.9%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 1.2599999999999999e-179 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div51.0%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval51.0%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv51.1%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr51.1%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. sqrt-prod62.4%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      2. *-commutative62.4%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
    7. Applied egg-rr62.4%

      \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{-259}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{elif}\;\ell \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 11: 43.4% accurate, 1.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;\ell \leq -1.6 \cdot 10^{-260}:\\ \;\;\;\;\left|\frac{d}{t_0}\right|\\ \mathbf{elif}\;\ell \leq -6.5 \cdot 10^{-307}:\\ \;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\ \mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= l -1.6e-260)
     (fabs (/ d t_0))
     (if (<= l -6.5e-307)
       (/ d (+ 1.0 (+ t_0 -1.0)))
       (if (<= l 7.6e-180)
         (* (- d) (sqrt (/ 1.0 (* h l))))
         (* d (sqrt (/ (/ 1.0 h) l))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (l <= -1.6e-260) {
		tmp = fabs((d / t_0));
	} else if (l <= -6.5e-307) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 7.6e-180) {
		tmp = -d * sqrt((1.0 / (h * l)));
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (l <= (-1.6d-260)) then
        tmp = abs((d / t_0))
    else if (l <= (-6.5d-307)) then
        tmp = d / (1.0d0 + (t_0 + (-1.0d0)))
    else if (l <= 7.6d-180) then
        tmp = -d * sqrt((1.0d0 / (h * l)))
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (l <= -1.6e-260) {
		tmp = Math.abs((d / t_0));
	} else if (l <= -6.5e-307) {
		tmp = d / (1.0 + (t_0 + -1.0));
	} else if (l <= 7.6e-180) {
		tmp = -d * Math.sqrt((1.0 / (h * l)));
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if l <= -1.6e-260:
		tmp = math.fabs((d / t_0))
	elif l <= -6.5e-307:
		tmp = d / (1.0 + (t_0 + -1.0))
	elif l <= 7.6e-180:
		tmp = -d * math.sqrt((1.0 / (h * l)))
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (l <= -1.6e-260)
		tmp = abs(Float64(d / t_0));
	elseif (l <= -6.5e-307)
		tmp = Float64(d / Float64(1.0 + Float64(t_0 + -1.0)));
	elseif (l <= 7.6e-180)
		tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(h * l))));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (l <= -1.6e-260)
		tmp = abs((d / t_0));
	elseif (l <= -6.5e-307)
		tmp = d / (1.0 + (t_0 + -1.0));
	elseif (l <= 7.6e-180)
		tmp = -d * sqrt((1.0 / (h * l)));
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.6e-260], N[Abs[N[(d / t$95$0), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, -6.5e-307], N[(d / N[(1.0 + N[(t$95$0 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.6e-180], N[((-d) * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;\ell \leq -1.6 \cdot 10^{-260}:\\
\;\;\;\;\left|\frac{d}{t_0}\right|\\

\mathbf{elif}\;\ell \leq -6.5 \cdot 10^{-307}:\\
\;\;\;\;\frac{d}{1 + \left(t_0 + -1\right)}\\

\mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.59999999999999997e-260

    1. Initial program 62.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified62.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 7.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\left(\sqrt{d} \cdot \sqrt{d}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. sqrt-prod26.8%

        \[\leadsto \color{blue}{\sqrt{d \cdot d}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. unpow226.8%

        \[\leadsto \sqrt{\color{blue}{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod22.9%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv22.9%

        \[\leadsto \sqrt{\color{blue}{\frac{{d}^{2}}{h \cdot \ell}}} \]
      6. add-sqr-sqrt22.9%

        \[\leadsto \sqrt{\color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell}} \cdot \sqrt{\frac{{d}^{2}}{h \cdot \ell}}}} \]
      7. rem-sqrt-square22.9%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{{d}^{2}}{h \cdot \ell}}\right|} \]
      8. sqrt-div26.8%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{{d}^{2}}}{\sqrt{h \cdot \ell}}}\right| \]
      9. unpow226.8%

        \[\leadsto \left|\frac{\sqrt{\color{blue}{d \cdot d}}}{\sqrt{h \cdot \ell}}\right| \]
      10. sqrt-prod0.0%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{h \cdot \ell}}\right| \]
      11. add-sqr-sqrt45.9%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right| \]
    5. Applied egg-rr45.9%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{h \cdot \ell}}\right|} \]

    if -1.59999999999999997e-260 < l < -6.5000000000000001e-307

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u47.9%

        \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    7. Applied egg-rr47.9%

      \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-udef69.7%

        \[\leadsto \frac{d}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)} - 1}} \]
      2. expm1-log1p69.7%

        \[\leadsto \frac{d}{e^{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}\right)} - 1} \]
      3. log1p-udef69.7%

        \[\leadsto \frac{d}{e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)}} - 1} \]
      4. add-exp-log69.7%

        \[\leadsto \frac{d}{\color{blue}{\left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)} - 1} \]
      5. associate--l+69.7%

        \[\leadsto \frac{d}{\color{blue}{1 + \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right) - 1\right)}} \]
      6. expm1-log1p69.7%

        \[\leadsto \frac{d}{1 + \left(\color{blue}{\sqrt{h \cdot \ell}} - 1\right)} \]
    9. Applied egg-rr69.7%

      \[\leadsto \frac{d}{\color{blue}{1 + \left(\sqrt{h \cdot \ell} - 1\right)}} \]

    if -6.5000000000000001e-307 < l < 7.59999999999999999e-180

    1. Initial program 81.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified81.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr4.1%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. associate-*r*45.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg45.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    6. Simplified45.9%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 7.59999999999999999e-180 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    5. Simplified52.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification49.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.6 \cdot 10^{-260}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{elif}\;\ell \leq -6.5 \cdot 10^{-307}:\\ \;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\ \mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-180}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]

Alternative 12: 42.5% accurate, 2.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.25 \cdot 10^{-259}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -1.9 \cdot 10^{-306}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 3.05 \cdot 10^{-176}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -2.25e-259)
   (* d (- (pow (* h l) -0.5)))
   (if (<= l -1.9e-306)
     (/ d (sqrt (* h l)))
     (if (<= l 3.05e-176)
       (* (- d) (sqrt (/ 1.0 (* h l))))
       (* d (sqrt (/ (/ 1.0 h) l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -2.25e-259) {
		tmp = d * -pow((h * l), -0.5);
	} else if (l <= -1.9e-306) {
		tmp = d / sqrt((h * l));
	} else if (l <= 3.05e-176) {
		tmp = -d * sqrt((1.0 / (h * l)));
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (l <= (-2.25d-259)) then
        tmp = d * -((h * l) ** (-0.5d0))
    else if (l <= (-1.9d-306)) then
        tmp = d / sqrt((h * l))
    else if (l <= 3.05d-176) then
        tmp = -d * sqrt((1.0d0 / (h * l)))
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -2.25e-259) {
		tmp = d * -Math.pow((h * l), -0.5);
	} else if (l <= -1.9e-306) {
		tmp = d / Math.sqrt((h * l));
	} else if (l <= 3.05e-176) {
		tmp = -d * Math.sqrt((1.0 / (h * l)));
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= -2.25e-259:
		tmp = d * -math.pow((h * l), -0.5)
	elif l <= -1.9e-306:
		tmp = d / math.sqrt((h * l))
	elif l <= 3.05e-176:
		tmp = -d * math.sqrt((1.0 / (h * l)))
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -2.25e-259)
		tmp = Float64(d * Float64(-(Float64(h * l) ^ -0.5)));
	elseif (l <= -1.9e-306)
		tmp = Float64(d / sqrt(Float64(h * l)));
	elseif (l <= 3.05e-176)
		tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(h * l))));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (l <= -2.25e-259)
		tmp = d * -((h * l) ^ -0.5);
	elseif (l <= -1.9e-306)
		tmp = d / sqrt((h * l));
	elseif (l <= 3.05e-176)
		tmp = -d * sqrt((1.0 / (h * l)));
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -2.25e-259], N[(d * (-N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -1.9e-306], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 3.05e-176], N[((-d) * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.25 \cdot 10^{-259}:\\
\;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\

\mathbf{elif}\;\ell \leq -1.9 \cdot 10^{-306}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\

\mathbf{elif}\;\ell \leq 3.05 \cdot 10^{-176}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -2.24999999999999987e-259

    1. Initial program 62.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified62.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr20.0%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.8%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg45.8%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      3. unpow-145.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}\right) \]
      4. metadata-eval45.8%

        \[\leadsto d \cdot \left(-\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(2 \cdot -0.5\right)}}}\right) \]
      5. pow-sqr45.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      6. rem-sqrt-square45.8%

        \[\leadsto d \cdot \left(-\color{blue}{\left|{\left(h \cdot \ell\right)}^{-0.5}\right|}\right) \]
      7. rem-square-sqrt45.6%

        \[\leadsto d \cdot \left(-\left|\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right|\right) \]
      8. fabs-sqr45.6%

        \[\leadsto d \cdot \left(-\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      9. rem-square-sqrt45.8%

        \[\leadsto d \cdot \left(-\color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
    6. Simplified45.8%

      \[\leadsto \color{blue}{d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]

    if -2.24999999999999987e-259 < l < -1.9e-306

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]

    if -1.9e-306 < l < 3.0500000000000001e-176

    1. Initial program 81.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified81.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr4.1%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. associate-*r*45.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg45.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    6. Simplified45.9%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 3.0500000000000001e-176 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    5. Simplified52.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification48.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.25 \cdot 10^{-259}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -1.9 \cdot 10^{-306}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 3.05 \cdot 10^{-176}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]

Alternative 13: 43.5% accurate, 2.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{-261}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{-308}:\\ \;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -5.2e-261)
   (* d (- (pow (* h l) -0.5)))
   (if (<= l 2.5e-308)
     (/ d (+ 1.0 (+ (sqrt (* h l)) -1.0)))
     (if (<= l 1.26e-179)
       (* (- d) (sqrt (/ 1.0 (* h l))))
       (* d (sqrt (/ (/ 1.0 h) l)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -5.2e-261) {
		tmp = d * -pow((h * l), -0.5);
	} else if (l <= 2.5e-308) {
		tmp = d / (1.0 + (sqrt((h * l)) + -1.0));
	} else if (l <= 1.26e-179) {
		tmp = -d * sqrt((1.0 / (h * l)));
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (l <= (-5.2d-261)) then
        tmp = d * -((h * l) ** (-0.5d0))
    else if (l <= 2.5d-308) then
        tmp = d / (1.0d0 + (sqrt((h * l)) + (-1.0d0)))
    else if (l <= 1.26d-179) then
        tmp = -d * sqrt((1.0d0 / (h * l)))
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -5.2e-261) {
		tmp = d * -Math.pow((h * l), -0.5);
	} else if (l <= 2.5e-308) {
		tmp = d / (1.0 + (Math.sqrt((h * l)) + -1.0));
	} else if (l <= 1.26e-179) {
		tmp = -d * Math.sqrt((1.0 / (h * l)));
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= -5.2e-261:
		tmp = d * -math.pow((h * l), -0.5)
	elif l <= 2.5e-308:
		tmp = d / (1.0 + (math.sqrt((h * l)) + -1.0))
	elif l <= 1.26e-179:
		tmp = -d * math.sqrt((1.0 / (h * l)))
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -5.2e-261)
		tmp = Float64(d * Float64(-(Float64(h * l) ^ -0.5)));
	elseif (l <= 2.5e-308)
		tmp = Float64(d / Float64(1.0 + Float64(sqrt(Float64(h * l)) + -1.0)));
	elseif (l <= 1.26e-179)
		tmp = Float64(Float64(-d) * sqrt(Float64(1.0 / Float64(h * l))));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (l <= -5.2e-261)
		tmp = d * -((h * l) ^ -0.5);
	elseif (l <= 2.5e-308)
		tmp = d / (1.0 + (sqrt((h * l)) + -1.0));
	elseif (l <= 1.26e-179)
		tmp = -d * sqrt((1.0 / (h * l)));
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -5.2e-261], N[(d * (-N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, 2.5e-308], N[(d / N[(1.0 + N[(N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.26e-179], N[((-d) * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -5.2 \cdot 10^{-261}:\\
\;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\

\mathbf{elif}\;\ell \leq 2.5 \cdot 10^{-308}:\\
\;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\

\mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -5.2000000000000002e-261

    1. Initial program 62.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified62.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr20.0%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.8%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg45.8%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      3. unpow-145.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}\right) \]
      4. metadata-eval45.8%

        \[\leadsto d \cdot \left(-\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(2 \cdot -0.5\right)}}}\right) \]
      5. pow-sqr45.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      6. rem-sqrt-square45.8%

        \[\leadsto d \cdot \left(-\color{blue}{\left|{\left(h \cdot \ell\right)}^{-0.5}\right|}\right) \]
      7. rem-square-sqrt45.6%

        \[\leadsto d \cdot \left(-\left|\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right|\right) \]
      8. fabs-sqr45.6%

        \[\leadsto d \cdot \left(-\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      9. rem-square-sqrt45.8%

        \[\leadsto d \cdot \left(-\color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
    6. Simplified45.8%

      \[\leadsto \color{blue}{d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]

    if -5.2000000000000002e-261 < l < 2.49999999999999977e-308

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u47.9%

        \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    7. Applied egg-rr47.9%

      \[\leadsto \frac{d}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}} \]
    8. Step-by-step derivation
      1. expm1-udef69.7%

        \[\leadsto \frac{d}{\color{blue}{e^{\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)} - 1}} \]
      2. expm1-log1p69.7%

        \[\leadsto \frac{d}{e^{\mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)}\right)} - 1} \]
      3. log1p-udef69.7%

        \[\leadsto \frac{d}{e^{\color{blue}{\log \left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)}} - 1} \]
      4. add-exp-log69.7%

        \[\leadsto \frac{d}{\color{blue}{\left(1 + \mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right)\right)} - 1} \]
      5. associate--l+69.7%

        \[\leadsto \frac{d}{\color{blue}{1 + \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{h \cdot \ell}\right)\right) - 1\right)}} \]
      6. expm1-log1p69.7%

        \[\leadsto \frac{d}{1 + \left(\color{blue}{\sqrt{h \cdot \ell}} - 1\right)} \]
    9. Applied egg-rr69.7%

      \[\leadsto \frac{d}{\color{blue}{1 + \left(\sqrt{h \cdot \ell} - 1\right)}} \]

    if 2.49999999999999977e-308 < l < 1.2599999999999999e-179

    1. Initial program 81.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified81.7%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr4.1%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.9%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. associate-*r*45.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg45.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    6. Simplified45.9%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 1.2599999999999999e-179 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    5. Simplified52.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification49.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.2 \cdot 10^{-261}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq 2.5 \cdot 10^{-308}:\\ \;\;\;\;\frac{d}{1 + \left(\sqrt{h \cdot \ell} + -1\right)}\\ \mathbf{elif}\;\ell \leq 1.26 \cdot 10^{-179}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]

Alternative 14: 42.3% accurate, 2.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.4 \cdot 10^{-260} \lor \neg \left(\ell \leq 7.2 \cdot 10^{-307}\right) \land \ell \leq 5.2 \cdot 10^{-179}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (or (<= l -4.4e-260) (and (not (<= l 7.2e-307)) (<= l 5.2e-179)))
   (* d (- (pow (* h l) -0.5)))
   (/ d (sqrt (* h l)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if ((l <= -4.4e-260) || (!(l <= 7.2e-307) && (l <= 5.2e-179))) {
		tmp = d * -pow((h * l), -0.5);
	} else {
		tmp = d / sqrt((h * l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if ((l <= (-4.4d-260)) .or. (.not. (l <= 7.2d-307)) .and. (l <= 5.2d-179)) then
        tmp = d * -((h * l) ** (-0.5d0))
    else
        tmp = d / sqrt((h * l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if ((l <= -4.4e-260) || (!(l <= 7.2e-307) && (l <= 5.2e-179))) {
		tmp = d * -Math.pow((h * l), -0.5);
	} else {
		tmp = d / Math.sqrt((h * l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if (l <= -4.4e-260) or (not (l <= 7.2e-307) and (l <= 5.2e-179)):
		tmp = d * -math.pow((h * l), -0.5)
	else:
		tmp = d / math.sqrt((h * l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if ((l <= -4.4e-260) || (!(l <= 7.2e-307) && (l <= 5.2e-179)))
		tmp = Float64(d * Float64(-(Float64(h * l) ^ -0.5)));
	else
		tmp = Float64(d / sqrt(Float64(h * l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if ((l <= -4.4e-260) || (~((l <= 7.2e-307)) && (l <= 5.2e-179)))
		tmp = d * -((h * l) ^ -0.5);
	else
		tmp = d / sqrt((h * l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[Or[LessEqual[l, -4.4e-260], And[N[Not[LessEqual[l, 7.2e-307]], $MachinePrecision], LessEqual[l, 5.2e-179]]], N[(d * (-N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.4 \cdot 10^{-260} \lor \neg \left(\ell \leq 7.2 \cdot 10^{-307}\right) \land \ell \leq 5.2 \cdot 10^{-179}:\\
\;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.40000000000000034e-260 or 7.20000000000000014e-307 < l < 5.20000000000000011e-179

    1. Initial program 66.0%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.5%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr17.3%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.8%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg45.8%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      3. unpow-145.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}\right) \]
      4. metadata-eval45.8%

        \[\leadsto d \cdot \left(-\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(2 \cdot -0.5\right)}}}\right) \]
      5. pow-sqr45.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      6. rem-sqrt-square45.2%

        \[\leadsto d \cdot \left(-\color{blue}{\left|{\left(h \cdot \ell\right)}^{-0.5}\right|}\right) \]
      7. rem-square-sqrt45.0%

        \[\leadsto d \cdot \left(-\left|\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right|\right) \]
      8. fabs-sqr45.0%

        \[\leadsto d \cdot \left(-\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      9. rem-square-sqrt45.2%

        \[\leadsto d \cdot \left(-\color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
    6. Simplified45.2%

      \[\leadsto \color{blue}{d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]

    if -4.40000000000000034e-260 < l < 7.20000000000000014e-307 or 5.20000000000000011e-179 < l

    1. Initial program 68.3%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified68.3%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 50.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div50.6%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval50.6%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv50.7%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr50.7%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification47.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.4 \cdot 10^{-260} \lor \neg \left(\ell \leq 7.2 \cdot 10^{-307}\right) \land \ell \leq 5.2 \cdot 10^{-179}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 15: 42.5% accurate, 2.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} t_0 := d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{if}\;\ell \leq -2.3 \cdot 10^{-260}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{-308}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 8.2 \cdot 10^{-180}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0 (* d (- (pow (* h l) -0.5)))))
   (if (<= l -2.3e-260)
     t_0
     (if (<= l 2e-308)
       (/ d (sqrt (* h l)))
       (if (<= l 8.2e-180) t_0 (* d (sqrt (/ (/ 1.0 h) l))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = d * -pow((h * l), -0.5);
	double tmp;
	if (l <= -2.3e-260) {
		tmp = t_0;
	} else if (l <= 2e-308) {
		tmp = d / sqrt((h * l));
	} else if (l <= 8.2e-180) {
		tmp = t_0;
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = d * -((h * l) ** (-0.5d0))
    if (l <= (-2.3d-260)) then
        tmp = t_0
    else if (l <= 2d-308) then
        tmp = d / sqrt((h * l))
    else if (l <= 8.2d-180) then
        tmp = t_0
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = d * -Math.pow((h * l), -0.5);
	double tmp;
	if (l <= -2.3e-260) {
		tmp = t_0;
	} else if (l <= 2e-308) {
		tmp = d / Math.sqrt((h * l));
	} else if (l <= 8.2e-180) {
		tmp = t_0;
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = d * -math.pow((h * l), -0.5)
	tmp = 0
	if l <= -2.3e-260:
		tmp = t_0
	elif l <= 2e-308:
		tmp = d / math.sqrt((h * l))
	elif l <= 8.2e-180:
		tmp = t_0
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = Float64(d * Float64(-(Float64(h * l) ^ -0.5)))
	tmp = 0.0
	if (l <= -2.3e-260)
		tmp = t_0;
	elseif (l <= 2e-308)
		tmp = Float64(d / sqrt(Float64(h * l)));
	elseif (l <= 8.2e-180)
		tmp = t_0;
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = d * -((h * l) ^ -0.5);
	tmp = 0.0;
	if (l <= -2.3e-260)
		tmp = t_0;
	elseif (l <= 2e-308)
		tmp = d / sqrt((h * l));
	elseif (l <= 8.2e-180)
		tmp = t_0;
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[(d * (-N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[l, -2.3e-260], t$95$0, If[LessEqual[l, 2e-308], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8.2e-180], t$95$0, N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\
\mathbf{if}\;\ell \leq -2.3 \cdot 10^{-260}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;\ell \leq 2 \cdot 10^{-308}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\

\mathbf{elif}\;\ell \leq 8.2 \cdot 10^{-180}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.3e-260 or 1.9999999999999998e-308 < l < 8.2e-180

    1. Initial program 66.0%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.5%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr17.3%

      \[\leadsto \color{blue}{\sqrt{\frac{{d}^{2}}{h \cdot \ell} \cdot {\left(1 + {\left(\left(D \cdot 0.5\right) \cdot \frac{M}{d}\right)}^{2} \cdot \left(-0.5 \cdot \frac{h}{\ell}\right)\right)}^{2}}} \]
    4. Taylor expanded in d around -inf 45.8%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    5. Step-by-step derivation
      1. mul-1-neg45.8%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. distribute-rgt-neg-in45.8%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      3. unpow-145.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}}\right) \]
      4. metadata-eval45.8%

        \[\leadsto d \cdot \left(-\sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{\left(2 \cdot -0.5\right)}}}\right) \]
      5. pow-sqr45.8%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      6. rem-sqrt-square45.2%

        \[\leadsto d \cdot \left(-\color{blue}{\left|{\left(h \cdot \ell\right)}^{-0.5}\right|}\right) \]
      7. rem-square-sqrt45.0%

        \[\leadsto d \cdot \left(-\left|\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right|\right) \]
      8. fabs-sqr45.0%

        \[\leadsto d \cdot \left(-\color{blue}{\sqrt{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \sqrt{{\left(h \cdot \ell\right)}^{-0.5}}}\right) \]
      9. rem-square-sqrt45.2%

        \[\leadsto d \cdot \left(-\color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
    6. Simplified45.2%

      \[\leadsto \color{blue}{d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]

    if -2.3e-260 < l < 1.9999999999999998e-308

    1. Initial program 84.4%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified84.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 47.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. sqrt-div47.9%

        \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
      2. metadata-eval47.9%

        \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
      3. un-div-inv47.9%

        \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
    5. Applied egg-rr47.9%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]

    if 8.2e-180 < l

    1. Initial program 65.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 51.0%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. associate-/r*52.1%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    5. Simplified52.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification47.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.3 \cdot 10^{-260}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq 2 \cdot 10^{-308}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 8.2 \cdot 10^{-180}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]

Alternative 16: 27.1% accurate, 3.2× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \frac{d}{\sqrt{h \cdot \ell}} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m) :precision binary64 (/ d (sqrt (* h l))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return d / sqrt((h * l));
}
M_m = abs(M)
D_m = abs(D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    code = d / sqrt((h * l))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	return d / Math.sqrt((h * l));
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	return d / math.sqrt((h * l))
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	return Float64(d / sqrt(Float64(h * l)))
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
	tmp = d / sqrt((h * l));
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\frac{d}{\sqrt{h \cdot \ell}}
\end{array}
Derivation
  1. Initial program 66.9%

    \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
  2. Simplified66.6%

    \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{\frac{d \cdot 2}{D}}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
  3. Taylor expanded in d around inf 23.8%

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  4. Step-by-step derivation
    1. sqrt-div23.5%

      \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
    2. metadata-eval23.5%

      \[\leadsto d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}} \]
    3. un-div-inv23.5%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  5. Applied egg-rr23.5%

    \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  6. Final simplification23.5%

    \[\leadsto \frac{d}{\sqrt{h \cdot \ell}} \]

Reproduce

?
herbie shell --seed 2023336 
(FPCore (d h l M D)
  :name "Henrywood and Agarwal, Equation (12)"
  :precision binary64
  (* (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0))) (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))