Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.0% → 82.7%
Time: 23.9s
Alternatives: 19
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 alternatives:

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

Initial Program: 66.0% accurate, 1.0× speedup?

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

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

Alternative 1: 82.7% accurate, 0.8× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.75000000000000009e86 < h < -1.999999999999994e-310

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < h

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

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

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

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

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

Alternative 2: 82.7% accurate, 0.8× speedup?

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

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

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


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

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

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

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

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

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

    if -1.4999999999999999e-75 < l < -3.999999999999988e-310

    1. Initial program 72.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      5. distribute-lft-neg-out87.7%

        \[\leadsto \left(e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      6. distribute-rgt-neg-in87.7%

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

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

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

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

    if -3.999999999999988e-310 < l

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

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

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

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

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

Alternative 3: 81.2% accurate, 0.8× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.5999999999999998e-205 < d < -1.999999999999994e-310

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d

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

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

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

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

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

Alternative 4: 79.7% accurate, 1.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6e-205 < d < 1.89999999999999993e-307

    1. Initial program 25.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. Simplified25.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.89999999999999993e-307 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 77.8% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq 7.6 \cdot 10^{-117}:\\
\;\;\;\;\left(1 - t\_1\right) \cdot \left(d \cdot {\left(h \cdot \ell\right)}^{-0.5}\right)\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.999999999999988e-310 < l < 7.59999999999999945e-117

    1. Initial program 72.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(-e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}}\right) \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      10. distribute-rgt-neg-in93.2%

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

        \[\leadsto \left(\left(-e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}}\right) \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      12. exp-to-pow94.6%

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

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

    if 7.59999999999999945e-117 < l

    1. Initial program 57.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. Simplified56.5%

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

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

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

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

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

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

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

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

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

Alternative 6: 76.1% accurate, 1.0× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.999999999999988e-310 < l < 1.1200000000000001e236

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.1200000000000001e236 < l

    1. Initial program 36.6%

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

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 46.9%

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod43.5%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out43.5%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in43.5%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval43.5%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow46.8%

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

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

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

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

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

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

Alternative 7: 75.9% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.999999999999988e-310 < l < 2.10000000000000006e236

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.10000000000000006e236 < l

    1. Initial program 36.6%

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

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 46.9%

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod43.5%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out43.5%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in43.5%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval43.5%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow46.8%

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

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

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

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

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

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

Alternative 8: 75.8% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      5. distribute-lft-neg-out73.6%

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

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

        \[\leadsto \left(e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \cdot \left(-d\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{{\left(\frac{D}{\frac{d \cdot 2}{M}}\right)}^{2}}{\ell} \cdot h\right)\right) \]
      8. exp-to-pow76.0%

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

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

    if -3.999999999999988e-310 < l < 2.75e236

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.75e236 < l

    1. Initial program 36.6%

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

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 46.9%

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod43.5%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out43.5%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in43.5%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval43.5%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow46.8%

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

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

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

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

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

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

