Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.0% → 78.7%
Time: 22.7s
Alternatives: 14
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 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.0% 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: 78.7% accurate, 0.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\ \mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{-224}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \mathbf{elif}\;d \leq 9.4 \cdot 10^{-185}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+116}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5)))))
   (if (<= d -5e-310)
     (* (/ 1.0 (sqrt (/ l d))) (* (/ (sqrt (- d)) (sqrt (- h))) t_0))
     (if (<= d 5.2e-224)
       (* (sqrt (/ d l)) (* t_0 (/ (sqrt d) (sqrt h))))
       (if (<= d 9.4e-185)
         (/
          (* d (fma -0.5 (* (/ h l) (pow (/ (* D M_m) (* d 2.0)) 2.0)) 1.0))
          (sqrt (* l h)))
         (if (<= d 5.6e+116)
           (*
            (fma h (* -0.5 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)) 1.0)
            (/ (/ d (sqrt h)) (sqrt l)))
           (*
            (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
            (/ d (* (sqrt h) (sqrt l))))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = 1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5));
	double tmp;
	if (d <= -5e-310) {
		tmp = (1.0 / sqrt((l / d))) * ((sqrt(-d) / sqrt(-h)) * t_0);
	} else if (d <= 5.2e-224) {
		tmp = sqrt((d / l)) * (t_0 * (sqrt(d) / sqrt(h)));
	} else if (d <= 9.4e-185) {
		tmp = (d * fma(-0.5, ((h / l) * pow(((D * M_m) / (d * 2.0)), 2.0)), 1.0)) / sqrt((l * h));
	} else if (d <= 5.6e+116) {
		tmp = fma(h, (-0.5 * (pow((0.5 * (D * (M_m / d))), 2.0) / l)), 1.0) * ((d / sqrt(h)) / sqrt(l));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5)))
	tmp = 0.0
	if (d <= -5e-310)
		tmp = Float64(Float64(1.0 / sqrt(Float64(l / d))) * Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0));
	elseif (d <= 5.2e-224)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	elseif (d <= 9.4e-185)
		tmp = Float64(Float64(d * fma(-0.5, Float64(Float64(h / l) * (Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0)), 1.0)) / sqrt(Float64(l * h)));
	elseif (d <= 5.6e+116)
		tmp = Float64(fma(h, Float64(-0.5 * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l)));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5e-310], N[(N[(1.0 / N[Sqrt[N[(l / d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.2e-224], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 9.4e-185], N[(N[(d * N[(-0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 5.6e+116], N[(N[(h * N[(-0.5 * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\
\mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right)\\

\mathbf{elif}\;d \leq 5.2 \cdot 10^{-224}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\

\mathbf{elif}\;d \leq 9.4 \cdot 10^{-185}:\\
\;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\

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

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


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

    1. Initial program 67.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. Simplified67.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. clear-num67.1%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{\ell}{d}}}} \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) \]
      2. sqrt-div67.9%

        \[\leadsto \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\ell}{d}}}} \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. metadata-eval67.9%

        \[\leadsto \frac{\color{blue}{1}}{\sqrt{\frac{\ell}{d}}} \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) \]
    5. Applied egg-rr67.9%

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\frac{\ell}{d}}}} \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) \]
    6. Step-by-step derivation
      1. frac-2neg67.9%

        \[\leadsto \frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\sqrt{\color{blue}{\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) \]
      2. sqrt-div77.7%

        \[\leadsto \frac{1}{\sqrt{\frac{\ell}{d}}} \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) \]
    7. Applied egg-rr77.7%

      \[\leadsto \frac{1}{\sqrt{\frac{\ell}{d}}} \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 -4.999999999999985e-310 < d < 5.2000000000000004e-224

    1. Initial program 54.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. Simplified54.5%

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

        \[\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) \]
      2. div-inv76.1%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{d} \cdot 1}{\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) \]
      2. *-rgt-identity76.0%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\frac{\color{blue}{\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) \]
    7. Simplified76.0%

      \[\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 5.2000000000000004e-224 < d < 9.4000000000000004e-185

    1. Initial program 45.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. Simplified44.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. sub-neg44.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.4000000000000004e-185 < d < 5.60000000000000009e116

    1. Initial program 70.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. Simplified70.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. sub-neg70.4%

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

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

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

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

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

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

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

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

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

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

    if 5.60000000000000009e116 < d

    1. Initial program 69.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. Simplified71.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. sub-neg71.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\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)\\ \mathbf{elif}\;d \leq 5.2 \cdot 10^{-224}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \mathbf{elif}\;d \leq 9.4 \cdot 10^{-185}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{elif}\;d \leq 5.6 \cdot 10^{+116}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 75.0% accurate, 0.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}\\ t_1 := \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\\ \mathbf{if}\;d \leq -5 \cdot 10^{-160}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot t\_1\right)\right)\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-208}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\ \;\;\;\;\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(t\_0 \cdot 0.5\right)\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-185}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot t\_0, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot t\_1, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (pow (/ (* D M_m) (* d 2.0)) 2.0))
        (t_1 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)))
   (if (<= d -5e-160)
     (* (* (sqrt (/ d l)) (sqrt (/ d h))) (- 1.0 (* 0.5 (* h t_1))))
     (if (<= d -1.8e-208)
       (* d (- (sqrt (/ 1.0 (* l h)))))
       (if (<= d 1.45e-296)
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* t_0 0.5))))
         (if (<= d 7.5e-185)
           (/ (* d (fma -0.5 (* (/ h l) t_0) 1.0)) (sqrt (* l h)))
           (* (fma h (* -0.5 t_1) 1.0) (/ (/ d (sqrt h)) (sqrt l)))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = pow(((D * M_m) / (d * 2.0)), 2.0);
	double t_1 = pow((0.5 * (D * (M_m / d))), 2.0) / l;
	double tmp;
	if (d <= -5e-160) {
		tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (0.5 * (h * t_1)));
	} else if (d <= -1.8e-208) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else if (d <= 1.45e-296) {
		tmp = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (t_0 * 0.5)));
	} else if (d <= 7.5e-185) {
		tmp = (d * fma(-0.5, ((h / l) * t_0), 1.0)) / sqrt((l * h));
	} else {
		tmp = fma(h, (-0.5 * t_1), 1.0) * ((d / sqrt(h)) / sqrt(l));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0
	t_1 = Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)
	tmp = 0.0
	if (d <= -5e-160)
		tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * Float64(1.0 - Float64(0.5 * Float64(h * t_1))));
	elseif (d <= -1.8e-208)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	elseif (d <= 1.45e-296)
		tmp = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(t_0 * 0.5))));
	elseif (d <= 7.5e-185)
		tmp = Float64(Float64(d * fma(-0.5, Float64(Float64(h / l) * t_0), 1.0)) / sqrt(Float64(l * h)));
	else
		tmp = Float64(fma(h, Float64(-0.5 * t_1), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l)));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]}, If[LessEqual[d, -5e-160], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(0.5 * N[(h * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.8e-208], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, 1.45e-296], 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[(t$95$0 * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 7.5e-185], N[(N[(d * N[(-0.5 * N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(h * N[(-0.5 * t$95$1), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}\\
t_1 := \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\\
\mathbf{if}\;d \leq -5 \cdot 10^{-160}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot t\_1\right)\right)\\

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

\mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\
\;\;\;\;\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(t\_0 \cdot 0.5\right)\right)\\

\mathbf{elif}\;d \leq 7.5 \cdot 10^{-185}:\\
\;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot t\_0, 1\right)}{\sqrt{\ell \cdot h}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot t\_1, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\


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

    1. Initial program 72.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified72.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. clear-num72.8%

        \[\leadsto \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 \color{blue}{\frac{1}{\frac{\ell}{h}}}\right)\right) \]
      2. un-div-inv73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.99999999999999994e-160 < d < -1.7999999999999999e-208

    1. Initial program 35.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. Simplified35.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.7999999999999999e-208 < d < 1.44999999999999991e-296

    1. Initial program 54.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. Add Preprocessing

    if 1.44999999999999991e-296 < d < 7.49999999999999978e-185

    1. Initial program 49.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. Simplified49.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. sub-neg49.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.49999999999999978e-185 < d

    1. Initial program 70.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. 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. sub-neg70.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{-160}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -1.8 \cdot 10^{-208}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\ \;\;\;\;\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({\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2} \cdot 0.5\right)\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-185}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 74.8% accurate, 0.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\\ t_1 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;h \leq 7.5 \cdot 10^{-307}:\\ \;\;\;\;\left(t\_1 \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot t\_0\right)\right)\\ \mathbf{elif}\;h \leq 3.7 \cdot 10^{-71}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2} \cdot \left(\frac{h}{\ell} \cdot -0.5\right)\right)\\ \mathbf{elif}\;h \leq 1.4 \cdot 10^{+109}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot t\_0, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \mathbf{else}:\\ \;\;\;\;t\_1 \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)) (t_1 (sqrt (/ d l))))
   (if (<= h 7.5e-307)
     (* (* t_1 (sqrt (/ d h))) (- 1.0 (* 0.5 (* h t_0))))
     (if (<= h 3.7e-71)
       (*
        (/ d (* (sqrt h) (sqrt l)))
        (+ 1.0 (* (pow (/ (* D M_m) (* d 2.0)) 2.0) (* (/ h l) -0.5))))
       (if (<= h 1.4e+109)
         (* (fma h (* -0.5 t_0) 1.0) (/ (/ d (sqrt h)) (sqrt l)))
         (*
          t_1
          (*
           (+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5)))
           (/ (sqrt d) (sqrt h)))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = pow((0.5 * (D * (M_m / d))), 2.0) / l;
	double t_1 = sqrt((d / l));
	double tmp;
	if (h <= 7.5e-307) {
		tmp = (t_1 * sqrt((d / h))) * (1.0 - (0.5 * (h * t_0)));
	} else if (h <= 3.7e-71) {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (pow(((D * M_m) / (d * 2.0)), 2.0) * ((h / l) * -0.5)));
	} else if (h <= 1.4e+109) {
		tmp = fma(h, (-0.5 * t_0), 1.0) * ((d / sqrt(h)) / sqrt(l));
	} else {
		tmp = t_1 * ((1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5))) * (sqrt(d) / sqrt(h)));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)
	t_1 = sqrt(Float64(d / l))
	tmp = 0.0
	if (h <= 7.5e-307)
		tmp = Float64(Float64(t_1 * sqrt(Float64(d / h))) * Float64(1.0 - Float64(0.5 * Float64(h * t_0))));
	elseif (h <= 3.7e-71)
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64((Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0) * Float64(Float64(h / l) * -0.5))));
	elseif (h <= 1.4e+109)
		tmp = Float64(fma(h, Float64(-0.5 * t_0), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l)));
	else
		tmp = Float64(t_1 * Float64(Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) * Float64(sqrt(d) / sqrt(h))));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, 7.5e-307], N[(N[(t$95$1 * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(0.5 * N[(h * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3.7e-71], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 1.4e+109], N[(N[(h * N[(-0.5 * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 * N[(N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;h \leq 7.5 \cdot 10^{-307}:\\
\;\;\;\;\left(t\_1 \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot t\_0\right)\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if h < 7.5000000000000006e-307

    1. Initial program 66.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.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. clear-num66.9%

        \[\leadsto \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 \color{blue}{\frac{1}{\frac{\ell}{h}}}\right)\right) \]
      2. un-div-inv67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7.5000000000000006e-307 < h < 3.6999999999999996e-71

    1. Initial program 70.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. Simplified70.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. sub-neg70.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.6999999999999996e-71 < h < 1.4000000000000001e109

    1. Initial program 70.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. Simplified70.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. sub-neg70.4%

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

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

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

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

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

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

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

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

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

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

    if 1.4000000000000001e109 < h

    1. Initial program 58.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. Simplified60.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. sqrt-div86.3%

        \[\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) \]
      2. div-inv86.2%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{d} \cdot 1}{\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) \]
      2. *-rgt-identity86.3%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\frac{\color{blue}{\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) \]
    7. Simplified86.3%

      \[\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 4 regimes into one program.
  4. Final simplification80.6%

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

Alternative 4: 79.3% accurate, 0.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\ t_1 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right) \cdot t\_1\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-223}:\\ \;\;\;\;t\_1 \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \mathbf{elif}\;d \leq 10^{+184}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* (/ h l) (* (pow (* D (/ (/ M_m 2.0) d)) 2.0) -0.5))))
        (t_1 (sqrt (/ d l))))
   (if (<= d -5e-310)
     (* (* (/ (sqrt (- d)) (sqrt (- h))) t_0) t_1)
     (if (<= d 1.05e-223)
       (* t_1 (* t_0 (/ (sqrt d) (sqrt h))))
       (if (<= d 1e+184)
         (*
          (fma h (* -0.5 (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)) 1.0)
          (/ (/ d (sqrt h)) (sqrt l)))
         (*
          (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
          (/ d (* (sqrt h) (sqrt l)))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = 1.0 + ((h / l) * (pow((D * ((M_m / 2.0) / d)), 2.0) * -0.5));
	double t_1 = sqrt((d / l));
	double tmp;
	if (d <= -5e-310) {
		tmp = ((sqrt(-d) / sqrt(-h)) * t_0) * t_1;
	} else if (d <= 1.05e-223) {
		tmp = t_1 * (t_0 * (sqrt(d) / sqrt(h)));
	} else if (d <= 1e+184) {
		tmp = fma(h, (-0.5 * (pow((0.5 * (D * (M_m / d))), 2.0) / l)), 1.0) * ((d / sqrt(h)) / sqrt(l));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5)))
	t_1 = sqrt(Float64(d / l))
	tmp = 0.0
	if (d <= -5e-310)
		tmp = Float64(Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * t_0) * t_1);
	elseif (d <= 1.05e-223)
		tmp = Float64(t_1 * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	elseif (d <= 1e+184)
		tmp = Float64(fma(h, Float64(-0.5 * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)), 1.0) * Float64(Float64(d / sqrt(h)) / sqrt(l)));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, -5e-310], N[(N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[d, 1.05e-223], N[(t$95$1 * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1e+184], N[(N[(h * N[(-0.5 * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision] * N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := 1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\\
t_1 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot t\_0\right) \cdot t\_1\\

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

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

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


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

    1. Initial program 67.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. Simplified67.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. frac-2neg67.9%

        \[\leadsto \frac{1}{\sqrt{\frac{\ell}{d}}} \cdot \left(\sqrt{\color{blue}{\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) \]
      2. sqrt-div77.7%

        \[\leadsto \frac{1}{\sqrt{\frac{\ell}{d}}} \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) \]
    5. Applied egg-rr76.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 -4.999999999999985e-310 < d < 1.04999999999999991e-223

    1. Initial program 54.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. Simplified54.5%

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

        \[\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) \]
      2. div-inv76.1%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\color{blue}{\frac{\sqrt{d} \cdot 1}{\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) \]
      2. *-rgt-identity76.0%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\frac{\color{blue}{\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) \]
    7. Simplified76.0%

      \[\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.04999999999999991e-223 < d < 1.00000000000000002e184

    1. Initial program 66.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. Simplified66.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. sub-neg66.2%

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000002e184 < d

    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. Simplified76.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. sub-neg76.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\left(\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) \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-223}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \mathbf{elif}\;d \leq 10^{+184}:\\ \;\;\;\;\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right) \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 73.7% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}\\ \mathbf{if}\;d \leq -4.4 \cdot 10^{-160}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -2.9 \cdot 10^{-208}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\ \;\;\;\;\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(t\_0 \cdot 0.5\right)\right)\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{-184}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot t\_0, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (pow (/ (* D M_m) (* d 2.0)) 2.0)))
   (if (<= d -4.4e-160)
     (*
      (* (sqrt (/ d l)) (sqrt (/ d h)))
      (- 1.0 (* 0.5 (* h (/ (pow (* 0.5 (* D (/ M_m d))) 2.0) l)))))
     (if (<= d -2.9e-208)
       (* d (- (sqrt (/ 1.0 (* l h)))))
       (if (<= d 1.45e-296)
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* t_0 0.5))))
         (if (<= d 2.2e-184)
           (/ (* d (fma -0.5 (* (/ h l) t_0) 1.0)) (sqrt (* l h)))
           (*
            (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
            (/ d (* (sqrt h) (sqrt l))))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = pow(((D * M_m) / (d * 2.0)), 2.0);
	double tmp;
	if (d <= -4.4e-160) {
		tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (0.5 * (h * (pow((0.5 * (D * (M_m / d))), 2.0) / l))));
	} else if (d <= -2.9e-208) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else if (d <= 1.45e-296) {
		tmp = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (t_0 * 0.5)));
	} else if (d <= 2.2e-184) {
		tmp = (d * fma(-0.5, ((h / l) * t_0), 1.0)) / sqrt((l * h));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0
	tmp = 0.0
	if (d <= -4.4e-160)
		tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * Float64(1.0 - Float64(0.5 * Float64(h * Float64((Float64(0.5 * Float64(D * Float64(M_m / d))) ^ 2.0) / l)))));
	elseif (d <= -2.9e-208)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	elseif (d <= 1.45e-296)
		tmp = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(t_0 * 0.5))));
	elseif (d <= 2.2e-184)
		tmp = Float64(Float64(d * fma(-0.5, Float64(Float64(h / l) * t_0), 1.0)) / sqrt(Float64(l * h)));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -4.4e-160], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(0.5 * N[(h * N[(N[Power[N[(0.5 * N[(D * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.9e-208], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[d, 1.45e-296], 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[(t$95$0 * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.2e-184], N[(N[(d * N[(-0.5 * N[(N[(h / l), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}\\
\mathbf{if}\;d \leq -4.4 \cdot 10^{-160}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M\_m}{d}\right)\right)}^{2}}{\ell}\right)\right)\\

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

\mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\
\;\;\;\;\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(t\_0 \cdot 0.5\right)\right)\\

\mathbf{elif}\;d \leq 2.2 \cdot 10^{-184}:\\
\;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot t\_0, 1\right)}{\sqrt{\ell \cdot h}}\\

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


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

    1. Initial program 72.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified72.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. clear-num72.8%

        \[\leadsto \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 \color{blue}{\frac{1}{\frac{\ell}{h}}}\right)\right) \]
      2. un-div-inv73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.4e-160 < d < -2.8999999999999999e-208

    1. Initial program 35.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. Simplified35.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -2.8999999999999999e-208 < d < 1.44999999999999991e-296

    1. Initial program 54.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. Add Preprocessing

    if 1.44999999999999991e-296 < d < 2.19999999999999992e-184

    1. Initial program 49.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. Simplified49.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. sub-neg49.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.19999999999999992e-184 < d

    1. Initial program 70.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. 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. sub-neg70.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.4 \cdot 10^{-160}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -2.9 \cdot 10^{-208}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq 1.45 \cdot 10^{-296}:\\ \;\;\;\;\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({\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2} \cdot 0.5\right)\right)\\ \mathbf{elif}\;d \leq 2.2 \cdot 10^{-184}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 61.8% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\ t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ t_2 := {\left(D \cdot M\_m\right)}^{2}\\ \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -2.1 \cdot 10^{-213}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h (pow l 3.0))))
        (t_1 (* d (- (sqrt (/ 1.0 (* l h))))))
        (t_2 (pow (* D M_m) 2.0)))
   (if (<= d -1.05e+113)
     t_1
     (if (<= d -5e+60)
       (* t_0 (* -0.125 (* t_2 (/ -1.0 d))))
       (if (<= d -2.1e-213)
         t_1
         (if (<= d -1.65e-274)
           (* -0.125 (* t_2 (/ t_0 (- d))))
           (*
            (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
            (/ d (* (sqrt h) (sqrt l))))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = sqrt((h / pow(l, 3.0)));
	double t_1 = d * -sqrt((1.0 / (l * h)));
	double t_2 = pow((D * M_m), 2.0);
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	} else if (d <= -2.1e-213) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = -0.125 * (t_2 * (t_0 / -d));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (sqrt(h) * sqrt(l)));
	}
	return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
    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_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sqrt((h / (l ** 3.0d0)))
    t_1 = d * -sqrt((1.0d0 / (l * h)))
    t_2 = (d_1 * m_m) ** 2.0d0
    if (d <= (-1.05d+113)) then
        tmp = t_1
    else if (d <= (-5d+60)) then
        tmp = t_0 * ((-0.125d0) * (t_2 * ((-1.0d0) / d)))
    else if (d <= (-2.1d-213)) then
        tmp = t_1
    else if (d <= (-1.65d-274)) then
        tmp = (-0.125d0) * (t_2 * (t_0 / -d))
    else
        tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / (sqrt(h) * sqrt(l)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
	double t_0 = Math.sqrt((h / Math.pow(l, 3.0)));
	double t_1 = d * -Math.sqrt((1.0 / (l * h)));
	double t_2 = Math.pow((D * M_m), 2.0);
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	} else if (d <= -2.1e-213) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = -0.125 * (t_2 * (t_0 / -d));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (Math.sqrt(h) * Math.sqrt(l)));
	}
	return tmp;
}
M_m = math.fabs(M)
[d, h, l, M_m, D] = sort([d, h, l, M_m, D])
def code(d, h, l, M_m, D):
	t_0 = math.sqrt((h / math.pow(l, 3.0)))
	t_1 = d * -math.sqrt((1.0 / (l * h)))
	t_2 = math.pow((D * M_m), 2.0)
	tmp = 0
	if d <= -1.05e+113:
		tmp = t_1
	elif d <= -5e+60:
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)))
	elif d <= -2.1e-213:
		tmp = t_1
	elif d <= -1.65e-274:
		tmp = -0.125 * (t_2 * (t_0 / -d))
	else:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / (math.sqrt(h) * math.sqrt(l)))
	return tmp
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = sqrt(Float64(h / (l ^ 3.0)))
	t_1 = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))))
	t_2 = Float64(D * M_m) ^ 2.0
	tmp = 0.0
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = Float64(t_0 * Float64(-0.125 * Float64(t_2 * Float64(-1.0 / d))));
	elseif (d <= -2.1e-213)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = Float64(-0.125 * Float64(t_2 * Float64(t_0 / Float64(-d))));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / Float64(sqrt(h) * sqrt(l))));
	end
	return tmp
