Henrywood and Agarwal, Equation (12)

Percentage Accurate: 67.0% → 80.4%
Time: 37.3s
Alternatives: 24
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 24 alternatives:

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

Initial Program: 67.0% accurate, 1.0× speedup?

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

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

Alternative 1: 80.4% accurate, 0.6× speedup?

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

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

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


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

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

    if -5.00000000000023e-311 < h < 5.8999999999999998e172

    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. Simplified66.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.8999999999999998e172 < h

    1. Initial program 45.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. Simplified45.0%

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

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

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

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

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

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

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

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

Alternative 2: 78.4% accurate, 0.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{h}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\ t_2 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\ \;\;\;\;t_2 \cdot \left(t_0 \cdot \left(1 + {\left(\frac{\frac{M}{d}}{\frac{-2}{D}}\right)}^{2} \cdot \frac{-0.5}{\frac{\ell}{h}}\right)\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \left(t_0 \cdot \left(1 + \frac{{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}}{\ell} \cdot \left(h \cdot -0.5\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ d h)))
        (t_1
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M D) (* d 2.0)) 2.0))))))
        (t_2 (sqrt (/ d l))))
   (if (<= t_1 -1e-244)
     (*
      t_2
      (* t_0 (+ 1.0 (* (pow (/ (/ M d) (/ -2.0 D)) 2.0) (/ -0.5 (/ l h))))))
     (if (or (<= t_1 5e-202) (not (<= t_1 1e+254)))
       (fabs (/ d (sqrt (* h l))))
       (*
        t_2
        (*
         t_0
         (+ 1.0 (* (/ (pow (* D (* M (/ 0.5 d))) 2.0) l) (* h -0.5)))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((d / h));
	double t_1 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = sqrt((d / l));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_2 * (t_0 * (1.0 + (pow(((M / d) / (-2.0 / D)), 2.0) * (-0.5 / (l / h)))));
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = fabs((d / sqrt((h * l))));
	} else {
		tmp = t_2 * (t_0 * (1.0 + ((pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sqrt((d / h))
    t_1 = (((d / h) ** 0.5d0) * ((d / l) ** 0.5d0)) * (1.0d0 - ((h / l) * (0.5d0 * (((m * d_1) / (d * 2.0d0)) ** 2.0d0))))
    t_2 = sqrt((d / l))
    if (t_1 <= (-1d-244)) then
        tmp = t_2 * (t_0 * (1.0d0 + ((((m / d) / ((-2.0d0) / d_1)) ** 2.0d0) * ((-0.5d0) / (l / h)))))
    else if ((t_1 <= 5d-202) .or. (.not. (t_1 <= 1d+254))) then
        tmp = abs((d / sqrt((h * l))))
    else
        tmp = t_2 * (t_0 * (1.0d0 + ((((d_1 * (m * (0.5d0 / d))) ** 2.0d0) / l) * (h * (-0.5d0)))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((d / h));
	double t_1 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = Math.sqrt((d / l));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_2 * (t_0 * (1.0 + (Math.pow(((M / d) / (-2.0 / D)), 2.0) * (-0.5 / (l / h)))));
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	} else {
		tmp = t_2 * (t_0 * (1.0 + ((Math.pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((d / h))
	t_1 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((M * D) / (d * 2.0)), 2.0))))
	t_2 = math.sqrt((d / l))
	tmp = 0
	if t_1 <= -1e-244:
		tmp = t_2 * (t_0 * (1.0 + (math.pow(((M / d) / (-2.0 / D)), 2.0) * (-0.5 / (l / h)))))
	elif (t_1 <= 5e-202) or not (t_1 <= 1e+254):
		tmp = math.fabs((d / math.sqrt((h * l))))
	else:
		tmp = t_2 * (t_0 * (1.0 + ((math.pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(d / h))
	t_1 = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)))))
	t_2 = sqrt(Float64(d / l))
	tmp = 0.0
	if (t_1 <= -1e-244)
		tmp = Float64(t_2 * Float64(t_0 * Float64(1.0 + Float64((Float64(Float64(M / d) / Float64(-2.0 / D)) ^ 2.0) * Float64(-0.5 / Float64(l / h))))));
	elseif ((t_1 <= 5e-202) || !(t_1 <= 1e+254))
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	else
		tmp = Float64(t_2 * Float64(t_0 * Float64(1.0 + Float64(Float64((Float64(D * Float64(M * Float64(0.5 / d))) ^ 2.0) / l) * Float64(h * -0.5)))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((d / h));
	t_1 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((M * D) / (d * 2.0)) ^ 2.0))));
	t_2 = sqrt((d / l));
	tmp = 0.0;
	if (t_1 <= -1e-244)
		tmp = t_2 * (t_0 * (1.0 + ((((M / d) / (-2.0 / D)) ^ 2.0) * (-0.5 / (l / h)))));
	elseif ((t_1 <= 5e-202) || ~((t_1 <= 1e+254)))
		tmp = abs((d / sqrt((h * l))));
	else
		tmp = t_2 * (t_0 * (1.0 + ((((D * (M * (0.5 / d))) ^ 2.0) / l) * (h * -0.5))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -1e-244], N[(t$95$2 * N[(t$95$0 * N[(1.0 + N[(N[Power[N[(N[(M / d), $MachinePrecision] / N[(-2.0 / D), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, 5e-202], N[Not[LessEqual[t$95$1, 1e+254]], $MachinePrecision]], N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(t$95$2 * N[(t$95$0 * N[(1.0 + N[(N[(N[Power[N[(D * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision] * N[(h * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{h}}\\
t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\
t_2 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\
\;\;\;\;t_2 \cdot \left(t_0 \cdot \left(1 + {\left(\frac{\frac{M}{d}}{\frac{-2}{D}}\right)}^{2} \cdot \frac{-0.5}{\frac{\ell}{h}}\right)\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\

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


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

    1. Initial program 88.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. Simplified87.8%

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

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

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

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

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

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

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

    if -9.9999999999999993e-245 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 4.99999999999999973e-202 or 9.9999999999999994e253 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 24.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. Simplified22.6%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/229.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\sqrt{\color{blue}{\frac{d}{\ell}}} \cdot \sqrt{\frac{d}{h}}\right| \]
      11. sqrt-prod29.5%

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

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

        \[\leadsto \left|\color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}}\right| \]
      14. sqrt-unprod35.4%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}}\right| \]
      15. add-sqr-sqrt57.7%

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

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

    if 4.99999999999999973e-202 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 9.9999999999999994e253

    1. Initial program 97.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. Simplified99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 79.7% accurate, 0.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\ t_2 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\ \;\;\;\;t_2 \cdot \left(t_0 \cdot \left(1 - 0.5 \cdot {\left(\sqrt{\frac{h}{\ell}} \cdot \left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)\right)}^{2}\right)\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \left(t_2 \cdot \left(1 + \frac{{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}}{\ell} \cdot \left(h \cdot -0.5\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ d l)))
        (t_1
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M D) (* d 2.0)) 2.0))))))
        (t_2 (sqrt (/ d h))))
   (if (<= t_1 -1e-244)
     (*
      t_2
      (*
       t_0
       (- 1.0 (* 0.5 (pow (* (sqrt (/ h l)) (* 0.5 (* D (/ M d)))) 2.0)))))
     (if (or (<= t_1 5e-202) (not (<= t_1 1e+254)))
       (fabs (/ d (sqrt (* h l))))
       (*
        t_0
        (*
         t_2
         (+ 1.0 (* (/ (pow (* D (* M (/ 0.5 d))) 2.0) l) (* h -0.5)))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((d / l));
	double t_1 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = sqrt((d / h));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_2 * (t_0 * (1.0 - (0.5 * pow((sqrt((h / l)) * (0.5 * (D * (M / d)))), 2.0))));
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = fabs((d / sqrt((h * l))));
	} else {
		tmp = t_0 * (t_2 * (1.0 + ((pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = sqrt((d / l))
    t_1 = (((d / h) ** 0.5d0) * ((d / l) ** 0.5d0)) * (1.0d0 - ((h / l) * (0.5d0 * (((m * d_1) / (d * 2.0d0)) ** 2.0d0))))
    t_2 = sqrt((d / h))
    if (t_1 <= (-1d-244)) then
        tmp = t_2 * (t_0 * (1.0d0 - (0.5d0 * ((sqrt((h / l)) * (0.5d0 * (d_1 * (m / d)))) ** 2.0d0))))
    else if ((t_1 <= 5d-202) .or. (.not. (t_1 <= 1d+254))) then
        tmp = abs((d / sqrt((h * l))))
    else
        tmp = t_0 * (t_2 * (1.0d0 + ((((d_1 * (m * (0.5d0 / d))) ** 2.0d0) / l) * (h * (-0.5d0)))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((d / l));
	double t_1 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = Math.sqrt((d / h));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_2 * (t_0 * (1.0 - (0.5 * Math.pow((Math.sqrt((h / l)) * (0.5 * (D * (M / d)))), 2.0))));
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	} else {
		tmp = t_0 * (t_2 * (1.0 + ((Math.pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((d / l))
	t_1 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((M * D) / (d * 2.0)), 2.0))))
	t_2 = math.sqrt((d / h))
	tmp = 0
	if t_1 <= -1e-244:
		tmp = t_2 * (t_0 * (1.0 - (0.5 * math.pow((math.sqrt((h / l)) * (0.5 * (D * (M / d)))), 2.0))))
	elif (t_1 <= 5e-202) or not (t_1 <= 1e+254):
		tmp = math.fabs((d / math.sqrt((h * l))))
	else:
		tmp = t_0 * (t_2 * (1.0 + ((math.pow((D * (M * (0.5 / d))), 2.0) / l) * (h * -0.5))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(d / l))
	t_1 = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)))))
	t_2 = sqrt(Float64(d / h))
	tmp = 0.0
	if (t_1 <= -1e-244)
		tmp = Float64(t_2 * Float64(t_0 * Float64(1.0 - Float64(0.5 * (Float64(sqrt(Float64(h / l)) * Float64(0.5 * Float64(D * Float64(M / d)))) ^ 2.0)))));
	elseif ((t_1 <= 5e-202) || !(t_1 <= 1e+254))
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	else
		tmp = Float64(t_0 * Float64(t_2 * Float64(1.0 + Float64(Float64((Float64(D * Float64(M * Float64(0.5 / d))) ^ 2.0) / l) * Float64(h * -0.5)))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((d / l));
	t_1 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((M * D) / (d * 2.0)) ^ 2.0))));
	t_2 = sqrt((d / h));
	tmp = 0.0;
	if (t_1 <= -1e-244)
		tmp = t_2 * (t_0 * (1.0 - (0.5 * ((sqrt((h / l)) * (0.5 * (D * (M / d)))) ^ 2.0))));
	elseif ((t_1 <= 5e-202) || ~((t_1 <= 1e+254)))
		tmp = abs((d / sqrt((h * l))));
	else
		tmp = t_0 * (t_2 * (1.0 + ((((D * (M * (0.5 / d))) ^ 2.0) / l) * (h * -0.5))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -1e-244], N[(t$95$2 * N[(t$95$0 * N[(1.0 - N[(0.5 * N[Power[N[(N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision] * N[(0.5 * N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, 5e-202], N[Not[LessEqual[t$95$1, 1e+254]], $MachinePrecision]], N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(t$95$0 * N[(t$95$2 * N[(1.0 + N[(N[(N[Power[N[(D * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision] * N[(h * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\
t_2 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\
\;\;\;\;t_2 \cdot \left(t_0 \cdot \left(1 - 0.5 \cdot {\left(\sqrt{\frac{h}{\ell}} \cdot \left(0.5 \cdot \left(D \cdot \frac{M}{d}\right)\right)\right)}^{2}\right)\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\

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


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

    1. Initial program 88.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. Simplified87.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999993e-245 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 4.99999999999999973e-202 or 9.9999999999999994e253 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 24.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. Simplified22.6%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/229.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\sqrt{\color{blue}{\frac{d}{\ell}}} \cdot \sqrt{\frac{d}{h}}\right| \]
      11. sqrt-prod29.5%

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

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

        \[\leadsto \left|\color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}}\right| \]
      14. sqrt-unprod35.4%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}}\right| \]
      15. add-sqr-sqrt57.7%

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

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

    if 4.99999999999999973e-202 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 9.9999999999999994e253

    1. Initial program 97.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. Simplified99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 79.7% accurate, 0.3× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := D \cdot \left(M \cdot \frac{0.5}{d}\right)\\ t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\ t_2 := \sqrt{\frac{d}{\ell}}\\ t_3 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\ \;\;\;\;t_3 \cdot \left(\left(1 - 0.5 \cdot {\left(t_0 \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \cdot t_2\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \left(t_3 \cdot \left(1 + \frac{{t_0}^{2}}{\ell} \cdot \left(h \cdot -0.5\right)\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (* D (* M (/ 0.5 d))))
        (t_1
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* M D) (* d 2.0)) 2.0))))))
        (t_2 (sqrt (/ d l)))
        (t_3 (sqrt (/ d h))))
   (if (<= t_1 -1e-244)
     (* t_3 (* (- 1.0 (* 0.5 (pow (* t_0 (sqrt (/ h l))) 2.0))) t_2))
     (if (or (<= t_1 5e-202) (not (<= t_1 1e+254)))
       (fabs (/ d (sqrt (* h l))))
       (* t_2 (* t_3 (+ 1.0 (* (/ (pow t_0 2.0) l) (* h -0.5)))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = D * (M * (0.5 / d));
	double t_1 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = sqrt((d / l));
	double t_3 = sqrt((d / h));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_3 * ((1.0 - (0.5 * pow((t_0 * sqrt((h / l))), 2.0))) * t_2);
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = fabs((d / sqrt((h * l))));
	} else {
		tmp = t_2 * (t_3 * (1.0 + ((pow(t_0, 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = d_1 * (m * (0.5d0 / d))
    t_1 = (((d / h) ** 0.5d0) * ((d / l) ** 0.5d0)) * (1.0d0 - ((h / l) * (0.5d0 * (((m * d_1) / (d * 2.0d0)) ** 2.0d0))))
    t_2 = sqrt((d / l))
    t_3 = sqrt((d / h))
    if (t_1 <= (-1d-244)) then
        tmp = t_3 * ((1.0d0 - (0.5d0 * ((t_0 * sqrt((h / l))) ** 2.0d0))) * t_2)
    else if ((t_1 <= 5d-202) .or. (.not. (t_1 <= 1d+254))) then
        tmp = abs((d / sqrt((h * l))))
    else
        tmp = t_2 * (t_3 * (1.0d0 + (((t_0 ** 2.0d0) / l) * (h * (-0.5d0)))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = D * (M * (0.5 / d));
	double t_1 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((M * D) / (d * 2.0)), 2.0))));
	double t_2 = Math.sqrt((d / l));
	double t_3 = Math.sqrt((d / h));
	double tmp;
	if (t_1 <= -1e-244) {
		tmp = t_3 * ((1.0 - (0.5 * Math.pow((t_0 * Math.sqrt((h / l))), 2.0))) * t_2);
	} else if ((t_1 <= 5e-202) || !(t_1 <= 1e+254)) {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	} else {
		tmp = t_2 * (t_3 * (1.0 + ((Math.pow(t_0, 2.0) / l) * (h * -0.5))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = D * (M * (0.5 / d))
	t_1 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((M * D) / (d * 2.0)), 2.0))))
	t_2 = math.sqrt((d / l))
	t_3 = math.sqrt((d / h))
	tmp = 0
	if t_1 <= -1e-244:
		tmp = t_3 * ((1.0 - (0.5 * math.pow((t_0 * math.sqrt((h / l))), 2.0))) * t_2)
	elif (t_1 <= 5e-202) or not (t_1 <= 1e+254):
		tmp = math.fabs((d / math.sqrt((h * l))))
	else:
		tmp = t_2 * (t_3 * (1.0 + ((math.pow(t_0, 2.0) / l) * (h * -0.5))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = Float64(D * Float64(M * Float64(0.5 / d)))
	t_1 = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(M * D) / Float64(d * 2.0)) ^ 2.0)))))
	t_2 = sqrt(Float64(d / l))
	t_3 = sqrt(Float64(d / h))
	tmp = 0.0
	if (t_1 <= -1e-244)
		tmp = Float64(t_3 * Float64(Float64(1.0 - Float64(0.5 * (Float64(t_0 * sqrt(Float64(h / l))) ^ 2.0))) * t_2));
	elseif ((t_1 <= 5e-202) || !(t_1 <= 1e+254))
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	else
		tmp = Float64(t_2 * Float64(t_3 * Float64(1.0 + Float64(Float64((t_0 ^ 2.0) / l) * Float64(h * -0.5)))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = D * (M * (0.5 / d));
	t_1 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((M * D) / (d * 2.0)) ^ 2.0))));
	t_2 = sqrt((d / l));
	t_3 = sqrt((d / h));
	tmp = 0.0;
	if (t_1 <= -1e-244)
		tmp = t_3 * ((1.0 - (0.5 * ((t_0 * sqrt((h / l))) ^ 2.0))) * t_2);
	elseif ((t_1 <= 5e-202) || ~((t_1 <= 1e+254)))
		tmp = abs((d / sqrt((h * l))));
	else
		tmp = t_2 * (t_3 * (1.0 + (((t_0 ^ 2.0) / l) * (h * -0.5))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(D * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(M * D), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, -1e-244], N[(t$95$3 * N[(N[(1.0 - N[(0.5 * N[Power[N[(t$95$0 * N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, 5e-202], N[Not[LessEqual[t$95$1, 1e+254]], $MachinePrecision]], N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(t$95$2 * N[(t$95$3 * N[(1.0 + N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] / l), $MachinePrecision] * N[(h * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := D \cdot \left(M \cdot \frac{0.5}{d}\right)\\
t_1 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{M \cdot D}{d \cdot 2}\right)}^{2}\right)\right)\\
t_2 := \sqrt{\frac{d}{\ell}}\\
t_3 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-244}:\\
\;\;\;\;t_3 \cdot \left(\left(1 - 0.5 \cdot {\left(t_0 \cdot \sqrt{\frac{h}{\ell}}\right)}^{2}\right) \cdot t_2\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{-202} \lor \neg \left(t_1 \leq 10^{+254}\right):\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\

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


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

    1. Initial program 88.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. Simplified87.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999993e-245 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 4.99999999999999973e-202 or 9.9999999999999994e253 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l))))

    1. Initial program 24.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. Simplified22.6%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/229.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\sqrt{\color{blue}{\frac{d}{\ell}}} \cdot \sqrt{\frac{d}{h}}\right| \]
      11. sqrt-prod29.5%

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

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

        \[\leadsto \left|\color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}}\right| \]
      14. sqrt-unprod35.4%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}}\right| \]
      15. add-sqr-sqrt57.7%

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

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

    if 4.99999999999999973e-202 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 1 2)) (pow.f64 (/.f64 d l) (/.f64 1 2))) (-.f64 1 (*.f64 (*.f64 (/.f64 1 2) (pow.f64 (/.f64 (*.f64 M D) (*.f64 2 d)) 2)) (/.f64 h l)))) < 9.9999999999999994e253

    1. Initial program 97.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. Simplified99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 79.5% accurate, 0.8× speedup?

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

\mathbf{elif}\;d \leq 3.8 \cdot 10^{-204}:\\
\;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot t_0\\

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


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

    1. Initial program 67.2%

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

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

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

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

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

    if -1.999999999999994e-310 < d < 3.79999999999999983e-204

    1. Initial program 43.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. Simplified41.1%

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

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

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

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

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

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

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

    if 3.79999999999999983e-204 < d

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.7% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d < 3.79999999999999983e-204

    1. Initial program 43.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. Simplified41.1%

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

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

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

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

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

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

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

    if 3.79999999999999983e-204 < d

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 77.5% accurate, 0.8× speedup?

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

\mathbf{elif}\;h \leq 1.22 \cdot 10^{+215}:\\
\;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\frac{\sqrt{\ell}}{1 + -0.5 \cdot t_1}}\\

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


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

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000023e-311 < h < 1.22000000000000007e215

    1. Initial program 68.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.22000000000000007e215 < h

    1. Initial program 29.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. Simplified29.1%

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

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

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

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

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

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

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

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

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

Alternative 8: 64.2% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 61.5%

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

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

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

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

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

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

    if -1.40000000000000006e-73 < l < -1.02e-302

    1. Initial program 81.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. Simplified83.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.02e-302 < l

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 66.6% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq -1.02 \cdot 10^{-302}:\\
\;\;\;\;\left(t_0 \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1\right) \cdot \frac{-d}{\sqrt{h \cdot \ell}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\frac{\sqrt{\ell}}{1 + -0.5 \cdot \frac{h \cdot t_0}{\ell}}}\\


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

    1. Initial program 61.5%

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

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

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

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

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

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

    if -1.50000000000000003e-74 < l < -1.02e-302

    1. Initial program 81.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. Simplified83.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.02e-302 < l

    1. Initial program 64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 74.6% accurate, 1.0× speedup?

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

\mathbf{elif}\;d \leq 4 \cdot 10^{-204}:\\
\;\;\;\;\frac{\frac{d}{\frac{\sqrt{\ell}}{t_0 \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1}}}{\sqrt{h}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\frac{\sqrt{\ell}}{1 + -0.5 \cdot \frac{h \cdot t_0}{\ell}}}\\


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

    1. Initial program 67.2%

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

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

    if -1.999999999999994e-310 < d < 4e-204

    1. Initial program 43.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. Simplified41.1%

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

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

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

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

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

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

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

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

    if 4e-204 < d

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 75.5% accurate, 1.0× speedup?

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

\mathbf{elif}\;d \leq 3.8 \cdot 10^{-204}:\\
\;\;\;\;\frac{\frac{d}{\frac{\sqrt{\ell}}{t_0 \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1}}}{\sqrt{h}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\frac{\sqrt{\ell}}{1 + -0.5 \cdot \frac{h \cdot t_0}{\ell}}}\\


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

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d < 3.79999999999999983e-204

    1. Initial program 43.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. Simplified41.1%

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

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

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

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

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

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

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

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

    if 3.79999999999999983e-204 < d

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 76.1% accurate, 1.0× speedup?

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

\mathbf{elif}\;d \leq 3.8 \cdot 10^{-204}:\\
\;\;\;\;\frac{\frac{d}{\frac{\sqrt{\ell}}{t_0 \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1}}}{\sqrt{h}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\frac{\sqrt{\ell}}{1 + -0.5 \cdot \frac{h \cdot t_0}{\ell}}}\\


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

    1. Initial program 67.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d < 3.79999999999999983e-204

    1. Initial program 43.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. Simplified41.1%

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

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

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

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

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

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

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

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

    if 3.79999999999999983e-204 < d

    1. Initial program 71.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 61.9% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 61.5%

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

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

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

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

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

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

    if -9.20000000000000025e-76 < l < -1.02e-302

    1. Initial program 81.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. Simplified83.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.02e-302 < l < 1.25e207

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.25e207 < l

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -9.2 \cdot 10^{-76}:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;\ell \leq -1.02 \cdot 10^{-302}:\\ \;\;\;\;\left({\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2} \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1\right) \cdot \frac{-d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+207}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]

Alternative 14: 57.1% accurate, 1.5× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;\ell \leq -1.34 \cdot 10^{-79}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt[3]{h \cdot \left(\ell \cdot t_0\right)}}\\ \mathbf{elif}\;\ell \leq 2.15 \cdot 10^{+207}:\\ \;\;\;\;\frac{d}{t_0} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= l -1.34e-79)
     (* d (- (sqrt (/ (/ 1.0 h) l))))
     (if (<= l -2e-310)
       (/ d (cbrt (* h (* l t_0))))
       (if (<= l 2.15e+207)
         (*
          (/ d t_0)
          (+ 1.0 (* -0.5 (* (/ h l) (pow (* D (* M (/ 0.5 d))) 2.0)))))
         (/ d (* (sqrt l) (sqrt h))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (l <= -1.34e-79) {
		tmp = d * -sqrt(((1.0 / h) / l));
	} else if (l <= -2e-310) {
		tmp = d / cbrt((h * (l * t_0)));
	} else if (l <= 2.15e+207) {
		tmp = (d / t_0) * (1.0 + (-0.5 * ((h / l) * pow((D * (M * (0.5 / d))), 2.0))));
	} else {
		tmp = d / (sqrt(l) * sqrt(h));
	}
	return tmp;
}
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (l <= -1.34e-79) {
		tmp = d * -Math.sqrt(((1.0 / h) / l));
	} else if (l <= -2e-310) {
		tmp = d / Math.cbrt((h * (l * t_0)));
	} else if (l <= 2.15e+207) {
		tmp = (d / t_0) * (1.0 + (-0.5 * ((h / l) * Math.pow((D * (M * (0.5 / d))), 2.0))));
	} else {
		tmp = d / (Math.sqrt(l) * Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (l <= -1.34e-79)
		tmp = Float64(d * Float64(-sqrt(Float64(Float64(1.0 / h) / l))));
	elseif (l <= -2e-310)
		tmp = Float64(d / cbrt(Float64(h * Float64(l * t_0))));
	elseif (l <= 2.15e+207)
		tmp = Float64(Float64(d / t_0) * Float64(1.0 + Float64(-0.5 * Float64(Float64(h / l) * (Float64(D * Float64(M * Float64(0.5 / d))) ^ 2.0)))));
	else
		tmp = Float64(d / Float64(sqrt(l) * sqrt(h)));
	end
	return tmp
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.34e-79], N[(d * (-N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -2e-310], N[(d / N[Power[N[(h * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.15e+207], N[(N[(d / t$95$0), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(D * N[(M * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;\ell \leq -1.34 \cdot 10^{-79}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{d}{\sqrt[3]{h \cdot \left(\ell \cdot t_0\right)}}\\

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

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


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

    1. Initial program 61.5%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/241.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \left(-\sqrt{\ell}\right)}} \]
    10. Taylor expanded in d around 0 45.5%

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

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

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

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

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

    if -1.34e-79 < l < -1.999999999999994e-310

    1. Initial program 79.1%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/216.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < l < 2.1499999999999999e207

    1. Initial program 68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1499999999999999e207 < l

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

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

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

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

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

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

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

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

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

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

Alternative 15: 61.2% accurate, 1.5× speedup?

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

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

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

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


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

    1. Initial program 61.5%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/241.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \left(-\sqrt{\ell}\right)}} \]
    10. Taylor expanded in d around 0 45.5%

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

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

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

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

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

    if -1.9000000000000001e-73 < l < -1.02e-302

    1. Initial program 81.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. Simplified83.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.02e-302 < l < 6.19999999999999961e208

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.19999999999999961e208 < l

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.9 \cdot 10^{-73}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{elif}\;\ell \leq -1.02 \cdot 10^{-302}:\\ \;\;\;\;\left({\left(D \cdot \frac{M}{d \cdot 2}\right)}^{2} \cdot \left(\frac{h}{\ell} \cdot -0.5\right) + -1\right) \cdot \frac{-d}{\sqrt{h \cdot \ell}}\\ \mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+208}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]

Alternative 16: 46.0% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{-79}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt[3]{h \cdot \left(\ell \cdot \sqrt{h \cdot \ell}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= l -2.2e-79)
   (* d (- (sqrt (/ (/ 1.0 h) l))))
   (if (<= l -2e-310)
     (/ d (cbrt (* h (* l (sqrt (* h l))))))
     (/ d (* (sqrt l) (sqrt h))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -2.2e-79) {
		tmp = d * -sqrt(((1.0 / h) / l));
	} else if (l <= -2e-310) {
		tmp = d / cbrt((h * (l * sqrt((h * l)))));
	} else {
		tmp = d / (sqrt(l) * sqrt(h));
	}
	return tmp;
}
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -2.2e-79) {
		tmp = d * -Math.sqrt(((1.0 / h) / l));
	} else if (l <= -2e-310) {
		tmp = d / Math.cbrt((h * (l * Math.sqrt((h * l)))));
	} else {
		tmp = d / (Math.sqrt(l) * Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= -2.2e-79)
		tmp = Float64(d * Float64(-sqrt(Float64(Float64(1.0 / h) / l))));
	elseif (l <= -2e-310)
		tmp = Float64(d / cbrt(Float64(h * Float64(l * sqrt(Float64(h * l))))));
	else
		tmp = Float64(d / Float64(sqrt(l) * sqrt(h)));
	end
	return tmp
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[l, -2.2e-79], N[(d * (-N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -2e-310], N[(d / N[Power[N[(h * N[(l * N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.2 \cdot 10^{-79}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{d}{\sqrt[3]{h \cdot \left(\ell \cdot \sqrt{h \cdot \ell}\right)}}\\

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


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

    1. Initial program 61.5%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/241.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \left(-\sqrt{\ell}\right)}} \]
    10. Taylor expanded in d around 0 45.5%

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

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

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

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

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

    if -2.1999999999999999e-79 < l < -1.999999999999994e-310

    1. Initial program 79.1%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/216.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-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. Simplified63.1%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{-79}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\frac{d}{\sqrt[3]{h \cdot \left(\ell \cdot \sqrt{h \cdot \ell}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]

Alternative 17: 47.6% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -5.6 \cdot 10^{+85}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{elif}\;h \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;d \cdot \frac{-1}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= h -5.6e+85)
   (sqrt (/ d (* l (/ h d))))
   (if (<= h 3.2e-308)
     (* d (/ -1.0 (sqrt (* h l))))
     (/ d (* (sqrt l) (sqrt h))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -5.6e+85) {
		tmp = sqrt((d / (l * (h / d))));
	} else if (h <= 3.2e-308) {
		tmp = d * (-1.0 / sqrt((h * l)));
	} else {
		tmp = d / (sqrt(l) * sqrt(h));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (h <= (-5.6d+85)) then
        tmp = sqrt((d / (l * (h / d))))
    else if (h <= 3.2d-308) then
        tmp = d * ((-1.0d0) / sqrt((h * l)))
    else
        tmp = d / (sqrt(l) * sqrt(h))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -5.6e+85) {
		tmp = Math.sqrt((d / (l * (h / d))));
	} else if (h <= 3.2e-308) {
		tmp = d * (-1.0 / Math.sqrt((h * l)));
	} else {
		tmp = d / (Math.sqrt(l) * Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if h <= -5.6e+85:
		tmp = math.sqrt((d / (l * (h / d))))
	elif h <= 3.2e-308:
		tmp = d * (-1.0 / math.sqrt((h * l)))
	else:
		tmp = d / (math.sqrt(l) * math.sqrt(h))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (h <= -5.6e+85)
		tmp = sqrt(Float64(d / Float64(l * Float64(h / d))));
	elseif (h <= 3.2e-308)
		tmp = Float64(d * Float64(-1.0 / sqrt(Float64(h * l))));
	else
		tmp = Float64(d / Float64(sqrt(l) * sqrt(h)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (h <= -5.6e+85)
		tmp = sqrt((d / (l * (h / d))));
	elseif (h <= 3.2e-308)
		tmp = d * (-1.0 / sqrt((h * l)));
	else
		tmp = d / (sqrt(l) * sqrt(h));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[h, -5.6e+85], N[Sqrt[N[(d / N[(l * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[h, 3.2e-308], N[(d * N[(-1.0 / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -5.6 \cdot 10^{+85}:\\
\;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\

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

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


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

    1. Initial program 63.8%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/235.9%

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{1 \cdot d}{\frac{h}{d} \cdot \ell}}} \]
      4. *-un-lft-identity33.5%

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

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

    if -5.5999999999999998e85 < h < 3.2000000000000001e-308

    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.3%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/231.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-d}{-\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      3. distribute-lft-neg-in0.0%

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

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-308 < h

    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. Simplified62.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -5.6 \cdot 10^{+85}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{elif}\;h \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;d \cdot \frac{-1}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]

Alternative 18: 48.6% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -3.1 \cdot 10^{+86}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;h \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;d \cdot \frac{-1}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= h -3.1e+86)
   (* (sqrt (/ d h)) (sqrt (/ d l)))
   (if (<= h 3.2e-308)
     (* d (/ -1.0 (sqrt (* h l))))
     (/ d (* (sqrt l) (sqrt h))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -3.1e+86) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (h <= 3.2e-308) {
		tmp = d * (-1.0 / sqrt((h * l)));
	} else {
		tmp = d / (sqrt(l) * sqrt(h));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (h <= (-3.1d+86)) then
        tmp = sqrt((d / h)) * sqrt((d / l))
    else if (h <= 3.2d-308) then
        tmp = d * ((-1.0d0) / sqrt((h * l)))
    else
        tmp = d / (sqrt(l) * sqrt(h))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -3.1e+86) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (h <= 3.2e-308) {
		tmp = d * (-1.0 / Math.sqrt((h * l)));
	} else {
		tmp = d / (Math.sqrt(l) * Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if h <= -3.1e+86:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif h <= 3.2e-308:
		tmp = d * (-1.0 / math.sqrt((h * l)))
	else:
		tmp = d / (math.sqrt(l) * math.sqrt(h))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (h <= -3.1e+86)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (h <= 3.2e-308)
		tmp = Float64(d * Float64(-1.0 / sqrt(Float64(h * l))));
	else
		tmp = Float64(d / Float64(sqrt(l) * sqrt(h)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (h <= -3.1e+86)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (h <= 3.2e-308)
		tmp = d * (-1.0 / sqrt((h * l)));
	else
		tmp = d / (sqrt(l) * sqrt(h));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[h, -3.1e+86], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3.2e-308], N[(d * N[(-1.0 / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -3.1 \cdot 10^{+86}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

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

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


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

    1. Initial program 63.8%

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/235.9%

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

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

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

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

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

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

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

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

    if -3.1000000000000002e86 < h < 3.2000000000000001e-308

    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.3%

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/231.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-d}{-\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      3. distribute-lft-neg-in0.0%

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

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

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

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

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

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

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

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

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

    if 3.2000000000000001e-308 < h

    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. Simplified62.9%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -3.1 \cdot 10^{+86}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;h \leq 3.2 \cdot 10^{-308}:\\ \;\;\;\;d \cdot \frac{-1}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]

Alternative 19: 43.7% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -6 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= h -6e+91) (sqrt (/ d (* l (/ h d)))) (fabs (/ d (sqrt (* h l))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -6e+91) {
		tmp = sqrt((d / (l * (h / d))));
	} else {
		tmp = fabs((d / sqrt((h * l))));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (h <= (-6d+91)) then
        tmp = sqrt((d / (l * (h / d))))
    else
        tmp = abs((d / sqrt((h * l))))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -6e+91) {
		tmp = Math.sqrt((d / (l * (h / d))));
	} else {
		tmp = Math.abs((d / Math.sqrt((h * l))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if h <= -6e+91:
		tmp = math.sqrt((d / (l * (h / d))))
	else:
		tmp = math.fabs((d / math.sqrt((h * l))))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (h <= -6e+91)
		tmp = sqrt(Float64(d / Float64(l * Float64(h / d))));
	else
		tmp = abs(Float64(d / sqrt(Float64(h * l))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (h <= -6e+91)
		tmp = sqrt((d / (l * (h / d))));
	else
		tmp = abs((d / sqrt((h * l))));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[h, -6e+91], N[Sqrt[N[(d / N[(l * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -6 \cdot 10^{+91}:\\
\;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\

\mathbf{else}:\\
\;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -6.00000000000000012e91

    1. Initial program 62.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. Simplified60.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 34.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity34.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/234.2%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/234.2%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down31.7%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr31.7%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/231.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified31.7%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. *-commutative31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
      2. clear-num31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{h}{d}}} \cdot \frac{d}{\ell}} \]
      3. frac-times31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{1 \cdot d}{\frac{h}{d} \cdot \ell}}} \]
      4. *-un-lft-identity31.7%

        \[\leadsto \sqrt{\frac{\color{blue}{d}}{\frac{h}{d} \cdot \ell}} \]
    9. Applied egg-rr31.7%

      \[\leadsto \sqrt{\color{blue}{\frac{d}{\frac{h}{d} \cdot \ell}}} \]

    if -6.00000000000000012e91 < h

    1. Initial program 66.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified66.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 34.7%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity34.7%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/234.7%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/234.7%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down30.4%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr30.4%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/230.4%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified30.4%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. sqrt-prod34.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
      2. frac-2neg34.7%

        \[\leadsto \sqrt{\color{blue}{\frac{-d}{-\ell}}} \cdot \sqrt{\frac{d}{h}} \]
      3. sqrt-undiv12.3%

        \[\leadsto \color{blue}{\frac{\sqrt{-d}}{\sqrt{-\ell}}} \cdot \sqrt{\frac{d}{h}} \]
      4. *-commutative12.3%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}} \]
      5. add-sqr-sqrt12.3%

        \[\leadsto \color{blue}{\sqrt{\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}} \cdot \sqrt{\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}}} \]
      6. sqrt-prod9.5%

        \[\leadsto \color{blue}{\sqrt{\left(\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\right)}} \]
      7. rem-sqrt-square12.3%

        \[\leadsto \color{blue}{\left|\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}\right|} \]
      8. *-commutative12.3%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{-d}}{\sqrt{-\ell}} \cdot \sqrt{\frac{d}{h}}}\right| \]
      9. sqrt-undiv34.7%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{-d}{-\ell}}} \cdot \sqrt{\frac{d}{h}}\right| \]
      10. frac-2neg34.7%

        \[\leadsto \left|\sqrt{\color{blue}{\frac{d}{\ell}}} \cdot \sqrt{\frac{d}{h}}\right| \]
      11. sqrt-prod30.4%

        \[\leadsto \left|\color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}}\right| \]
      12. frac-times26.4%

        \[\leadsto \left|\sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}}\right| \]
      13. sqrt-div29.0%

        \[\leadsto \left|\color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}}\right| \]
      14. sqrt-unprod26.8%

        \[\leadsto \left|\frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}}\right| \]
      15. add-sqr-sqrt43.2%

        \[\leadsto \left|\frac{\color{blue}{d}}{\sqrt{\ell \cdot h}}\right| \]
    9. Applied egg-rr43.2%

      \[\leadsto \color{blue}{\left|\frac{d}{\sqrt{\ell \cdot h}}\right|} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification41.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -6 \cdot 10^{+91}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{else}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \end{array} \]

Alternative 20: 41.7% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;h \leq -7.2 \cdot 10^{+88}:\\ \;\;\;\;\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\\ \mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\ \;\;\;\;\frac{-d}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{t_0}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= h -7.2e+88)
     (sqrt (* (/ d h) (/ d l)))
     (if (<= h -7.8e-243) (/ (- d) t_0) (/ d t_0)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (h <= -7.2e+88) {
		tmp = sqrt(((d / h) * (d / l)));
	} else if (h <= -7.8e-243) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (h <= (-7.2d+88)) then
        tmp = sqrt(((d / h) * (d / l)))
    else if (h <= (-7.8d-243)) then
        tmp = -d / t_0
    else
        tmp = d / t_0
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (h <= -7.2e+88) {
		tmp = Math.sqrt(((d / h) * (d / l)));
	} else if (h <= -7.8e-243) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if h <= -7.2e+88:
		tmp = math.sqrt(((d / h) * (d / l)))
	elif h <= -7.8e-243:
		tmp = -d / t_0
	else:
		tmp = d / t_0
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (h <= -7.2e+88)
		tmp = sqrt(Float64(Float64(d / h) * Float64(d / l)));
	elseif (h <= -7.8e-243)
		tmp = Float64(Float64(-d) / t_0);
	else
		tmp = Float64(d / t_0);
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (h <= -7.2e+88)
		tmp = sqrt(((d / h) * (d / l)));
	elseif (h <= -7.8e-243)
		tmp = -d / t_0;
	else
		tmp = d / t_0;
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, -7.2e+88], N[Sqrt[N[(N[(d / h), $MachinePrecision] * N[(d / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[h, -7.8e-243], N[((-d) / t$95$0), $MachinePrecision], N[(d / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;h \leq -7.2 \cdot 10^{+88}:\\
\;\;\;\;\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\\

\mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\
\;\;\;\;\frac{-d}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{t_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -7.2000000000000004e88

    1. Initial program 62.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. Simplified60.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 34.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity34.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/234.2%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/234.2%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down31.7%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr31.7%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/231.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified31.7%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]

    if -7.2000000000000004e88 < h < -7.8000000000000003e-243

    1. Initial program 68.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. Simplified71.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 33.8%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity33.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/233.8%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/233.8%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down27.0%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr27.0%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/227.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified27.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times22.8%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div22.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt14.0%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr14.0%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
    10. Step-by-step derivation
      1. sqrt-prod0.0%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      2. associate-/l/0.0%

        \[\leadsto \color{blue}{\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      3. *-un-lft-identity0.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}} \]
      5. sqr-neg0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\left(-\sqrt{\ell}\right) \cdot \left(-\sqrt{\ell}\right)}}} \]
      6. sqrt-unprod0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{\sqrt{-\sqrt{\ell}} \cdot \sqrt{-\sqrt{\ell}}}} \]
      7. add-sqr-sqrt0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-\sqrt{\ell}}} \]
      8. neg-mul-10.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-1 \cdot \sqrt{\ell}}} \]
      9. times-frac0.0%

        \[\leadsto \color{blue}{\frac{1}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      10. metadata-eval0.0%

        \[\leadsto \color{blue}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}} \]
      11. associate-/l/0.0%

        \[\leadsto -1 \cdot \color{blue}{\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      12. sqrt-prod47.9%

        \[\leadsto -1 \cdot \frac{d}{\color{blue}{\sqrt{\ell \cdot h}}} \]
      13. *-commutative47.9%

        \[\leadsto -1 \cdot \frac{d}{\sqrt{\color{blue}{h \cdot \ell}}} \]
    11. Applied egg-rr47.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{d}{\sqrt{h \cdot \ell}}} \]
    12. Step-by-step derivation
      1. mul-1-neg47.9%

        \[\leadsto \color{blue}{-\frac{d}{\sqrt{h \cdot \ell}}} \]
      2. distribute-neg-frac47.9%

        \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]
    13. Simplified47.9%

      \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]

    if -7.8000000000000003e-243 < h

    1. Initial program 64.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. Simplified63.7%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 35.1%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity35.1%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/235.1%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/235.1%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down31.9%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr31.9%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/231.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified31.9%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times28.0%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div31.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod38.9%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt41.8%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr41.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -7.2 \cdot 10^{+88}:\\ \;\;\;\;\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\\ \mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\ \;\;\;\;\frac{-d}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 21: 41.5% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;h \leq -2.55 \cdot 10^{+92}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\ \;\;\;\;\frac{-d}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{t_0}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (* h l))))
   (if (<= h -2.55e+92)
     (sqrt (/ d (* l (/ h d))))
     (if (<= h -7.8e-243) (/ (- d) t_0) (/ d t_0)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (h <= -2.55e+92) {
		tmp = sqrt((d / (l * (h / d))));
	} else if (h <= -7.8e-243) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (h <= (-2.55d+92)) then
        tmp = sqrt((d / (l * (h / d))))
    else if (h <= (-7.8d-243)) then
        tmp = -d / t_0
    else
        tmp = d / t_0
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (h <= -2.55e+92) {
		tmp = Math.sqrt((d / (l * (h / d))));
	} else if (h <= -7.8e-243) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if h <= -2.55e+92:
		tmp = math.sqrt((d / (l * (h / d))))
	elif h <= -7.8e-243:
		tmp = -d / t_0
	else:
		tmp = d / t_0
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (h <= -2.55e+92)
		tmp = sqrt(Float64(d / Float64(l * Float64(h / d))));
	elseif (h <= -7.8e-243)
		tmp = Float64(Float64(-d) / t_0);
	else
		tmp = Float64(d / t_0);
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (h <= -2.55e+92)
		tmp = sqrt((d / (l * (h / d))));
	elseif (h <= -7.8e-243)
		tmp = -d / t_0;
	else
		tmp = d / t_0;
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, -2.55e+92], N[Sqrt[N[(d / N[(l * N[(h / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[h, -7.8e-243], N[((-d) / t$95$0), $MachinePrecision], N[(d / t$95$0), $MachinePrecision]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;h \leq -2.55 \cdot 10^{+92}:\\
\;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\

\mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\
\;\;\;\;\frac{-d}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{t_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -2.5500000000000001e92

    1. Initial program 62.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. Simplified60.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 34.2%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity34.2%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/234.2%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/234.2%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down31.7%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr31.7%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/231.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified31.7%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. *-commutative31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
      2. clear-num31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{h}{d}}} \cdot \frac{d}{\ell}} \]
      3. frac-times31.7%

        \[\leadsto \sqrt{\color{blue}{\frac{1 \cdot d}{\frac{h}{d} \cdot \ell}}} \]
      4. *-un-lft-identity31.7%

        \[\leadsto \sqrt{\frac{\color{blue}{d}}{\frac{h}{d} \cdot \ell}} \]
    9. Applied egg-rr31.7%

      \[\leadsto \sqrt{\color{blue}{\frac{d}{\frac{h}{d} \cdot \ell}}} \]

    if -2.5500000000000001e92 < h < -7.8000000000000003e-243

    1. Initial program 68.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. Simplified71.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 33.8%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity33.8%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/233.8%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/233.8%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down27.0%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr27.0%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/227.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified27.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times22.8%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div22.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod0.0%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt14.0%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr14.0%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
    10. Step-by-step derivation
      1. sqrt-prod0.0%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      2. associate-/l/0.0%

        \[\leadsto \color{blue}{\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      3. *-un-lft-identity0.0%

        \[\leadsto \frac{\color{blue}{1 \cdot \frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
      4. add-sqr-sqrt0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}} \]
      5. sqr-neg0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\left(-\sqrt{\ell}\right) \cdot \left(-\sqrt{\ell}\right)}}} \]
      6. sqrt-unprod0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{\sqrt{-\sqrt{\ell}} \cdot \sqrt{-\sqrt{\ell}}}} \]
      7. add-sqr-sqrt0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-\sqrt{\ell}}} \]
      8. neg-mul-10.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-1 \cdot \sqrt{\ell}}} \]
      9. times-frac0.0%

        \[\leadsto \color{blue}{\frac{1}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      10. metadata-eval0.0%

        \[\leadsto \color{blue}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}} \]
      11. associate-/l/0.0%

        \[\leadsto -1 \cdot \color{blue}{\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      12. sqrt-prod47.9%

        \[\leadsto -1 \cdot \frac{d}{\color{blue}{\sqrt{\ell \cdot h}}} \]
      13. *-commutative47.9%

        \[\leadsto -1 \cdot \frac{d}{\sqrt{\color{blue}{h \cdot \ell}}} \]
    11. Applied egg-rr47.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{d}{\sqrt{h \cdot \ell}}} \]
    12. Step-by-step derivation
      1. mul-1-neg47.9%

        \[\leadsto \color{blue}{-\frac{d}{\sqrt{h \cdot \ell}}} \]
      2. distribute-neg-frac47.9%

        \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]
    13. Simplified47.9%

      \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]

    if -7.8000000000000003e-243 < h

    1. Initial program 64.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. Simplified63.7%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 35.1%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity35.1%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/235.1%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/235.1%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down31.9%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr31.9%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/231.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified31.9%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times28.0%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div31.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod38.9%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt41.8%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr41.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification42.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -2.55 \cdot 10^{+92}:\\ \;\;\;\;\sqrt{\frac{d}{\ell \cdot \frac{h}{d}}}\\ \mathbf{elif}\;h \leq -7.8 \cdot 10^{-243}:\\ \;\;\;\;\frac{-d}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 22: 43.7% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq 8.2 \cdot 10^{-222}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= d 8.2e-222) (* d (- (sqrt (/ (/ 1.0 h) l)))) (/ d (sqrt (* h l)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= 8.2e-222) {
		tmp = d * -sqrt(((1.0 / h) / l));
	} else {
		tmp = d / sqrt((h * l));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: tmp
    if (d <= 8.2d-222) then
        tmp = d * -sqrt(((1.0d0 / h) / l))
    else
        tmp = d / sqrt((h * l))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= 8.2e-222) {
		tmp = d * -Math.sqrt(((1.0 / h) / l));
	} else {
		tmp = d / Math.sqrt((h * l));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= 8.2e-222:
		tmp = d * -math.sqrt(((1.0 / h) / l))
	else:
		tmp = d / math.sqrt((h * l))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= 8.2e-222)
		tmp = Float64(d * Float64(-sqrt(Float64(Float64(1.0 / h) / l))));
	else
		tmp = Float64(d / sqrt(Float64(h * l)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= 8.2e-222)
		tmp = d * -sqrt(((1.0 / h) / l));
	else
		tmp = d / sqrt((h * l));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[d, 8.2e-222], N[(d * (-N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision])), $MachinePrecision], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq 8.2 \cdot 10^{-222}:\\
\;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 8.2000000000000006e-222

    1. Initial program 63.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. Simplified63.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 29.9%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity29.9%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/229.9%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/229.9%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down26.1%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr26.1%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/226.1%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified26.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. sqrt-prod29.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} \]
      2. frac-2neg29.9%

        \[\leadsto \sqrt{\color{blue}{\frac{-d}{-\ell}}} \cdot \sqrt{\frac{d}{h}} \]
      3. sqrt-undiv27.6%

        \[\leadsto \color{blue}{\frac{\sqrt{-d}}{\sqrt{-\ell}}} \cdot \sqrt{\frac{d}{h}} \]
      4. *-commutative27.6%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}}} \]
      5. sqrt-div0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} \cdot \frac{\sqrt{-d}}{\sqrt{-\ell}} \]
      6. frac-2neg0.0%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{h}} \cdot \color{blue}{\frac{-\sqrt{-d}}{-\sqrt{-\ell}}} \]
      7. frac-times0.0%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(-\sqrt{-d}\right)}{\sqrt{h} \cdot \left(-\sqrt{-\ell}\right)}} \]
    9. Applied egg-rr2.7%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h} \cdot \left(-\sqrt{\ell}\right)}} \]
    10. Taylor expanded in d around 0 33.1%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    11. Step-by-step derivation
      1. associate-*r*33.1%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. neg-mul-133.1%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      3. associate-/r*34.3%

        \[\leadsto \left(-d\right) \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    12. Simplified34.3%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]

    if 8.2000000000000006e-222 < d

    1. Initial program 68.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. Simplified68.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 40.6%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity40.6%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/240.6%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/240.6%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down36.3%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr36.3%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/236.3%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified36.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times32.4%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div37.5%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod48.1%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt48.3%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr48.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification40.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 8.2 \cdot 10^{-222}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 23: 43.6% accurate, 3.1× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{h \cdot \ell}\\ \mathbf{if}\;d \leq 2.55 \cdot 10^{-224}:\\ \;\;\;\;\frac{-d}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{t_0}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (* h l)))) (if (<= d 2.55e-224) (/ (- d) t_0) (/ d t_0))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h * l));
	double tmp;
	if (d <= 2.55e-224) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((h * l))
    if (d <= 2.55d-224) then
        tmp = -d / t_0
    else
        tmp = d / t_0
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h * l));
	double tmp;
	if (d <= 2.55e-224) {
		tmp = -d / t_0;
	} else {
		tmp = d / t_0;
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((h * l))
	tmp = 0
	if d <= 2.55e-224:
		tmp = -d / t_0
	else:
		tmp = d / t_0
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h * l))
	tmp = 0.0
	if (d <= 2.55e-224)
		tmp = Float64(Float64(-d) / t_0);
	else
		tmp = Float64(d / t_0);
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h * l));
	tmp = 0.0;
	if (d <= 2.55e-224)
		tmp = -d / t_0;
	else
		tmp = d / t_0;
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, 2.55e-224], N[((-d) / t$95$0), $MachinePrecision], N[(d / t$95$0), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{h \cdot \ell}\\
\mathbf{if}\;d \leq 2.55 \cdot 10^{-224}:\\
\;\;\;\;\frac{-d}{t_0}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{t_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < 2.5500000000000001e-224

    1. Initial program 63.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. Simplified63.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 29.9%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity29.9%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/229.9%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/229.9%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down26.1%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr26.1%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/226.1%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified26.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times17.6%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div18.2%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod3.1%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt13.6%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr13.6%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
    10. Step-by-step derivation
      1. sqrt-prod3.8%

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      2. associate-/l/3.8%

        \[\leadsto \color{blue}{\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      3. *-un-lft-identity3.8%

        \[\leadsto \frac{\color{blue}{1 \cdot \frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
      4. add-sqr-sqrt3.8%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\sqrt{\ell} \cdot \sqrt{\ell}}}} \]
      5. sqr-neg3.8%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\sqrt{\color{blue}{\left(-\sqrt{\ell}\right) \cdot \left(-\sqrt{\ell}\right)}}} \]
      6. sqrt-unprod0.0%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{\sqrt{-\sqrt{\ell}} \cdot \sqrt{-\sqrt{\ell}}}} \]
      7. add-sqr-sqrt2.7%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-\sqrt{\ell}}} \]
      8. neg-mul-12.7%

        \[\leadsto \frac{1 \cdot \frac{d}{\sqrt{h}}}{\color{blue}{-1 \cdot \sqrt{\ell}}} \]
      9. times-frac2.7%

        \[\leadsto \color{blue}{\frac{1}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}} \]
      10. metadata-eval2.7%

        \[\leadsto \color{blue}{-1} \cdot \frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}} \]
      11. associate-/l/2.7%

        \[\leadsto -1 \cdot \color{blue}{\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      12. sqrt-prod33.7%

        \[\leadsto -1 \cdot \frac{d}{\color{blue}{\sqrt{\ell \cdot h}}} \]
      13. *-commutative33.7%

        \[\leadsto -1 \cdot \frac{d}{\sqrt{\color{blue}{h \cdot \ell}}} \]
    11. Applied egg-rr33.7%

      \[\leadsto \color{blue}{-1 \cdot \frac{d}{\sqrt{h \cdot \ell}}} \]
    12. Step-by-step derivation
      1. mul-1-neg33.7%

        \[\leadsto \color{blue}{-\frac{d}{\sqrt{h \cdot \ell}}} \]
      2. distribute-neg-frac33.7%

        \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]
    13. Simplified33.7%

      \[\leadsto \color{blue}{\frac{-d}{\sqrt{h \cdot \ell}}} \]

    if 2.5500000000000001e-224 < d

    1. Initial program 68.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. Simplified68.0%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 40.6%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. *-rgt-identity40.6%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
      2. pow1/240.6%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
      3. pow1/240.6%

        \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
      4. pow-prod-down36.3%

        \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    5. Applied egg-rr36.3%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
    6. Step-by-step derivation
      1. unpow1/236.3%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    7. Simplified36.3%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    8. Step-by-step derivation
      1. frac-times32.4%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
      2. sqrt-div37.5%

        \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
      3. sqrt-unprod48.1%

        \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
      4. add-sqr-sqrt48.3%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
    9. Applied egg-rr48.3%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification40.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq 2.55 \cdot 10^{-224}:\\ \;\;\;\;\frac{-d}{\sqrt{h \cdot \ell}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 24: 26.7% accurate, 3.2× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \frac{d}{\sqrt{h \cdot \ell}} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D) :precision binary64 (/ d (sqrt (* h l))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	return d / sqrt((h * l));
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
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 / sqrt((h * l))
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	return d / Math.sqrt((h * l));
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	return d / math.sqrt((h * l))
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	return Float64(d / sqrt(Float64(h * l)))
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp = code(d, h, l, M, D)
	tmp = d / sqrt((h * l));
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\frac{d}{\sqrt{h \cdot \ell}}
\end{array}
Derivation
  1. Initial program 65.7%

    \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
  2. Simplified65.2%

    \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(\frac{M}{\frac{-2}{D} \cdot d}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
  3. Taylor expanded in M around 0 34.6%

    \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
  4. Step-by-step derivation
    1. *-rgt-identity34.6%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}} \]
    2. pow1/234.6%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell}\right)}^{0.5}} \cdot \sqrt{\frac{d}{h}} \]
    3. pow1/234.6%

      \[\leadsto {\left(\frac{d}{\ell}\right)}^{0.5} \cdot \color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \]
    4. pow-prod-down30.6%

      \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
  5. Applied egg-rr30.6%

    \[\leadsto \color{blue}{{\left(\frac{d}{\ell} \cdot \frac{d}{h}\right)}^{0.5}} \]
  6. Step-by-step derivation
    1. unpow1/230.6%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
  7. Simplified30.6%

    \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
  8. Step-by-step derivation
    1. frac-times24.1%

      \[\leadsto \sqrt{\color{blue}{\frac{d \cdot d}{\ell \cdot h}}} \]
    2. sqrt-div26.7%

      \[\leadsto \color{blue}{\frac{\sqrt{d \cdot d}}{\sqrt{\ell \cdot h}}} \]
    3. sqrt-unprod22.9%

      \[\leadsto \frac{\color{blue}{\sqrt{d} \cdot \sqrt{d}}}{\sqrt{\ell \cdot h}} \]
    4. add-sqr-sqrt28.9%

      \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell \cdot h}} \]
  9. Applied egg-rr28.9%

    \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell \cdot h}}} \]
  10. Final simplification28.9%

    \[\leadsto \frac{d}{\sqrt{h \cdot \ell}} \]

Reproduce

?
herbie shell --seed 2023301 
(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)))))