Alternative 9: 72.9% accurate, 1.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(d \cdot \left(-{\left(\frac{1}{\color{blue}{e^{\log \left(\ell \cdot h\right)}}}\right)}^{0.5}\right)\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \]
      9. exp-neg70.0%

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

        \[\leadsto \left(d \cdot \left(-\color{blue}{e^{\left(-\log \left(\ell \cdot h\right)\right) \cdot 0.5}}\right)\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \]
      11. distribute-lft-neg-out70.0%

        \[\leadsto \left(d \cdot \left(-e^{\color{blue}{-\log \left(\ell \cdot h\right) \cdot 0.5}}\right)\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \]
      12. distribute-rgt-neg-in70.0%

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

        \[\leadsto \left(d \cdot \left(-e^{\log \left(\ell \cdot h\right) \cdot \color{blue}{-0.5}}\right)\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \]
      14. exp-to-pow72.1%

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

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

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

    if -3.999999999999988e-310 < l < 1.45e236

    1. Initial program 66.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.45e236 < l

    1. Initial program 36.6%

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

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 46.9%

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod43.5%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out43.5%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in43.5%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval43.5%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow46.8%

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

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

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

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

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

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

Alternative 10: 63.0% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 81.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.10000000000000003e-42 < d < -1.999999999999994e-310

    1. Initial program 46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 63.2% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 81.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.10000000000000003e-42 < d < -1.999999999999994e-310

    1. Initial program 46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 51.2% accurate, 1.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -5.8 \cdot 10^{-49}:\\ \;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \mathbf{elif}\;d \leq 1.05 \cdot 10^{-285}:\\ \;\;\;\;-0.125 \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(\left(M\_m \cdot D\_m\right) \cdot \left(M\_m \cdot \left(-D\_m\right)\right)\right)}{d}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({\ell}^{-0.5} \cdot {h}^{-0.5}\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= d -5.8e-49)
   (* (- d) (sqrt (/ (/ 1.0 h) l)))
   (if (<= d 1.05e-285)
     (*
      -0.125
      (/ (* (sqrt (/ h (pow l 3.0))) (* (* M_m D_m) (* M_m (- D_m)))) d))
     (* d (* (pow l -0.5) (pow h -0.5))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -5.8e-49) {
		tmp = -d * sqrt(((1.0 / h) / l));
	} else if (d <= 1.05e-285) {
		tmp = -0.125 * ((sqrt((h / pow(l, 3.0))) * ((M_m * D_m) * (M_m * -D_m))) / d);
	} else {
		tmp = d * (pow(l, -0.5) * pow(h, -0.5));
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (d <= (-5.8d-49)) then
        tmp = -d * sqrt(((1.0d0 / h) / l))
    else if (d <= 1.05d-285) then
        tmp = (-0.125d0) * ((sqrt((h / (l ** 3.0d0))) * ((m_m * d_m) * (m_m * -d_m))) / d)
    else
        tmp = d * ((l ** (-0.5d0)) * (h ** (-0.5d0)))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -5.8e-49) {
		tmp = -d * Math.sqrt(((1.0 / h) / l));
	} else if (d <= 1.05e-285) {
		tmp = -0.125 * ((Math.sqrt((h / Math.pow(l, 3.0))) * ((M_m * D_m) * (M_m * -D_m))) / d);
	} else {
		tmp = d * (Math.pow(l, -0.5) * Math.pow(h, -0.5));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if d <= -5.8e-49:
		tmp = -d * math.sqrt(((1.0 / h) / l))
	elif d <= 1.05e-285:
		tmp = -0.125 * ((math.sqrt((h / math.pow(l, 3.0))) * ((M_m * D_m) * (M_m * -D_m))) / d)
	else:
		tmp = d * (math.pow(l, -0.5) * math.pow(h, -0.5))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (d <= -5.8e-49)
		tmp = Float64(Float64(-d) * sqrt(Float64(Float64(1.0 / h) / l)));
	elseif (d <= 1.05e-285)
		tmp = Float64(-0.125 * Float64(Float64(sqrt(Float64(h / (l ^ 3.0))) * Float64(Float64(M_m * D_m) * Float64(M_m * Float64(-D_m)))) / d));
	else
		tmp = Float64(d * Float64((l ^ -0.5) * (h ^ -0.5)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (d <= -5.8e-49)
		tmp = -d * sqrt(((1.0 / h) / l));
	elseif (d <= 1.05e-285)
		tmp = -0.125 * ((sqrt((h / (l ^ 3.0))) * ((M_m * D_m) * (M_m * -D_m))) / d);
	else
		tmp = d * ((l ^ -0.5) * (h ^ -0.5));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -5.8e-49], N[((-d) * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.05e-285], N[(-0.125 * N[(N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(M$95$m * (-D$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] * N[Power[h, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.8 \cdot 10^{-49}:\\
\;\;\;\;\left(-d\right) \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\

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

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


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

    1. Initial program 81.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.8e-49 < d < 1.04999999999999992e-285

    1. Initial program 42.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. Simplified37.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.04999999999999992e-285 < d

    1. Initial program 63.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. Simplified62.6%

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 43.1%

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

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

        \[\leadsto d \cdot {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \]
      3. exp-neg41.0%

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod41.5%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out41.5%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in41.5%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval41.5%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow43.6%

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

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

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

        \[\leadsto d \cdot \color{blue}{\left({\ell}^{-0.5} \cdot {h}^{-0.5}\right)} \]
    11. Applied egg-rr51.3%

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

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

Alternative 13: 46.1% accurate, 1.6× speedup?

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

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.7999999999999999e-213 < l

    1. Initial program 60.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. Simplified59.2%

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 44.6%

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

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

        \[\leadsto d \cdot {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \]
      3. exp-neg42.3%

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod42.9%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out42.9%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in42.9%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval42.9%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow45.2%

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

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

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

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

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

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

Alternative 14: 43.0% accurate, 2.9× speedup?

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

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


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

    1. Initial program 68.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.7999999999999999e-213 < l

    1. Initial program 60.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. Simplified59.2%

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

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

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

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 44.6%

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

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

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

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

Alternative 15: 42.9% accurate, 2.9× speedup?

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

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


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

    1. Initial program 68.8%

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

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

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified9.4%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 2.2%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 11.5%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. unpow1/211.5%

        \[\leadsto d \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}} \]
      2. rem-exp-log11.4%

        \[\leadsto d \cdot {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \]
      3. exp-neg11.4%

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod11.4%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out11.4%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in11.4%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval11.4%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow11.5%

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    9. Simplified11.5%

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    10. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    11. Step-by-step derivation
      1. *-commutative0.0%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot \left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right)} \]
      2. *-commutative0.0%

        \[\leadsto \sqrt{\frac{1}{\color{blue}{\ell \cdot h}}} \cdot \left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \]
      3. *-commutative0.0%

        \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot \color{blue}{\left({\left(\sqrt{-1}\right)}^{2} \cdot d\right)} \]
      4. unpow20.0%

        \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot d\right) \]
      5. rem-square-sqrt43.9%

        \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot \left(\color{blue}{-1} \cdot d\right) \]
      6. neg-mul-143.9%

        \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot \color{blue}{\left(-d\right)} \]
    12. Simplified43.9%

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\ell \cdot h}} \cdot \left(-d\right)} \]

    if 6.5e-213 < l

    1. Initial program 60.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. Simplified59.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr68.1%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified69.3%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 41.3%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 44.6%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. associate-/r*45.2%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    9. Simplified45.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 6.5 \cdot 10^{-213}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 42.9% accurate, 3.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq 1.15 \cdot 10^{-210}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l 1.15e-210)
   (* d (- (pow (* h l) -0.5)))
   (* d (sqrt (/ (/ 1.0 h) l)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= 1.15e-210) {
		tmp = d * -pow((h * l), -0.5);
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (l <= 1.15d-210) then
        tmp = d * -((h * l) ** (-0.5d0))
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= 1.15e-210) {
		tmp = d * -Math.pow((h * l), -0.5);
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= 1.15e-210:
		tmp = d * -math.pow((h * l), -0.5)
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= 1.15e-210)
		tmp = Float64(d * Float64(-(Float64(h * l) ^ -0.5)));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (l <= 1.15e-210)
		tmp = d * -((h * l) ^ -0.5);
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, 1.15e-210], N[(d * (-N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 1.15 \cdot 10^{-210}:\\
\;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.15e-210

    1. Initial program 68.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified67.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr8.0%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified9.4%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 2.2%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in h around -inf 0.0%

      \[\leadsto \color{blue}{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. associate-*l*0.0%

        \[\leadsto \color{blue}{d \cdot \left({\left(\sqrt{-1}\right)}^{2} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
      2. unpow20.0%

        \[\leadsto d \cdot \left(\color{blue}{\left(\sqrt{-1} \cdot \sqrt{-1}\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right) \]
      3. rem-square-sqrt43.9%

        \[\leadsto d \cdot \left(\color{blue}{-1} \cdot \sqrt{\frac{1}{h \cdot \ell}}\right) \]
      4. associate-*r*43.9%

        \[\leadsto \color{blue}{\left(d \cdot -1\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      5. *-commutative43.9%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      6. neg-mul-143.9%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      7. *-commutative43.9%

        \[\leadsto \color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot \left(-d\right)} \]
      8. unpow1/243.9%

        \[\leadsto \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}} \cdot \left(-d\right) \]
      9. rem-exp-log42.1%

        \[\leadsto {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \cdot \left(-d\right) \]
      10. exp-neg42.1%

        \[\leadsto {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \cdot \left(-d\right) \]
      11. exp-prod42.1%

        \[\leadsto \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \cdot \left(-d\right) \]
      12. distribute-lft-neg-out42.1%

        \[\leadsto e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \cdot \left(-d\right) \]
      13. distribute-rgt-neg-in42.1%

        \[\leadsto e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \cdot \left(-d\right) \]
      14. metadata-eval42.1%

        \[\leadsto e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \cdot \left(-d\right) \]
      15. exp-to-pow43.9%

        \[\leadsto \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \cdot \left(-d\right) \]
    9. Simplified43.9%

      \[\leadsto \color{blue}{{\left(h \cdot \ell\right)}^{-0.5} \cdot \left(-d\right)} \]

    if 1.15e-210 < l

    1. Initial program 60.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. Simplified59.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr68.1%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified69.3%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 41.3%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 44.6%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. associate-/r*45.2%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    9. Simplified45.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification44.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.15 \cdot 10^{-210}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 37.9% accurate, 3.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -2.8 \cdot 10^{-190}:\\ \;\;\;\;\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= d -2.8e-190) (sqrt (* d (/ (/ d h) l))) (* d (sqrt (/ (/ 1.0 h) l)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -2.8e-190) {
		tmp = sqrt((d * ((d / h) / l)));
	} else {
		tmp = d * sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (d <= (-2.8d-190)) then
        tmp = sqrt((d * ((d / h) / l)))
    else
        tmp = d * sqrt(((1.0d0 / h) / l))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -2.8e-190) {
		tmp = Math.sqrt((d * ((d / h) / l)));
	} else {
		tmp = d * Math.sqrt(((1.0 / h) / l));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if d <= -2.8e-190:
		tmp = math.sqrt((d * ((d / h) / l)))
	else:
		tmp = d * math.sqrt(((1.0 / h) / l))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (d <= -2.8e-190)
		tmp = sqrt(Float64(d * Float64(Float64(d / h) / l)));
	else
		tmp = Float64(d * sqrt(Float64(Float64(1.0 / h) / l)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (d <= -2.8e-190)
		tmp = sqrt((d * ((d / h) / l)));
	else
		tmp = d * sqrt(((1.0 / h) / l));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -2.8e-190], N[Sqrt[N[(d * N[(N[(d / h), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d * N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.8 \cdot 10^{-190}:\\
\;\;\;\;\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.80000000000000005e-190

    1. Initial program 78.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. Simplified76.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr0.0%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified0.0%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 0.0%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Step-by-step derivation
      1. sqrt-unprod37.5%

        \[\leadsto \color{blue}{\sqrt{d \cdot \frac{d}{h \cdot \ell}}} \]
      2. associate-/r*37.4%

        \[\leadsto \sqrt{d \cdot \color{blue}{\frac{\frac{d}{h}}{\ell}}} \]
    8. Applied egg-rr37.4%

      \[\leadsto \color{blue}{\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}} \]

    if -2.80000000000000005e-190 < d

    1. Initial program 56.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. Simplified55.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr57.8%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified59.9%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 32.7%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 38.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. associate-/r*38.6%

        \[\leadsto d \cdot \sqrt{\color{blue}{\frac{\frac{1}{h}}{\ell}}} \]
    9. Simplified38.6%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{\frac{1}{h}}{\ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 18: 37.9% accurate, 3.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -2.7 \cdot 10^{-190}:\\ \;\;\;\;\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(h \cdot \ell\right)}^{-0.5}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= d -2.7e-190) (sqrt (* d (/ (/ d h) l))) (* d (pow (* h l) -0.5))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -2.7e-190) {
		tmp = sqrt((d * ((d / h) / l)));
	} else {
		tmp = d * pow((h * l), -0.5);
	}
	return tmp;
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8) :: tmp
    if (d <= (-2.7d-190)) then
        tmp = sqrt((d * ((d / h) / l)))
    else
        tmp = d * ((h * l) ** (-0.5d0))
    end if
    code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (d <= -2.7e-190) {
		tmp = Math.sqrt((d * ((d / h) / l)));
	} else {
		tmp = d * Math.pow((h * l), -0.5);
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if d <= -2.7e-190:
		tmp = math.sqrt((d * ((d / h) / l)))
	else:
		tmp = d * math.pow((h * l), -0.5)
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (d <= -2.7e-190)
		tmp = sqrt(Float64(d * Float64(Float64(d / h) / l)));
	else
		tmp = Float64(d * (Float64(h * l) ^ -0.5));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	tmp = 0.0;
	if (d <= -2.7e-190)
		tmp = sqrt((d * ((d / h) / l)));
	else
		tmp = d * ((h * l) ^ -0.5);
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -2.7e-190], N[Sqrt[N[(d * N[(N[(d / h), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d * N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{-190}:\\
\;\;\;\;\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot {\left(h \cdot \ell\right)}^{-0.5}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -2.6999999999999999e-190

    1. Initial program 78.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. Simplified76.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr0.0%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified0.0%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 0.0%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Step-by-step derivation
      1. sqrt-unprod37.5%

        \[\leadsto \color{blue}{\sqrt{d \cdot \frac{d}{h \cdot \ell}}} \]
      2. associate-/r*37.4%

        \[\leadsto \sqrt{d \cdot \color{blue}{\frac{\frac{d}{h}}{\ell}}} \]
    8. Applied egg-rr37.4%

      \[\leadsto \color{blue}{\sqrt{d \cdot \frac{\frac{d}{h}}{\ell}}} \]

    if -2.6999999999999999e-190 < d

    1. Initial program 56.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. Simplified55.8%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Add Preprocessing
    4. Applied egg-rr57.8%

      \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
    5. Simplified59.9%

      \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
    6. Taylor expanded in d around inf 32.7%

      \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
    7. Taylor expanded in d around 0 38.1%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    8. Step-by-step derivation
      1. unpow1/238.1%

        \[\leadsto d \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}} \]
      2. rem-exp-log36.4%

        \[\leadsto d \cdot {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \]
      3. exp-neg36.4%

        \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
      4. exp-prod36.9%

        \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
      5. distribute-lft-neg-out36.9%

        \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
      6. distribute-rgt-neg-in36.9%

        \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
      7. metadata-eval36.9%

        \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
      8. exp-to-pow38.6%

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
    9. Simplified38.6%

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 19: 26.2% accurate, 3.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ d \cdot {\left(h \cdot \ell\right)}^{-0.5} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m) :precision binary64 (* d (pow (* h l) -0.5)))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return d * pow((h * l), -0.5);
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    code = d * ((h * l) ** (-0.5d0))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	return d * Math.pow((h * l), -0.5);
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	return d * math.pow((h * l), -0.5)
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	return Float64(d * (Float64(h * l) ^ -0.5))
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
	tmp = d * ((h * l) ^ -0.5);
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := N[(d * N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
d \cdot {\left(h \cdot \ell\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 64.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. Simplified63.6%

    \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
  3. Add Preprocessing
  4. Applied egg-rr35.4%

    \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(M \cdot \frac{D}{d \cdot 2}\right)}^{2}\right)\right)\right)}{\sqrt{h}}} \]
  5. Simplified36.8%

    \[\leadsto \color{blue}{\sqrt{d} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D \cdot \left(0.5 \cdot \frac{M}{d}\right)\right)}^{2}}{\ell}, 1\right)}{\sqrt{h}}\right)} \]
  6. Taylor expanded in d around inf 20.1%

    \[\leadsto \sqrt{d} \cdot \color{blue}{\sqrt{\frac{d}{h \cdot \ell}}} \]
  7. Taylor expanded in d around 0 26.6%

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  8. Step-by-step derivation
    1. unpow1/226.6%

      \[\leadsto d \cdot \color{blue}{{\left(\frac{1}{h \cdot \ell}\right)}^{0.5}} \]
    2. rem-exp-log25.5%

      \[\leadsto d \cdot {\left(\frac{1}{\color{blue}{e^{\log \left(h \cdot \ell\right)}}}\right)}^{0.5} \]
    3. exp-neg25.5%

      \[\leadsto d \cdot {\color{blue}{\left(e^{-\log \left(h \cdot \ell\right)}\right)}}^{0.5} \]
    4. exp-prod25.8%

      \[\leadsto d \cdot \color{blue}{e^{\left(-\log \left(h \cdot \ell\right)\right) \cdot 0.5}} \]
    5. distribute-lft-neg-out25.8%

      \[\leadsto d \cdot e^{\color{blue}{-\log \left(h \cdot \ell\right) \cdot 0.5}} \]
    6. distribute-rgt-neg-in25.8%

      \[\leadsto d \cdot e^{\color{blue}{\log \left(h \cdot \ell\right) \cdot \left(-0.5\right)}} \]
    7. metadata-eval25.8%

      \[\leadsto d \cdot e^{\log \left(h \cdot \ell\right) \cdot \color{blue}{-0.5}} \]
    8. exp-to-pow26.9%

      \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}} \]
  9. Simplified26.9%

    \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
  10. Add Preprocessing

Reproduce

?
herbie shell --seed 2024132 
(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)))))