Henrywood and Agarwal, Equation (12)

Percentage Accurate: 65.5% → 77.7%
Time: 22.5s
Alternatives: 16
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 65.5% 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: 77.7% accurate, 0.8× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{-d}\\ \mathbf{if}\;\ell \leq -1.62 \cdot 10^{+103}:\\ \;\;\;\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot \frac{t_0}{\sqrt{-\ell}}\right) \cdot \left(1 - \frac{h \cdot \left(0.5 \cdot {\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2}\right)}{\ell}\right)\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{-310}:\\ \;\;\;\;\frac{t_0}{\sqrt{-h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - 0.5 \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \mathsf{fma}\left({\left(\left(D \cdot -0.5\right) \cdot \frac{M}{d}\right)}^{2}, \frac{h}{\ell} \cdot -0.5, 1\right)\\ \end{array} \end{array} \]
NOTE: M 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))))
   (if (<= l -1.62e+103)
     (*
      (* (pow (/ d h) 0.5) (/ t_0 (sqrt (- l))))
      (- 1.0 (/ (* h (* 0.5 (pow (* (* 0.5 M) (/ D d)) 2.0))) l)))
     (if (<= l -4e-310)
       (*
        (/ t_0 (sqrt (- h)))
        (*
         (sqrt (/ d l))
         (- 1.0 (* 0.5 (* (pow (* (/ D d) (/ M 2.0)) 2.0) (/ h l))))))
       (*
        (/ d (* (sqrt h) (sqrt l)))
        (fma (pow (* (* D -0.5) (/ M d)) 2.0) (* (/ h l) -0.5) 1.0))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt(-d);
	double tmp;
	if (l <= -1.62e+103) {
		tmp = (pow((d / h), 0.5) * (t_0 / sqrt(-l))) * (1.0 - ((h * (0.5 * pow(((0.5 * M) * (D / d)), 2.0))) / l));
	} else if (l <= -4e-310) {
		tmp = (t_0 / sqrt(-h)) * (sqrt((d / l)) * (1.0 - (0.5 * (pow(((D / d) * (M / 2.0)), 2.0) * (h / l)))));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * fma(pow(((D * -0.5) * (M / d)), 2.0), ((h / l) * -0.5), 1.0);
	}
	return tmp;
}
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(-d))
	tmp = 0.0
	if (l <= -1.62e+103)
		tmp = Float64(Float64((Float64(d / h) ^ 0.5) * Float64(t_0 / sqrt(Float64(-l)))) * Float64(1.0 - Float64(Float64(h * Float64(0.5 * (Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0))) / l)));
	elseif (l <= -4e-310)
		tmp = Float64(Float64(t_0 / sqrt(Float64(-h))) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(0.5 * Float64((Float64(Float64(D / d) * Float64(M / 2.0)) ^ 2.0) * Float64(h / l))))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * fma((Float64(Float64(D * -0.5) * Float64(M / d)) ^ 2.0), Float64(Float64(h / l) * -0.5), 1.0));
	end
	return tmp
