Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.6% → 79.1%
Time: 25.2s
Alternatives: 17
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 17 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 66.6% accurate, 1.0× speedup?

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

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

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

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

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


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

    1. Initial program 60.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. Simplified61.8%

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

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

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

      \[\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.5e-52 < l < -4.999999999999985e-310

    1. Initial program 70.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified70.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. associate-*r/74.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times74.9%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*74.9%

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D}{d} \cdot \frac{M}{2}\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(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Step-by-step derivation
      1. frac-2neg74.9%

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.7%

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 64.3%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified65.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. associate-*r/68.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} \cdot h}{\ell}}\right) \]
      2. frac-times66.8%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*68.3%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac69.1%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Step-by-step derivation
      1. frac-2neg69.1%

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.7%

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 64.3%

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

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

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

      \[\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 < h

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.7%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 74.3% 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}\;\ell \leq -4.6 \cdot 10^{+224}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq 2.3 \cdot 10^{-297}:\\ \;\;\;\;\left(1 - 0.5 \cdot \left(h \cdot \frac{{\left(\frac{D}{d} \cdot \frac{M\_m}{2}\right)}^{2}}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D \cdot \frac{\frac{M\_m}{d}}{2}\right)}^{2}\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
 (if (<= l -4.6e+224)
   (* d (- (pow (* l h) -0.5)))
   (if (<= l 2.3e-297)
     (*
      (- 1.0 (* 0.5 (* h (/ (pow (* (/ D d) (/ M_m 2.0)) 2.0) l))))
      (* (sqrt (/ d l)) (sqrt (/ d h))))
     (*
      (/ d (* (sqrt h) (sqrt l)))
      (+ 1.0 (* (* (/ h l) -0.5) (pow (* D (/ (/ M_m d) 2.0)) 2.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 tmp;
	if (l <= -4.6e+224) {
		tmp = d * -pow((l * h), -0.5);
	} else if (l <= 2.3e-297) {
		tmp = (1.0 - (0.5 * (h * (pow(((D / d) * (M_m / 2.0)), 2.0) / l)))) * (sqrt((d / l)) * sqrt((d / h)));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((D * ((M_m / d) / 2.0)), 2.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) :: tmp
    if (l <= (-4.6d+224)) then
        tmp = d * -((l * h) ** (-0.5d0))
    else if (l <= 2.3d-297) then
        tmp = (1.0d0 - (0.5d0 * (h * ((((d_1 / d) * (m_m / 2.0d0)) ** 2.0d0) / l)))) * (sqrt((d / l)) * sqrt((d / h)))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((d_1 * ((m_m / d) / 2.0d0)) ** 2.0d0)))
    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.6e+224) {
		tmp = d * -Math.pow((l * h), -0.5);
	} else if (l <= 2.3e-297) {
		tmp = (1.0 - (0.5 * (h * (Math.pow(((D / d) * (M_m / 2.0)), 2.0) / l)))) * (Math.sqrt((d / l)) * Math.sqrt((d / h)));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((D * ((M_m / d) / 2.0)), 2.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):
	tmp = 0
	if l <= -4.6e+224:
		tmp = d * -math.pow((l * h), -0.5)
	elif l <= 2.3e-297:
		tmp = (1.0 - (0.5 * (h * (math.pow(((D / d) * (M_m / 2.0)), 2.0) / l)))) * (math.sqrt((d / l)) * math.sqrt((d / h)))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((D * ((M_m / d) / 2.0)), 2.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)
	tmp = 0.0
	if (l <= -4.6e+224)
		tmp = Float64(d * Float64(-(Float64(l * h) ^ -0.5)));
	elseif (l <= 2.3e-297)
		tmp = Float64(Float64(1.0 - Float64(0.5 * Float64(h * Float64((Float64(Float64(D / d) * Float64(M_m / 2.0)) ^ 2.0) / l)))) * Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D * Float64(Float64(M_m / d) / 2.0)) ^ 2.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)
	tmp = 0.0;
	if (l <= -4.6e+224)
		tmp = d * -((l * h) ^ -0.5);
	elseif (l <= 2.3e-297)
		tmp = (1.0 - (0.5 * (h * ((((D / d) * (M_m / 2.0)) ^ 2.0) / l)))) * (sqrt((d / l)) * sqrt((d / h)));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((D * ((M_m / d) / 2.0)) ^ 2.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_] := If[LessEqual[l, -4.6e+224], N[(d * (-N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, 2.3e-297], N[(N[(1.0 - N[(0.5 * N[(h * N[(N[Power[N[(N[(D / d), $MachinePrecision] * N[(M$95$m / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D * N[(N[(M$95$m / d), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $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.6 \cdot 10^{+224}:\\
\;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\

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

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


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

    1. Initial program 42.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. Simplified42.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. associate-*r/42.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} \cdot h}{\ell}}\right) \]
      2. frac-times42.4%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*42.4%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac47.0%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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. unpow-10.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(h \cdot \ell\right)}^{-0.5} \cdot \left(\color{blue}{-1} \cdot d\right) \]
      12. mul-1-neg68.8%

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

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

    if -4.60000000000000039e224 < l < 2.2999999999999999e-297

    1. Initial program 69.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. Simplified71.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. associate-*r/73.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times72.1%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*73.9%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac73.9%

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

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

    if 2.2999999999999999e-297 < l

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.8%

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 42.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. Simplified42.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. associate-*r/42.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} \cdot h}{\ell}}\right) \]
      2. frac-times42.4%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*42.4%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac47.0%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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. unpow-10.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(h \cdot \ell\right)}^{-0.5} \cdot \left(\color{blue}{-1} \cdot d\right) \]
      12. mul-1-neg68.8%

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

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

    if -1.2000000000000001e221 < l < -4.99999999999999955e-308

    1. Initial program 69.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}{\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 -4.99999999999999955e-308 < l

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.7%

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

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

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

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

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

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

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

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

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -2.39999999999999996e-213

    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. 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. Step-by-step derivation
      1. associate-*r/70.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} \cdot h}{\ell}}\right) \]
      2. frac-times69.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} \cdot h}{\ell}\right) \]
      3. associate-/l*70.3%

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

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

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

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

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

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Step-by-step derivation
      1. pow171.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.39999999999999996e-213 < h < -4.999999999999985e-310

    1. Initial program 56.9%

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

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

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 64.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. Simplified64.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. Applied egg-rr78.7%

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

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

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

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

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

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

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

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

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

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

Alternative 7: 66.1% 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 -4.7 \cdot 10^{-213}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(D \cdot \frac{0.5 \cdot M\_m}{d}\right)}^{2}}{\ell}\right)\right)\\ \mathbf{elif}\;h \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(\frac{D \cdot M\_m}{d}\right)}^{2}}{\ell \cdot 4}\right)\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 (<= h -4.7e-213)
   (*
    (sqrt (* (/ d l) (/ d h)))
    (+ 1.0 (* -0.5 (* h (/ (pow (* D (/ (* 0.5 M_m) d)) 2.0) l)))))
   (if (<= h -5e-310)
     (* (/ (sqrt (- d)) (sqrt (- h))) (sqrt (/ d l)))
     (*
      (+ 1.0 (* -0.5 (* h (/ (pow (/ (* D M_m) d) 2.0) (* l 4.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 (h <= -4.7e-213) {
		tmp = sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (pow((D * ((0.5 * M_m) / d)), 2.0) / l))));
	} else if (h <= -5e-310) {
		tmp = (sqrt(-d) / sqrt(-h)) * sqrt((d / l));
	} else {
		tmp = (1.0 + (-0.5 * (h * (pow(((D * M_m) / d), 2.0) / (l * 4.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 (h <= (-4.7d-213)) then
        tmp = sqrt(((d / l) * (d / h))) * (1.0d0 + ((-0.5d0) * (h * (((d_1 * ((0.5d0 * m_m) / d)) ** 2.0d0) / l))))
    else if (h <= (-5d-310)) then
        tmp = (sqrt(-d) / sqrt(-h)) * sqrt((d / l))
    else
        tmp = (1.0d0 + ((-0.5d0) * (h * ((((d_1 * m_m) / d) ** 2.0d0) / (l * 4.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 (h <= -4.7e-213) {
		tmp = Math.sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (Math.pow((D * ((0.5 * M_m) / d)), 2.0) / l))));
	} else if (h <= -5e-310) {
		tmp = (Math.sqrt(-d) / Math.sqrt(-h)) * Math.sqrt((d / l));
	} else {
		tmp = (1.0 + (-0.5 * (h * (Math.pow(((D * M_m) / d), 2.0) / (l * 4.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 h <= -4.7e-213:
		tmp = math.sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (math.pow((D * ((0.5 * M_m) / d)), 2.0) / l))))
	elif h <= -5e-310:
		tmp = (math.sqrt(-d) / math.sqrt(-h)) * math.sqrt((d / l))
	else:
		tmp = (1.0 + (-0.5 * (h * (math.pow(((D * M_m) / d), 2.0) / (l * 4.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 (h <= -4.7e-213)
		tmp = Float64(sqrt(Float64(Float64(d / l) * Float64(d / h))) * Float64(1.0 + Float64(-0.5 * Float64(h * Float64((Float64(D * Float64(Float64(0.5 * M_m) / d)) ^ 2.0) / l)))));
	elseif (h <= -5e-310)
		tmp = Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * sqrt(Float64(d / l)));
	else
		tmp = Float64(Float64(1.0 + Float64(-0.5 * Float64(h * Float64((Float64(Float64(D * M_m) / d) ^ 2.0) / Float64(l * 4.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 (h <= -4.7e-213)
		tmp = sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (((D * ((0.5 * M_m) / d)) ^ 2.0) / l))));
	elseif (h <= -5e-310)
		tmp = (sqrt(-d) / sqrt(-h)) * sqrt((d / l));
	else
		tmp = (1.0 + (-0.5 * (h * ((((D * M_m) / d) ^ 2.0) / (l * 4.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[h, -4.7e-213], N[(N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(h * N[(N[Power[N[(D * N[(N[(0.5 * M$95$m), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, -5e-310], N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(-0.5 * N[(h * N[(N[Power[N[(N[(D * M$95$m), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision] / N[(l * 4.0), $MachinePrecision]), $MachinePrecision]), $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}\;h \leq -4.7 \cdot 10^{-213}:\\
\;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(D \cdot \frac{0.5 \cdot M\_m}{d}\right)}^{2}}{\ell}\right)\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -4.7e-213

    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. 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. Step-by-step derivation
      1. associate-*r/70.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} \cdot h}{\ell}}\right) \]
      2. frac-times69.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} \cdot h}{\ell}\right) \]
      3. associate-/l*70.3%

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

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

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

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

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

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Step-by-step derivation
      1. pow171.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.7e-213 < h < -4.999999999999985e-310

    1. Initial program 56.9%

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

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

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 64.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. Simplified64.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. associate-*r/65.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times66.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 65.7% accurate, 1.4× 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 -1 \cdot 10^{-212}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(D \cdot \frac{0.5 \cdot M\_m}{d}\right)}^{2}}{\ell}\right)\right)\\ \mathbf{elif}\;h \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(\frac{D \cdot M\_m}{d}\right)}^{2}}{\ell \cdot 4}\right)\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 (<= h -1e-212)
   (*
    (sqrt (* (/ d l) (/ d h)))
    (+ 1.0 (* -0.5 (* h (/ (pow (* D (/ (* 0.5 M_m) d)) 2.0) l)))))
   (if (<= h -5e-310)
     (* d (- (sqrt (/ 1.0 (* l h)))))
     (*
      (+ 1.0 (* -0.5 (* h (/ (pow (/ (* D M_m) d) 2.0) (* l 4.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 (h <= -1e-212) {
		tmp = sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (pow((D * ((0.5 * M_m) / d)), 2.0) / l))));
	} else if (h <= -5e-310) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else {
		tmp = (1.0 + (-0.5 * (h * (pow(((D * M_m) / d), 2.0) / (l * 4.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 (h <= (-1d-212)) then
        tmp = sqrt(((d / l) * (d / h))) * (1.0d0 + ((-0.5d0) * (h * (((d_1 * ((0.5d0 * m_m) / d)) ** 2.0d0) / l))))
    else if (h <= (-5d-310)) then
        tmp = d * -sqrt((1.0d0 / (l * h)))
    else
        tmp = (1.0d0 + ((-0.5d0) * (h * ((((d_1 * m_m) / d) ** 2.0d0) / (l * 4.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 (h <= -1e-212) {
		tmp = Math.sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (Math.pow((D * ((0.5 * M_m) / d)), 2.0) / l))));
	} else if (h <= -5e-310) {
		tmp = d * -Math.sqrt((1.0 / (l * h)));
	} else {
		tmp = (1.0 + (-0.5 * (h * (Math.pow(((D * M_m) / d), 2.0) / (l * 4.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 h <= -1e-212:
		tmp = math.sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (math.pow((D * ((0.5 * M_m) / d)), 2.0) / l))))
	elif h <= -5e-310:
		tmp = d * -math.sqrt((1.0 / (l * h)))
	else:
		tmp = (1.0 + (-0.5 * (h * (math.pow(((D * M_m) / d), 2.0) / (l * 4.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 (h <= -1e-212)
		tmp = Float64(sqrt(Float64(Float64(d / l) * Float64(d / h))) * Float64(1.0 + Float64(-0.5 * Float64(h * Float64((Float64(D * Float64(Float64(0.5 * M_m) / d)) ^ 2.0) / l)))));
	elseif (h <= -5e-310)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	else
		tmp = Float64(Float64(1.0 + Float64(-0.5 * Float64(h * Float64((Float64(Float64(D * M_m) / d) ^ 2.0) / Float64(l * 4.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 (h <= -1e-212)
		tmp = sqrt(((d / l) * (d / h))) * (1.0 + (-0.5 * (h * (((D * ((0.5 * M_m) / d)) ^ 2.0) / l))));
	elseif (h <= -5e-310)
		tmp = d * -sqrt((1.0 / (l * h)));
	else
		tmp = (1.0 + (-0.5 * (h * ((((D * M_m) / d) ^ 2.0) / (l * 4.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[h, -1e-212], N[(N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(h * N[(N[Power[N[(D * N[(N[(0.5 * M$95$m), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, -5e-310], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(N[(1.0 + N[(-0.5 * N[(h * N[(N[Power[N[(N[(D * M$95$m), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision] / N[(l * 4.0), $MachinePrecision]), $MachinePrecision]), $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}\;h \leq -1 \cdot 10^{-212}:\\
\;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(D \cdot \frac{0.5 \cdot M\_m}{d}\right)}^{2}}{\ell}\right)\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -9.99999999999999954e-213

    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. 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. Step-by-step derivation
      1. associate-*r/70.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} \cdot h}{\ell}}\right) \]
      2. frac-times69.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} \cdot h}{\ell}\right) \]
      3. associate-/l*70.3%

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

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

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

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

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

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Step-by-step derivation
      1. pow171.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999954e-213 < h < -4.999999999999985e-310

    1. Initial program 56.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified60.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. associate-*r/60.8%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times56.9%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*60.8%

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

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

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

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 64.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. Simplified64.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. associate-*r/65.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times66.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 57.4% accurate, 1.4× 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{1}{\ell \cdot h}\\ \mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-\sqrt{t\_0}\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{t\_0}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + -0.5 \cdot \left(h \cdot \frac{{\left(\frac{D \cdot M\_m}{d}\right)}^{2}}{\ell \cdot 4}\right)\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 (/ 1.0 (* l h))))
   (if (<= l -1.12e-106)
     (* d (- (sqrt t_0)))
     (if (<= l -5e-310)
       (* d (cbrt (pow t_0 1.5)))
       (*
        (+ 1.0 (* -0.5 (* h (/ (pow (/ (* D M_m) d) 2.0) (* l 4.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 = 1.0 / (l * h);
	double tmp;
	if (l <= -1.12e-106) {
		tmp = d * -sqrt(t_0);
	} else if (l <= -5e-310) {
		tmp = d * cbrt(pow(t_0, 1.5));
	} else {
		tmp = (1.0 + (-0.5 * (h * (pow(((D * M_m) / d), 2.0) / (l * 4.0))))) * (d / sqrt((l * h)));
	}
	return tmp;
}
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 = 1.0 / (l * h);
	double tmp;
	if (l <= -1.12e-106) {
		tmp = d * -Math.sqrt(t_0);
	} else if (l <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow(t_0, 1.5));
	} else {
		tmp = (1.0 + (-0.5 * (h * (Math.pow(((D * M_m) / d), 2.0) / (l * 4.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(1.0 / Float64(l * h))
	tmp = 0.0
	if (l <= -1.12e-106)
		tmp = Float64(d * Float64(-sqrt(t_0)));
	elseif (l <= -5e-310)
		tmp = Float64(d * cbrt((t_0 ^ 1.5)));
	else
		tmp = Float64(Float64(1.0 + Float64(-0.5 * Float64(h * Float64((Float64(Float64(D * M_m) / d) ^ 2.0) / Float64(l * 4.0))))) * Float64(d / 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[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.12e-106], N[(d * (-N[Sqrt[t$95$0], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -5e-310], N[(d * N[Power[N[Power[t$95$0, 1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(-0.5 * N[(h * N[(N[Power[N[(N[(D * M$95$m), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision] / N[(l * 4.0), $MachinePrecision]), $MachinePrecision]), $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 := \frac{1}{\ell \cdot h}\\
\mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\
\;\;\;\;d \cdot \left(-\sqrt{t\_0}\right)\\

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \sqrt[3]{{t\_0}^{1.5}}\\

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


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

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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.9%

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

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

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

    if -1.12e-106 < l < -4.999999999999985e-310

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Step-by-step derivation
      1. add-cbrt-cube38.3%

        \[\leadsto d \cdot \color{blue}{\sqrt[3]{\left(\sqrt{\frac{1}{h \cdot \ell}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}}} \]
      2. pow1/338.3%

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

        \[\leadsto d \cdot {\left(\color{blue}{\frac{1}{h \cdot \ell}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{0.3333333333333333} \]
      4. pow138.3%

        \[\leadsto d \cdot {\left(\color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{1}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{0.3333333333333333} \]
      5. pow1/238.3%

        \[\leadsto d \cdot {\left({\left(\frac{1}{h \cdot \ell}\right)}^{1} \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up38.3%

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

        \[\leadsto d \cdot {\left({\color{blue}{\left(\frac{\frac{1}{h}}{\ell}\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      8. metadata-eval38.3%

        \[\leadsto d \cdot {\left({\left(\frac{\frac{1}{h}}{\ell}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    6. Applied egg-rr38.3%

      \[\leadsto d \cdot \color{blue}{{\left({\left(\frac{\frac{1}{h}}{\ell}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    7. Step-by-step derivation
      1. unpow1/338.3%

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

        \[\leadsto d \cdot \sqrt[3]{{\color{blue}{\left(\frac{1}{h \cdot \ell}\right)}}^{1.5}} \]
    8. Simplified38.3%

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

    if -4.999999999999985e-310 < l

    1. Initial program 64.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. Simplified64.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. associate-*r/65.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times66.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 45.4% 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} t_0 := \frac{1}{\ell \cdot h}\\ \mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-\sqrt{t\_0}\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{t\_0}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({\ell}^{-0.5} \cdot {h}^{-0.5}\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 (/ 1.0 (* l h))))
   (if (<= l -1.12e-106)
     (* d (- (sqrt t_0)))
     (if (<= l -5e-310)
       (* d (cbrt (pow t_0 1.5)))
       (* d (* (pow l -0.5) (pow h -0.5)))))))
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 / (l * h);
	double tmp;
	if (l <= -1.12e-106) {
		tmp = d * -sqrt(t_0);
	} else if (l <= -5e-310) {
		tmp = d * cbrt(pow(t_0, 1.5));
	} else {
		tmp = d * (pow(l, -0.5) * pow(h, -0.5));
	}
	return tmp;
}
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 = 1.0 / (l * h);
	double tmp;
	if (l <= -1.12e-106) {
		tmp = d * -Math.sqrt(t_0);
	} else if (l <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow(t_0, 1.5));
	} else {
		tmp = d * (Math.pow(l, -0.5) * Math.pow(h, -0.5));
	}
	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(l * h))
	tmp = 0.0
	if (l <= -1.12e-106)
		tmp = Float64(d * Float64(-sqrt(t_0)));
	elseif (l <= -5e-310)
		tmp = Float64(d * cbrt((t_0 ^ 1.5)));
	else
		tmp = Float64(d * Float64((l ^ -0.5) * (h ^ -0.5)));
	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[(l * h), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.12e-106], N[(d * (-N[Sqrt[t$95$0], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -5e-310], N[(d * N[Power[N[Power[t$95$0, 1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] * N[Power[h, -0.5], $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{1}{\ell \cdot h}\\
\mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\
\;\;\;\;d \cdot \left(-\sqrt{t\_0}\right)\\

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \sqrt[3]{{t\_0}^{1.5}}\\

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


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

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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.9%

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

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

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

    if -1.12e-106 < l < -4.999999999999985e-310

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Step-by-step derivation
      1. add-cbrt-cube38.3%

        \[\leadsto d \cdot \color{blue}{\sqrt[3]{\left(\sqrt{\frac{1}{h \cdot \ell}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}}} \]
      2. pow1/338.3%

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

        \[\leadsto d \cdot {\left(\color{blue}{\frac{1}{h \cdot \ell}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{0.3333333333333333} \]
      4. pow138.3%

        \[\leadsto d \cdot {\left(\color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{1}} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{0.3333333333333333} \]
      5. pow1/238.3%

        \[\leadsto d \cdot {\left({\left(\frac{1}{h \cdot \ell}\right)}^{1} \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. pow-prod-up38.3%

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

        \[\leadsto d \cdot {\left({\color{blue}{\left(\frac{\frac{1}{h}}{\ell}\right)}}^{\left(1 + 0.5\right)}\right)}^{0.3333333333333333} \]
      8. metadata-eval38.3%

        \[\leadsto d \cdot {\left({\left(\frac{\frac{1}{h}}{\ell}\right)}^{\color{blue}{1.5}}\right)}^{0.3333333333333333} \]
    6. Applied egg-rr38.3%

      \[\leadsto d \cdot \color{blue}{{\left({\left(\frac{\frac{1}{h}}{\ell}\right)}^{1.5}\right)}^{0.3333333333333333}} \]
    7. Step-by-step derivation
      1. unpow1/338.3%

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

        \[\leadsto d \cdot \sqrt[3]{{\color{blue}{\left(\frac{1}{h \cdot \ell}\right)}}^{1.5}} \]
    8. Simplified38.3%

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

    if -4.999999999999985e-310 < l

    1. Initial program 64.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. Simplified64.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. associate-*r/65.9%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times66.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    10. Simplified48.1%

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    11. Step-by-step derivation
      1. *-commutative48.1%

        \[\leadsto d \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{-0.5} \]
      2. unpow-prod-down54.9%

        \[\leadsto d \cdot \color{blue}{\left({\ell}^{-0.5} \cdot {h}^{-0.5}\right)} \]
    12. Applied egg-rr54.9%

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

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

Alternative 11: 44.0% 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 -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;\ell \leq 2.2 \cdot 10^{-283}:\\ \;\;\;\;\frac{d}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({\ell}^{-0.5} \cdot {h}^{-0.5}\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
 (if (<= l -1.12e-106)
   (* d (- (sqrt (/ 1.0 (* l h)))))
   (if (<= l 2.2e-283)
     (/ d (sqrt (* l h)))
     (* d (* (pow l -0.5) (pow h -0.5))))))
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 <= -1.12e-106) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else if (l <= 2.2e-283) {
		tmp = d / sqrt((l * h));
	} else {
		tmp = d * (pow(l, -0.5) * pow(h, -0.5));
	}
	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 <= (-1.12d-106)) then
        tmp = d * -sqrt((1.0d0 / (l * h)))
    else if (l <= 2.2d-283) then
        tmp = d / sqrt((l * h))
    else
        tmp = d * ((l ** (-0.5d0)) * (h ** (-0.5d0)))
    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 <= -1.12e-106) {
		tmp = d * -Math.sqrt((1.0 / (l * h)));
	} else if (l <= 2.2e-283) {
		tmp = d / Math.sqrt((l * h));
	} else {
		tmp = d * (Math.pow(l, -0.5) * Math.pow(h, -0.5));
	}
	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 <= -1.12e-106:
		tmp = d * -math.sqrt((1.0 / (l * h)))
	elif l <= 2.2e-283:
		tmp = d / math.sqrt((l * h))
	else:
		tmp = d * (math.pow(l, -0.5) * math.pow(h, -0.5))
	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 <= -1.12e-106)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	elseif (l <= 2.2e-283)
		tmp = Float64(d / sqrt(Float64(l * h)));
	else
		tmp = Float64(d * Float64((l ^ -0.5) * (h ^ -0.5)));
	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 <= -1.12e-106)
		tmp = d * -sqrt((1.0 / (l * h)));
	elseif (l <= 2.2e-283)
		tmp = d / sqrt((l * h));
	else
		tmp = d * ((l ^ -0.5) * (h ^ -0.5));
	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, -1.12e-106], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, 2.2e-283], N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] * N[Power[h, -0.5], $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 -1.12 \cdot 10^{-106}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\

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

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


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

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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.9%

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

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

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

    if -1.12e-106 < l < 2.1999999999999998e-283

    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.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. Taylor expanded in d around inf 35.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{\ell \cdot h}}} \]
      2. associate-*r/35.7%

        \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{\ell \cdot h}}} \]
      3. *-rgt-identity35.7%

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{h \cdot \ell}}} \]
    10. Simplified35.7%

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

    if 2.1999999999999998e-283 < l

    1. Initial program 64.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. Simplified64.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. associate-*r/65.8%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times65.9%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.8%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac63.6%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Taylor expanded in d around inf 47.2%

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

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}} \]
      4. rem-sqrt-square48.0%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    10. Simplified48.0%

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    11. Step-by-step derivation
      1. *-commutative48.0%

        \[\leadsto d \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{-0.5} \]
      2. unpow-prod-down55.1%

        \[\leadsto d \cdot \color{blue}{\left({\ell}^{-0.5} \cdot {h}^{-0.5}\right)} \]
    12. Applied egg-rr55.1%

      \[\leadsto d \cdot \color{blue}{\left({\ell}^{-0.5} \cdot {h}^{-0.5}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification52.5%

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

Alternative 12: 44.0% 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 -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{elif}\;\ell \leq 3.2 \cdot 10^{-283}:\\ \;\;\;\;\frac{d}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{h}^{-0.5}}{\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 (<= l -1.12e-106)
   (* d (- (sqrt (/ 1.0 (* l h)))))
   (if (<= l 3.2e-283) (/ d (sqrt (* l h))) (* d (/ (pow h -0.5) (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 (l <= -1.12e-106) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else if (l <= 3.2e-283) {
		tmp = d / sqrt((l * h));
	} else {
		tmp = d * (pow(h, -0.5) / 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 (l <= (-1.12d-106)) then
        tmp = d * -sqrt((1.0d0 / (l * h)))
    else if (l <= 3.2d-283) then
        tmp = d / sqrt((l * h))
    else
        tmp = d * ((h ** (-0.5d0)) / 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 (l <= -1.12e-106) {
		tmp = d * -Math.sqrt((1.0 / (l * h)));
	} else if (l <= 3.2e-283) {
		tmp = d / Math.sqrt((l * h));
	} else {
		tmp = d * (Math.pow(h, -0.5) / 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 l <= -1.12e-106:
		tmp = d * -math.sqrt((1.0 / (l * h)))
	elif l <= 3.2e-283:
		tmp = d / math.sqrt((l * h))
	else:
		tmp = d * (math.pow(h, -0.5) / 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 (l <= -1.12e-106)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	elseif (l <= 3.2e-283)
		tmp = Float64(d / sqrt(Float64(l * h)));
	else
		tmp = Float64(d * Float64((h ^ -0.5) / 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 (l <= -1.12e-106)
		tmp = d * -sqrt((1.0 / (l * h)));
	elseif (l <= 3.2e-283)
		tmp = d / sqrt((l * h));
	else
		tmp = d * ((h ^ -0.5) / 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[l, -1.12e-106], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, 3.2e-283], N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[h, -0.5], $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}
\mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\

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

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


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

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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.9%

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

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

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

    if -1.12e-106 < l < 3.20000000000000012e-283

    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.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. Taylor expanded in d around inf 35.6%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{\ell \cdot h}}} \]
      2. associate-*r/35.7%

        \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{\ell \cdot h}}} \]
      3. *-rgt-identity35.7%

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

        \[\leadsto \frac{d}{\sqrt{\color{blue}{h \cdot \ell}}} \]
    10. Simplified35.7%

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

    if 3.20000000000000012e-283 < l

    1. Initial program 64.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. Simplified64.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. associate-*r/65.8%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times65.9%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.8%

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

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

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

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

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

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

        \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac63.6%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Taylor expanded in d around inf 47.2%

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

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}} \]
      4. rem-sqrt-square48.0%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    10. Simplified48.0%

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    11. Step-by-step derivation
      1. add-sqr-sqrt47.8%

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

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

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

        \[\leadsto d \cdot \sqrt{{\left(h \cdot \ell\right)}^{\color{blue}{-1}}} \]
      5. inv-pow47.2%

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

        \[\leadsto d \cdot \sqrt{\frac{1}{\color{blue}{\ell \cdot h}}} \]
      7. associate-/l/47.6%

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

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

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

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

        \[\leadsto d \cdot \frac{{h}^{\color{blue}{-0.5}}}{\sqrt{\ell}} \]
    12. Applied egg-rr55.1%

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

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

Alternative 13: 40.1% 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} \mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \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 -1.12e-106)
   (* d (- (sqrt (/ 1.0 (* l h)))))
   (* d (pow (* l h) -0.5))))
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 <= -1.12e-106) {
		tmp = d * -sqrt((1.0 / (l * h)));
	} else {
		tmp = d * pow((l * h), -0.5);
	}
	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 <= (-1.12d-106)) then
        tmp = d * -sqrt((1.0d0 / (l * h)))
    else
        tmp = d * ((l * h) ** (-0.5d0))
    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 <= -1.12e-106) {
		tmp = d * -Math.sqrt((1.0 / (l * h)));
	} else {
		tmp = d * Math.pow((l * h), -0.5);
	}
	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 <= -1.12e-106:
		tmp = d * -math.sqrt((1.0 / (l * h)))
	else:
		tmp = d * math.pow((l * h), -0.5)
	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 <= -1.12e-106)
		tmp = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(l * h)))));
	else
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	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 <= -1.12e-106)
		tmp = d * -sqrt((1.0 / (l * h)));
	else
		tmp = d * ((l * h) ^ -0.5);
	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, -1.12e-106], N[(d * (-N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $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 -1.12 \cdot 10^{-106}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{1}{\ell \cdot h}}\right)\\

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


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

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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.9%

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

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

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

    if -1.12e-106 < l

    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. Step-by-step derivation
      1. associate-*r/68.0%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times68.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*68.0%

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \frac{\color{blue}{h \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}}{\ell}\right) \]
      2. associate-/l*66.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(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/66.4%

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D}{d} \cdot \frac{M}{2}\right)}}^{2}}{\ell}\right)\right) \]
    7. Simplified66.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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Taylor expanded in d around inf 44.1%

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

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

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

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

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

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

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

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

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

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

Alternative 14: 40.1% accurate, 3.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(\ell \cdot h\right)}^{-0.5}\\ \mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\ \;\;\;\;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 (pow (* l h) -0.5)))
   (if (<= l -1.12e-106) (* 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 = pow((l * h), -0.5);
	double tmp;
	if (l <= -1.12e-106) {
		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 = (l * h) ** (-0.5d0)
    if (l <= (-1.12d-106)) 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.pow((l * h), -0.5);
	double tmp;
	if (l <= -1.12e-106) {
		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.pow((l * h), -0.5)
	tmp = 0
	if l <= -1.12e-106:
		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 = Float64(l * h) ^ -0.5
	tmp = 0.0
	if (l <= -1.12e-106)
		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 = (l * h) ^ -0.5;
	tmp = 0.0;
	if (l <= -1.12e-106)
		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[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]}, If[LessEqual[l, -1.12e-106], 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 := {\left(\ell \cdot h\right)}^{-0.5}\\
\mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\
\;\;\;\;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 l < -1.12e-106

    1. Initial program 61.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.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. associate-*r/65.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} \cdot h}{\ell}}\right) \]
      2. frac-times63.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*65.3%

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \color{blue}{\left(h \cdot \frac{{\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/64.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(\frac{M \cdot D}{d \cdot 2}\right)}}^{2}}{\ell}\right)\right) \]
      4. *-commutative64.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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
      5. times-frac66.5%

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

      \[\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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. 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}}} \]
    9. 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. unpow-10.0%

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

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

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

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

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

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

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

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

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

        \[\leadsto {\left(h \cdot \ell\right)}^{-0.5} \cdot \left(\color{blue}{-1} \cdot d\right) \]
      12. mul-1-neg57.9%

        \[\leadsto {\left(h \cdot \ell\right)}^{-0.5} \cdot \color{blue}{\left(-d\right)} \]
    10. Simplified57.9%

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

    if -1.12e-106 < l

    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. Step-by-step derivation
      1. associate-*r/68.0%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times68.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*68.0%

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \frac{\color{blue}{h \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}}{\ell}\right) \]
      2. associate-/l*66.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(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/66.4%

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D}{d} \cdot \frac{M}{2}\right)}}^{2}}{\ell}\right)\right) \]
    7. Simplified66.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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Taylor expanded in d around inf 44.1%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.12 \cdot 10^{-106}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 34.6% accurate, 3.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}\;\ell \leq -1.4 \cdot 10^{-106}:\\ \;\;\;\;\sqrt{\frac{d \cdot \frac{d}{h}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \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 -1.4e-106) (sqrt (/ (* d (/ d h)) l)) (* d (pow (* l h) -0.5))))
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 <= -1.4e-106) {
		tmp = sqrt(((d * (d / h)) / l));
	} else {
		tmp = d * pow((l * h), -0.5);
	}
	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 <= (-1.4d-106)) then
        tmp = sqrt(((d * (d / h)) / l))
    else
        tmp = d * ((l * h) ** (-0.5d0))
    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 <= -1.4e-106) {
		tmp = Math.sqrt(((d * (d / h)) / l));
	} else {
		tmp = d * Math.pow((l * h), -0.5);
	}
	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 <= -1.4e-106:
		tmp = math.sqrt(((d * (d / h)) / l))
	else:
		tmp = d * math.pow((l * h), -0.5)
	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 <= -1.4e-106)
		tmp = sqrt(Float64(Float64(d * Float64(d / h)) / l));
	else
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	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 <= -1.4e-106)
		tmp = sqrt(((d * (d / h)) / l));
	else
		tmp = d * ((l * h) ^ -0.5);
	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, -1.4e-106], N[Sqrt[N[(N[(d * N[(d / h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $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 -1.4 \cdot 10^{-106}:\\
\;\;\;\;\sqrt{\frac{d \cdot \frac{d}{h}}{\ell}}\\

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


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

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

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

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

        \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot 1\right)\right)}^{1}} \]
      2. pow1/251.6%

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

        \[\leadsto {\left({\left(\frac{d}{h}\right)}^{0.5} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}}\right)}^{1} \]
      4. pow1/251.6%

        \[\leadsto {\left({\left(\frac{d}{h}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}}\right)}^{1} \]
      5. pow-prod-down40.5%

        \[\leadsto {\color{blue}{\left({\left(\frac{d}{h} \cdot \frac{d}{\ell}\right)}^{0.5}\right)}}^{1} \]
    6. Applied egg-rr40.5%

      \[\leadsto \color{blue}{{\left({\left(\frac{d}{h} \cdot \frac{d}{\ell}\right)}^{0.5}\right)}^{1}} \]
    7. Step-by-step derivation
      1. unpow140.5%

        \[\leadsto \color{blue}{{\left(\frac{d}{h} \cdot \frac{d}{\ell}\right)}^{0.5}} \]
      2. unpow1/240.5%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
      3. associate-*r/37.7%

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

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

    if -1.39999999999999994e-106 < l

    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. Step-by-step derivation
      1. associate-*r/68.0%

        \[\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} \cdot h}{\ell}}\right) \]
      2. frac-times68.0%

        \[\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} \cdot h}{\ell}\right) \]
      3. associate-/l*68.0%

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \frac{\color{blue}{h \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}}{\ell}\right) \]
      2. associate-/l*66.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(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
      3. associate-*r/66.4%

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D}{d} \cdot \frac{M}{2}\right)}}^{2}}{\ell}\right)\right) \]
    7. Simplified66.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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
    8. Taylor expanded in d around inf 44.1%

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

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

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

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

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

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

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

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

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

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

Alternative 16: 25.8% 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 {\left(\ell \cdot h\right)}^{-0.5} \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 (pow (* l h) -0.5)))
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 * pow((l * h), -0.5);
}
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 * ((l * h) ** (-0.5d0))
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.pow((l * h), -0.5);
}
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.pow((l * h), -0.5)
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 * (Float64(l * h) ^ -0.5))
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 * ((l * h) ^ -0.5);
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[Power[N[(l * h), $MachinePrecision], -0.5], $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 {\left(\ell \cdot h\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 64.4%

    \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
  2. Simplified65.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. associate-*r/67.1%

      \[\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} \cdot h}{\ell}}\right) \]
    2. frac-times66.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} \cdot h}{\ell}\right) \]
    3. associate-/l*67.1%

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

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

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

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \frac{\color{blue}{h \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}}{\ell}\right) \]
    2. associate-/l*66.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(M \cdot \frac{D}{d \cdot 2}\right)}^{2}}{\ell}\right)}\right) \]
    3. associate-*r/65.7%

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

      \[\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 M}}{d \cdot 2}\right)}^{2}}{\ell}\right)\right) \]
    5. times-frac66.4%

      \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left(h \cdot \frac{{\color{blue}{\left(\frac{D}{d} \cdot \frac{M}{2}\right)}}^{2}}{\ell}\right)\right) \]
  7. Simplified66.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}{d} \cdot \frac{M}{2}\right)}^{2}}{\ell}\right)}\right) \]
  8. Taylor expanded in d around inf 32.3%

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

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

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

      \[\leadsto d \cdot \sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot {\left(h \cdot \ell\right)}^{-0.5}}} \]
    4. rem-sqrt-square32.7%

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

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

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

      \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
  10. Simplified32.7%

    \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
  11. Final simplification32.7%

    \[\leadsto d \cdot {\left(\ell \cdot h\right)}^{-0.5} \]
  12. Add Preprocessing

Alternative 17: 25.8% accurate, 3.2× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ [d, h, l, M_m, D] = \mathsf{sort}([d, h, l, M_m, D])\\ \\ \frac{d}{\sqrt{\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 (* 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((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((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((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((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(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((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[(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])\\
\\
\frac{d}{\sqrt{\ell \cdot h}}
\end{array}
Derivation
  1. Initial program 64.4%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{\ell \cdot h}}} \]
    2. associate-*r/32.6%

      \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{\ell \cdot h}}} \]
    3. *-rgt-identity32.6%

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

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

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

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

Reproduce

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