Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.6% → 83.2%
Time: 26.4s
Alternatives: 24
Speedup: 1.4×

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 24 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.6% 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: 83.2% accurate, 0.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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\ \mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{d}}{\sqrt{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\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 (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l))))
   (if (<= l -5e-310)
     (* (sqrt (/ d l)) (* (/ (sqrt (- d)) (sqrt (- h))) t_0))
     (* (/ (sqrt d) (sqrt l)) (* t_0 (/ (sqrt d) (sqrt h)))))))
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 = 1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double tmp;
	if (l <= -5e-310) {
		tmp = sqrt((d / l)) * ((sqrt(-d) / sqrt(-h)) * t_0);
	} else {
		tmp = (sqrt(d) / sqrt(l)) * (t_0 * (sqrt(d) / sqrt(h)));
	}
	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 = 1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)
    if (l <= (-5d-310)) then
        tmp = sqrt((d / l)) * ((sqrt(-d) / sqrt(-h)) * t_0)
    else
        tmp = (sqrt(d) / sqrt(l)) * (t_0 * (sqrt(d) / sqrt(h)))
    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 = 1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double tmp;
	if (l <= -5e-310) {
		tmp = Math.sqrt((d / l)) * ((Math.sqrt(-d) / Math.sqrt(-h)) * t_0);
	} else {
		tmp = (Math.sqrt(d) / Math.sqrt(l)) * (t_0 * (Math.sqrt(d) / Math.sqrt(h)));
	}
	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 = 1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)
	tmp = 0
	if l <= -5e-310:
		tmp = math.sqrt((d / l)) * ((math.sqrt(-d) / math.sqrt(-h)) * t_0)
	else:
		tmp = (math.sqrt(d) / math.sqrt(l)) * (t_0 * (math.sqrt(d) / math.sqrt(h)))
	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(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l))
	tmp = 0.0
	if (l <= -5e-310)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0));
	else
		tmp = Float64(Float64(sqrt(d) / sqrt(l)) * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	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 = 1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l);
	tmp = 0.0;
	if (l <= -5e-310)
		tmp = sqrt((d / l)) * ((sqrt(-d) / sqrt(-h)) * t_0);
	else
		tmp = (sqrt(d) / sqrt(l)) * (t_0 * (sqrt(d) / sqrt(h)));
	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[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -5e-310], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{d}}{\sqrt{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.999999999999985e-310

    1. Initial program 71.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. Simplified71.2%

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

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

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

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 67.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. Simplified66.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 72.3% 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{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right) \leq \infty:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \left(M\_m \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left|\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\ \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 (/ (* D_m M_m) (* d 2.0)) 2.0)))))
      INFINITY)
   (*
    (sqrt (/ d l))
    (*
     (sqrt (/ d h))
     (+ 1.0 (* (/ h l) (* -0.5 (pow (* D_m (* M_m (/ 0.5 d))) 2.0))))))
   (* (* (fabs (/ (pow (* D_m M_m) 2.0) d)) (sqrt (/ h (pow l 3.0)))) -0.125)))
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(((D_m * M_m) / (d * 2.0)), 2.0))))) <= ((double) INFINITY)) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * pow((D_m * (M_m * (0.5 / d))), 2.0)))));
	} else {
		tmp = (fabs((pow((D_m * M_m), 2.0) / d)) * sqrt((h / pow(l, 3.0)))) * -0.125;
	}
	return tmp;
}
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(((D_m * M_m) / (d * 2.0)), 2.0))))) <= Double.POSITIVE_INFINITY) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * Math.pow((D_m * (M_m * (0.5 / d))), 2.0)))));
	} else {
		tmp = (Math.abs((Math.pow((D_m * M_m), 2.0) / d)) * Math.sqrt((h / Math.pow(l, 3.0)))) * -0.125;
	}
	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(((D_m * M_m) / (d * 2.0)), 2.0))))) <= math.inf:
		tmp = math.sqrt((d / l)) * (math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * math.pow((D_m * (M_m * (0.5 / d))), 2.0)))))
	else:
		tmp = (math.fabs((math.pow((D_m * M_m), 2.0) / d)) * math.sqrt((h / math.pow(l, 3.0)))) * -0.125
	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(D_m * M_m) / Float64(d * 2.0)) ^ 2.0))))) <= Inf)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(D_m * Float64(M_m * Float64(0.5 / d))) ^ 2.0))))));
	else
		tmp = Float64(Float64(abs(Float64((Float64(D_m * M_m) ^ 2.0) / d)) * sqrt(Float64(h / (l ^ 3.0)))) * -0.125);
	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 * (((D_m * M_m) / (d * 2.0)) ^ 2.0))))) <= Inf)
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * ((D_m * (M_m * (0.5 / d))) ^ 2.0)))));
	else
		tmp = (abs((((D_m * M_m) ^ 2.0) / d)) * sqrt((h / (l ^ 3.0)))) * -0.125;
	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[(D$95$m * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[Sqrt[N[(d / 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[(D$95$m * N[(M$95$m * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Abs[N[(N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.125), $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{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right) \leq \infty:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \left(M\_m \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left|\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < +inf.0

    1. Initial program 81.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. Simplified81.3%

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l))))

    1. Initial program 0.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. Simplified0.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt0.0%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\color{blue}{{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)}^{2}}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      4. associate-*r/21.2%

        \[\leadsto \left(\sqrt{{\color{blue}{\left(\frac{{D}^{2} \cdot {M}^{2}}{d}\right)}}^{2}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      5. pow-prod-down31.7%

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

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

        \[\leadsto \left(\sqrt{\color{blue}{\frac{{\left(D \cdot M\right)}^{2}}{d} \cdot \frac{{\left(D \cdot M\right)}^{2}}{d}}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      2. rem-sqrt-square31.8%

        \[\leadsto \left(\color{blue}{\left|\frac{{\left(D \cdot M\right)}^{2}}{d}\right|} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    12. Simplified31.8%

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

    \[\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{D \cdot M}{d \cdot 2}\right)}^{2}\right)\right) \leq \infty:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left|\frac{{\left(D \cdot M\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.0% 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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\ t_1 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;h \leq -1.9 \cdot 10^{+293}:\\ \;\;\;\;\left(\left|\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\ \mathbf{elif}\;h \leq -1.5 \cdot 10^{-182}:\\ \;\;\;\;t\_1 \cdot \left(t\_0 \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\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 (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l)))
        (t_1 (sqrt (/ d l))))
   (if (<= h -1.9e+293)
     (* (* (fabs (/ (pow (* D_m M_m) 2.0) d)) (sqrt (/ h (pow l 3.0)))) -0.125)
     (if (<= h -1.5e-182)
       (* t_1 (* t_0 (sqrt (/ d h))))
       (if (<= h -2e-310)
         (*
          (* d (sqrt (/ 1.0 (* l h))))
          (+ -1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
         (* t_1 (* t_0 (/ (sqrt d) (sqrt h)))))))))
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 = 1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double t_1 = sqrt((d / l));
	double tmp;
	if (h <= -1.9e+293) {
		tmp = (fabs((pow((D_m * M_m), 2.0) / d)) * sqrt((h / pow(l, 3.0)))) * -0.125;
	} else if (h <= -1.5e-182) {
		tmp = t_1 * (t_0 * sqrt((d / h)));
	} else if (h <= -2e-310) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0))));
	} else {
		tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
	}
	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 = 1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)
    t_1 = sqrt((d / l))
    if (h <= (-1.9d+293)) then
        tmp = (abs((((d_m * m_m) ** 2.0d0) / d)) * sqrt((h / (l ** 3.0d0)))) * (-0.125d0)
    else if (h <= (-1.5d-182)) then
        tmp = t_1 * (t_0 * sqrt((d / h)))
    else if (h <= (-2d-310)) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + (0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))))
    else
        tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)))
    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 = 1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double t_1 = Math.sqrt((d / l));
	double tmp;
	if (h <= -1.9e+293) {
		tmp = (Math.abs((Math.pow((D_m * M_m), 2.0) / d)) * Math.sqrt((h / Math.pow(l, 3.0)))) * -0.125;
	} else if (h <= -1.5e-182) {
		tmp = t_1 * (t_0 * Math.sqrt((d / h)));
	} else if (h <= -2e-310) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + (0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0))));
	} else {
		tmp = t_1 * (t_0 * (Math.sqrt(d) / Math.sqrt(h)));
	}
	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 = 1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)
	t_1 = math.sqrt((d / l))
	tmp = 0
	if h <= -1.9e+293:
		tmp = (math.fabs((math.pow((D_m * M_m), 2.0) / d)) * math.sqrt((h / math.pow(l, 3.0)))) * -0.125
	elif h <= -1.5e-182:
		tmp = t_1 * (t_0 * math.sqrt((d / h)))
	elif h <= -2e-310:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + (0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))))
	else:
		tmp = t_1 * (t_0 * (math.sqrt(d) / math.sqrt(h)))
	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(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l))
	t_1 = sqrt(Float64(d / l))
	tmp = 0.0
	if (h <= -1.9e+293)
		tmp = Float64(Float64(abs(Float64((Float64(D_m * M_m) ^ 2.0) / d)) * sqrt(Float64(h / (l ^ 3.0)))) * -0.125);
	elseif (h <= -1.5e-182)
		tmp = Float64(t_1 * Float64(t_0 * sqrt(Float64(d / h))));
	elseif (h <= -2e-310)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))));
	else
		tmp = Float64(t_1 * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	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 = 1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l);
	t_1 = sqrt((d / l));
	tmp = 0.0;
	if (h <= -1.9e+293)
		tmp = (abs((((D_m * M_m) ^ 2.0) / d)) * sqrt((h / (l ^ 3.0)))) * -0.125;
	elseif (h <= -1.5e-182)
		tmp = t_1 * (t_0 * sqrt((d / h)));
	elseif (h <= -2e-310)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + (0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0))));
	else
		tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
	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[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, -1.9e+293], N[(N[(N[Abs[N[(N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision], If[LessEqual[h, -1.5e-182], N[(t$95$1 * N[(t$95$0 * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, -2e-310], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + N[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;h \leq -1.9 \cdot 10^{+293}:\\
\;\;\;\;\left(\left|\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\

\mathbf{elif}\;h \leq -1.5 \cdot 10^{-182}:\\
\;\;\;\;t\_1 \cdot \left(t\_0 \cdot \sqrt{\frac{d}{h}}\right)\\

\mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if h < -1.90000000000000007e293

    1. Initial program 13.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. Simplified13.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt13.0%

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    8. Simplified13.0%

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

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

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

        \[\leadsto \left(\sqrt{\color{blue}{{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)}^{2}}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      4. associate-*r/73.0%

        \[\leadsto \left(\sqrt{{\color{blue}{\left(\frac{{D}^{2} \cdot {M}^{2}}{d}\right)}}^{2}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      5. pow-prod-down93.0%

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

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

        \[\leadsto \left(\sqrt{\color{blue}{\frac{{\left(D \cdot M\right)}^{2}}{d} \cdot \frac{{\left(D \cdot M\right)}^{2}}{d}}} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      2. rem-sqrt-square93.0%

        \[\leadsto \left(\color{blue}{\left|\frac{{\left(D \cdot M\right)}^{2}}{d}\right|} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    12. Simplified93.0%

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

    if -1.90000000000000007e293 < h < -1.5000000000000001e-182

    1. Initial program 79.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. Simplified79.0%

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

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

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

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

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

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

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

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

    if -1.5000000000000001e-182 < h < -1.999999999999994e-310

    1. Initial program 56.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. Simplified56.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow156.7%

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < h

    1. Initial program 67.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. Simplified66.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -1.9 \cdot 10^{+293}:\\ \;\;\;\;\left(\left|\frac{{\left(D \cdot M\right)}^{2}}{d}\right| \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125\\ \mathbf{elif}\;h \leq -1.5 \cdot 10^{-182}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 79.4% 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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\ t_1 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;t\_1 \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\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 (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l)))
        (t_1 (sqrt (/ d l))))
   (if (<= l -5e-310)
     (* t_1 (* (/ (sqrt (- d)) (sqrt (- h))) t_0))
     (* t_1 (* t_0 (/ (sqrt d) (sqrt h)))))))
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 = 1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double t_1 = sqrt((d / l));
	double tmp;
	if (l <= -5e-310) {
		tmp = t_1 * ((sqrt(-d) / sqrt(-h)) * t_0);
	} else {
		tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
	}
	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 = 1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)
    t_1 = sqrt((d / l))
    if (l <= (-5d-310)) then
        tmp = t_1 * ((sqrt(-d) / sqrt(-h)) * t_0)
    else
        tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)))
    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 = 1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l);
	double t_1 = Math.sqrt((d / l));
	double tmp;
	if (l <= -5e-310) {
		tmp = t_1 * ((Math.sqrt(-d) / Math.sqrt(-h)) * t_0);
	} else {
		tmp = t_1 * (t_0 * (Math.sqrt(d) / Math.sqrt(h)));
	}
	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 = 1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)
	t_1 = math.sqrt((d / l))
	tmp = 0
	if l <= -5e-310:
		tmp = t_1 * ((math.sqrt(-d) / math.sqrt(-h)) * t_0)
	else:
		tmp = t_1 * (t_0 * (math.sqrt(d) / math.sqrt(h)))
	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(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l))
	t_1 = sqrt(Float64(d / l))
	tmp = 0.0
	if (l <= -5e-310)
		tmp = Float64(t_1 * Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0));
	else
		tmp = Float64(t_1 * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	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 = 1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l);
	t_1 = sqrt((d / l));
	tmp = 0.0;
	if (l <= -5e-310)
		tmp = t_1 * ((sqrt(-d) / sqrt(-h)) * t_0);
	else
		tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
	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[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -5e-310], N[(t$95$1 * N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $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 := 1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;t\_1 \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -4.999999999999985e-310

    1. Initial program 71.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. Simplified71.2%

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

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

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

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 67.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. Simplified66.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 78.2% 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{\frac{d}{\ell}}\\ \mathbf{if}\;\ell \leq -1.95 \cdot 10^{-308}:\\ \;\;\;\;t\_0 \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\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 (sqrt (/ d l))))
   (if (<= l -1.95e-308)
     (*
      t_0
      (*
       (/ (sqrt (- d)) (sqrt (- h)))
       (+ 1.0 (* (/ h l) (* -0.5 (pow (* D_m (/ (/ M_m 2.0) d)) 2.0))))))
     (*
      t_0
      (*
       (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l))
       (/ (sqrt d) (sqrt h)))))))
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 <= -1.95e-308) {
		tmp = t_0 * ((sqrt(-d) / sqrt(-h)) * (1.0 + ((h / l) * (-0.5 * pow((D_m * ((M_m / 2.0) / d)), 2.0)))));
	} else {
		tmp = t_0 * ((1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * (sqrt(d) / sqrt(h)));
	}
	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 <= (-1.95d-308)) then
        tmp = t_0 * ((sqrt(-d) / sqrt(-h)) * (1.0d0 + ((h / l) * ((-0.5d0) * ((d_m * ((m_m / 2.0d0) / d)) ** 2.0d0)))))
    else
        tmp = t_0 * ((1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)) * (sqrt(d) / sqrt(h)))
    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 <= -1.95e-308) {
		tmp = t_0 * ((Math.sqrt(-d) / Math.sqrt(-h)) * (1.0 + ((h / l) * (-0.5 * Math.pow((D_m * ((M_m / 2.0) / d)), 2.0)))));
	} else {
		tmp = t_0 * ((1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * (Math.sqrt(d) / Math.sqrt(h)));
	}
	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 <= -1.95e-308:
		tmp = t_0 * ((math.sqrt(-d) / math.sqrt(-h)) * (1.0 + ((h / l) * (-0.5 * math.pow((D_m * ((M_m / 2.0) / d)), 2.0)))))
	else:
		tmp = t_0 * ((1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * (math.sqrt(d) / math.sqrt(h)))
	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 <= -1.95e-308)
		tmp = Float64(t_0 * Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0))))));
	else
		tmp = Float64(t_0 * Float64(Float64(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l)) * Float64(sqrt(d) / sqrt(h))));
	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 <= -1.95e-308)
		tmp = t_0 * ((sqrt(-d) / sqrt(-h)) * (1.0 + ((h / l) * (-0.5 * ((D_m * ((M_m / 2.0) / d)) ^ 2.0)))));
	else
		tmp = t_0 * ((1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l)) * (sqrt(d) / sqrt(h)));
	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, -1.95e-308], N[(t$95$0 * N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $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 -1.95 \cdot 10^{-308}:\\
\;\;\;\;t\_0 \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2}\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.95e-308

    1. Initial program 71.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. Simplified71.8%

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

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

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

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

    if -1.95e-308 < l

    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. Simplified65.6%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 72.1% 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{\frac{d}{\ell}}\\ \mathbf{if}\;\ell \leq 1.55 \cdot 10^{-97}:\\ \;\;\;\;t\_0 \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2}\right)\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 (sqrt (/ d l))))
   (if (<= l 1.55e-97)
     (*
      t_0
      (*
       (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l))
       (sqrt (/ d h))))
     (*
      t_0
      (*
       (/ (sqrt d) (sqrt h))
       (+ 1.0 (* (/ h l) (* -0.5 (pow (* D_m (/ (/ M_m 2.0) 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 = sqrt((d / l));
	double tmp;
	if (l <= 1.55e-97) {
		tmp = t_0 * ((1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * sqrt((d / h)));
	} else {
		tmp = t_0 * ((sqrt(d) / sqrt(h)) * (1.0 + ((h / l) * (-0.5 * pow((D_m * ((M_m / 2.0) / 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 = sqrt((d / l))
    if (l <= 1.55d-97) then
        tmp = t_0 * ((1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)) * sqrt((d / h)))
    else
        tmp = t_0 * ((sqrt(d) / sqrt(h)) * (1.0d0 + ((h / l) * ((-0.5d0) * ((d_m * ((m_m / 2.0d0) / 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 = Math.sqrt((d / l));
	double tmp;
	if (l <= 1.55e-97) {
		tmp = t_0 * ((1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * Math.sqrt((d / h)));
	} else {
		tmp = t_0 * ((Math.sqrt(d) / Math.sqrt(h)) * (1.0 + ((h / l) * (-0.5 * Math.pow((D_m * ((M_m / 2.0) / 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 = math.sqrt((d / l))
	tmp = 0
	if l <= 1.55e-97:
		tmp = t_0 * ((1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * math.sqrt((d / h)))
	else:
		tmp = t_0 * ((math.sqrt(d) / math.sqrt(h)) * (1.0 + ((h / l) * (-0.5 * math.pow((D_m * ((M_m / 2.0) / 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 = sqrt(Float64(d / l))
	tmp = 0.0
	if (l <= 1.55e-97)
		tmp = Float64(t_0 * Float64(Float64(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l)) * sqrt(Float64(d / h))));
	else
		tmp = Float64(t_0 * Float64(Float64(sqrt(d) / sqrt(h)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(D_m * Float64(Float64(M_m / 2.0) / 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 = sqrt((d / l));
	tmp = 0.0;
	if (l <= 1.55e-97)
		tmp = t_0 * ((1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l)) * sqrt((d / h)));
	else
		tmp = t_0 * ((sqrt(d) / sqrt(h)) * (1.0 + ((h / l) * (-0.5 * ((D_m * ((M_m / 2.0) / 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[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, 1.55e-97], N[(t$95$0 * N[(N[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $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 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;\ell \leq 1.55 \cdot 10^{-97}:\\
\;\;\;\;t\_0 \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.55000000000000001e-97

    1. Initial program 73.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. Simplified73.2%

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

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

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

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

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

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

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

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

    if 1.55000000000000001e-97 < l

    1. Initial program 58.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. Simplified58.7%

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

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

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

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

Alternative 7: 72.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} t_0 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ t_1 := \sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - h \cdot \left(0.125 \cdot \frac{{\left(M\_m \cdot \frac{D\_m}{d}\right)}^{2}}{\ell}\right)\right)\right)\\ \mathbf{if}\;h \leq -2.2 \cdot 10^{+125}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\ \mathbf{elif}\;h \leq 1.55 \cdot 10^{+109}:\\ \;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \mathbf{elif}\;h \leq 3.8 \cdot 10^{+192}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(D\_m \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\ \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 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0))))
        (t_1
         (*
          (sqrt (/ d h))
          (*
           (sqrt (/ d l))
           (- 1.0 (* h (* 0.125 (/ (pow (* M_m (/ D_m d)) 2.0) l))))))))
   (if (<= h -2.2e+125)
     t_1
     (if (<= h -2e-310)
       (* (* d (sqrt (/ 1.0 (* l h)))) (+ -1.0 t_0))
       (if (<= h 1.55e+109)
         (* (- 1.0 t_0) (* d (sqrt (/ (/ 1.0 l) h))))
         (if (<= h 3.8e+192)
           t_1
           (/
            (* (pow (* D_m M_m) 2.0) (/ (* (sqrt h) -0.125) (pow l 1.5)))
            d)))))))
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 = 0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double t_1 = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - (h * (0.125 * (pow((M_m * (D_m / d)), 2.0) / l)))));
	double tmp;
	if (h <= -2.2e+125) {
		tmp = t_1;
	} else if (h <= -2e-310) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (h <= 1.55e+109) {
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	} else if (h <= 3.8e+192) {
		tmp = t_1;
	} else {
		tmp = (pow((D_m * M_m), 2.0) * ((sqrt(h) * -0.125) / pow(l, 1.5))) / d;
	}
	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 = 0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))
    t_1 = sqrt((d / h)) * (sqrt((d / l)) * (1.0d0 - (h * (0.125d0 * (((m_m * (d_m / d)) ** 2.0d0) / l)))))
    if (h <= (-2.2d+125)) then
        tmp = t_1
    else if (h <= (-2d-310)) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + t_0)
    else if (h <= 1.55d+109) then
        tmp = (1.0d0 - t_0) * (d * sqrt(((1.0d0 / l) / h)))
    else if (h <= 3.8d+192) then
        tmp = t_1
    else
        tmp = (((d_m * m_m) ** 2.0d0) * ((sqrt(h) * (-0.125d0)) / (l ** 1.5d0))) / d
    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 = 0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double t_1 = Math.sqrt((d / h)) * (Math.sqrt((d / l)) * (1.0 - (h * (0.125 * (Math.pow((M_m * (D_m / d)), 2.0) / l)))));
	double tmp;
	if (h <= -2.2e+125) {
		tmp = t_1;
	} else if (h <= -2e-310) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (h <= 1.55e+109) {
		tmp = (1.0 - t_0) * (d * Math.sqrt(((1.0 / l) / h)));
	} else if (h <= 3.8e+192) {
		tmp = t_1;
	} else {
		tmp = (Math.pow((D_m * M_m), 2.0) * ((Math.sqrt(h) * -0.125) / Math.pow(l, 1.5))) / d;
	}
	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 = 0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))
	t_1 = math.sqrt((d / h)) * (math.sqrt((d / l)) * (1.0 - (h * (0.125 * (math.pow((M_m * (D_m / d)), 2.0) / l)))))
	tmp = 0
	if h <= -2.2e+125:
		tmp = t_1
	elif h <= -2e-310:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0)
	elif h <= 1.55e+109:
		tmp = (1.0 - t_0) * (d * math.sqrt(((1.0 / l) / h)))
	elif h <= 3.8e+192:
		tmp = t_1
	else:
		tmp = (math.pow((D_m * M_m), 2.0) * ((math.sqrt(h) * -0.125) / math.pow(l, 1.5))) / d
	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(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))
	t_1 = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(h * Float64(0.125 * Float64((Float64(M_m * Float64(D_m / d)) ^ 2.0) / l))))))
	tmp = 0.0
	if (h <= -2.2e+125)
		tmp = t_1;
	elseif (h <= -2e-310)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + t_0));
	elseif (h <= 1.55e+109)
		tmp = Float64(Float64(1.0 - t_0) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	elseif (h <= 3.8e+192)
		tmp = t_1;
	else
		tmp = Float64(Float64((Float64(D_m * M_m) ^ 2.0) * Float64(Float64(sqrt(h) * -0.125) / (l ^ 1.5))) / d);
	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 = 0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0));
	t_1 = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - (h * (0.125 * (((M_m * (D_m / d)) ^ 2.0) / l)))));
	tmp = 0.0;
	if (h <= -2.2e+125)
		tmp = t_1;
	elseif (h <= -2e-310)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	elseif (h <= 1.55e+109)
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	elseif (h <= 3.8e+192)
		tmp = t_1;
	else
		tmp = (((D_m * M_m) ^ 2.0) * ((sqrt(h) * -0.125) / (l ^ 1.5))) / d;
	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[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(h * N[(0.125 * N[(N[Power[N[(M$95$m * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[h, -2.2e+125], t$95$1, If[LessEqual[h, -2e-310], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 1.55e+109], N[(N[(1.0 - t$95$0), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3.8e+192], t$95$1, N[(N[(N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(N[Sqrt[h], $MachinePrecision] * -0.125), $MachinePrecision] / N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
t_1 := \sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - h \cdot \left(0.125 \cdot \frac{{\left(M\_m \cdot \frac{D\_m}{d}\right)}^{2}}{\ell}\right)\right)\right)\\
\mathbf{if}\;h \leq -2.2 \cdot 10^{+125}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\

\mathbf{elif}\;h \leq 1.55 \cdot 10^{+109}:\\
\;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\

\mathbf{elif}\;h \leq 3.8 \cdot 10^{+192}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;\frac{{\left(D\_m \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if h < -2.19999999999999991e125 or 1.54999999999999996e109 < h < 3.7999999999999999e192

    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}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in h around -inf 53.6%

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

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

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

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

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

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

    if -2.19999999999999991e125 < h < -1.999999999999994e-310

    1. Initial program 71.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. Simplified70.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow170.3%

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < h < 1.54999999999999996e109

    1. Initial program 76.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. Simplified75.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow175.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.7999999999999999e192 < h

    1. Initial program 37.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. Simplified37.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt37.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left({D}^{2} \cdot {M}^{2}\right) \cdot \left(\sqrt{\frac{h}{{\ell}^{3}}} \cdot -0.125\right)}{d}} \]
      4. pow-prod-down54.4%

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

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

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \color{blue}{\frac{\sqrt{h} \cdot -0.125}{\sqrt{{\ell}^{3}}}}}{d} \]
      7. sqrt-pow179.0%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{\color{blue}{{\ell}^{\left(\frac{3}{2}\right)}}}}{d} \]
      8. metadata-eval79.0%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{\color{blue}{1.5}}}}{d} \]
    10. Applied egg-rr79.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -2.2 \cdot 10^{+125}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - h \cdot \left(0.125 \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}\right)\right)\right)\\ \mathbf{elif}\;h \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\\ \mathbf{elif}\;h \leq 1.55 \cdot 10^{+109}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \mathbf{elif}\;h \leq 3.8 \cdot 10^{+192}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - h \cdot \left(0.125 \cdot \frac{{\left(M \cdot \frac{D}{d}\right)}^{2}}{\ell}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 71.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} t_0 := \left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\\ \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot t\_0\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{-159}:\\ \;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D\_m \cdot M\_m\right)}^{2}}{d \cdot {\ell}^{1.5}}\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{+155}:\\ \;\;\;\;t\_0 \cdot {\left(\frac{\ell}{d}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\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
         (*
          (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l))
          (sqrt (/ d h)))))
   (if (<= d 3.2e-308)
     (* (sqrt (/ d l)) t_0)
     (if (<= d 1.8e-159)
       (* -0.125 (/ (* (sqrt h) (pow (* D_m M_m) 2.0)) (* d (pow l 1.5))))
       (if (<= d 3.7e+155)
         (* t_0 (pow (/ l d) -0.5))
         (*
          (- 1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0))))
          (* d (sqrt (/ (/ 1.0 l) h)))))))))
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 = (1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * sqrt((d / h));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = sqrt((d / l)) * t_0;
	} else if (d <= 1.8e-159) {
		tmp = -0.125 * ((sqrt(h) * pow((D_m * M_m), 2.0)) / (d * pow(l, 1.5)));
	} else if (d <= 3.7e+155) {
		tmp = t_0 * pow((l / d), -0.5);
	} else {
		tmp = (1.0 - (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0)))) * (d * sqrt(((1.0 / l) / h)));
	}
	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 = (1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)) * sqrt((d / h))
    if (d <= 3.2d-308) then
        tmp = sqrt((d / l)) * t_0
    else if (d <= 1.8d-159) then
        tmp = (-0.125d0) * ((sqrt(h) * ((d_m * m_m) ** 2.0d0)) / (d * (l ** 1.5d0)))
    else if (d <= 3.7d+155) then
        tmp = t_0 * ((l / d) ** (-0.5d0))
    else
        tmp = (1.0d0 - (0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0)))) * (d * sqrt(((1.0d0 / l) / h)))
    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 = (1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * Math.sqrt((d / h));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = Math.sqrt((d / l)) * t_0;
	} else if (d <= 1.8e-159) {
		tmp = -0.125 * ((Math.sqrt(h) * Math.pow((D_m * M_m), 2.0)) / (d * Math.pow(l, 1.5)));
	} else if (d <= 3.7e+155) {
		tmp = t_0 * Math.pow((l / d), -0.5);
	} else {
		tmp = (1.0 - (0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0)))) * (d * Math.sqrt(((1.0 / l) / h)));
	}
	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 = (1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * math.sqrt((d / h))
	tmp = 0
	if d <= 3.2e-308:
		tmp = math.sqrt((d / l)) * t_0
	elif d <= 1.8e-159:
		tmp = -0.125 * ((math.sqrt(h) * math.pow((D_m * M_m), 2.0)) / (d * math.pow(l, 1.5)))
	elif d <= 3.7e+155:
		tmp = t_0 * math.pow((l / d), -0.5)
	else:
		tmp = (1.0 - (0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0)))) * (d * math.sqrt(((1.0 / l) / h)))
	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(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l)) * sqrt(Float64(d / h)))
	tmp = 0.0
	if (d <= 3.2e-308)
		tmp = Float64(sqrt(Float64(d / l)) * t_0);
	elseif (d <= 1.8e-159)
		tmp = Float64(-0.125 * Float64(Float64(sqrt(h) * (Float64(D_m * M_m) ^ 2.0)) / Float64(d * (l ^ 1.5))));
	elseif (d <= 3.7e+155)
		tmp = Float64(t_0 * (Float64(l / d) ^ -0.5));
	else
		tmp = Float64(Float64(1.0 - Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	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 = (1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l)) * sqrt((d / h));
	tmp = 0.0;
	if (d <= 3.2e-308)
		tmp = sqrt((d / l)) * t_0;
	elseif (d <= 1.8e-159)
		tmp = -0.125 * ((sqrt(h) * ((D_m * M_m) ^ 2.0)) / (d * (l ^ 1.5)));
	elseif (d <= 3.7e+155)
		tmp = t_0 * ((l / d) ^ -0.5);
	else
		tmp = (1.0 - (0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0)))) * (d * sqrt(((1.0 / l) / h)));
	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[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 3.2e-308], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision], If[LessEqual[d, 1.8e-159], N[(-0.125 * N[(N[(N[Sqrt[h], $MachinePrecision] * N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(d * N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 3.7e+155], N[(t$95$0 * N[Power[N[(l / d), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\\
\mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot t\_0\\

\mathbf{elif}\;d \leq 1.8 \cdot 10^{-159}:\\
\;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D\_m \cdot M\_m\right)}^{2}}{d \cdot {\ell}^{1.5}}\\

\mathbf{elif}\;d \leq 3.7 \cdot 10^{+155}:\\
\;\;\;\;t\_0 \cdot {\left(\frac{\ell}{d}\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < 3.2000000000000001e-308

    1. Initial program 71.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. Simplified71.4%

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-308 < d < 1.80000000000000011e-159

    1. Initial program 35.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. Simplified32.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt32.9%

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    8. Simplified40.6%

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

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

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

        \[\leadsto \color{blue}{\frac{\left({D}^{2} \cdot {M}^{2}\right) \cdot \sqrt{h}}{d \cdot \sqrt{{\ell}^{3}}}} \cdot -0.125 \]
      4. pow-prod-down57.5%

        \[\leadsto \frac{\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot \sqrt{h}}{d \cdot \sqrt{{\ell}^{3}}} \cdot -0.125 \]
      5. sqrt-pow166.7%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \sqrt{h}}{d \cdot \color{blue}{{\ell}^{\left(\frac{3}{2}\right)}}} \cdot -0.125 \]
      6. metadata-eval66.7%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \sqrt{h}}{d \cdot {\ell}^{\color{blue}{1.5}}} \cdot -0.125 \]
    10. Applied egg-rr66.7%

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

    if 1.80000000000000011e-159 < d < 3.6999999999999998e155

    1. Initial program 82.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. Simplified82.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6999999999999998e155 < d

    1. Initial program 67.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. Simplified67.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow167.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{elif}\;d \leq 1.8 \cdot 10^{-159}:\\ \;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D \cdot M\right)}^{2}}{d \cdot {\ell}^{1.5}}\\ \mathbf{elif}\;d \leq 3.7 \cdot 10^{+155}:\\ \;\;\;\;\left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right) \cdot {\left(\frac{\ell}{d}\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 68.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} \mathbf{if}\;h \leq 1.75 \cdot 10^{+192}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(D\_m \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\ \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 (<= h 1.75e+192)
   (*
    (sqrt (/ d l))
    (*
     (+ 1.0 (/ (* (* h -0.5) (pow (* D_m (/ M_m (* d 2.0))) 2.0)) l))
     (sqrt (/ d h))))
   (/ (* (pow (* D_m M_m) 2.0) (/ (* (sqrt h) -0.125) (pow l 1.5))) d)))
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 (h <= 1.75e+192) {
		tmp = sqrt((d / l)) * ((1.0 + (((h * -0.5) * pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * sqrt((d / h)));
	} else {
		tmp = (pow((D_m * M_m), 2.0) * ((sqrt(h) * -0.125) / pow(l, 1.5))) / d;
	}
	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 (h <= 1.75d+192) then
        tmp = sqrt((d / l)) * ((1.0d0 + (((h * (-0.5d0)) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / l)) * sqrt((d / h)))
    else
        tmp = (((d_m * m_m) ** 2.0d0) * ((sqrt(h) * (-0.125d0)) / (l ** 1.5d0))) / d
    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 (h <= 1.75e+192) {
		tmp = Math.sqrt((d / l)) * ((1.0 + (((h * -0.5) * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * Math.sqrt((d / h)));
	} else {
		tmp = (Math.pow((D_m * M_m), 2.0) * ((Math.sqrt(h) * -0.125) / Math.pow(l, 1.5))) / d;
	}
	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 h <= 1.75e+192:
		tmp = math.sqrt((d / l)) * ((1.0 + (((h * -0.5) * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / l)) * math.sqrt((d / h)))
	else:
		tmp = (math.pow((D_m * M_m), 2.0) * ((math.sqrt(h) * -0.125) / math.pow(l, 1.5))) / d
	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 (h <= 1.75e+192)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(Float64(Float64(h * -0.5) * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / l)) * sqrt(Float64(d / h))));
	else
		tmp = Float64(Float64((Float64(D_m * M_m) ^ 2.0) * Float64(Float64(sqrt(h) * -0.125) / (l ^ 1.5))) / d);
	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 (h <= 1.75e+192)
		tmp = sqrt((d / l)) * ((1.0 + (((h * -0.5) * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / l)) * sqrt((d / h)));
	else
		tmp = (((D_m * M_m) ^ 2.0) * ((sqrt(h) * -0.125) / (l ^ 1.5))) / d;
	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[h, 1.75e+192], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(N[(N[(h * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(N[Sqrt[h], $MachinePrecision] * -0.125), $MachinePrecision] / N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $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}\;h \leq 1.75 \cdot 10^{+192}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{{\left(D\_m \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 1.74999999999999991e192

    1. Initial program 71.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. Simplified71.4%

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

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

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

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

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

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

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

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

    if 1.74999999999999991e192 < h

    1. Initial program 37.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. Simplified37.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt37.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\left({D}^{2} \cdot {M}^{2}\right) \cdot \left(\sqrt{\frac{h}{{\ell}^{3}}} \cdot -0.125\right)}{d}} \]
      4. pow-prod-down54.4%

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

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

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \color{blue}{\frac{\sqrt{h} \cdot -0.125}{\sqrt{{\ell}^{3}}}}}{d} \]
      7. sqrt-pow179.0%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{\color{blue}{{\ell}^{\left(\frac{3}{2}\right)}}}}{d} \]
      8. metadata-eval79.0%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{\color{blue}{1.5}}}}{d} \]
    10. Applied egg-rr79.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq 1.75 \cdot 10^{+192}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{\left(h \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}}{\ell}\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{h} \cdot -0.125}{{\ell}^{1.5}}}{d}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 69.9% 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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\ \mathbf{elif}\;d \leq 5.4 \cdot 10^{-135}:\\ \;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D\_m \cdot M\_m\right)}^{2}}{d \cdot {\ell}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\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 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
   (if (<= d 3.2e-308)
     (* (* d (sqrt (/ 1.0 (* l h)))) (+ -1.0 t_0))
     (if (<= d 5.4e-135)
       (* -0.125 (/ (* (sqrt h) (pow (* D_m M_m) 2.0)) (* d (pow l 1.5))))
       (* (- 1.0 t_0) (* d (sqrt (/ (/ 1.0 l) h))))))))
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 = 0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (d <= 5.4e-135) {
		tmp = -0.125 * ((sqrt(h) * pow((D_m * M_m), 2.0)) / (d * pow(l, 1.5)));
	} else {
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	}
	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 = 0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))
    if (d <= 3.2d-308) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + t_0)
    else if (d <= 5.4d-135) then
        tmp = (-0.125d0) * ((sqrt(h) * ((d_m * m_m) ** 2.0d0)) / (d * (l ** 1.5d0)))
    else
        tmp = (1.0d0 - t_0) * (d * sqrt(((1.0d0 / l) / h)))
    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 = 0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (d <= 5.4e-135) {
		tmp = -0.125 * ((Math.sqrt(h) * Math.pow((D_m * M_m), 2.0)) / (d * Math.pow(l, 1.5)));
	} else {
		tmp = (1.0 - t_0) * (d * Math.sqrt(((1.0 / l) / h)));
	}
	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 = 0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))
	tmp = 0
	if d <= 3.2e-308:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0)
	elif d <= 5.4e-135:
		tmp = -0.125 * ((math.sqrt(h) * math.pow((D_m * M_m), 2.0)) / (d * math.pow(l, 1.5)))
	else:
		tmp = (1.0 - t_0) * (d * math.sqrt(((1.0 / l) / h)))
	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(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))
	tmp = 0.0
	if (d <= 3.2e-308)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + t_0));
	elseif (d <= 5.4e-135)
		tmp = Float64(-0.125 * Float64(Float64(sqrt(h) * (Float64(D_m * M_m) ^ 2.0)) / Float64(d * (l ^ 1.5))));
	else
		tmp = Float64(Float64(1.0 - t_0) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	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 = 0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0));
	tmp = 0.0;
	if (d <= 3.2e-308)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	elseif (d <= 5.4e-135)
		tmp = -0.125 * ((sqrt(h) * ((D_m * M_m) ^ 2.0)) / (d * (l ^ 1.5)));
	else
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	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[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 3.2e-308], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.4e-135], N[(-0.125 * N[(N[(N[Sqrt[h], $MachinePrecision] * N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(d * N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
\mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\

\mathbf{elif}\;d \leq 5.4 \cdot 10^{-135}:\\
\;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D\_m \cdot M\_m\right)}^{2}}{d \cdot {\ell}^{1.5}}\\

\mathbf{else}:\\
\;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\


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

    1. Initial program 71.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. Simplified70.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow170.8%

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

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-308 < d < 5.39999999999999997e-135

    1. Initial program 36.6%

      \[\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. Simplified34.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt34.0%

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    8. Simplified40.6%

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

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

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

        \[\leadsto \color{blue}{\frac{\left({D}^{2} \cdot {M}^{2}\right) \cdot \sqrt{h}}{d \cdot \sqrt{{\ell}^{3}}}} \cdot -0.125 \]
      4. pow-prod-down58.0%

        \[\leadsto \frac{\color{blue}{{\left(D \cdot M\right)}^{2}} \cdot \sqrt{h}}{d \cdot \sqrt{{\ell}^{3}}} \cdot -0.125 \]
      5. sqrt-pow165.9%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \sqrt{h}}{d \cdot \color{blue}{{\ell}^{\left(\frac{3}{2}\right)}}} \cdot -0.125 \]
      6. metadata-eval65.9%

        \[\leadsto \frac{{\left(D \cdot M\right)}^{2} \cdot \sqrt{h}}{d \cdot {\ell}^{\color{blue}{1.5}}} \cdot -0.125 \]
    10. Applied egg-rr65.9%

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

    if 5.39999999999999997e-135 < d

    1. Initial program 79.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. Simplified79.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\\ \mathbf{elif}\;d \leq 5.4 \cdot 10^{-135}:\\ \;\;\;\;-0.125 \cdot \frac{\sqrt{h} \cdot {\left(D \cdot M\right)}^{2}}{d \cdot {\ell}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 68.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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{-160}:\\ \;\;\;\;-0.125 \cdot \left(\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\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 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
   (if (<= d 3.2e-308)
     (* (* d (sqrt (/ 1.0 (* l h)))) (+ -1.0 t_0))
     (if (<= d 2.7e-160)
       (* -0.125 (* (/ (pow (* D_m M_m) 2.0) d) (sqrt (/ h (pow l 3.0)))))
       (* (- 1.0 t_0) (* d (sqrt (/ (/ 1.0 l) h))))))))
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 = 0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (d <= 2.7e-160) {
		tmp = -0.125 * ((pow((D_m * M_m), 2.0) / d) * sqrt((h / pow(l, 3.0))));
	} else {
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	}
	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 = 0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))
    if (d <= 3.2d-308) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + t_0)
    else if (d <= 2.7d-160) then
        tmp = (-0.125d0) * ((((d_m * m_m) ** 2.0d0) / d) * sqrt((h / (l ** 3.0d0))))
    else
        tmp = (1.0d0 - t_0) * (d * sqrt(((1.0d0 / l) / h)))
    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 = 0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (d <= 3.2e-308) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else if (d <= 2.7e-160) {
		tmp = -0.125 * ((Math.pow((D_m * M_m), 2.0) / d) * Math.sqrt((h / Math.pow(l, 3.0))));
	} else {
		tmp = (1.0 - t_0) * (d * Math.sqrt(((1.0 / l) / h)));
	}
	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 = 0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))
	tmp = 0
	if d <= 3.2e-308:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0)
	elif d <= 2.7e-160:
		tmp = -0.125 * ((math.pow((D_m * M_m), 2.0) / d) * math.sqrt((h / math.pow(l, 3.0))))
	else:
		tmp = (1.0 - t_0) * (d * math.sqrt(((1.0 / l) / h)))
	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(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))
	tmp = 0.0
	if (d <= 3.2e-308)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + t_0));
	elseif (d <= 2.7e-160)
		tmp = Float64(-0.125 * Float64(Float64((Float64(D_m * M_m) ^ 2.0) / d) * sqrt(Float64(h / (l ^ 3.0)))));
	else
		tmp = Float64(Float64(1.0 - t_0) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	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 = 0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0));
	tmp = 0.0;
	if (d <= 3.2e-308)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	elseif (d <= 2.7e-160)
		tmp = -0.125 * ((((D_m * M_m) ^ 2.0) / d) * sqrt((h / (l ^ 3.0))));
	else
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	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[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, 3.2e-308], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.7e-160], N[(-0.125 * N[(N[(N[Power[N[(D$95$m * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision] * N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
\mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\

\mathbf{elif}\;d \leq 2.7 \cdot 10^{-160}:\\
\;\;\;\;-0.125 \cdot \left(\frac{{\left(D\_m \cdot M\_m\right)}^{2}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\


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

    1. Initial program 71.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. Simplified70.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow170.8%

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

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-308 < d < 2.7000000000000001e-160

    1. Initial program 35.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. Simplified32.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. add-cube-cbrt32.9%

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right)} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    8. Simplified40.6%

      \[\leadsto \color{blue}{\left(\left({D}^{2} \cdot \frac{{M}^{2}}{d}\right) \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125} \]
    9. Taylor expanded in D around 0 39.7%

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

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

        \[\leadsto \left(\frac{\left(D \cdot D\right) \cdot \color{blue}{\left(M \cdot M\right)}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      3. swap-sqr55.7%

        \[\leadsto \left(\frac{\color{blue}{\left(D \cdot M\right) \cdot \left(D \cdot M\right)}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
      4. unpow255.7%

        \[\leadsto \left(\frac{\color{blue}{{\left(D \cdot M\right)}^{2}}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right) \cdot -0.125 \]
    11. Simplified55.7%

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

    if 2.7000000000000001e-160 < d

    1. Initial program 77.6%

      \[\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. Simplified77.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow177.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\\ \mathbf{elif}\;d \leq 2.7 \cdot 10^{-160}:\\ \;\;\;\;-0.125 \cdot \left(\frac{{\left(D \cdot M\right)}^{2}}{d} \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 69.8% 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} t_0 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+131}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\\ \mathbf{elif}\;\ell \leq -1.95 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\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 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
   (if (<= l -4.5e+131)
     (* (sqrt (/ d h)) (/ (sqrt (- d)) (sqrt (- l))))
     (if (<= l -1.95e-308)
       (* (* d (sqrt (/ 1.0 (* l h)))) (+ -1.0 t_0))
       (* (- 1.0 t_0) (* d (sqrt (/ (/ 1.0 l) h))))))))
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 = 0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (l <= -4.5e+131) {
		tmp = sqrt((d / h)) * (sqrt(-d) / sqrt(-l));
	} else if (l <= -1.95e-308) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else {
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	}
	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 = 0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))
    if (l <= (-4.5d+131)) then
        tmp = sqrt((d / h)) * (sqrt(-d) / sqrt(-l))
    else if (l <= (-1.95d-308)) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + t_0)
    else
        tmp = (1.0d0 - t_0) * (d * sqrt(((1.0d0 / l) / h)))
    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 = 0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (l <= -4.5e+131) {
		tmp = Math.sqrt((d / h)) * (Math.sqrt(-d) / Math.sqrt(-l));
	} else if (l <= -1.95e-308) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else {
		tmp = (1.0 - t_0) * (d * Math.sqrt(((1.0 / l) / h)));
	}
	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 = 0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))
	tmp = 0
	if l <= -4.5e+131:
		tmp = math.sqrt((d / h)) * (math.sqrt(-d) / math.sqrt(-l))
	elif l <= -1.95e-308:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0)
	else:
		tmp = (1.0 - t_0) * (d * math.sqrt(((1.0 / l) / h)))
	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(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))
	tmp = 0.0
	if (l <= -4.5e+131)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-l))));
	elseif (l <= -1.95e-308)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + t_0));
	else
		tmp = Float64(Float64(1.0 - t_0) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	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 = 0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0));
	tmp = 0.0;
	if (l <= -4.5e+131)
		tmp = sqrt((d / h)) * (sqrt(-d) / sqrt(-l));
	elseif (l <= -1.95e-308)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	else
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	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[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.5e+131], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -1.95e-308], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
\mathbf{if}\;\ell \leq -4.5 \cdot 10^{+131}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\\

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