end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
	t_0 = sqrt((h / (l ^ 3.0)));
	t_1 = d * -sqrt((1.0 / (l * h)));
	t_2 = (D * M_m) ^ 2.0;
	tmp = 0.0;
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	elseif (d <= -2.1e-213)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = -0.125 * (t_2 * (t_0 / -d));
	else
		tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / (sqrt(h) * sqrt(l)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -5e+60], N[(t$95$0 * N[(-0.125 * N[(t$95$2 * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.1e-213], t$95$1, If[LessEqual[d, -1.65e-274], N[(-0.125 * N[(t$95$2 * N[(t$95$0 / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\
t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\
t_2 := {\left(D \cdot M\_m\right)}^{2}\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\
\;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\

\mathbf{elif}\;d \leq -2.1 \cdot 10^{-213}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\
\;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.0499999999999999e113 or -4.99999999999999975e60 < d < -2.0999999999999998e-213

    1. Initial program 70.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. Simplified70.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.0499999999999999e113 < d < -4.99999999999999975e60

    1. Initial program 63.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. Simplified63.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-sqr-sqrt3.0%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod3.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative3.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative3.0%

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

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\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)\right) \cdot \left(\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
    5. Applied egg-rr3.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.0999999999999998e-213 < d < -1.6499999999999999e-274

    1. Initial program 34.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. Simplified34.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. add-sqr-sqrt0.8%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod1.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative1.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative1.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.6499999999999999e-274 < d

    1. Initial program 66.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. 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. sub-neg67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -2.1 \cdot 10^{-213}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 57.5% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\ t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ t_2 := {\left(D \cdot M\_m\right)}^{2}\\ \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{+60}:\\ \;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{-212}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M\_m}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h (pow l 3.0))))
        (t_1 (* d (- (sqrt (/ 1.0 (* l h))))))
        (t_2 (pow (* D M_m) 2.0)))
   (if (<= d -1.05e+113)
     t_1
     (if (<= d -4.5e+60)
       (* t_0 (* -0.125 (* t_2 (/ -1.0 d))))
       (if (<= d -1.05e-212)
         t_1
         (if (<= d -1.65e-274)
           (* -0.125 (* t_2 (/ t_0 (- d))))
           (/
            (* d (fma -0.5 (* (/ h l) (pow (/ (* D M_m) (* d 2.0)) 2.0)) 1.0))
            (sqrt (* l h)))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = sqrt((h / pow(l, 3.0)));
	double t_1 = d * -sqrt((1.0 / (l * h)));
	double t_2 = pow((D * M_m), 2.0);
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -4.5e+60) {
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	} else if (d <= -1.05e-212) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = -0.125 * (t_2 * (t_0 / -d));
	} else {
		tmp = (d * fma(-0.5, ((h / l) * pow(((D * M_m) / (d * 2.0)), 2.0)), 1.0)) / sqrt((l * h));
	}
	return tmp;
}
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = sqrt(Float64(h / (l ^ 3.0)))
	t_1 = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))))
	t_2 = Float64(D * M_m) ^ 2.0
	tmp = 0.0
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -4.5e+60)
		tmp = Float64(t_0 * Float64(-0.125 * Float64(t_2 * Float64(-1.0 / d))));
	elseif (d <= -1.05e-212)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = Float64(-0.125 * Float64(t_2 * Float64(t_0 / Float64(-d))));
	else
		tmp = Float64(Float64(d * fma(-0.5, Float64(Float64(h / l) * (Float64(Float64(D * M_m) / Float64(d * 2.0)) ^ 2.0)), 1.0)) / sqrt(Float64(l * h)));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -4.5e+60], N[(t$95$0 * N[(-0.125 * N[(t$95$2 * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.05e-212], t$95$1, If[LessEqual[d, -1.65e-274], N[(-0.125 * N[(t$95$2 * N[(t$95$0 / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d * N[(-0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(N[(D * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\
t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\
t_2 := {\left(D \cdot M\_m\right)}^{2}\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -4.5 \cdot 10^{+60}:\\
\;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\

\mathbf{elif}\;d \leq -1.05 \cdot 10^{-212}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\
\;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.0499999999999999e113 or -4.50000000000000013e60 < d < -1.05e-212

    1. Initial program 70.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. Simplified70.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.0499999999999999e113 < d < -4.50000000000000013e60

    1. Initial program 63.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. Simplified63.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-sqr-sqrt3.0%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod3.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative3.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative3.0%

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

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\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)\right) \cdot \left(\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
    5. Applied egg-rr3.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.05e-212 < d < -1.6499999999999999e-274

    1. Initial program 34.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. Simplified34.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. add-sqr-sqrt0.8%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod1.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative1.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative1.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.6499999999999999e-274 < d

    1. Initial program 66.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. 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. sub-neg67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -4.5 \cdot 10^{+60}:\\ \;\;\;\;\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{-212}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\ell} \cdot {\left(\frac{D \cdot M}{d \cdot 2}\right)}^{2}, 1\right)}{\sqrt{\ell \cdot h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 72.2% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;d \leq -1.85 \cdot 10^{-260}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.99999999999999994e-160 or -2.8999999999999999e-208 < d < -1.8500000000000001e-260

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

        \[\leadsto \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 \color{blue}{\frac{1}{\frac{\ell}{h}}}\right)\right) \]
      2. un-div-inv72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.99999999999999994e-160 < d < -2.8999999999999999e-208

    1. Initial program 35.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. Simplified35.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.8500000000000001e-260 < d

    1. Initial program 65.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.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. sub-neg66.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 56.8% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\ t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ t_2 := {\left(D \cdot M\_m\right)}^{2}\\ \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-213}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h (pow l 3.0))))
        (t_1 (* d (- (sqrt (/ 1.0 (* l h))))))
        (t_2 (pow (* D M_m) 2.0)))
   (if (<= d -1.05e+113)
     t_1
     (if (<= d -5e+60)
       (* t_0 (* -0.125 (* t_2 (/ -1.0 d))))
       (if (<= d -8e-213)
         t_1
         (if (<= d -1.65e-274)
           (* -0.125 (* t_2 (/ t_0 (- d))))
           (*
            (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
            (/ d (sqrt (* l h))))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = sqrt((h / pow(l, 3.0)));
	double t_1 = d * -sqrt((1.0 / (l * h)));
	double t_2 = pow((D * M_m), 2.0);
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	} else if (d <= -8e-213) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = -0.125 * (t_2 * (t_0 / -d));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / sqrt((l * h)));
	}
	return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
    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_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sqrt((h / (l ** 3.0d0)))
    t_1 = d * -sqrt((1.0d0 / (l * h)))
    t_2 = (d_1 * m_m) ** 2.0d0
    if (d <= (-1.05d+113)) then
        tmp = t_1
    else if (d <= (-5d+60)) then
        tmp = t_0 * ((-0.125d0) * (t_2 * ((-1.0d0) / d)))
    else if (d <= (-8d-213)) then
        tmp = t_1
    else if (d <= (-1.65d-274)) then
        tmp = (-0.125d0) * (t_2 * (t_0 / -d))
    else
        tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / sqrt((l * h)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
	double t_0 = Math.sqrt((h / Math.pow(l, 3.0)));
	double t_1 = d * -Math.sqrt((1.0 / (l * h)));
	double t_2 = Math.pow((D * M_m), 2.0);
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	} else if (d <= -8e-213) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = -0.125 * (t_2 * (t_0 / -d));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / Math.sqrt((l * h)));
	}
	return tmp;
}
M_m = math.fabs(M)
[d, h, l, M_m, D] = sort([d, h, l, M_m, D])
def code(d, h, l, M_m, D):
	t_0 = math.sqrt((h / math.pow(l, 3.0)))
	t_1 = d * -math.sqrt((1.0 / (l * h)))
	t_2 = math.pow((D * M_m), 2.0)
	tmp = 0
	if d <= -1.05e+113:
		tmp = t_1
	elif d <= -5e+60:
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)))
	elif d <= -8e-213:
		tmp = t_1
	elif d <= -1.65e-274:
		tmp = -0.125 * (t_2 * (t_0 / -d))
	else:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / math.sqrt((l * h)))
	return tmp
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = sqrt(Float64(h / (l ^ 3.0)))
	t_1 = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))))
	t_2 = Float64(D * M_m) ^ 2.0
	tmp = 0.0
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = Float64(t_0 * Float64(-0.125 * Float64(t_2 * Float64(-1.0 / d))));
	elseif (d <= -8e-213)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = Float64(-0.125 * Float64(t_2 * Float64(t_0 / Float64(-d))));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / sqrt(Float64(l * h))));
	end
	return tmp