end
NOTE: M 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[(-d)], $MachinePrecision]}, If[LessEqual[l, -1.62e+103], N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[(t$95$0 / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h * N[(0.5 * N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -4e-310], N[(N[(t$95$0 / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(0.5 * N[(N[Power[N[(N[(D / d), $MachinePrecision] * N[(M / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[(N[(D * -0.5), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{-d}\\
\mathbf{if}\;\ell \leq -1.62 \cdot 10^{+103}:\\
\;\;\;\;\left({\left(\frac{d}{h}\right)}^{0.5} \cdot \frac{t_0}{\sqrt{-\ell}}\right) \cdot \left(1 - \frac{h \cdot \left(0.5 \cdot {\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2}\right)}{\ell}\right)\\

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

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


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

    1. Initial program 52.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. Step-by-step derivation
      1. associate-*r/55.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.62000000000000007e103 < l < -3.999999999999988e-310

    1. Initial program 59.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. Simplified59.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-2neg59.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-div78.4%

        \[\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-rr78.4%

      \[\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.999999999999988e-310 < l

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 78.4% accurate, 0.8× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4 \cdot 10^{-310}:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - 0.5 \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \mathsf{fma}\left({\left(\left(D \cdot -0.5\right) \cdot \frac{M}{d}\right)}^{2}, \frac{h}{\ell} \cdot -0.5, 1\right)\\ \end{array} \end{array} \]
NOTE: M 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 -4e-310)
   (*
    (/ (sqrt (- d)) (sqrt (- h)))
    (*
     (sqrt (/ d l))
     (- 1.0 (* 0.5 (* (pow (* (/ D d) (/ M 2.0)) 2.0) (/ h l))))))
   (*
    (/ d (* (sqrt h) (sqrt l)))
    (fma (pow (* (* D -0.5) (/ M d)) 2.0) (* (/ h l) -0.5) 1.0))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -4e-310) {
		tmp = (sqrt(-d) / sqrt(-h)) * (sqrt((d / l)) * (1.0 - (0.5 * (pow(((D / d) * (M / 2.0)), 2.0) * (h / l)))));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * fma(pow(((D * -0.5) * (M / d)), 2.0), ((h / l) * -0.5), 1.0);
	}
	return tmp;
}
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= -4e-310)
		tmp = Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(0.5 * Float64((Float64(Float64(D / d) * Float64(M / 2.0)) ^ 2.0) * Float64(h / l))))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * fma((Float64(Float64(D * -0.5) * Float64(M / d)) ^ 2.0), Float64(Float64(h / l) * -0.5), 1.0));
	end
	return tmp
end
NOTE: M 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, -4e-310], N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(0.5 * N[(N[Power[N[(N[(D / d), $MachinePrecision] * N[(M / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[(N[(D * -0.5), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - 0.5 \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right)\\

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


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

    1. Initial program 57.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. Simplified58.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. frac-2neg58.0%

        \[\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-div72.4%

        \[\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-rr72.4%

      \[\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.999999999999988e-310 < l

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

Alternative 3: 72.0% accurate, 0.8× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -1.4 \cdot 10^{+244}:\\ \;\;\;\;d \cdot \sqrt{\frac{\sqrt[3]{{\ell}^{-2}}}{h \cdot \sqrt[3]{\ell}}}\\ \mathbf{elif}\;h \leq 3.4 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left({\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot -0.5\right)}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \mathsf{fma}\left({\left(\left(D \cdot -0.5\right) \cdot \frac{M}{d}\right)}^{2}, \frac{h}{\ell} \cdot -0.5, 1\right)\\ \end{array} \end{array} \]
NOTE: M 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 -1.4e+244)
   (* d (sqrt (/ (cbrt (pow l -2.0)) (* h (cbrt l)))))
   (if (<= h 3.4e-297)
     (*
      (sqrt (/ d l))
      (*
       (sqrt (/ d h))
       (+ 1.0 (/ (* h (* (pow (* (* 0.5 M) (/ D d)) 2.0) -0.5)) l))))
     (*
      (/ d (* (sqrt h) (sqrt l)))
      (fma (pow (* (* D -0.5) (/ M d)) 2.0) (* (/ h l) -0.5) 1.0)))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -1.4e+244) {
		tmp = d * sqrt((cbrt(pow(l, -2.0)) / (h * cbrt(l))));
	} else if (h <= 3.4e-297) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h * (pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * fma(pow(((D * -0.5) * (M / d)), 2.0), ((h / l) * -0.5), 1.0);
	}
	return tmp;
}
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (h <= -1.4e+244)
		tmp = Float64(d * sqrt(Float64(cbrt((l ^ -2.0)) / Float64(h * cbrt(l)))));
	elseif (h <= 3.4e-297)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h * Float64((Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0) * -0.5)) / l))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * fma((Float64(Float64(D * -0.5) * Float64(M / d)) ^ 2.0), Float64(Float64(h / l) * -0.5), 1.0));
	end
	return tmp
end
NOTE: M 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, -1.4e+244], N[(d * N[Sqrt[N[(N[Power[N[Power[l, -2.0], $MachinePrecision], 1/3], $MachinePrecision] / N[(h * N[Power[l, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3.4e-297], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h * N[(N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[(N[(D * -0.5), $MachinePrecision] * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -1.4 \cdot 10^{+244}:\\
\;\;\;\;d \cdot \sqrt{\frac{\sqrt[3]{{\ell}^{-2}}}{h \cdot \sqrt[3]{\ell}}}\\

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

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


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

    1. Initial program 20.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. Simplified20.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.39999999999999995e244 < h < 3.39999999999999983e-297

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

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

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

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

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

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

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

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

    if 3.39999999999999983e-297 < h

    1. Initial program 71.2%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -1.4 \cdot 10^{+244}:\\ \;\;\;\;d \cdot \sqrt{\frac{\sqrt[3]{{\ell}^{-2}}}{h \cdot \sqrt[3]{\ell}}}\\ \mathbf{elif}\;h \leq 3.4 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left({\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot -0.5\right)}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \mathsf{fma}\left({\left(\left(D \cdot -0.5\right) \cdot \frac{M}{d}\right)}^{2}, \frac{h}{\ell} \cdot -0.5, 1\right)\\ \end{array} \]

Alternative 4: 71.9% accurate, 0.8× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -1.85 \cdot 10^{+245}:\\ \;\;\;\;d \cdot \sqrt{\frac{\sqrt[3]{{\ell}^{-2}}}{h \cdot \sqrt[3]{\ell}}}\\ \mathbf{elif}\;h \leq 3.4 \cdot 10^{-297}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left({\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot -0.5\right)}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 -1.85e+245)
   (* d (sqrt (/ (cbrt (pow l -2.0)) (* h (cbrt l)))))
   (if (<= h 3.4e-297)
     (*
      (sqrt (/ d l))
      (*
       (sqrt (/ d h))
       (+ 1.0 (/ (* h (* (pow (* (* 0.5 M) (/ D d)) 2.0) -0.5)) l))))
     (*
      (/ d (* (sqrt h) (sqrt l)))
      (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0)))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -1.85e+245) {
		tmp = d * sqrt((cbrt(pow(l, -2.0)) / (h * cbrt(l))));
	} else if (h <= 3.4e-297) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h * (pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (h <= -1.85e+245) {
		tmp = d * Math.sqrt((Math.cbrt(Math.pow(l, -2.0)) / (h * Math.cbrt(l))));
	} else if (h <= 3.4e-297) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + ((h * (Math.pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (h <= -1.85e+245)
		tmp = Float64(d * sqrt(Float64(cbrt((l ^ -2.0)) / Float64(h * cbrt(l)))));
	elseif (h <= 3.4e-297)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h * Float64((Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0) * -0.5)) / l))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
NOTE: M 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, -1.85e+245], N[(d * N[Sqrt[N[(N[Power[N[Power[l, -2.0], $MachinePrecision], 1/3], $MachinePrecision] / N[(h * N[Power[l, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 3.4e-297], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h * N[(N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -1.85 \cdot 10^{+245}:\\
\;\;\;\;d \cdot \sqrt{\frac{\sqrt[3]{{\ell}^{-2}}}{h \cdot \sqrt[3]{\ell}}}\\

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

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


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

    1. Initial program 20.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. Simplified20.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.85e245 < h < 3.39999999999999983e-297

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

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

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

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

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

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

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

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

    if 3.39999999999999983e-297 < h

    1. Initial program 71.2%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Step-by-step derivation
      1. expm1-log1p-u38.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 65.6% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -1.1 \cdot 10^{+235}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;d \leq -1.42 \cdot 10^{-139}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}} \cdot \left(1 + \frac{{\left(D \cdot \frac{M}{\frac{d}{0.5}}\right)}^{2}}{\ell} \cdot \left(h \cdot -0.5\right)\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt{\log \left(e^{\frac{1}{\ell \cdot h}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 -1.1e+235)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (if (<= d -1.42e-139)
     (*
      (sqrt (/ (pow d 2.0) (* l h)))
      (+ 1.0 (* (/ (pow (* D (/ M (/ d 0.5))) 2.0) l) (* h -0.5))))
     (if (<= d -5e-310)
       (* d (sqrt (log (exp (/ 1.0 (* l h))))))
       (*
        (/ d (* (sqrt h) (sqrt l)))
        (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0))))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -1.1e+235) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (d <= -1.42e-139) {
		tmp = sqrt((pow(d, 2.0) / (l * h))) * (1.0 + ((pow((D * (M / (d / 0.5))), 2.0) / l) * (h * -0.5)));
	} else if (d <= -5e-310) {
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 <= (-1.1d+235)) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else if (d <= (-1.42d-139)) then
        tmp = sqrt(((d ** 2.0d0) / (l * h))) * (1.0d0 + ((((d_1 * (m / (d / 0.5d0))) ** 2.0d0) / l) * (h * (-0.5d0))))
    else if (d <= (-5d-310)) then
        tmp = d * sqrt(log(exp((1.0d0 / (l * h)))))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -1.1e+235) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (d <= -1.42e-139) {
		tmp = Math.sqrt((Math.pow(d, 2.0) / (l * h))) * (1.0 + ((Math.pow((D * (M / (d / 0.5))), 2.0) / l) * (h * -0.5)));
	} else if (d <= -5e-310) {
		tmp = d * Math.sqrt(Math.log(Math.exp((1.0 / (l * h)))));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -1.1e+235:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif d <= -1.42e-139:
		tmp = math.sqrt((math.pow(d, 2.0) / (l * h))) * (1.0 + ((math.pow((D * (M / (d / 0.5))), 2.0) / l) * (h * -0.5)))
	elif d <= -5e-310:
		tmp = d * math.sqrt(math.log(math.exp((1.0 / (l * h)))))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -1.1e+235)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (d <= -1.42e-139)
		tmp = Float64(sqrt(Float64((d ^ 2.0) / Float64(l * h))) * Float64(1.0 + Float64(Float64((Float64(D * Float64(M / Float64(d / 0.5))) ^ 2.0) / l) * Float64(h * -0.5))));
	elseif (d <= -5e-310)
		tmp = Float64(d * sqrt(log(exp(Float64(1.0 / Float64(l * h))))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -1.1e+235)
		tmp = sqrt((d / l)) * sqrt((d / h));
	elseif (d <= -1.42e-139)
		tmp = sqrt(((d ^ 2.0) / (l * h))) * (1.0 + ((((D * (M / (d / 0.5))) ^ 2.0) / l) * (h * -0.5)));
	elseif (d <= -5e-310)
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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, -1.1e+235], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.42e-139], N[(N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(N[Power[N[(D * N[(M / N[(d / 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / l), $MachinePrecision] * N[(h * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -5e-310], N[(d * N[Sqrt[N[Log[N[Exp[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.1 \cdot 10^{+235}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.1e235

    1. Initial program 84.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. Simplified92.2%

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

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

    if -1.1e235 < d < -1.41999999999999997e-139

    1. Initial program 59.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. Step-by-step derivation
      1. associate-*r/64.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.41999999999999997e-139 < d < -4.999999999999985e-310

    1. Initial program 46.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. Simplified46.8%

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < d

    1. Initial program 71.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. Step-by-step derivation
      1. expm1-log1p-u38.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 72.6% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 4.5 \cdot 10^{-201}:\\ \;\;\;\;\left(1 - \frac{h \cdot \left(0.5 \cdot {\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2}\right)}{\ell}\right) \cdot \left({\left(\frac{d}{h}\right)}^{0.5} \cdot \sqrt{\frac{d}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 4.5e-201)
   (*
    (- 1.0 (/ (* h (* 0.5 (pow (* (* 0.5 M) (/ D d)) 2.0))) l))
    (* (pow (/ d h) 0.5) (sqrt (/ d l))))
   (*
    (/ d (* (sqrt h) (sqrt l)))
    (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 4.5e-201) {
		tmp = (1.0 - ((h * (0.5 * pow(((0.5 * M) * (D / d)), 2.0))) / l)) * (pow((d / h), 0.5) * sqrt((d / l)));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 (l <= 4.5d-201) then
        tmp = (1.0d0 - ((h * (0.5d0 * (((0.5d0 * m) * (d_1 / d)) ** 2.0d0))) / l)) * (((d / h) ** 0.5d0) * sqrt((d / l)))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 4.5e-201) {
		tmp = (1.0 - ((h * (0.5 * Math.pow(((0.5 * M) * (D / d)), 2.0))) / l)) * (Math.pow((d / h), 0.5) * Math.sqrt((d / l)));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= 4.5e-201:
		tmp = (1.0 - ((h * (0.5 * math.pow(((0.5 * M) * (D / d)), 2.0))) / l)) * (math.pow((d / h), 0.5) * math.sqrt((d / l)))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= 4.5e-201)
		tmp = Float64(Float64(1.0 - Float64(Float64(h * Float64(0.5 * (Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0))) / l)) * Float64((Float64(d / h) ^ 0.5) * sqrt(Float64(d / l))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= 4.5e-201)
		tmp = (1.0 - ((h * (0.5 * (((0.5 * M) * (D / d)) ^ 2.0))) / l)) * (((d / h) ^ 0.5) * sqrt((d / l)));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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, 4.5e-201], N[(N[(1.0 - N[(N[(h * N[(0.5 * N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 4.5 \cdot 10^{-201}:\\
\;\;\;\;\left(1 - \frac{h \cdot \left(0.5 \cdot {\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2}\right)}{\ell}\right) \cdot \left({\left(\frac{d}{h}\right)}^{0.5} \cdot \sqrt{\frac{d}{\ell}}\right)\\

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


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

    1. Initial program 61.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. Step-by-step derivation
      1. associate-*r/64.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \color{blue}{{\left({\left(\frac{d}{\ell}\right)}^{1.5}\right)}^{0.3333333333333333}}\right) \cdot \left(1 - \frac{\left({\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right) \cdot h}{\ell}\right) \]
      4. pow1/355.7%

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

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

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

        \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{{\left({\left(\frac{d}{\ell}\right)}^{1.5}\right)}^{0.3333333333333333}}\right)} - 1\right)\right) \cdot \left(1 - \frac{\left({\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right) \cdot h}{\ell}\right) \]
      8. pow-pow45.4%

        \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{{\left(\frac{d}{\ell}\right)}^{\left(1.5 \cdot 0.3333333333333333\right)}}\right)} - 1\right)\right) \cdot \left(1 - \frac{\left({\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right) \cdot h}{\ell}\right) \]
      9. metadata-eval45.4%

        \[\leadsto \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot \left(e^{\mathsf{log1p}\left({\left(\frac{d}{\ell}\right)}^{\color{blue}{0.5}}\right)} - 1\right)\right) \cdot \left(1 - \frac{\left({\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right) \cdot h}{\ell}\right) \]
      10. unpow1/245.4%

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

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

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

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

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

    if 4.5000000000000002e-201 < l

    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. Step-by-step derivation
      1. expm1-log1p-u39.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 61.2% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.5 \cdot 10^{-166}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt{\log \left(e^{\frac{1}{\ell \cdot h}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 -3.5e-166)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (if (<= l -4e-310)
     (* d (sqrt (log (exp (/ 1.0 (* l h))))))
     (*
      (/ d (* (sqrt h) (sqrt l)))
      (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0)))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -3.5e-166) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (l <= -4e-310) {
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 (l <= (-3.5d-166)) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else if (l <= (-4d-310)) then
        tmp = d * sqrt(log(exp((1.0d0 / (l * h)))))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -3.5e-166) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (l <= -4e-310) {
		tmp = d * Math.sqrt(Math.log(Math.exp((1.0 / (l * h)))));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= -3.5e-166:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif l <= -4e-310:
		tmp = d * math.sqrt(math.log(math.exp((1.0 / (l * h)))))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= -3.5e-166)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (l <= -4e-310)
		tmp = Float64(d * sqrt(log(exp(Float64(1.0 / Float64(l * h))))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= -3.5e-166)
		tmp = sqrt((d / l)) * sqrt((d / h));
	elseif (l <= -4e-310)
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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, -3.5e-166], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -4e-310], N[(d * N[Sqrt[N[Log[N[Exp[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.5 \cdot 10^{-166}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

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

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


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

    1. Initial program 56.6%

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

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

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

    if -3.4999999999999999e-166 < l < -3.999999999999988e-310

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

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

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

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

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

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

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

        \[\leadsto d \cdot \sqrt{\log \left(e^{\color{blue}{\frac{1}{h \cdot \ell}}}\right)} \]
    7. Applied egg-rr41.3%

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

    if -3.999999999999988e-310 < l

    1. Initial program 71.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. Step-by-step derivation
      1. expm1-log1p-u38.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 72.3% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 3.5 \cdot 10^{-307}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - 0.5 \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 3.5e-307)
   (*
    (*
     (sqrt (/ d l))
     (- 1.0 (* 0.5 (* (pow (* (/ D d) (/ M 2.0)) 2.0) (/ h l)))))
    (sqrt (/ d h)))
   (*
    (/ d (* (sqrt h) (sqrt l)))
    (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.5e-307) {
		tmp = (sqrt((d / l)) * (1.0 - (0.5 * (pow(((D / d) * (M / 2.0)), 2.0) * (h / l))))) * sqrt((d / h));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 (l <= 3.5d-307) then
        tmp = (sqrt((d / l)) * (1.0d0 - (0.5d0 * ((((d_1 / d) * (m / 2.0d0)) ** 2.0d0) * (h / l))))) * sqrt((d / h))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.5e-307) {
		tmp = (Math.sqrt((d / l)) * (1.0 - (0.5 * (Math.pow(((D / d) * (M / 2.0)), 2.0) * (h / l))))) * Math.sqrt((d / h));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= 3.5e-307:
		tmp = (math.sqrt((d / l)) * (1.0 - (0.5 * (math.pow(((D / d) * (M / 2.0)), 2.0) * (h / l))))) * math.sqrt((d / h))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= 3.5e-307)
		tmp = Float64(Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(0.5 * Float64((Float64(Float64(D / d) * Float64(M / 2.0)) ^ 2.0) * Float64(h / l))))) * sqrt(Float64(d / h)));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= 3.5e-307)
		tmp = (sqrt((d / l)) * (1.0 - (0.5 * ((((D / d) * (M / 2.0)) ^ 2.0) * (h / l))))) * sqrt((d / h));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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, 3.5e-307], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(0.5 * N[(N[Power[N[(N[(D / d), $MachinePrecision] * N[(M / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3.5 \cdot 10^{-307}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - 0.5 \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{h}}\\

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


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

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

      \[\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 3.5000000000000002e-307 < l

    1. Initial program 71.2%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Step-by-step derivation
      1. expm1-log1p-u38.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 72.3% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 3.1 \cdot 10^{-307}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot -0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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 3.1e-307)
   (*
    (sqrt (/ d l))
    (*
     (sqrt (/ d h))
     (+ 1.0 (* (/ h l) (* (pow (* (/ D d) (/ M 2.0)) 2.0) -0.5)))))
   (*
    (/ d (* (sqrt h) (sqrt l)))
    (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.1e-307) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (pow(((D / d) * (M / 2.0)), 2.0) * -0.5))));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 (l <= 3.1d-307) then
        tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0d0 + ((h / l) * ((((d_1 / d) * (m / 2.0d0)) ** 2.0d0) * (-0.5d0)))))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.1e-307) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + ((h / l) * (Math.pow(((D / d) * (M / 2.0)), 2.0) * -0.5))));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= 3.1e-307:
		tmp = math.sqrt((d / l)) * (math.sqrt((d / h)) * (1.0 + ((h / l) * (math.pow(((D / d) * (M / 2.0)), 2.0) * -0.5))))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= 3.1e-307)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(Float64(D / d) * Float64(M / 2.0)) ^ 2.0) * -0.5)))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= 3.1e-307)
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * ((((D / d) * (M / 2.0)) ^ 2.0) * -0.5))));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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, 3.1e-307], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(N[(D / d), $MachinePrecision] * N[(M / 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3.1 \cdot 10^{-307}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(\frac{D}{d} \cdot \frac{M}{2}\right)}^{2} \cdot -0.5\right)\right)\right)\\

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


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

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

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

    if 3.0999999999999998e-307 < l

    1. Initial program 71.2%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Step-by-step derivation
      1. expm1-log1p-u38.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 72.6% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 2.1 \cdot 10^{-202}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left({\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot -0.5\right)}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)\\ \end{array} \end{array} \]
NOTE: M 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.1e-202)
   (*
    (sqrt (/ d l))
    (*
     (sqrt (/ d h))
     (+ 1.0 (/ (* h (* (pow (* (* 0.5 M) (/ D d)) 2.0) -0.5)) l))))
   (*
    (/ d (* (sqrt h) (sqrt l)))
    (+ 1.0 (* (* (/ h l) -0.5) (pow (* M (* 0.5 (/ D d))) 2.0))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 2.1e-202) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h * (pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)));
	} else {
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
NOTE: M 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 (l <= 2.1d-202) then
        tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0d0 + ((h * ((((0.5d0 * m) * (d_1 / d)) ** 2.0d0) * (-0.5d0))) / l)))
    else
        tmp = (d / (sqrt(h) * sqrt(l))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((m * (0.5d0 * (d_1 / d))) ** 2.0d0)))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 2.1e-202) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + ((h * (Math.pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)));
	} else {
		tmp = (d / (Math.sqrt(h) * Math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * Math.pow((M * (0.5 * (D / d))), 2.0)));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= 2.1e-202:
		tmp = math.sqrt((d / l)) * (math.sqrt((d / h)) * (1.0 + ((h * (math.pow(((0.5 * M) * (D / d)), 2.0) * -0.5)) / l)))
	else:
		tmp = (d / (math.sqrt(h) * math.sqrt(l))) * (1.0 + (((h / l) * -0.5) * math.pow((M * (0.5 * (D / d))), 2.0)))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= 2.1e-202)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h * Float64((Float64(Float64(0.5 * M) * Float64(D / d)) ^ 2.0) * -0.5)) / l))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(h) * sqrt(l))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(M * Float64(0.5 * Float64(D / d))) ^ 2.0))));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= 2.1e-202)
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h * ((((0.5 * M) * (D / d)) ^ 2.0) * -0.5)) / l)));
	else
		tmp = (d / (sqrt(h) * sqrt(l))) * (1.0 + (((h / l) * -0.5) * ((M * (0.5 * (D / d))) ^ 2.0)));
	end
	tmp_2 = tmp;
end
NOTE: M 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.1e-202], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h * N[(N[Power[N[(N[(0.5 * M), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[h], $MachinePrecision] * N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(M * N[(0.5 * N[(D / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 2.1 \cdot 10^{-202}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left({\left(\left(0.5 \cdot M\right) \cdot \frac{D}{d}\right)}^{2} \cdot -0.5\right)}{\ell}\right)\right)\\

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


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

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

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

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

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

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

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

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

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

    if 2.09999999999999985e-202 < l

    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. Step-by-step derivation
      1. expm1-log1p-u39.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 46.9% accurate, 1.1× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{-165}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt{\log \left(e^{\frac{1}{\ell \cdot h}}\right)}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M 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 -4.5e-165)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (if (<= l -4e-310)
     (* d (sqrt (log (exp (/ 1.0 (* l h))))))
     (* d (/ (pow l -0.5) (sqrt h))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -4.5e-165) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (l <= -4e-310) {
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	} else {
		tmp = d * (pow(l, -0.5) / sqrt(h));
	}
	return tmp;
}
NOTE: M 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 (l <= (-4.5d-165)) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else if (l <= (-4d-310)) then
        tmp = d * sqrt(log(exp((1.0d0 / (l * h)))))
    else
        tmp = d * ((l ** (-0.5d0)) / sqrt(h))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= -4.5e-165) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (l <= -4e-310) {
		tmp = d * Math.sqrt(Math.log(Math.exp((1.0 / (l * h)))));
	} else {
		tmp = d * (Math.pow(l, -0.5) / Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= -4.5e-165:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif l <= -4e-310:
		tmp = d * math.sqrt(math.log(math.exp((1.0 / (l * h)))))
	else:
		tmp = d * (math.pow(l, -0.5) / math.sqrt(h))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= -4.5e-165)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (l <= -4e-310)
		tmp = Float64(d * sqrt(log(exp(Float64(1.0 / Float64(l * h))))));
	else
		tmp = Float64(d * Float64((l ^ -0.5) / sqrt(h)));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= -4.5e-165)
		tmp = sqrt((d / l)) * sqrt((d / h));
	elseif (l <= -4e-310)
		tmp = d * sqrt(log(exp((1.0 / (l * h)))));
	else
		tmp = d * ((l ^ -0.5) / sqrt(h));
	end
	tmp_2 = tmp;
end
NOTE: M 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, -4.5e-165], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -4e-310], N[(d * N[Sqrt[N[Log[N[Exp[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.5 \cdot 10^{-165}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

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

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


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

    1. Initial program 56.6%

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

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

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

    if -4.49999999999999992e-165 < l < -3.999999999999988e-310

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

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

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

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

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

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

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

        \[\leadsto d \cdot \sqrt{\log \left(e^{\color{blue}{\frac{1}{h \cdot \ell}}}\right)} \]
    7. Applied egg-rr41.3%

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

    if -3.999999999999988e-310 < l

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{-165}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -4 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt{\log \left(e^{\frac{1}{\ell \cdot h}}\right)}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \]

Alternative 12: 39.4% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{\left(\frac{1}{\ell \cdot h}\right)}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M 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 -2.7e-97)
   (sqrt (/ (pow d 2.0) (* l h)))
   (if (<= d -5e-310)
     (* d (cbrt (pow (/ 1.0 (* l h)) 1.5)))
     (* d (/ (pow l -0.5) (sqrt h))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.7e-97) {
		tmp = sqrt((pow(d, 2.0) / (l * h)));
	} else if (d <= -5e-310) {
		tmp = d * cbrt(pow((1.0 / (l * h)), 1.5));
	} else {
		tmp = d * (pow(l, -0.5) / sqrt(h));
	}
	return tmp;
}
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.7e-97) {
		tmp = Math.sqrt((Math.pow(d, 2.0) / (l * h)));
	} else if (d <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow((1.0 / (l * h)), 1.5));
	} else {
		tmp = d * (Math.pow(l, -0.5) / Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -2.7e-97)
		tmp = sqrt(Float64((d ^ 2.0) / Float64(l * h)));
	elseif (d <= -5e-310)
		tmp = Float64(d * cbrt((Float64(1.0 / Float64(l * h)) ^ 1.5)));
	else
		tmp = Float64(d * Float64((l ^ -0.5) / sqrt(h)));
	end
	return tmp
end
NOTE: M 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, -2.7e-97], N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[d, -5e-310], N[(d * N[Power[N[Power[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\

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

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.69999999999999985e-97 < d < -4.999999999999985e-310

    1. Initial program 46.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. Simplified46.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot {\left({\left(\frac{\frac{1}{\ell}}{h}\right)}^{1} \cdot \color{blue}{{\left(\frac{\frac{1}{\ell}}{h}\right)}^{0.5}}\right)}^{0.3333333333333333} \]
      6. metadata-eval21.0%

        \[\leadsto d \cdot {\left({\left(\frac{\frac{1}{\ell}}{h}\right)}^{1} \cdot {\left(\frac{\frac{1}{\ell}}{h}\right)}^{\color{blue}{\left(\frac{1}{2}\right)}}\right)}^{0.3333333333333333} \]
      7. pow-prod-up21.0%

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

        \[\leadsto d \cdot {\left({\color{blue}{\left(\frac{1}{h \cdot \ell}\right)}}^{\left(1 + \frac{1}{2}\right)}\right)}^{0.3333333333333333} \]
      9. metadata-eval21.0%

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

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

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

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

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

    if -4.999999999999985e-310 < d

    1. Initial program 71.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 38.2% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-154}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M 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 -2.05e-97)
   (sqrt (/ (pow d 2.0) (* l h)))
   (if (<= d 1.7e-154)
     (* d (sqrt (/ 1.0 (* l h))))
     (* d (/ (pow l -0.5) (sqrt h))))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.05e-97) {
		tmp = sqrt((pow(d, 2.0) / (l * h)));
	} else if (d <= 1.7e-154) {
		tmp = d * sqrt((1.0 / (l * h)));
	} else {
		tmp = d * (pow(l, -0.5) / sqrt(h));
	}
	return tmp;
}
NOTE: M 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 <= (-2.05d-97)) then
        tmp = sqrt(((d ** 2.0d0) / (l * h)))
    else if (d <= 1.7d-154) then
        tmp = d * sqrt((1.0d0 / (l * h)))
    else
        tmp = d * ((l ** (-0.5d0)) / sqrt(h))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.05e-97) {
		tmp = Math.sqrt((Math.pow(d, 2.0) / (l * h)));
	} else if (d <= 1.7e-154) {
		tmp = d * Math.sqrt((1.0 / (l * h)));
	} else {
		tmp = d * (Math.pow(l, -0.5) / Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -2.05e-97:
		tmp = math.sqrt((math.pow(d, 2.0) / (l * h)))
	elif d <= 1.7e-154:
		tmp = d * math.sqrt((1.0 / (l * h)))
	else:
		tmp = d * (math.pow(l, -0.5) / math.sqrt(h))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -2.05e-97)
		tmp = sqrt(Float64((d ^ 2.0) / Float64(l * h)));
	elseif (d <= 1.7e-154)
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(l * h))));
	else
		tmp = Float64(d * Float64((l ^ -0.5) / sqrt(h)));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -2.05e-97)
		tmp = sqrt(((d ^ 2.0) / (l * h)));
	elseif (d <= 1.7e-154)
		tmp = d * sqrt((1.0 / (l * h)));
	else
		tmp = d * ((l ^ -0.5) / sqrt(h));
	end
	tmp_2 = tmp;
end
NOTE: M 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, -2.05e-97], N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[d, 1.7e-154], N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\

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

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.04999999999999996e-97 < d < 1.6999999999999999e-154

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

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

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

    if 1.6999999999999999e-154 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\ \mathbf{elif}\;d \leq 1.7 \cdot 10^{-154}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \]

Alternative 14: 45.1% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 3.1 \cdot 10^{-307}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \end{array} \]
NOTE: M 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 3.1e-307)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (* d (/ (pow l -0.5) (sqrt h)))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.1e-307) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else {
		tmp = d * (pow(l, -0.5) / sqrt(h));
	}
	return tmp;
}
NOTE: M 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 (l <= 3.1d-307) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else
        tmp = d * ((l ** (-0.5d0)) / sqrt(h))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (l <= 3.1e-307) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else {
		tmp = d * (Math.pow(l, -0.5) / Math.sqrt(h));
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if l <= 3.1e-307:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	else:
		tmp = d * (math.pow(l, -0.5) / math.sqrt(h))
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (l <= 3.1e-307)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	else
		tmp = Float64(d * Float64((l ^ -0.5) / sqrt(h)));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (l <= 3.1e-307)
		tmp = sqrt((d / l)) * sqrt((d / h));
	else
		tmp = d * ((l ^ -0.5) / sqrt(h));
	end
	tmp_2 = tmp;
end
NOTE: M 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, 3.1e-307], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 3.1 \cdot 10^{-307}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

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


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

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

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

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

    if 3.0999999999999998e-307 < l

    1. Initial program 71.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 3.1 \cdot 10^{-307}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{{\ell}^{-0.5}}{\sqrt{h}}\\ \end{array} \]

Alternative 15: 34.6% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \end{array} \]
NOTE: M 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 -2.05e-97) (sqrt (/ (pow d 2.0) (* l h))) (* d (pow (* l h) -0.5))))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.05e-97) {
		tmp = sqrt((pow(d, 2.0) / (l * h)));
	} else {
		tmp = d * pow((l * h), -0.5);
	}
	return tmp;
}
NOTE: M 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 <= (-2.05d-97)) then
        tmp = sqrt(((d ** 2.0d0) / (l * h)))
    else
        tmp = d * ((l * h) ** (-0.5d0))
    end if
    code = tmp
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.05e-97) {
		tmp = Math.sqrt((Math.pow(d, 2.0) / (l * h)));
	} else {
		tmp = d * Math.pow((l * h), -0.5);
	}
	return tmp;
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -2.05e-97:
		tmp = math.sqrt((math.pow(d, 2.0) / (l * h)))
	else:
		tmp = d * math.pow((l * h), -0.5)
	return tmp
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -2.05e-97)
		tmp = sqrt(Float64((d ^ 2.0) / Float64(l * h)));
	else
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	end
	return tmp
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -2.05e-97)
		tmp = sqrt(((d ^ 2.0) / (l * h)));
	else
		tmp = d * ((l * h) ^ -0.5);
	end
	tmp_2 = tmp;
end
NOTE: M 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, -2.05e-97], N[Sqrt[N[(N[Power[d, 2.0], $MachinePrecision] / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\

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


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

    1. Initial program 66.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.04999999999999996e-97 < d

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \]
      5. sqr-pow33.4%

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

        \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right)} \]
      7. sqr-pow33.5%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -2.05 \cdot 10^{-97}:\\ \;\;\;\;\sqrt{\frac{{d}^{2}}{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]

Alternative 16: 26.4% accurate, 3.1× speedup?

\[\begin{array}{l} M = |M|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ d \cdot {\left(\ell \cdot h\right)}^{-0.5} \end{array} \]
NOTE: M 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 (pow (* l h) -0.5)))
M = abs(M);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	return d * pow((l * h), -0.5);
}
NOTE: M 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 * ((l * h) ** (-0.5d0))
end function
M = Math.abs(M);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	return d * Math.pow((l * h), -0.5);
}
M = abs(M)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	return d * math.pow((l * h), -0.5)
M = abs(M)
M, D = sort([M, D])
function code(d, h, l, M, D)
	return Float64(d * (Float64(l * h) ^ -0.5))
end
M = abs(M)
M, D = num2cell(sort([M, D])){:}
function tmp = code(d, h, l, M, D)
	tmp = d * ((l * h) ^ -0.5);
end
NOTE: M 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[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
d \cdot {\left(\ell \cdot h\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 65.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. Step-by-step derivation
    1. associate-*r/65.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d \cdot \left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \]
    5. sqr-pow26.4%

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

      \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right)} \]
    7. sqr-pow26.4%

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

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

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

Reproduce

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