\mathbf{else}:\\
\;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\


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

    1. Initial program 60.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. Simplified60.4%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt15.7%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt12.9%

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
      3. sqr-neg56.5%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
      4. add-sqr-sqrt56.5%

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

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

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

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

    if -4.5000000000000002e131 < l < -1.95e-308

    1. Initial program 76.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. Simplified75.9%

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

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

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

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

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

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

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

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

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

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

    if -1.95e-308 < l

    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. 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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow165.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+131}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\\ \mathbf{elif}\;\ell \leq -1.95 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 61.3% accurate, 1.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} t_0 := 1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ t_1 := \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{if}\;\ell \leq -2.9 \cdot 10^{-69}:\\ \;\;\;\;\left(-d\right) \cdot t\_1\\ \mathbf{elif}\;\ell \leq 1.48 \cdot 10^{-164}:\\ \;\;\;\;t\_0 \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(d \cdot t\_1\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 (- 1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
        (t_1 (sqrt (/ (/ 1.0 l) h))))
   (if (<= l -2.9e-69)
     (* (- d) t_1)
     (if (<= l 1.48e-164)
       (* t_0 (sqrt (* (/ d l) (/ d h))))
       (* t_0 (* d t_1))))))
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 = 1.0 - (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0)));
	double t_1 = sqrt(((1.0 / l) / h));
	double tmp;
	if (l <= -2.9e-69) {
		tmp = -d * t_1;
	} else if (l <= 1.48e-164) {
		tmp = t_0 * sqrt(((d / l) * (d / h)));
	} else {
		tmp = t_0 * (d * t_1);
	}
	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 = 1.0d0 - (0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0)))
    t_1 = sqrt(((1.0d0 / l) / h))
    if (l <= (-2.9d-69)) then
        tmp = -d * t_1
    else if (l <= 1.48d-164) then
        tmp = t_0 * sqrt(((d / l) * (d / h)))
    else
        tmp = t_0 * (d * t_1)
    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 = 1.0 - (0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0)));
	double t_1 = Math.sqrt(((1.0 / l) / h));
	double tmp;
	if (l <= -2.9e-69) {
		tmp = -d * t_1;
	} else if (l <= 1.48e-164) {
		tmp = t_0 * Math.sqrt(((d / l) * (d / h)));
	} else {
		tmp = t_0 * (d * t_1);
	}
	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 = 1.0 - (0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0)))
	t_1 = math.sqrt(((1.0 / l) / h))
	tmp = 0
	if l <= -2.9e-69:
		tmp = -d * t_1
	elif l <= 1.48e-164:
		tmp = t_0 * math.sqrt(((d / l) * (d / h)))
	else:
		tmp = t_0 * (d * t_1)
	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(1.0 - Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0))))
	t_1 = sqrt(Float64(Float64(1.0 / l) / h))
	tmp = 0.0
	if (l <= -2.9e-69)
		tmp = Float64(Float64(-d) * t_1);
	elseif (l <= 1.48e-164)
		tmp = Float64(t_0 * sqrt(Float64(Float64(d / l) * Float64(d / h))));
	else
		tmp = Float64(t_0 * Float64(d * t_1));
	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 = 1.0 - (0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0)));
	t_1 = sqrt(((1.0 / l) / h));
	tmp = 0.0;
	if (l <= -2.9e-69)
		tmp = -d * t_1;
	elseif (l <= 1.48e-164)
		tmp = t_0 * sqrt(((d / l) * (d / h)));
	else
		tmp = t_0 * (d * t_1);
	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[(1.0 - N[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -2.9e-69], N[((-d) * t$95$1), $MachinePrecision], If[LessEqual[l, 1.48e-164], N[(t$95$0 * N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(d * t$95$1), $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 := 1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
t_1 := \sqrt{\frac{\frac{1}{\ell}}{h}}\\
\mathbf{if}\;\ell \leq -2.9 \cdot 10^{-69}:\\
\;\;\;\;\left(-d\right) \cdot t\_1\\

\mathbf{elif}\;\ell \leq 1.48 \cdot 10^{-164}:\\
\;\;\;\;t\_0 \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(d \cdot t\_1\right)\\


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

    1. Initial program 62.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. Simplified62.8%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt62.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*62.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg62.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in62.4%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      7. associate-/r*62.9%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/62.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*62.9%

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

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

    if -2.8999999999999998e-69 < l < 1.48000000000000001e-164

    1. Initial program 80.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. Simplified79.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow179.4%

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

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

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

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

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

    if 1.48000000000000001e-164 < l

    1. Initial program 64.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. 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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow163.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.9 \cdot 10^{-69}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;\ell \leq 1.48 \cdot 10^{-164}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 61.2% accurate, 1.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} t_0 := 1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{if}\;\ell \leq -2.2 \cdot 10^{-68}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{-175}:\\ \;\;\;\;t\_0 \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\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 (- 1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0))))))
   (if (<= l -2.2e-68)
     (* (- d) (sqrt (/ (/ 1.0 l) h)))
     (if (<= l 5.2e-175)
       (* t_0 (sqrt (* (/ d l) (/ d h))))
       (* t_0 (* d (pow (* l h) -0.5)))))))
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 = 1.0 - (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0)));
	double tmp;
	if (l <= -2.2e-68) {
		tmp = -d * sqrt(((1.0 / l) / h));
	} else if (l <= 5.2e-175) {
		tmp = t_0 * sqrt(((d / l) * (d / h)));
	} else {
		tmp = t_0 * (d * pow((l * h), -0.5));
	}
	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 = 1.0d0 - (0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0)))
    if (l <= (-2.2d-68)) then
        tmp = -d * sqrt(((1.0d0 / l) / h))
    else if (l <= 5.2d-175) then
        tmp = t_0 * sqrt(((d / l) * (d / h)))
    else
        tmp = t_0 * (d * ((l * h) ** (-0.5d0)))
    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 = 1.0 - (0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0)));
	double tmp;
	if (l <= -2.2e-68) {
		tmp = -d * Math.sqrt(((1.0 / l) / h));
	} else if (l <= 5.2e-175) {
		tmp = t_0 * Math.sqrt(((d / l) * (d / h)));
	} else {
		tmp = t_0 * (d * Math.pow((l * h), -0.5));
	}
	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 = 1.0 - (0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0)))
	tmp = 0
	if l <= -2.2e-68:
		tmp = -d * math.sqrt(((1.0 / l) / h))
	elif l <= 5.2e-175:
		tmp = t_0 * math.sqrt(((d / l) * (d / h)))
	else:
		tmp = t_0 * (d * math.pow((l * h), -0.5))
	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(1.0 - Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0))))
	tmp = 0.0
	if (l <= -2.2e-68)
		tmp = Float64(Float64(-d) * sqrt(Float64(Float64(1.0 / l) / h)));
	elseif (l <= 5.2e-175)
		tmp = Float64(t_0 * sqrt(Float64(Float64(d / l) * Float64(d / h))));
	else
		tmp = Float64(t_0 * Float64(d * (Float64(l * h) ^ -0.5)));
	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 = 1.0 - (0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0)));
	tmp = 0.0;
	if (l <= -2.2e-68)
		tmp = -d * sqrt(((1.0 / l) / h));
	elseif (l <= 5.2e-175)
		tmp = t_0 * sqrt(((d / l) * (d / h)));
	else
		tmp = t_0 * (d * ((l * h) ^ -0.5));
	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[(1.0 - N[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.2e-68], N[((-d) * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.2e-175], N[(t$95$0 * N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $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 := 1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
\mathbf{if}\;\ell \leq -2.2 \cdot 10^{-68}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\

\mathbf{elif}\;\ell \leq 5.2 \cdot 10^{-175}:\\
\;\;\;\;t\_0 \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\

\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\right)\\


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

    1. Initial program 62.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. Simplified62.8%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt62.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*62.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg62.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in62.4%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      7. associate-/r*62.9%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/62.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*62.9%

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

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

    if -2.20000000000000002e-68 < l < 5.2e-175

    1. Initial program 81.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. Simplified80.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow180.0%

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

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

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

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

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

    if 5.2e-175 < l

    1. Initial program 64.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. Simplified62.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(d \cdot \color{blue}{\left|{\left(h \cdot \ell\right)}^{-0.5}\right|}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \]
      5. rem-square-sqrt67.1%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{-68}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;\ell \leq 5.2 \cdot 10^{-175}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 56.4% accurate, 1.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}\;d \leq -1.4 \cdot 10^{-125}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-278}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\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 (<= d -1.4e-125)
   (* (- d) (sqrt (/ (/ 1.0 l) h)))
   (if (<= d 1.6e-278)
     (/ d (sqrt (+ -1.0 (fma l h 1.0))))
     (*
      (- 1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0))))
      (* d (pow (* l h) -0.5))))))
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 (d <= -1.4e-125) {
		tmp = -d * sqrt(((1.0 / l) / h));
	} else if (d <= 1.6e-278) {
		tmp = d / sqrt((-1.0 + fma(l, h, 1.0)));
	} else {
		tmp = (1.0 - (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0)))) * (d * pow((l * h), -0.5));
	}
	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 (d <= -1.4e-125)
		tmp = Float64(Float64(-d) * sqrt(Float64(Float64(1.0 / l) / h)));
	elseif (d <= 1.6e-278)
		tmp = Float64(d / sqrt(Float64(-1.0 + fma(l, h, 1.0))));
	else
		tmp = Float64(Float64(1.0 - Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))) * Float64(d * (Float64(l * h) ^ -0.5)));
	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[d, -1.4e-125], N[((-d) * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6e-278], N[(d / N[Sqrt[N[(-1.0 + N[(l * h + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $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}\;d \leq -1.4 \cdot 10^{-125}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\

\mathbf{elif}\;d \leq 1.6 \cdot 10^{-278}:\\
\;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\

\mathbf{else}:\\
\;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\right)\\


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

    1. Initial program 79.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. Simplified79.1%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt62.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*62.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg62.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in62.4%

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

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/62.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*62.8%

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

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

    if -1.4e-125 < d < 1.60000000000000009e-278

    1. Initial program 51.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. Simplified48.5%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. sqrt-div0.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \cdot \left(-\sqrt{\frac{d}{\ell}}\right) \]
      2. add-sqr-sqrt0.2%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      8. add-sqr-sqrt2.1%

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

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h \cdot \ell}}} \]
      10. *-commutative20.1%

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

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

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    10. Applied egg-rr35.6%

      \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    11. Step-by-step derivation
      1. sub-neg35.6%

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} + \left(-1\right)}}} \]
      2. metadata-eval35.6%

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{-1 + e^{\mathsf{log1p}\left(\ell \cdot h\right)}}}} \]
      4. log1p-undefine35.6%

        \[\leadsto \frac{d}{\sqrt{-1 + e^{\color{blue}{\log \left(1 + \ell \cdot h\right)}}}} \]
      5. rem-exp-log35.6%

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

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

        \[\leadsto \frac{d}{\sqrt{-1 + \color{blue}{\mathsf{fma}\left(\ell, h, 1\right)}}} \]
    12. Simplified35.6%

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

    if 1.60000000000000009e-278 < d

    1. Initial program 70.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. Simplified69.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow169.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.4 \cdot 10^{-125}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq 1.6 \cdot 10^{-278}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \left(d \cdot {\left(\ell \cdot h\right)}^{-0.5}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 69.2% accurate, 1.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} t_0 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{if}\;\ell \leq -1.95 \cdot 10^{-308}:\\ \;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\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 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
   (if (<= l -1.95e-308)
     (* (* d (sqrt (/ 1.0 (* l h)))) (+ -1.0 t_0))
     (* (- 1.0 t_0) (* d (sqrt (/ (/ 1.0 l) h)))))))
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 = 0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (l <= -1.95e-308) {
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else {
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	}
	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 = 0.5d0 * ((h / l) * (((m_m / 2.0d0) * (d_m / d)) ** 2.0d0))
    if (l <= (-1.95d-308)) then
        tmp = (d * sqrt((1.0d0 / (l * h)))) * ((-1.0d0) + t_0)
    else
        tmp = (1.0d0 - t_0) * (d * sqrt(((1.0d0 / l) / h)))
    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 = 0.5 * ((h / l) * Math.pow(((M_m / 2.0) * (D_m / d)), 2.0));
	double tmp;
	if (l <= -1.95e-308) {
		tmp = (d * Math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	} else {
		tmp = (1.0 - t_0) * (d * Math.sqrt(((1.0 / l) / h)));
	}
	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 = 0.5 * ((h / l) * math.pow(((M_m / 2.0) * (D_m / d)), 2.0))
	tmp = 0
	if l <= -1.95e-308:
		tmp = (d * math.sqrt((1.0 / (l * h)))) * (-1.0 + t_0)
	else:
		tmp = (1.0 - t_0) * (d * math.sqrt(((1.0 / l) / h)))
	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(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))
	tmp = 0.0
	if (l <= -1.95e-308)
		tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(l * h)))) * Float64(-1.0 + t_0));
	else
		tmp = Float64(Float64(1.0 - t_0) * Float64(d * sqrt(Float64(Float64(1.0 / l) / h))));
	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 = 0.5 * ((h / l) * (((M_m / 2.0) * (D_m / d)) ^ 2.0));
	tmp = 0.0;
	if (l <= -1.95e-308)
		tmp = (d * sqrt((1.0 / (l * h)))) * (-1.0 + t_0);
	else
		tmp = (1.0 - t_0) * (d * sqrt(((1.0 / l) / h)));
	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[(0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(M$95$m / 2.0), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.95e-308], N[(N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - t$95$0), $MachinePrecision] * N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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 := 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\\
\mathbf{if}\;\ell \leq -1.95 \cdot 10^{-308}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{\ell \cdot h}}\right) \cdot \left(-1 + t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;\left(1 - t\_0\right) \cdot \left(d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.95e-308

    1. Initial program 71.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. Simplified71.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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow171.1%

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

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

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

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

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

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

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

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

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

    if -1.95e-308 < l

    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. 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}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. pow165.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 46.0% 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} \mathbf{if}\;d \leq -3.5 \cdot 10^{-127}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{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 (<= d -3.5e-127)
   (* (- d) (sqrt (/ (/ 1.0 l) h)))
   (if (<= d -2e-310)
     (/ d (sqrt (+ -1.0 (fma l h 1.0))))
     (/ (/ 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 (d <= -3.5e-127) {
		tmp = -d * sqrt(((1.0 / l) / h));
	} else if (d <= -2e-310) {
		tmp = d / sqrt((-1.0 + fma(l, h, 1.0)));
	} else {
		tmp = (d / sqrt(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 (d <= -3.5e-127)
		tmp = Float64(Float64(-d) * sqrt(Float64(Float64(1.0 / l) / h)));
	elseif (d <= -2e-310)
		tmp = Float64(d / sqrt(Float64(-1.0 + fma(l, h, 1.0))));
	else
		tmp = Float64(Float64(d / sqrt(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[d, -3.5e-127], N[((-d) * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2e-310], N[(d / N[Sqrt[N[(-1.0 + N[(l * h + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $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}\;d \leq -3.5 \cdot 10^{-127}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\

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

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


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

    1. Initial program 79.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. Simplified79.1%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt62.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*62.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg62.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in62.4%

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

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/62.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*62.8%

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

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

    if -3.49999999999999989e-127 < d < -1.999999999999994e-310

    1. Initial program 57.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. Simplified53.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt14.8%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. sqrt-div0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \cdot \left(-\sqrt{\frac{d}{\ell}}\right) \]
      2. add-sqr-sqrt0.0%

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

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
      4. sqr-neg0.0%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
      5. add-sqr-sqrt0.0%

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      8. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\ell}} \]
      9. sqrt-prod22.6%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h \cdot \ell}}} \]
      10. *-commutative22.6%

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

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\ell \cdot h\right)\right)}}} \]
      2. expm1-undefine40.3%

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    10. Applied egg-rr40.3%

      \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    11. Step-by-step derivation
      1. sub-neg40.3%

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} + \left(-1\right)}}} \]
      2. metadata-eval40.3%

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

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

        \[\leadsto \frac{d}{\sqrt{-1 + e^{\color{blue}{\log \left(1 + \ell \cdot h\right)}}}} \]
      5. rem-exp-log40.3%

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

        \[\leadsto \frac{d}{\sqrt{-1 + \color{blue}{\left(\ell \cdot h + 1\right)}}} \]
      7. fma-define40.3%

        \[\leadsto \frac{d}{\sqrt{-1 + \color{blue}{\mathsf{fma}\left(\ell, h, 1\right)}}} \]
    12. Simplified40.3%

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

    if -1.999999999999994e-310 < d

    1. Initial program 67.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.4%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt8.2%

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

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

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

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

        \[\leadsto \color{blue}{\frac{-\sqrt{d}}{-\sqrt{h}}} \cdot \left(-\sqrt{\frac{d}{\ell}}\right) \]
      3. add-sqr-sqrt0.3%

        \[\leadsto \frac{-\sqrt{d}}{-\sqrt{h}} \cdot \color{blue}{\left(\sqrt{-\sqrt{\frac{d}{\ell}}} \cdot \sqrt{-\sqrt{\frac{d}{\ell}}}\right)} \]
      4. sqrt-unprod42.4%

        \[\leadsto \frac{-\sqrt{d}}{-\sqrt{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
      5. sqr-neg42.4%

        \[\leadsto \frac{-\sqrt{d}}{-\sqrt{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
      6. add-sqr-sqrt42.4%

        \[\leadsto \frac{-\sqrt{d}}{-\sqrt{h}} \cdot \sqrt{\color{blue}{\frac{d}{\ell}}} \]
      7. sqrt-div45.9%

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

        \[\leadsto \color{blue}{\frac{\left(-\sqrt{d}\right) \cdot \sqrt{d}}{\left(-\sqrt{h}\right) \cdot \sqrt{\ell}}} \]
      9. distribute-lft-neg-in45.9%

        \[\leadsto \frac{\color{blue}{-\sqrt{d} \cdot \sqrt{d}}}{\left(-\sqrt{h}\right) \cdot \sqrt{\ell}} \]
      10. add-sqr-sqrt46.1%

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

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

        \[\leadsto \color{blue}{\frac{\frac{-d}{-\sqrt{h}}}{\sqrt{\ell}}} \]
      2. neg-mul-144.5%

        \[\leadsto \frac{\frac{\color{blue}{-1 \cdot d}}{-\sqrt{h}}}{\sqrt{\ell}} \]
      3. neg-mul-144.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.5 \cdot 10^{-127}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 46.2% 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} \mathbf{if}\;d \leq -7.6 \cdot 10^{-124}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{\ell}}}{\sqrt{h}}\\ \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 (<= d -7.6e-124)
   (* (- d) (sqrt (/ (/ 1.0 l) h)))
   (if (<= d -2e-310)
     (/ d (sqrt (+ -1.0 (fma l h 1.0))))
     (/ (/ d (sqrt l)) (sqrt h)))))
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 (d <= -7.6e-124) {
		tmp = -d * sqrt(((1.0 / l) / h));
	} else if (d <= -2e-310) {
		tmp = d / sqrt((-1.0 + fma(l, h, 1.0)));
	} else {
		tmp = (d / sqrt(l)) / sqrt(h);
	}
	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 (d <= -7.6e-124)
		tmp = Float64(Float64(-d) * sqrt(Float64(Float64(1.0 / l) / h)));
	elseif (d <= -2e-310)
		tmp = Float64(d / sqrt(Float64(-1.0 + fma(l, h, 1.0))));
	else
		tmp = Float64(Float64(d / sqrt(l)) / sqrt(h));
	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[d, -7.6e-124], N[((-d) * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2e-310], N[(d / N[Sqrt[N[(-1.0 + N[(l * h + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[Sqrt[l], $MachinePrecision]), $MachinePrecision] / N[Sqrt[h], $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}\;d \leq -7.6 \cdot 10^{-124}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\

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

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


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

    1. Initial program 79.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. Simplified79.1%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt62.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*62.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg62.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in62.4%

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

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/62.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*62.8%

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

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

    if -7.60000000000000025e-124 < d < -1.999999999999994e-310

    1. Initial program 57.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. Simplified53.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt14.8%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. sqrt-div0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \cdot \left(-\sqrt{\frac{d}{\ell}}\right) \]
      2. add-sqr-sqrt0.0%

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

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
      4. sqr-neg0.0%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
      5. add-sqr-sqrt0.0%

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      8. add-sqr-sqrt0.0%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\ell}} \]
      9. sqrt-prod22.6%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h \cdot \ell}}} \]
      10. *-commutative22.6%

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

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\ell \cdot h\right)\right)}}} \]
      2. expm1-undefine40.3%

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    10. Applied egg-rr40.3%

      \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} - 1}}} \]
    11. Step-by-step derivation
      1. sub-neg40.3%

        \[\leadsto \frac{d}{\sqrt{\color{blue}{e^{\mathsf{log1p}\left(\ell \cdot h\right)} + \left(-1\right)}}} \]
      2. metadata-eval40.3%

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

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

        \[\leadsto \frac{d}{\sqrt{-1 + e^{\color{blue}{\log \left(1 + \ell \cdot h\right)}}}} \]
      5. rem-exp-log40.3%

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

        \[\leadsto \frac{d}{\sqrt{-1 + \color{blue}{\left(\ell \cdot h + 1\right)}}} \]
      7. fma-define40.3%

        \[\leadsto \frac{d}{\sqrt{-1 + \color{blue}{\mathsf{fma}\left(\ell, h, 1\right)}}} \]
    12. Simplified40.3%

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

    if -1.999999999999994e-310 < d

    1. Initial program 67.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.4%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt8.2%

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

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

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

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \cdot \left(-\sqrt{\frac{d}{\ell}}\right) \]
      2. add-sqr-sqrt0.3%

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

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
      4. sqr-neg42.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
      5. add-sqr-sqrt42.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \sqrt{\color{blue}{\frac{d}{\ell}}} \]
      6. sqrt-div45.9%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \]
      7. frac-times45.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{h} \cdot \sqrt{\ell}}} \]
      8. add-sqr-sqrt46.1%

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

        \[\leadsto \frac{d}{\color{blue}{\sqrt{h \cdot \ell}}} \]
      10. *-commutative41.3%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\ell}} \cdot d}{\sqrt{h}}} \]
      2. associate-*l/43.0%

        \[\leadsto \frac{\color{blue}{\frac{1 \cdot d}{\sqrt{\ell}}}}{\sqrt{h}} \]
      3. *-lft-identity43.0%

        \[\leadsto \frac{\frac{\color{blue}{d}}{\sqrt{\ell}}}{\sqrt{h}} \]
    12. Simplified43.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -7.6 \cdot 10^{-124}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt{-1 + \mathsf{fma}\left(\ell, h, 1\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{\ell}}}{\sqrt{h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 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 := \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{if}\;\ell \leq -2.7 \cdot 10^{-213}:\\ \;\;\;\;\left(-d\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;d \cdot t\_0\\ \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 (/ (/ 1.0 l) h))))
   (if (<= l -2.7e-213) (* (- d) t_0) (* d t_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 = sqrt(((1.0 / l) / h));
	double tmp;
	if (l <= -2.7e-213) {
		tmp = -d * t_0;
	} else {
		tmp = d * t_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 = sqrt(((1.0d0 / l) / h))
    if (l <= (-2.7d-213)) then
        tmp = -d * t_0
    else
        tmp = d * t_0
    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(((1.0 / l) / h));
	double tmp;
	if (l <= -2.7e-213) {
		tmp = -d * t_0;
	} else {
		tmp = d * t_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 = math.sqrt(((1.0 / l) / h))
	tmp = 0
	if l <= -2.7e-213:
		tmp = -d * t_0
	else:
		tmp = d * t_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 = sqrt(Float64(Float64(1.0 / l) / h))
	tmp = 0.0
	if (l <= -2.7e-213)
		tmp = Float64(Float64(-d) * t_0);
	else
		tmp = Float64(d * t_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 = sqrt(((1.0 / l) / h));
	tmp = 0.0;
	if (l <= -2.7e-213)
		tmp = -d * t_0;
	else
		tmp = d * t_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[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -2.7e-213], N[((-d) * t$95$0), $MachinePrecision], N[(d * t$95$0), $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{\frac{1}{\ell}}{h}}\\
\mathbf{if}\;\ell \leq -2.7 \cdot 10^{-213}:\\
\;\;\;\;\left(-d\right) \cdot t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.7000000000000001e-213

    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. Simplified69.3%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    6. Step-by-step derivation
      1. *-commutative0.0%

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

        \[\leadsto \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. rem-square-sqrt52.4%

        \[\leadsto \left(\color{blue}{-1} \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. associate-*r*52.4%

        \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      5. mul-1-neg52.4%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in52.4%

        \[\leadsto \color{blue}{d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      7. associate-/r*52.7%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}}\right) \]
      8. associate-/l/52.4%

        \[\leadsto d \cdot \left(-\sqrt{\color{blue}{\frac{1}{\ell \cdot h}}}\right) \]
      9. associate-/r*52.7%

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

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

    if -2.7000000000000001e-213 < l

    1. Initial program 68.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. Simplified66.4%

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{1 \cdot \frac{1}{h \cdot \ell}}} \]
      2. associate-/r*42.8%

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
      2. associate-/l/42.2%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{1}{\ell \cdot h}}} \]
      3. associate-/r*42.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.7 \cdot 10^{-213}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 42.5% accurate, 3.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.8 \cdot 10^{-216}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \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.8e-216) (/ d (- (sqrt (* l h)))) (* d (sqrt (/ (/ 1.0 l) h)))))
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.8e-216) {
		tmp = d / -sqrt((l * h));
	} else {
		tmp = d * sqrt(((1.0 / l) / h));
	}
	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.8d-216)) then
        tmp = d / -sqrt((l * h))
    else
        tmp = d * sqrt(((1.0d0 / l) / h))
    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.8e-216) {
		tmp = d / -Math.sqrt((l * h));
	} else {
		tmp = d * Math.sqrt(((1.0 / l) / h));
	}
	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.8e-216:
		tmp = d / -math.sqrt((l * h))
	else:
		tmp = d * math.sqrt(((1.0 / l) / h))
	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.8e-216)
		tmp = Float64(d / Float64(-sqrt(Float64(l * h))));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / l) / h)));
	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.8e-216)
		tmp = d / -sqrt((l * h));
	else
		tmp = d * sqrt(((1.0 / l) / h));
	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.8e-216], N[(d / (-N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / l), $MachinePrecision] / h), $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.8 \cdot 10^{-216}:\\