end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
	t_0 = sqrt((h / (l ^ 3.0)));
	t_1 = d * -sqrt((1.0 / (l * h)));
	t_2 = (D * M_m) ^ 2.0;
	tmp = 0.0;
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = t_0 * (-0.125 * (t_2 * (-1.0 / d)));
	elseif (d <= -8e-213)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = -0.125 * (t_2 * (t_0 / -d));
	else
		tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / sqrt((l * h)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -5e+60], N[(t$95$0 * N[(-0.125 * N[(t$95$2 * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -8e-213], t$95$1, If[LessEqual[d, -1.65e-274], N[(-0.125 * N[(t$95$2 * N[(t$95$0 / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{h}{{\ell}^{3}}}\\
t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\
t_2 := {\left(D \cdot M\_m\right)}^{2}\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\
\;\;\;\;t\_0 \cdot \left(-0.125 \cdot \left(t\_2 \cdot \frac{-1}{d}\right)\right)\\

\mathbf{elif}\;d \leq -8 \cdot 10^{-213}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\
\;\;\;\;-0.125 \cdot \left(t\_2 \cdot \frac{t\_0}{-d}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.0499999999999999e113 or -4.99999999999999975e60 < d < -7.9999999999999996e-213

    1. Initial program 70.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. Simplified70.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.0499999999999999e113 < d < -4.99999999999999975e60

    1. Initial program 63.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. Simplified63.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-sqr-sqrt3.0%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod3.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative3.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative3.0%

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

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\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)\right) \cdot \left(\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
    5. Applied egg-rr3.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.9999999999999996e-213 < d < -1.6499999999999999e-274

    1. Initial program 34.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. Simplified34.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. add-sqr-sqrt0.8%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod1.0%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative1.0%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative1.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.6499999999999999e-274 < d

    1. Initial program 66.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. 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. sub-neg67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{-1}{d}\right)\right)\\ \mathbf{elif}\;d \leq -8 \cdot 10^{-213}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 56.8% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \begin{array}{l} t_0 := -0.125 \cdot \left({\left(D \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;d \leq -1.18 \cdot 10^{-212}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D)
 :precision binary64
 (let* ((t_0
         (* -0.125 (* (pow (* D M_m) 2.0) (/ (sqrt (/ h (pow l 3.0))) (- d)))))
        (t_1 (* d (- (sqrt (/ 1.0 (* l h)))))))
   (if (<= d -1.05e+113)
     t_1
     (if (<= d -5e+60)
       t_0
       (if (<= d -1.18e-212)
         t_1
         (if (<= d -1.65e-274)
           t_0
           (*
            (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ M_m (* d 2.0))) 2.0)))
            (/ d (sqrt (* l h))))))))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	double t_0 = -0.125 * (pow((D * M_m), 2.0) * (sqrt((h / pow(l, 3.0))) / -d));
	double t_1 = d * -sqrt((1.0 / (l * h)));
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0;
	} else if (d <= -1.18e-212) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = t_0;
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D * (M_m / (d * 2.0))), 2.0))) * (d / sqrt((l * h)));
	}
	return tmp;
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
    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_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-0.125d0) * (((d_1 * m_m) ** 2.0d0) * (sqrt((h / (l ** 3.0d0))) / -d))
    t_1 = d * -sqrt((1.0d0 / (l * h)))
    if (d <= (-1.05d+113)) then
        tmp = t_1
    else if (d <= (-5d+60)) then
        tmp = t_0
    else if (d <= (-1.18d-212)) then
        tmp = t_1
    else if (d <= (-1.65d-274)) then
        tmp = t_0
    else
        tmp = (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * (m_m / (d * 2.0d0))) ** 2.0d0))) * (d / sqrt((l * h)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
	double t_0 = -0.125 * (Math.pow((D * M_m), 2.0) * (Math.sqrt((h / Math.pow(l, 3.0))) / -d));
	double t_1 = d * -Math.sqrt((1.0 / (l * h)));
	double tmp;
	if (d <= -1.05e+113) {
		tmp = t_1;
	} else if (d <= -5e+60) {
		tmp = t_0;
	} else if (d <= -1.18e-212) {
		tmp = t_1;
	} else if (d <= -1.65e-274) {
		tmp = t_0;
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / Math.sqrt((l * h)));
	}
	return tmp;
}
M_m = math.fabs(M)
[d, h, l, M_m, D] = sort([d, h, l, M_m, D])
def code(d, h, l, M_m, D):
	t_0 = -0.125 * (math.pow((D * M_m), 2.0) * (math.sqrt((h / math.pow(l, 3.0))) / -d))
	t_1 = d * -math.sqrt((1.0 / (l * h)))
	tmp = 0
	if d <= -1.05e+113:
		tmp = t_1
	elif d <= -5e+60:
		tmp = t_0
	elif d <= -1.18e-212:
		tmp = t_1
	elif d <= -1.65e-274:
		tmp = t_0
	else:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow((D * (M_m / (d * 2.0))), 2.0))) * (d / math.sqrt((l * h)))
	return tmp
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	t_0 = Float64(-0.125 * Float64((Float64(D * M_m) ^ 2.0) * Float64(sqrt(Float64(h / (l ^ 3.0))) / Float64(-d))))
	t_1 = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))))
	tmp = 0.0
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = t_0;
	elseif (d <= -1.18e-212)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(M_m / Float64(d * 2.0))) ^ 2.0))) * Float64(d / sqrt(Float64(l * h))));
	end
	return tmp