\;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.7999999999999995e-216

    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. Simplified69.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt10.5%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. mul-1-neg10.5%

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. distribute-rgt-neg-out10.5%

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

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

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

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

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

        \[\leadsto 0 - \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\ell}} \]
      7. sqrt-prod52.5%

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

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

      \[\leadsto \color{blue}{0 - \frac{d}{\sqrt{\ell \cdot h}}} \]
    9. Step-by-step derivation
      1. neg-sub052.5%

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

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

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

    if -6.7999999999999995e-216 < l

    1. Initial program 68.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. Simplified66.4%

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{1 \cdot \frac{1}{h \cdot \ell}}} \]
      2. associate-/r*42.8%

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
      2. associate-/l/42.2%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{1}{\ell \cdot h}}} \]
      3. associate-/r*42.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.8 \cdot 10^{-216}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{\ell}}{h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 42.5% accurate, 3.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 -5.8 \cdot 10^{-218}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \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.8e-218) (/ d (- (sqrt (* l h)))) (* 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.8e-218) {
		tmp = d / -sqrt((l * h));
	} 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.8d-218)) then
        tmp = d / -sqrt((l * h))
    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.8e-218) {
		tmp = d / -Math.sqrt((l * h));
	} 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.8e-218:
		tmp = d / -math.sqrt((l * h))
	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.8e-218)
		tmp = Float64(d / Float64(-sqrt(Float64(l * h))));
	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.8e-218)
		tmp = d / -sqrt((l * h));
	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.8e-218], N[(d / (-N[Sqrt[N[(l * h), $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.8 \cdot 10^{-218}:\\
\;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -5.8000000000000004e-218

    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. Simplified69.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt10.5%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. mul-1-neg10.5%

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. distribute-rgt-neg-out10.5%

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

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

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

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

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

        \[\leadsto 0 - \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\ell}} \]
      7. sqrt-prod52.5%

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

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

      \[\leadsto \color{blue}{0 - \frac{d}{\sqrt{\ell \cdot h}}} \]
    9. Step-by-step derivation
      1. neg-sub052.5%

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

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

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

    if -5.8000000000000004e-218 < l

    1. Initial program 68.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. Simplified66.4%

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

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

        \[\leadsto d \cdot \color{blue}{\left(1 \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      2. pow1/242.2%

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

        \[\leadsto d \cdot \left(1 \cdot {\color{blue}{\left({\left(h \cdot \ell\right)}^{-1}\right)}}^{0.5}\right) \]
      4. pow-pow42.3%

        \[\leadsto d \cdot \left(1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}}\right) \]
      5. metadata-eval42.3%

        \[\leadsto d \cdot \left(1 \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right) \]
    6. Applied egg-rr42.3%

      \[\leadsto d \cdot \color{blue}{\left(1 \cdot {\left(h \cdot \ell\right)}^{-0.5}\right)} \]
    7. Step-by-step derivation
      1. *-lft-identity42.3%

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

      \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    9. Taylor expanded in d around 0 42.2%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -5.8 \cdot 10^{-218}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 22: 42.3% accurate, 3.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 -9.6 \cdot 10^{-217}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \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 -9.6e-217) (/ d (- (sqrt (* l h)))) (* d (pow (* l h) -0.5))))
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 <= -9.6e-217) {
		tmp = d / -sqrt((l * h));
	} else {
		tmp = d * pow((l * h), -0.5);
	}
	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 <= (-9.6d-217)) then
        tmp = d / -sqrt((l * h))
    else
        tmp = d * ((l * h) ** (-0.5d0))
    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 <= -9.6e-217) {
		tmp = d / -Math.sqrt((l * h));
	} else {
		tmp = d * Math.pow((l * h), -0.5);
	}
	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 <= -9.6e-217:
		tmp = d / -math.sqrt((l * h))
	else:
		tmp = d * math.pow((l * h), -0.5)
	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 <= -9.6e-217)
		tmp = Float64(d / Float64(-sqrt(Float64(l * h))));
	else
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	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 <= -9.6e-217)
		tmp = d / -sqrt((l * h));
	else
		tmp = d * ((l * h) ^ -0.5);
	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, -9.6e-217], N[(d / (-N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $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 -9.6 \cdot 10^{-217}:\\
\;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -9.5999999999999995e-217

    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. Simplified69.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Add Preprocessing
    4. Taylor expanded in l around -inf 0.0%

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

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

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      3. rem-square-sqrt10.5%

        \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. mul-1-neg10.5%

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\left(-\sqrt{\frac{d}{\ell}}\right)} \]
    7. Step-by-step derivation
      1. distribute-rgt-neg-out10.5%

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

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

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

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

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

        \[\leadsto 0 - \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\ell}} \]
      7. sqrt-prod52.5%

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

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

      \[\leadsto \color{blue}{0 - \frac{d}{\sqrt{\ell \cdot h}}} \]
    9. Step-by-step derivation
      1. neg-sub052.5%

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

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

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

    if -9.5999999999999995e-217 < l

    1. Initial program 68.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. Simplified66.4%

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

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

        \[\leadsto d \cdot \color{blue}{\left(1 \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      2. pow1/242.2%

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

        \[\leadsto d \cdot \left(1 \cdot {\color{blue}{\left({\left(h \cdot \ell\right)}^{-1}\right)}}^{0.5}\right) \]
      4. pow-pow42.3%

        \[\leadsto d \cdot \left(1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}}\right) \]
      5. metadata-eval42.3%

        \[\leadsto d \cdot \left(1 \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right) \]
    6. Applied egg-rr42.3%

      \[\leadsto d \cdot \color{blue}{\left(1 \cdot {\left(h \cdot \ell\right)}^{-0.5}\right)} \]
    7. Step-by-step derivation
      1. *-lft-identity42.3%

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

      \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification47.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.6 \cdot 10^{-217}:\\ \;\;\;\;\frac{d}{-\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 23: 26.6% accurate, 3.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])\\ \\ d \cdot {\left(\ell \cdot h\right)}^{-0.5} \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 (pow (* l h) -0.5)))
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 * pow((l * h), -0.5);
}
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 * ((l * h) ** (-0.5d0))
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.pow((l * h), -0.5);
}
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.pow((l * h), -0.5)
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 * (Float64(l * h) ^ -0.5))
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 * ((l * h) ^ -0.5);
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[Power[N[(l * h), $MachinePrecision], -0.5], $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])\\
\\
d \cdot {\left(\ell \cdot h\right)}^{-0.5}
\end{array}
Derivation
  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.8%

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

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  5. Step-by-step derivation
    1. *-un-lft-identity26.1%

      \[\leadsto d \cdot \color{blue}{\left(1 \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    2. pow1/226.1%

      \[\leadsto d \cdot \left(1 \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}}\right) \]
    3. inv-pow26.1%

      \[\leadsto d \cdot \left(1 \cdot {\color{blue}{\left({\left(h \cdot \ell\right)}^{-1}\right)}}^{0.5}\right) \]
    4. pow-pow26.1%

      \[\leadsto d \cdot \left(1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}}\right) \]
    5. metadata-eval26.1%

      \[\leadsto d \cdot \left(1 \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right) \]
  6. Applied egg-rr26.1%

    \[\leadsto d \cdot \color{blue}{\left(1 \cdot {\left(h \cdot \ell\right)}^{-0.5}\right)} \]
  7. Step-by-step derivation
    1. *-lft-identity26.1%

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

    \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
  9. Final simplification26.1%

    \[\leadsto d \cdot {\left(\ell \cdot h\right)}^{-0.5} \]
  10. Add Preprocessing

Alternative 24: 26.6% 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{\ell \cdot h}} \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 (* l h))))
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((l * h));
}
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((l * h))
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((l * h));
}
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((l * h))
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(l * h)))
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((l * h));
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[(l * h), $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{\ell \cdot h}}
\end{array}
Derivation
  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.8%

    \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \left(M \cdot \frac{D}{d}\right)\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in l around -inf 0.0%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    3. rem-square-sqrt9.9%

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

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

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

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

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

      \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\sqrt{\left(-\sqrt{\frac{d}{\ell}}\right) \cdot \left(-\sqrt{\frac{d}{\ell}}\right)}} \]
    4. sqr-neg19.7%

      \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \sqrt{\color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{\ell}}}} \]
    5. add-sqr-sqrt19.7%

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{h} \cdot \sqrt{\ell}}} \]
    8. add-sqr-sqrt21.4%

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

      \[\leadsto \frac{d}{\color{blue}{\sqrt{h \cdot \ell}}} \]
    10. *-commutative26.1%

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

    \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2024129 
(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)))))