end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp_2 = code(d, h, l, M_m, D)
	t_0 = -0.125 * (((D * M_m) ^ 2.0) * (sqrt((h / (l ^ 3.0))) / -d));
	t_1 = d * -sqrt((1.0 / (l * h)));
	tmp = 0.0;
	if (d <= -1.05e+113)
		tmp = t_1;
	elseif (d <= -5e+60)
		tmp = t_0;
	elseif (d <= -1.18e-212)
		tmp = t_1;
	elseif (d <= -1.65e-274)
		tmp = t_0;
	else
		tmp = (1.0 + (((h / l) * -0.5) * ((D * (M_m / (d * 2.0))) ^ 2.0))) * (d / sqrt((l * h)));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := Block[{t$95$0 = N[(-0.125 * N[(N[Power[N[(D * M$95$m), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[d, -1.05e+113], t$95$1, If[LessEqual[d, -5e+60], t$95$0, If[LessEqual[d, -1.18e-212], t$95$1, If[LessEqual[d, -1.65e-274], t$95$0, N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
\begin{array}{l}
t_0 := -0.125 \cdot \left({\left(D \cdot M\_m\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\
t_1 := d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\
\mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;d \leq -1.18 \cdot 10^{-212}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.0499999999999999e113 or -4.99999999999999975e60 < d < -1.17999999999999996e-212

    1. Initial program 70.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. Simplified70.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if -1.0499999999999999e113 < d < -4.99999999999999975e60 or -1.17999999999999996e-212 < d < -1.6499999999999999e-274

    1. Initial program 49.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. Simplified49.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-sqr-sqrt2.0%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod2.1%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative2.1%

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative2.1%

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

        \[\leadsto \sqrt{\color{blue}{\left(\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\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)\right) \cdot \left(\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
    5. Applied egg-rr1.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.6499999999999999e-274 < d

    1. Initial program 66.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. 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. sub-neg67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+113}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{+60}:\\ \;\;\;\;-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ \mathbf{elif}\;d \leq -1.18 \cdot 10^{-212}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;d \leq -1.65 \cdot 10^{-274}:\\ \;\;\;\;-0.125 \cdot \left({\left(D \cdot M\right)}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{-d}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 72.9% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -3.60000000000000004e-305

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

    if -3.60000000000000004e-305 < h

    1. Initial program 66.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.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. sub-neg66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 56.2% accurate, 1.5× speedup?

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

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


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

    1. Initial program 66.0%

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

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

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

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

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

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

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

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

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

    if -4.29999999999999989e-274 < l

    1. Initial program 67.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. Simplified68.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. sub-neg68.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 43.0% accurate, 2.9× speedup?

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

\mathbf{else}:\\
\;\;\;\;d \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 5.5000000000000001e-285

    1. Initial program 66.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.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. Taylor expanded in l around -inf 0.0%

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

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

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

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

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

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

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

    if 5.5000000000000001e-285 < d

    1. Initial program 66.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. 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. Taylor expanded in d around inf 52.8%

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

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

Alternative 14: 26.6% accurate, 3.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ d \cdot \sqrt{\frac{1}{\ell \cdot h}} \end{array} \]
M_m = (fabs.f64 M)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D) :precision binary64 (* d (sqrt (/ 1.0 (* l h)))))
M_m = fabs(M);
assert(d < h && h < l && l < M_m && M_m < D);
double code(double d, double h, double l, double M_m, double D) {
	return d * sqrt((1.0 / (l * h)));
}
M_m = abs(m)
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_1)
    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_1
    code = d * sqrt((1.0d0 / (l * h)))
end function
M_m = Math.abs(M);
assert d < h && h < l && l < M_m && M_m < D;
public static double code(double d, double h, double l, double M_m, double D) {
	return d * Math.sqrt((1.0 / (l * h)));
}
M_m = math.fabs(M)
[d, h, l, M_m, D] = sort([d, h, l, M_m, D])
def code(d, h, l, M_m, D):
	return d * math.sqrt((1.0 / (l * h)))
M_m = abs(M)
d, h, l, M_m, D = sort([d, h, l, M_m, D])
function code(d, h, l, M_m, D)
	return Float64(d * sqrt(Float64(1.0 / Float64(l * h))))
end
M_m = abs(M);
d, h, l, M_m, D = num2cell(sort([d, h, l, M_m, D])){:}
function tmp = code(d, h, l, M_m, D)
	tmp = d * sqrt((1.0 / (l * h)));
end
M_m = N[Abs[M], $MachinePrecision]
NOTE: d, h, l, M_m, and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D_] := N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
[d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\
\\
d \cdot \sqrt{\frac{1}{\ell \cdot h}}
\end{array}
Derivation
  1. Initial program 66.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. Simplified67.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. Taylor expanded in d around inf 32.6%

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

    \[\leadsto d \cdot \sqrt{\frac{1}{\ell \cdot h}} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2024103 
(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)))))