Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.4% → 85.6%
Time: 2.0min
Alternatives: 20
Speedup: 1.0×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 20 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.4% 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: 85.6% accurate, 0.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} t_0 := \sqrt{-d}\\ \mathbf{if}\;\ell \leq -1.8 \cdot 10^{-305}:\\ \;\;\;\;\frac{t\_0}{\sqrt{-\ell}} \cdot \left(\frac{t\_0}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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
 (let* ((t_0 (sqrt (- d))))
   (if (<= l -1.8e-305)
     (*
      (/ t_0 (sqrt (- l)))
      (*
       (/ t_0 (sqrt (- h)))
       (+ 1.0 (* (/ h l) (* (pow (* D_m (/ (/ M_m 2.0) d)) 2.0) -0.5)))))
     (if (<= l 2.6e-251)
       (*
        (sqrt (/ d l))
        (*
         (sqrt (/ d h))
         (+ 1.0 (/ (* h (* -0.5 (pow (* M_m (* 0.5 (/ D_m d))) 2.0))) l))))
       (*
        d
        (/
         (fma h (* -0.5 (/ (pow (* D_m (/ (* M_m 0.5) 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 t_0 = sqrt(-d);
	double tmp;
	if (l <= -1.8e-305) {
		tmp = (t_0 / sqrt(-l)) * ((t_0 / sqrt(-h)) * (1.0 + ((h / l) * (pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))));
	} else if (l <= 2.6e-251) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h * (-0.5 * pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else {
		tmp = d * (fma(h, (-0.5 * (pow((D_m * ((M_m * 0.5) / 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)
	t_0 = sqrt(Float64(-d))
	tmp = 0.0
	if (l <= -1.8e-305)
		tmp = Float64(Float64(t_0 / sqrt(Float64(-l))) * Float64(Float64(t_0 / sqrt(Float64(-h))) * Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5)))));
	elseif (l <= 2.6e-251)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h * Float64(-0.5 * (Float64(M_m * Float64(0.5 * Float64(D_m / d))) ^ 2.0))) / l))));
	else
		tmp = Float64(d * Float64(fma(h, Float64(-0.5 * Float64((Float64(D_m * Float64(Float64(M_m * 0.5) / 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_] := Block[{t$95$0 = N[Sqrt[(-d)], $MachinePrecision]}, If[LessEqual[l, -1.8e-305], N[(N[(t$95$0 / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$0 / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.6e-251], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h * N[(-0.5 * N[Power[N[(M$95$m * N[(0.5 * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[(h * N[(-0.5 * N[(N[Power[N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d), $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}
t_0 := \sqrt{-d}\\
\mathbf{if}\;\ell \leq -1.8 \cdot 10^{-305}:\\
\;\;\;\;\frac{t\_0}{\sqrt{-\ell}} \cdot \left(\frac{t\_0}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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.80000000000000002e-305

    1. Initial program 66.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. Simplified65.0%

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

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

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

      \[\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. frac-2neg76.7%

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

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

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

    if -1.80000000000000002e-305 < l < 2.5999999999999999e-251

    1. Initial program 93.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. Simplified86.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. Applied egg-rr87.7%

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

    if 2.5999999999999999e-251 < l

    1. Initial program 61.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr73.9%

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

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

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

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

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

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

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

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

Alternative 2: 82.5% 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} t_0 := \sqrt{\frac{d}{h}}\\ t_1 := \sqrt{-d}\\ \mathbf{if}\;\ell \leq -1 \cdot 10^{-130}:\\ \;\;\;\;\left(\frac{t\_1}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\frac{t\_1}{\sqrt{-\ell}} \cdot \left(t\_0 \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{-249}:\\ \;\;\;\;\left(t\_0 \cdot \left(\sqrt{d} \cdot \frac{1}{\sqrt{\ell}}\right)\right) \cdot \left(1 - 0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\frac{M\_m}{2} \cdot \frac{D\_m}{d}\right)}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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
 (let* ((t_0 (sqrt (/ d h))) (t_1 (sqrt (- d))))
   (if (<= l -1e-130)
     (*
      (*
       (/ t_1 (sqrt (- h)))
       (+ 1.0 (* (/ h l) (* (pow (* D_m (/ (/ M_m 2.0) d)) 2.0) -0.5))))
      (sqrt (/ d l)))
     (if (<= l -5e-310)
       (*
        (/ t_1 (sqrt (- l)))
        (*
         t_0
         (+ 1.0 (/ (* h (* -0.5 (pow (* M_m (* 0.5 (/ D_m d))) 2.0))) l))))
       (if (<= l 7e-249)
         (*
          (* t_0 (* (sqrt d) (/ 1.0 (sqrt l))))
          (- 1.0 (* 0.5 (* (/ h l) (pow (* (/ M_m 2.0) (/ D_m d)) 2.0)))))
         (*
          d
          (/
           (fma h (* -0.5 (/ (pow (* D_m (/ (* M_m 0.5) 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 t_0 = sqrt((d / h));
	double t_1 = sqrt(-d);
	double tmp;
	if (l <= -1e-130) {
		tmp = ((t_1 / sqrt(-h)) * (1.0 + ((h / l) * (pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5)))) * sqrt((d / l));
	} else if (l <= -5e-310) {
		tmp = (t_1 / sqrt(-l)) * (t_0 * (1.0 + ((h * (-0.5 * pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else if (l <= 7e-249) {
		tmp = (t_0 * (sqrt(d) * (1.0 / sqrt(l)))) * (1.0 - (0.5 * ((h / l) * pow(((M_m / 2.0) * (D_m / d)), 2.0))));
	} else {
		tmp = d * (fma(h, (-0.5 * (pow((D_m * ((M_m * 0.5) / 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)
	t_0 = sqrt(Float64(d / h))
	t_1 = sqrt(Float64(-d))
	tmp = 0.0
	if (l <= -1e-130)
		tmp = Float64(Float64(Float64(t_1 / sqrt(Float64(-h))) * Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5)))) * sqrt(Float64(d / l)));
	elseif (l <= -5e-310)
		tmp = Float64(Float64(t_1 / sqrt(Float64(-l))) * Float64(t_0 * Float64(1.0 + Float64(Float64(h * Float64(-0.5 * (Float64(M_m * Float64(0.5 * Float64(D_m / d))) ^ 2.0))) / l))));
	elseif (l <= 7e-249)
		tmp = Float64(Float64(t_0 * Float64(sqrt(d) * Float64(1.0 / sqrt(l)))) * Float64(1.0 - Float64(0.5 * Float64(Float64(h / l) * (Float64(Float64(M_m / 2.0) * Float64(D_m / d)) ^ 2.0)))));
	else
		tmp = Float64(d * Float64(fma(h, Float64(-0.5 * Float64((Float64(D_m * Float64(Float64(M_m * 0.5) / 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_] := Block[{t$95$0 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[(-d)], $MachinePrecision]}, If[LessEqual[l, -1e-130], N[(N[(N[(t$95$1 / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -5e-310], N[(N[(t$95$1 / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision] * N[(t$95$0 * N[(1.0 + N[(N[(h * N[(-0.5 * N[Power[N[(M$95$m * N[(0.5 * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7e-249], N[(N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] * N[(1.0 / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - 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]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[(h * N[(-0.5 * N[(N[Power[N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d), $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}
t_0 := \sqrt{\frac{d}{h}}\\
t_1 := \sqrt{-d}\\
\mathbf{if}\;\ell \leq -1 \cdot 10^{-130}:\\
\;\;\;\;\left(\frac{t\_1}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \cdot \sqrt{\frac{d}{\ell}}\\

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

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

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


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

    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. Simplified58.8%

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

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

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

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

    if -1.0000000000000001e-130 < l < -4.999999999999985e-310

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

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

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

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

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

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

    if -4.999999999999985e-310 < l < 7.00000000000000025e-249

    1. Initial program 87.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. Simplified80.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. sqrt-div86.8%

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

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

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

    if 7.00000000000000025e-249 < l

    1. Initial program 62.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr74.2%

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

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

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

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

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

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

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

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

Alternative 3: 73.9% 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} t_0 := {\left(\ell \cdot h\right)}^{-0.25}\\ t_1 := \sqrt{\frac{d}{\ell}}\\ t_2 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;d \leq -1.55 \cdot 10^{+226}:\\ \;\;\;\;t\_1 \cdot \left(t\_2 \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{+143}:\\ \;\;\;\;d \cdot \left(-t\_0 \cdot t\_0\right)\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{-202}:\\ \;\;\;\;t\_1 \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot t\_2\right)\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(-0.125 \cdot \left({D\_m}^{2} \cdot \frac{{M\_m}^{2}}{-d}\right)\right)\\ \mathbf{elif}\;d \leq 2.25 \cdot 10^{-218}:\\ \;\;\;\;{\left(D\_m \cdot \frac{M\_m}{\sqrt{d}}\right)}^{2} \cdot \left(-0.125 \cdot \frac{\sqrt{h}}{{\ell}^{1.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D\_m \cdot M\_m\right)}{d}\right)}^{2}\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 (pow (* l h) -0.25)) (t_1 (sqrt (/ d l))) (t_2 (sqrt (/ d h))))
   (if (<= d -1.55e+226)
     (*
      t_1
      (* t_2 (+ 1.0 (/ (* h (* -0.5 (pow (* M_m (* 0.5 (/ D_m d))) 2.0))) l))))
     (if (<= d -1.05e+143)
       (* d (- (* t_0 t_0)))
       (if (<= d -4.8e-202)
         (*
          t_1
          (*
           (+ 1.0 (* (/ h l) (* (pow (* D_m (/ (/ M_m 2.0) d)) 2.0) -0.5)))
           t_2))
         (if (<= d -2e-310)
           (*
            (sqrt (/ h (pow l 3.0)))
            (* -0.125 (* (pow D_m 2.0) (/ (pow M_m 2.0) (- d)))))
           (if (<= d 2.25e-218)
             (*
              (pow (* D_m (/ M_m (sqrt d))) 2.0)
              (* -0.125 (/ (sqrt h) (pow l 1.5))))
             (*
              (+ 1.0 (* (* (/ h l) -0.5) (pow (/ (* 0.5 (* D_m M_m)) d) 2.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 = pow((l * h), -0.25);
	double t_1 = sqrt((d / l));
	double t_2 = sqrt((d / h));
	double tmp;
	if (d <= -1.55e+226) {
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else if (d <= -1.05e+143) {
		tmp = d * -(t_0 * t_0);
	} else if (d <= -4.8e-202) {
		tmp = t_1 * ((1.0 + ((h / l) * (pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2);
	} else if (d <= -2e-310) {
		tmp = sqrt((h / pow(l, 3.0))) * (-0.125 * (pow(D_m, 2.0) * (pow(M_m, 2.0) / -d)));
	} else if (d <= 2.25e-218) {
		tmp = pow((D_m * (M_m / sqrt(d))), 2.0) * (-0.125 * (sqrt(h) / pow(l, 1.5)));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow(((0.5 * (D_m * M_m)) / d), 2.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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = (l * h) ** (-0.25d0)
    t_1 = sqrt((d / l))
    t_2 = sqrt((d / h))
    if (d <= (-1.55d+226)) then
        tmp = t_1 * (t_2 * (1.0d0 + ((h * ((-0.5d0) * ((m_m * (0.5d0 * (d_m / d))) ** 2.0d0))) / l)))
    else if (d <= (-1.05d+143)) then
        tmp = d * -(t_0 * t_0)
    else if (d <= (-4.8d-202)) then
        tmp = t_1 * ((1.0d0 + ((h / l) * (((d_m * ((m_m / 2.0d0) / d)) ** 2.0d0) * (-0.5d0)))) * t_2)
    else if (d <= (-2d-310)) then
        tmp = sqrt((h / (l ** 3.0d0))) * ((-0.125d0) * ((d_m ** 2.0d0) * ((m_m ** 2.0d0) / -d)))
    else if (d <= 2.25d-218) then
        tmp = ((d_m * (m_m / sqrt(d))) ** 2.0d0) * ((-0.125d0) * (sqrt(h) / (l ** 1.5d0)))
    else
        tmp = (1.0d0 + (((h / l) * (-0.5d0)) * (((0.5d0 * (d_m * m_m)) / d) ** 2.0d0))) * (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 = Math.pow((l * h), -0.25);
	double t_1 = Math.sqrt((d / l));
	double t_2 = Math.sqrt((d / h));
	double tmp;
	if (d <= -1.55e+226) {
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * Math.pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else if (d <= -1.05e+143) {
		tmp = d * -(t_0 * t_0);
	} else if (d <= -4.8e-202) {
		tmp = t_1 * ((1.0 + ((h / l) * (Math.pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2);
	} else if (d <= -2e-310) {
		tmp = Math.sqrt((h / Math.pow(l, 3.0))) * (-0.125 * (Math.pow(D_m, 2.0) * (Math.pow(M_m, 2.0) / -d)));
	} else if (d <= 2.25e-218) {
		tmp = Math.pow((D_m * (M_m / Math.sqrt(d))), 2.0) * (-0.125 * (Math.sqrt(h) / Math.pow(l, 1.5)));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow(((0.5 * (D_m * M_m)) / d), 2.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 = math.pow((l * h), -0.25)
	t_1 = math.sqrt((d / l))
	t_2 = math.sqrt((d / h))
	tmp = 0
	if d <= -1.55e+226:
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * math.pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)))
	elif d <= -1.05e+143:
		tmp = d * -(t_0 * t_0)
	elif d <= -4.8e-202:
		tmp = t_1 * ((1.0 + ((h / l) * (math.pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2)
	elif d <= -2e-310:
		tmp = math.sqrt((h / math.pow(l, 3.0))) * (-0.125 * (math.pow(D_m, 2.0) * (math.pow(M_m, 2.0) / -d)))
	elif d <= 2.25e-218:
		tmp = math.pow((D_m * (M_m / math.sqrt(d))), 2.0) * (-0.125 * (math.sqrt(h) / math.pow(l, 1.5)))
	else:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow(((0.5 * (D_m * M_m)) / d), 2.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(l * h) ^ -0.25
	t_1 = sqrt(Float64(d / l))
	t_2 = sqrt(Float64(d / h))
	tmp = 0.0
	if (d <= -1.55e+226)
		tmp = Float64(t_1 * Float64(t_2 * Float64(1.0 + Float64(Float64(h * Float64(-0.5 * (Float64(M_m * Float64(0.5 * Float64(D_m / d))) ^ 2.0))) / l))));
	elseif (d <= -1.05e+143)
		tmp = Float64(d * Float64(-Float64(t_0 * t_0)));
	elseif (d <= -4.8e-202)
		tmp = Float64(t_1 * Float64(Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) * t_2));
	elseif (d <= -2e-310)
		tmp = Float64(sqrt(Float64(h / (l ^ 3.0))) * Float64(-0.125 * Float64((D_m ^ 2.0) * Float64((M_m ^ 2.0) / Float64(-d)))));
	elseif (d <= 2.25e-218)
		tmp = Float64((Float64(D_m * Float64(M_m / sqrt(d))) ^ 2.0) * Float64(-0.125 * Float64(sqrt(h) / (l ^ 1.5))));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(Float64(0.5 * Float64(D_m * M_m)) / d) ^ 2.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 = (l * h) ^ -0.25;
	t_1 = sqrt((d / l));
	t_2 = sqrt((d / h));
	tmp = 0.0;
	if (d <= -1.55e+226)
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * ((M_m * (0.5 * (D_m / d))) ^ 2.0))) / l)));
	elseif (d <= -1.05e+143)
		tmp = d * -(t_0 * t_0);
	elseif (d <= -4.8e-202)
		tmp = t_1 * ((1.0 + ((h / l) * (((D_m * ((M_m / 2.0) / d)) ^ 2.0) * -0.5))) * t_2);
	elseif (d <= -2e-310)
		tmp = sqrt((h / (l ^ 3.0))) * (-0.125 * ((D_m ^ 2.0) * ((M_m ^ 2.0) / -d)));
	elseif (d <= 2.25e-218)
		tmp = ((D_m * (M_m / sqrt(d))) ^ 2.0) * (-0.125 * (sqrt(h) / (l ^ 1.5)));
	else
		tmp = (1.0 + (((h / l) * -0.5) * (((0.5 * (D_m * M_m)) / d) ^ 2.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[Power[N[(l * h), $MachinePrecision], -0.25], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, -1.55e+226], N[(t$95$1 * N[(t$95$2 * N[(1.0 + N[(N[(h * N[(-0.5 * N[Power[N[(M$95$m * N[(0.5 * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1.05e+143], N[(d * (-N[(t$95$0 * t$95$0), $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -4.8e-202], N[(t$95$1 * N[(N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2e-310], N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-0.125 * N[(N[Power[D$95$m, 2.0], $MachinePrecision] * N[(N[Power[M$95$m, 2.0], $MachinePrecision] / (-d)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 2.25e-218], N[(N[Power[N[(D$95$m * N[(M$95$m / N[Sqrt[d], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.125 * N[(N[Sqrt[h], $MachinePrecision] / N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(N[(0.5 * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $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 := {\left(\ell \cdot h\right)}^{-0.25}\\
t_1 := \sqrt{\frac{d}{\ell}}\\
t_2 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;d \leq -1.55 \cdot 10^{+226}:\\
\;\;\;\;t\_1 \cdot \left(t\_2 \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\

\mathbf{elif}\;d \leq -1.05 \cdot 10^{+143}:\\
\;\;\;\;d \cdot \left(-t\_0 \cdot t\_0\right)\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if d < -1.54999999999999988e226

    1. Initial program 84.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. Simplified84.5%

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

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

    if -1.54999999999999988e226 < d < -1.04999999999999994e143

    1. Initial program 50.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. Add Preprocessing
    3. Taylor expanded in d around inf 0.6%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt85.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval0.6%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr90.3%

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

    if -1.04999999999999994e143 < d < -4.8000000000000002e-202

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

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

    if -4.8000000000000002e-202 < d < -1.999999999999994e-310

    1. Initial program 32.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. Add Preprocessing
    3. 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)} \]
    4. Step-by-step derivation
      1. associate-*r*0.0%

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

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

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

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

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

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

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

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

    if -1.999999999999994e-310 < d < 2.24999999999999988e-218

    1. Initial program 30.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. Add Preprocessing
    3. Taylor expanded in d around 0 46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.24999999999999988e-218 < d

    1. Initial program 71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.55 \cdot 10^{+226}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -1.05 \cdot 10^{+143}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.25} \cdot {\left(\ell \cdot h\right)}^{-0.25}\right)\\ \mathbf{elif}\;d \leq -4.8 \cdot 10^{-202}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\sqrt{\frac{h}{{\ell}^{3}}} \cdot \left(-0.125 \cdot \left({D}^{2} \cdot \frac{{M}^{2}}{-d}\right)\right)\\ \mathbf{elif}\;d \leq 2.25 \cdot 10^{-218}:\\ \;\;\;\;{\left(D \cdot \frac{M}{\sqrt{d}}\right)}^{2} \cdot \left(-0.125 \cdot \frac{\sqrt{h}}{{\ell}^{1.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D \cdot M\right)}{d}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 73.9% 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} t_0 := {\left(\ell \cdot h\right)}^{-0.25}\\ t_1 := \sqrt{\frac{d}{\ell}}\\ t_2 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;d \leq -6.2 \cdot 10^{+225}:\\ \;\;\;\;t\_1 \cdot \left(t\_2 \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -3.2 \cdot 10^{+141}:\\ \;\;\;\;d \cdot \left(-t\_0 \cdot t\_0\right)\\ \mathbf{elif}\;d \leq -6.5 \cdot 10^{-205}:\\ \;\;\;\;t\_1 \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot t\_2\right)\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;-0.125 \cdot \left({D\_m}^{2} \cdot \left(\left({M\_m}^{2} \cdot \frac{-1}{d}\right) \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right)\right)\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-219}:\\ \;\;\;\;{\left(D\_m \cdot \frac{M\_m}{\sqrt{d}}\right)}^{2} \cdot \left(-0.125 \cdot \frac{\sqrt{h}}{{\ell}^{1.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D\_m \cdot M\_m\right)}{d}\right)}^{2}\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 (pow (* l h) -0.25)) (t_1 (sqrt (/ d l))) (t_2 (sqrt (/ d h))))
   (if (<= d -6.2e+225)
     (*
      t_1
      (* t_2 (+ 1.0 (/ (* h (* -0.5 (pow (* M_m (* 0.5 (/ D_m d))) 2.0))) l))))
     (if (<= d -3.2e+141)
       (* d (- (* t_0 t_0)))
       (if (<= d -6.5e-205)
         (*
          t_1
          (*
           (+ 1.0 (* (/ h l) (* (pow (* D_m (/ (/ M_m 2.0) d)) 2.0) -0.5)))
           t_2))
         (if (<= d -2e-310)
           (*
            -0.125
            (*
             (pow D_m 2.0)
             (* (* (pow M_m 2.0) (/ -1.0 d)) (sqrt (/ h (pow l 3.0))))))
           (if (<= d 6e-219)
             (*
              (pow (* D_m (/ M_m (sqrt d))) 2.0)
              (* -0.125 (/ (sqrt h) (pow l 1.5))))
             (*
              (+ 1.0 (* (* (/ h l) -0.5) (pow (/ (* 0.5 (* D_m M_m)) d) 2.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 = pow((l * h), -0.25);
	double t_1 = sqrt((d / l));
	double t_2 = sqrt((d / h));
	double tmp;
	if (d <= -6.2e+225) {
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else if (d <= -3.2e+141) {
		tmp = d * -(t_0 * t_0);
	} else if (d <= -6.5e-205) {
		tmp = t_1 * ((1.0 + ((h / l) * (pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2);
	} else if (d <= -2e-310) {
		tmp = -0.125 * (pow(D_m, 2.0) * ((pow(M_m, 2.0) * (-1.0 / d)) * sqrt((h / pow(l, 3.0)))));
	} else if (d <= 6e-219) {
		tmp = pow((D_m * (M_m / sqrt(d))), 2.0) * (-0.125 * (sqrt(h) / pow(l, 1.5)));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * pow(((0.5 * (D_m * M_m)) / d), 2.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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = (l * h) ** (-0.25d0)
    t_1 = sqrt((d / l))
    t_2 = sqrt((d / h))
    if (d <= (-6.2d+225)) then
        tmp = t_1 * (t_2 * (1.0d0 + ((h * ((-0.5d0) * ((m_m * (0.5d0 * (d_m / d))) ** 2.0d0))) / l)))
    else if (d <= (-3.2d+141)) then
        tmp = d * -(t_0 * t_0)
    else if (d <= (-6.5d-205)) then
        tmp = t_1 * ((1.0d0 + ((h / l) * (((d_m * ((m_m / 2.0d0) / d)) ** 2.0d0) * (-0.5d0)))) * t_2)
    else if (d <= (-2d-310)) then
        tmp = (-0.125d0) * ((d_m ** 2.0d0) * (((m_m ** 2.0d0) * ((-1.0d0) / d)) * sqrt((h / (l ** 3.0d0)))))
    else if (d <= 6d-219) then
        tmp = ((d_m * (m_m / sqrt(d))) ** 2.0d0) * ((-0.125d0) * (sqrt(h) / (l ** 1.5d0)))
    else
        tmp = (1.0d0 + (((h / l) * (-0.5d0)) * (((0.5d0 * (d_m * m_m)) / d) ** 2.0d0))) * (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 = Math.pow((l * h), -0.25);
	double t_1 = Math.sqrt((d / l));
	double t_2 = Math.sqrt((d / h));
	double tmp;
	if (d <= -6.2e+225) {
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * Math.pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)));
	} else if (d <= -3.2e+141) {
		tmp = d * -(t_0 * t_0);
	} else if (d <= -6.5e-205) {
		tmp = t_1 * ((1.0 + ((h / l) * (Math.pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2);
	} else if (d <= -2e-310) {
		tmp = -0.125 * (Math.pow(D_m, 2.0) * ((Math.pow(M_m, 2.0) * (-1.0 / d)) * Math.sqrt((h / Math.pow(l, 3.0)))));
	} else if (d <= 6e-219) {
		tmp = Math.pow((D_m * (M_m / Math.sqrt(d))), 2.0) * (-0.125 * (Math.sqrt(h) / Math.pow(l, 1.5)));
	} else {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow(((0.5 * (D_m * M_m)) / d), 2.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 = math.pow((l * h), -0.25)
	t_1 = math.sqrt((d / l))
	t_2 = math.sqrt((d / h))
	tmp = 0
	if d <= -6.2e+225:
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * math.pow((M_m * (0.5 * (D_m / d))), 2.0))) / l)))
	elif d <= -3.2e+141:
		tmp = d * -(t_0 * t_0)
	elif d <= -6.5e-205:
		tmp = t_1 * ((1.0 + ((h / l) * (math.pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5))) * t_2)
	elif d <= -2e-310:
		tmp = -0.125 * (math.pow(D_m, 2.0) * ((math.pow(M_m, 2.0) * (-1.0 / d)) * math.sqrt((h / math.pow(l, 3.0)))))
	elif d <= 6e-219:
		tmp = math.pow((D_m * (M_m / math.sqrt(d))), 2.0) * (-0.125 * (math.sqrt(h) / math.pow(l, 1.5)))
	else:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow(((0.5 * (D_m * M_m)) / d), 2.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(l * h) ^ -0.25
	t_1 = sqrt(Float64(d / l))
	t_2 = sqrt(Float64(d / h))
	tmp = 0.0
	if (d <= -6.2e+225)
		tmp = Float64(t_1 * Float64(t_2 * Float64(1.0 + Float64(Float64(h * Float64(-0.5 * (Float64(M_m * Float64(0.5 * Float64(D_m / d))) ^ 2.0))) / l))));
	elseif (d <= -3.2e+141)
		tmp = Float64(d * Float64(-Float64(t_0 * t_0)));
	elseif (d <= -6.5e-205)
		tmp = Float64(t_1 * Float64(Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5))) * t_2));
	elseif (d <= -2e-310)
		tmp = Float64(-0.125 * Float64((D_m ^ 2.0) * Float64(Float64((M_m ^ 2.0) * Float64(-1.0 / d)) * sqrt(Float64(h / (l ^ 3.0))))));
	elseif (d <= 6e-219)
		tmp = Float64((Float64(D_m * Float64(M_m / sqrt(d))) ^ 2.0) * Float64(-0.125 * Float64(sqrt(h) / (l ^ 1.5))));
	else
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(Float64(0.5 * Float64(D_m * M_m)) / d) ^ 2.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 = (l * h) ^ -0.25;
	t_1 = sqrt((d / l));
	t_2 = sqrt((d / h));
	tmp = 0.0;
	if (d <= -6.2e+225)
		tmp = t_1 * (t_2 * (1.0 + ((h * (-0.5 * ((M_m * (0.5 * (D_m / d))) ^ 2.0))) / l)));
	elseif (d <= -3.2e+141)
		tmp = d * -(t_0 * t_0);
	elseif (d <= -6.5e-205)
		tmp = t_1 * ((1.0 + ((h / l) * (((D_m * ((M_m / 2.0) / d)) ^ 2.0) * -0.5))) * t_2);
	elseif (d <= -2e-310)
		tmp = -0.125 * ((D_m ^ 2.0) * (((M_m ^ 2.0) * (-1.0 / d)) * sqrt((h / (l ^ 3.0)))));
	elseif (d <= 6e-219)
		tmp = ((D_m * (M_m / sqrt(d))) ^ 2.0) * (-0.125 * (sqrt(h) / (l ^ 1.5)));
	else
		tmp = (1.0 + (((h / l) * -0.5) * (((0.5 * (D_m * M_m)) / d) ^ 2.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[Power[N[(l * h), $MachinePrecision], -0.25], $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, -6.2e+225], N[(t$95$1 * N[(t$95$2 * N[(1.0 + N[(N[(h * N[(-0.5 * N[Power[N[(M$95$m * N[(0.5 * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -3.2e+141], N[(d * (-N[(t$95$0 * t$95$0), $MachinePrecision])), $MachinePrecision], If[LessEqual[d, -6.5e-205], N[(t$95$1 * N[(N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2e-310], N[(-0.125 * N[(N[Power[D$95$m, 2.0], $MachinePrecision] * N[(N[(N[Power[M$95$m, 2.0], $MachinePrecision] * N[(-1.0 / d), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6e-219], N[(N[Power[N[(D$95$m * N[(M$95$m / N[Sqrt[d], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.125 * N[(N[Sqrt[h], $MachinePrecision] / N[Power[l, 1.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(N[(0.5 * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $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 := {\left(\ell \cdot h\right)}^{-0.25}\\
t_1 := \sqrt{\frac{d}{\ell}}\\
t_2 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;d \leq -6.2 \cdot 10^{+225}:\\
\;\;\;\;t\_1 \cdot \left(t\_2 \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\

\mathbf{elif}\;d \leq -3.2 \cdot 10^{+141}:\\
\;\;\;\;d \cdot \left(-t\_0 \cdot t\_0\right)\\

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 6 regimes
  2. if d < -6.1999999999999995e225

    1. Initial program 84.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. Simplified84.5%

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

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

    if -6.1999999999999995e225 < d < -3.20000000000000019e141

    1. Initial program 50.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. Add Preprocessing
    3. Taylor expanded in d around inf 0.6%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt85.4%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval0.6%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr90.3%

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

    if -3.20000000000000019e141 < d < -6.49999999999999956e-205

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

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

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

    1. Initial program 32.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. Add Preprocessing
    3. 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)} \]
    4. Step-by-step derivation
      1. associate-/l*0.0%

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

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

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

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

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

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

    if -1.999999999999994e-310 < d < 6.0000000000000002e-219

    1. Initial program 30.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. Add Preprocessing
    3. Taylor expanded in d around 0 46.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.0000000000000002e-219 < d

    1. Initial program 71.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.2 \cdot 10^{+225}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M \cdot \left(0.5 \cdot \frac{D}{d}\right)\right)}^{2}\right)}{\ell}\right)\right)\\ \mathbf{elif}\;d \leq -3.2 \cdot 10^{+141}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.25} \cdot {\left(\ell \cdot h\right)}^{-0.25}\right)\\ \mathbf{elif}\;d \leq -6.5 \cdot 10^{-205}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{h}{\ell} \cdot \left({\left(D \cdot \frac{\frac{M}{2}}{d}\right)}^{2} \cdot -0.5\right)\right) \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{elif}\;d \leq -2 \cdot 10^{-310}:\\ \;\;\;\;-0.125 \cdot \left({D}^{2} \cdot \left(\left({M}^{2} \cdot \frac{-1}{d}\right) \cdot \sqrt{\frac{h}{{\ell}^{3}}}\right)\right)\\ \mathbf{elif}\;d \leq 6 \cdot 10^{-219}:\\ \;\;\;\;{\left(D \cdot \frac{M}{\sqrt{d}}\right)}^{2} \cdot \left(-0.125 \cdot \frac{\sqrt{h}}{{\ell}^{1.5}}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D \cdot M\right)}{d}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell} \cdot \sqrt{h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 81.9% 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.8 \cdot 10^{-223}:\\ \;\;\;\;\left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-251}:\\ \;\;\;\;\left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h \cdot \left(-0.5 \cdot {\left(M\_m \cdot \left(0.5 \cdot \frac{D\_m}{d}\right)\right)}^{2}\right)}{\ell}\right)\right) \cdot \frac{1}{\sqrt{\frac{\ell}{d}}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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.8e-223)
   (*
    (*
     (/ (sqrt (- d)) (sqrt (- h)))
     (+ 1.0 (* (/ h l) (* (pow (* D_m (/ (/ M_m 2.0) d)) 2.0) -0.5))))
    (sqrt (/ d l)))
   (if (<= l 2.6e-251)
     (*
      (*
       (sqrt (/ d h))
       (+ 1.0 (/ (* h (* -0.5 (pow (* M_m (* 0.5 (/ D_m d))) 2.0))) l)))
      (/ 1.0 (sqrt (/ l d))))
     (*
      d
      (/
       (fma h (* -0.5 (/ (pow (* D_m (/ (* M_m 0.5) 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.8e-223) {
		tmp = ((sqrt(-d) / sqrt(-h)) * (1.0 + ((h / l) * (pow((D_m * ((M_m / 2.0) / d)), 2.0) * -0.5)))) * sqrt((d / l));
	} else if (l <= 2.6e-251) {
		tmp = (sqrt((d / h)) * (1.0 + ((h * (-0.5 * pow((M_m * (0.5 * (D_m / d))), 2.0))) / l))) * (1.0 / sqrt((l / d)));
	} else {
		tmp = d * (fma(h, (-0.5 * (pow((D_m * ((M_m * 0.5) / 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.8e-223)
		tmp = Float64(Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-h))) * Float64(1.0 + Float64(Float64(h / l) * Float64((Float64(D_m * Float64(Float64(M_m / 2.0) / d)) ^ 2.0) * -0.5)))) * sqrt(Float64(d / l)));
	elseif (l <= 2.6e-251)
		tmp = Float64(Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h * Float64(-0.5 * (Float64(M_m * Float64(0.5 * Float64(D_m / d))) ^ 2.0))) / l))) * Float64(1.0 / sqrt(Float64(l / d))));
	else
		tmp = Float64(d * Float64(fma(h, Float64(-0.5 * Float64((Float64(D_m * Float64(Float64(M_m * 0.5) / 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.8e-223], N[(N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D$95$m * N[(N[(M$95$m / 2.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.6e-251], N[(N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h * N[(-0.5 * N[Power[N[(M$95$m * N[(0.5 * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[N[(l / d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[(h * N[(-0.5 * N[(N[Power[N[(D$95$m * N[(N[(M$95$m * 0.5), $MachinePrecision] / d), $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.8 \cdot 10^{-223}:\\
\;\;\;\;\left(\frac{\sqrt{-d}}{\sqrt{-h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left({\left(D\_m \cdot \frac{\frac{M\_m}{2}}{d}\right)}^{2} \cdot -0.5\right)\right)\right) \cdot \sqrt{\frac{d}{\ell}}\\

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

\mathbf{else}:\\
\;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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.8000000000000002e-223

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

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

        \[\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-div77.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-rr77.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.8000000000000002e-223 < l < 2.5999999999999999e-251

    1. Initial program 82.9%

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

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

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

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

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

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

    if 2.5999999999999999e-251 < l

    1. Initial program 61.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr73.9%

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

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

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

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

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

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

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

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

Alternative 6: 76.4% 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 2.6 \cdot 10^{-251}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D\_m \cdot \left(M\_m \cdot 0.5\right)}{d}\right)}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\mathsf{fma}\left(h, -0.5 \cdot \frac{{\left(D\_m \cdot \frac{M\_m \cdot 0.5}{d}\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 2.6e-251)
   (*
    (sqrt (/ d l))
    (*
     (sqrt (/ d h))
     (+ 1.0 (* (/ h l) (* -0.5 (pow (/ (* D_m (* M_m 0.5)) d) 2.0))))))
   (*
    d
    (/
     (fma h (* -0.5 (/ (pow (* D_m (/ (* M_m 0.5) 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 <= 2.6e-251) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * pow(((D_m * (M_m * 0.5)) / d), 2.0)))));
	} else {
		tmp = d * (fma(h, (-0.5 * (pow((D_m * ((M_m * 0.5) / 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 <= 2.6e-251)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(D_m * Float64(M_m * 0.5)) / d) ^ 2.0))))));
	else
		tmp = Float64(d * Float64(fma(h, Float64(-0.5 * Float64((Float64(D_m * Float64(Float64(M_m * 0.5) / 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, 2.6e-251], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(D$95$m * N[(M$95$m * 0.5), $MachinePrecision]), $MachinePrecision] / d), $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[(N[(M$95$m * 0.5), $MachinePrecision] / d), $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 2.6 \cdot 10^{-251}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D\_m \cdot \left(M\_m \cdot 0.5\right)}{d}\right)}^{2}\right)\right)\right)\\

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


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

    1. Initial program 69.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. Simplified67.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5999999999999999e-251 < l

    1. Initial program 61.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Applied egg-rr73.9%

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

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

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

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

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

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

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

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

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

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \log \left(e^{t\_0}\right)\\

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -1.2500000000000001e-169 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

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

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{\ell \cdot h}}}\right)} \]
      2. inv-pow55.9%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(\ell \cdot h\right)}^{-1}}}}\right) \]
      3. sqrt-pow155.9%

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

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 65.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. Add Preprocessing
    3. Applied egg-rr74.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \log \left(e^{t\_0}\right)\\

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -5.99999999999999983e-168 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

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

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{\ell \cdot h}}}\right)} \]
      2. inv-pow55.9%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(\ell \cdot h\right)}^{-1}}}}\right) \]
      3. sqrt-pow155.9%

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

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

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

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

    if -4.999999999999985e-310 < l

    1. Initial program 65.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. Add Preprocessing
    3. Applied egg-rr74.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 66.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. Simplified65.0%

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

    if -4.999999999999985e-310 < l

    1. Initial program 65.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. Add Preprocessing
    3. Applied egg-rr74.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 73.0% 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 2.65 \cdot 10^{-254}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D\_m \cdot \left(M\_m \cdot 0.5\right)}{d}\right)}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{\ell} \cdot \sqrt{h}} \cdot \left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D\_m \cdot \left(0.5 \cdot \frac{M\_m}{d}\right)\right)}^{2}\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 2.65e-254)
   (*
    (sqrt (/ d l))
    (*
     (sqrt (/ d h))
     (+ 1.0 (* (/ h l) (* -0.5 (pow (/ (* D_m (* M_m 0.5)) d) 2.0))))))
   (*
    (/ d (* (sqrt l) (sqrt h)))
    (+ 1.0 (* (* (/ h l) -0.5) (pow (* D_m (* 0.5 (/ M_m d))) 2.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 (l <= 2.65e-254) {
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * pow(((D_m * (M_m * 0.5)) / d), 2.0)))));
	} else {
		tmp = (d / (sqrt(l) * sqrt(h))) * (1.0 + (((h / l) * -0.5) * pow((D_m * (0.5 * (M_m / d))), 2.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 (l <= 2.65d-254) then
        tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0d0 + ((h / l) * ((-0.5d0) * (((d_m * (m_m * 0.5d0)) / d) ** 2.0d0)))))
    else
        tmp = (d / (sqrt(l) * sqrt(h))) * (1.0d0 + (((h / l) * (-0.5d0)) * ((d_m * (0.5d0 * (m_m / d))) ** 2.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 (l <= 2.65e-254) {
		tmp = Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * Math.pow(((D_m * (M_m * 0.5)) / d), 2.0)))));
	} else {
		tmp = (d / (Math.sqrt(l) * Math.sqrt(h))) * (1.0 + (((h / l) * -0.5) * Math.pow((D_m * (0.5 * (M_m / d))), 2.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 l <= 2.65e-254:
		tmp = math.sqrt((d / l)) * (math.sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * math.pow(((D_m * (M_m * 0.5)) / d), 2.0)))))
	else:
		tmp = (d / (math.sqrt(l) * math.sqrt(h))) * (1.0 + (((h / l) * -0.5) * math.pow((D_m * (0.5 * (M_m / d))), 2.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 (l <= 2.65e-254)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(Float64(h / l) * Float64(-0.5 * (Float64(Float64(D_m * Float64(M_m * 0.5)) / d) ^ 2.0))))));
	else
		tmp = Float64(Float64(d / Float64(sqrt(l) * sqrt(h))) * Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D_m * Float64(0.5 * Float64(M_m / d))) ^ 2.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 (l <= 2.65e-254)
		tmp = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + ((h / l) * (-0.5 * (((D_m * (M_m * 0.5)) / d) ^ 2.0)))));
	else
		tmp = (d / (sqrt(l) * sqrt(h))) * (1.0 + (((h / l) * -0.5) * ((D_m * (0.5 * (M_m / d))) ^ 2.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[l, 2.65e-254], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(N[(h / l), $MachinePrecision] * N[(-0.5 * N[Power[N[(N[(D$95$m * N[(M$95$m * 0.5), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(0.5 * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $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 2.65 \cdot 10^{-254}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{h}{\ell} \cdot \left(-0.5 \cdot {\left(\frac{D\_m \cdot \left(M\_m \cdot 0.5\right)}{d}\right)}^{2}\right)\right)\right)\\

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


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

    1. Initial program 69.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.65000000000000018e-254 < l

    1. Initial program 62.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. Add Preprocessing
    3. Applied egg-rr74.1%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 59.2% accurate, 1.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])\\ \\ \begin{array}{l} t_0 := {\left(\ell \cdot h\right)}^{-0.5}\\ \mathbf{if}\;\ell \leq -3.2 \cdot 10^{-172}:\\ \;\;\;\;d \cdot \left(-t\_0\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(d \cdot t\_0\right)\right)\\ \mathbf{elif}\;\ell \leq 5.8 \cdot 10^{+165}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D\_m \cdot M\_m\right)}{d}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{\ell}}}{\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 (pow (* l h) -0.5)))
   (if (<= l -3.2e-172)
     (* d (- t_0))
     (if (<= l -5e-310)
       (log1p (expm1 (* d t_0)))
       (if (<= l 5.8e+165)
         (*
          (+ 1.0 (* (* (/ h l) -0.5) (pow (/ (* 0.5 (* D_m M_m)) d) 2.0)))
          (/ d (sqrt (* l h))))
         (* d (/ (sqrt (/ 1.0 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 = pow((l * h), -0.5);
	double tmp;
	if (l <= -3.2e-172) {
		tmp = d * -t_0;
	} else if (l <= -5e-310) {
		tmp = log1p(expm1((d * t_0)));
	} else if (l <= 5.8e+165) {
		tmp = (1.0 + (((h / l) * -0.5) * pow(((0.5 * (D_m * M_m)) / d), 2.0))) * (d / sqrt((l * h)));
	} else {
		tmp = d * (sqrt((1.0 / l)) / sqrt(h));
	}
	return tmp;
}
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((l * h), -0.5);
	double tmp;
	if (l <= -3.2e-172) {
		tmp = d * -t_0;
	} else if (l <= -5e-310) {
		tmp = Math.log1p(Math.expm1((d * t_0)));
	} else if (l <= 5.8e+165) {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow(((0.5 * (D_m * M_m)) / d), 2.0))) * (d / Math.sqrt((l * h)));
	} else {
		tmp = d * (Math.sqrt((1.0 / 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 = math.pow((l * h), -0.5)
	tmp = 0
	if l <= -3.2e-172:
		tmp = d * -t_0
	elif l <= -5e-310:
		tmp = math.log1p(math.expm1((d * t_0)))
	elif l <= 5.8e+165:
		tmp = (1.0 + (((h / l) * -0.5) * math.pow(((0.5 * (D_m * M_m)) / d), 2.0))) * (d / math.sqrt((l * h)))
	else:
		tmp = d * (math.sqrt((1.0 / 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(l * h) ^ -0.5
	tmp = 0.0
	if (l <= -3.2e-172)
		tmp = Float64(d * Float64(-t_0));
	elseif (l <= -5e-310)
		tmp = log1p(expm1(Float64(d * t_0)));
	elseif (l <= 5.8e+165)
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(Float64(0.5 * Float64(D_m * M_m)) / d) ^ 2.0))) * Float64(d / sqrt(Float64(l * h))));
	else
		tmp = Float64(d * Float64(sqrt(Float64(1.0 / 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_] := Block[{t$95$0 = N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]}, If[LessEqual[l, -3.2e-172], N[(d * (-t$95$0)), $MachinePrecision], If[LessEqual[l, -5e-310], N[Log[1 + N[(Exp[N[(d * t$95$0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], If[LessEqual[l, 5.8e+165], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(N[(0.5 * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Sqrt[N[(1.0 / l), $MachinePrecision]], $MachinePrecision] / N[Sqrt[h], $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(\ell \cdot h\right)}^{-0.5}\\
\mathbf{if}\;\ell \leq -3.2 \cdot 10^{-172}:\\
\;\;\;\;d \cdot \left(-t\_0\right)\\

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(d \cdot t\_0\right)\right)\\

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -3.2000000000000001e-172 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(d \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right)\right) \]
    7. Applied egg-rr48.3%

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

    if -4.999999999999985e-310 < l < 5.80000000000000011e165

    1. Initial program 68.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. Add Preprocessing
    3. Applied egg-rr73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.80000000000000011e165 < l

    1. Initial program 58.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. Add Preprocessing
    3. Taylor expanded in d around inf 61.4%

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

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

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

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

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

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

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

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

\mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \log \left(e^{t\_0}\right)\\

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -3.1e-171 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

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

        \[\leadsto d \cdot \color{blue}{\log \left(e^{\sqrt{\frac{1}{\ell \cdot h}}}\right)} \]
      2. inv-pow55.9%

        \[\leadsto d \cdot \log \left(e^{\sqrt{\color{blue}{{\left(\ell \cdot h\right)}^{-1}}}}\right) \]
      3. sqrt-pow155.9%

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

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

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

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

    if -4.999999999999985e-310 < l < 1.74999999999999998e165

    1. Initial program 68.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. Add Preprocessing
    3. Applied egg-rr73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.74999999999999998e165 < l

    1. Initial program 58.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. Add Preprocessing
    3. Taylor expanded in d around inf 61.4%

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

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

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

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

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

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

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

Alternative 13: 58.7% 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.6 \cdot 10^{-171}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-1.5}}\\ \mathbf{elif}\;\ell \leq 5.4 \cdot 10^{+163}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(D\_m \cdot \left(0.5 \cdot \frac{M\_m}{d}\right)\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{\ell}}}{\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 -4.6e-171)
   (* d (- (pow (* l h) -0.5)))
   (if (<= l -5e-310)
     (* d (cbrt (pow (* l h) -1.5)))
     (if (<= l 5.4e+163)
       (*
        (+ 1.0 (* (* (/ h l) -0.5) (pow (* D_m (* 0.5 (/ M_m d))) 2.0)))
        (/ d (sqrt (* l h))))
       (* d (/ (sqrt (/ 1.0 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 <= -4.6e-171) {
		tmp = d * -pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * cbrt(pow((l * h), -1.5));
	} else if (l <= 5.4e+163) {
		tmp = (1.0 + (((h / l) * -0.5) * pow((D_m * (0.5 * (M_m / d))), 2.0))) * (d / sqrt((l * h)));
	} else {
		tmp = d * (sqrt((1.0 / l)) / sqrt(h));
	}
	return tmp;
}
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 <= -4.6e-171) {
		tmp = d * -Math.pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow((l * h), -1.5));
	} else if (l <= 5.4e+163) {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow((D_m * (0.5 * (M_m / d))), 2.0))) * (d / Math.sqrt((l * h)));
	} else {
		tmp = d * (Math.sqrt((1.0 / 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)
	tmp = 0.0
	if (l <= -4.6e-171)
		tmp = Float64(d * Float64(-(Float64(l * h) ^ -0.5)));
	elseif (l <= -5e-310)
		tmp = Float64(d * cbrt((Float64(l * h) ^ -1.5)));
	elseif (l <= 5.4e+163)
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(D_m * Float64(0.5 * Float64(M_m / d))) ^ 2.0))) * Float64(d / sqrt(Float64(l * h))));
	else
		tmp = Float64(d * Float64(sqrt(Float64(1.0 / 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, -4.6e-171], N[(d * (-N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -5e-310], N[(d * N[Power[N[Power[N[(l * h), $MachinePrecision], -1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 5.4e+163], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(D$95$m * N[(0.5 * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Sqrt[N[(1.0 / l), $MachinePrecision]], $MachinePrecision] / N[Sqrt[h], $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.6 \cdot 10^{-171}:\\
\;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\

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

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -4.59999999999999956e-171 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 35.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval33.2%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr33.2%

      \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
    11. Step-by-step derivation
      1. add-cbrt-cube33.2%

        \[\leadsto d \cdot \left(\color{blue}{\sqrt[3]{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \]
      2. add-cbrt-cube33.2%

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

        \[\leadsto d \cdot \color{blue}{\sqrt[3]{\left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)}} \]
      4. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{\left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      5. metadata-eval45.9%

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

        \[\leadsto d \cdot \sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      7. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      8. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-0.75}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      9. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      10. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.5}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      11. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}}} \]
      12. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)}} \]
      13. metadata-eval45.9%

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\left(\ell \cdot h\right)}^{-0.75}}} \]
    13. Step-by-step derivation
      1. pow-sqr45.9%

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

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-1.5}}} \]
    14. Simplified45.9%

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

    if -4.999999999999985e-310 < l < 5.39999999999999998e163

    1. Initial program 68.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. Add Preprocessing
    3. Applied egg-rr73.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.39999999999999998e163 < l

    1. Initial program 58.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. Add Preprocessing
    3. Taylor expanded in d around inf 61.4%

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

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

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

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

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

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

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

Alternative 14: 58.7% 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 -5.5 \cdot 10^{-171}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-1.5}}\\ \mathbf{elif}\;\ell \leq 1.02 \cdot 10^{+163}:\\ \;\;\;\;\left(1 + \left(\frac{h}{\ell} \cdot -0.5\right) \cdot {\left(\frac{0.5 \cdot \left(D\_m \cdot M\_m\right)}{d}\right)}^{2}\right) \cdot \frac{d}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \frac{\sqrt{\frac{1}{\ell}}}{\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 -5.5e-171)
   (* d (- (pow (* l h) -0.5)))
   (if (<= l -5e-310)
     (* d (cbrt (pow (* l h) -1.5)))
     (if (<= l 1.02e+163)
       (*
        (+ 1.0 (* (* (/ h l) -0.5) (pow (/ (* 0.5 (* D_m M_m)) d) 2.0)))
        (/ d (sqrt (* l h))))
       (* d (/ (sqrt (/ 1.0 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 <= -5.5e-171) {
		tmp = d * -pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * cbrt(pow((l * h), -1.5));
	} else if (l <= 1.02e+163) {
		tmp = (1.0 + (((h / l) * -0.5) * pow(((0.5 * (D_m * M_m)) / d), 2.0))) * (d / sqrt((l * h)));
	} else {
		tmp = d * (sqrt((1.0 / l)) / sqrt(h));
	}
	return tmp;
}
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.5e-171) {
		tmp = d * -Math.pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow((l * h), -1.5));
	} else if (l <= 1.02e+163) {
		tmp = (1.0 + (((h / l) * -0.5) * Math.pow(((0.5 * (D_m * M_m)) / d), 2.0))) * (d / Math.sqrt((l * h)));
	} else {
		tmp = d * (Math.sqrt((1.0 / 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)
	tmp = 0.0
	if (l <= -5.5e-171)
		tmp = Float64(d * Float64(-(Float64(l * h) ^ -0.5)));
	elseif (l <= -5e-310)
		tmp = Float64(d * cbrt((Float64(l * h) ^ -1.5)));
	elseif (l <= 1.02e+163)
		tmp = Float64(Float64(1.0 + Float64(Float64(Float64(h / l) * -0.5) * (Float64(Float64(0.5 * Float64(D_m * M_m)) / d) ^ 2.0))) * Float64(d / sqrt(Float64(l * h))));
	else
		tmp = Float64(d * Float64(sqrt(Float64(1.0 / 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, -5.5e-171], N[(d * (-N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -5e-310], N[(d * N[Power[N[Power[N[(l * h), $MachinePrecision], -1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.02e+163], N[(N[(1.0 + N[(N[(N[(h / l), $MachinePrecision] * -0.5), $MachinePrecision] * N[Power[N[(N[(0.5 * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(d / N[Sqrt[N[(l * h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Sqrt[N[(1.0 / l), $MachinePrecision]], $MachinePrecision] / N[Sqrt[h], $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.5 \cdot 10^{-171}:\\
\;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\

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

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -5.50000000000000037e-171 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 35.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval33.2%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr33.2%

      \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
    11. Step-by-step derivation
      1. add-cbrt-cube33.2%

        \[\leadsto d \cdot \left(\color{blue}{\sqrt[3]{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \]
      2. add-cbrt-cube33.2%

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

        \[\leadsto d \cdot \color{blue}{\sqrt[3]{\left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)}} \]
      4. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{\left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      5. metadata-eval45.9%

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

        \[\leadsto d \cdot \sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      7. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      8. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-0.75}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      9. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      10. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.5}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      11. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}}} \]
      12. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)}} \]
      13. metadata-eval45.9%

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\left(\ell \cdot h\right)}^{-0.75}}} \]
    13. Step-by-step derivation
      1. pow-sqr45.9%

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

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-1.5}}} \]
    14. Simplified45.9%

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

    if -4.999999999999985e-310 < l < 1.02e163

    1. Initial program 68.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. Add Preprocessing
    3. Applied egg-rr73.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02e163 < l

    1. Initial program 58.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. Add Preprocessing
    3. Taylor expanded in d around inf 61.4%

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

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

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

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

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

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

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

Alternative 15: 46.9% 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}\;\ell \leq -1.6 \cdot 10^{-171}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-1.5}}\\ \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 -1.6e-171)
   (* d (- (pow (* l h) -0.5)))
   (if (<= l -5e-310)
     (* d (cbrt (pow (* l h) -1.5)))
     (* 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 <= -1.6e-171) {
		tmp = d * -pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * cbrt(pow((l * h), -1.5));
	} else {
		tmp = d * (pow(l, -0.5) * pow(h, -0.5));
	}
	return tmp;
}
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.6e-171) {
		tmp = d * -Math.pow((l * h), -0.5);
	} else if (l <= -5e-310) {
		tmp = d * Math.cbrt(Math.pow((l * h), -1.5));
	} 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 <= -1.6e-171)
		tmp = Float64(d * Float64(-(Float64(l * h) ^ -0.5)));
	elseif (l <= -5e-310)
		tmp = Float64(d * cbrt((Float64(l * h) ^ -1.5)));
	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, -1.6e-171], N[(d * (-N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision])), $MachinePrecision], If[LessEqual[l, -5e-310], N[(d * N[Power[N[Power[N[(l * h), $MachinePrecision], -1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(d * N[(N[Power[l, -0.5], $MachinePrecision] * N[Power[h, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_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.6 \cdot 10^{-171}:\\
\;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -1.6000000000000001e-171 < l < -4.999999999999985e-310

    1. Initial program 77.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. Add Preprocessing
    3. Taylor expanded in d around inf 35.7%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 35.7%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval33.2%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr33.2%

      \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
    11. Step-by-step derivation
      1. add-cbrt-cube33.2%

        \[\leadsto d \cdot \left(\color{blue}{\sqrt[3]{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \]
      2. add-cbrt-cube33.2%

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

        \[\leadsto d \cdot \color{blue}{\sqrt[3]{\left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)}} \]
      4. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{\left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      5. metadata-eval45.9%

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

        \[\leadsto d \cdot \sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      7. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      8. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-0.75}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      9. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.25 + -0.25\right)}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      10. metadata-eval45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.5}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      11. pow-prod-up45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}}} \]
      12. *-commutative45.9%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)}} \]
      13. metadata-eval45.9%

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\left(\ell \cdot h\right)}^{-0.75}}} \]
    13. Step-by-step derivation
      1. pow-sqr45.9%

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

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-1.5}}} \]
    14. Simplified45.9%

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

    if -4.999999999999985e-310 < l

    1. Initial program 65.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. Add Preprocessing
    3. Taylor expanded in d around inf 41.3%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 41.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -4.0999999999999998e-169 < l < -2.59999999999999996e-307

    1. Initial program 76.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. Add Preprocessing
    3. Taylor expanded in d around inf 36.6%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 36.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{\color{blue}{-0.25}} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}\right) \]
      3. metadata-eval34.0%

        \[\leadsto d \cdot \left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{\color{blue}{-0.25}}\right) \]
    10. Applied egg-rr34.0%

      \[\leadsto d \cdot \color{blue}{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
    11. Step-by-step derivation
      1. add-cbrt-cube34.0%

        \[\leadsto d \cdot \left(\color{blue}{\sqrt[3]{\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}}} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \]
      2. add-cbrt-cube34.0%

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

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

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

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

        \[\leadsto d \cdot \sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}} \cdot \left(\left({\left(h \cdot \ell\right)}^{-0.25} \cdot {\left(h \cdot \ell\right)}^{-0.25}\right) \cdot {\left(h \cdot \ell\right)}^{-0.25}\right)} \]
      7. *-commutative47.1%

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

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

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

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

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-0.5 + -0.25\right)}}} \]
      12. *-commutative47.1%

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\color{blue}{\left(\ell \cdot h\right)}}^{\left(-0.5 + -0.25\right)}} \]
      13. metadata-eval47.1%

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\ell \cdot h\right)}^{-0.75} \cdot {\left(\ell \cdot h\right)}^{-0.75}}} \]
    13. Step-by-step derivation
      1. pow-sqr47.1%

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

        \[\leadsto d \cdot \sqrt[3]{{\left(\ell \cdot h\right)}^{\color{blue}{-1.5}}} \]
    14. Simplified47.1%

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

    if -2.59999999999999996e-307 < l

    1. Initial program 65.9%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 41.0%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 41.0%

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

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

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

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

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

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

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

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

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

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

Alternative 17: 42.7% accurate, 2.7× 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(\ell \cdot h\right)}^{-0.5}\\ \mathbf{if}\;\ell \leq -6 \cdot 10^{-172}:\\ \;\;\;\;d \cdot \left(-t\_0\right)\\ \mathbf{elif}\;\ell \leq -6.3 \cdot 10^{-267}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{elif}\;\ell \leq 2.75 \cdot 10^{-250}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \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 (pow (* l h) -0.5)))
   (if (<= l -6e-172)
     (* d (- t_0))
     (if (<= l -6.3e-267)
       (* d (sqrt (/ 1.0 (* l h))))
       (if (<= l 2.75e-250) (* d (- (sqrt (/ (/ 1.0 h) l)))) (* 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 = pow((l * h), -0.5);
	double tmp;
	if (l <= -6e-172) {
		tmp = d * -t_0;
	} else if (l <= -6.3e-267) {
		tmp = d * sqrt((1.0 / (l * h)));
	} else if (l <= 2.75e-250) {
		tmp = d * -sqrt(((1.0 / h) / l));
	} 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 = (l * h) ** (-0.5d0)
    if (l <= (-6d-172)) then
        tmp = d * -t_0
    else if (l <= (-6.3d-267)) then
        tmp = d * sqrt((1.0d0 / (l * h)))
    else if (l <= 2.75d-250) then
        tmp = d * -sqrt(((1.0d0 / h) / l))
    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.pow((l * h), -0.5);
	double tmp;
	if (l <= -6e-172) {
		tmp = d * -t_0;
	} else if (l <= -6.3e-267) {
		tmp = d * Math.sqrt((1.0 / (l * h)));
	} else if (l <= 2.75e-250) {
		tmp = d * -Math.sqrt(((1.0 / h) / l));
	} 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.pow((l * h), -0.5)
	tmp = 0
	if l <= -6e-172:
		tmp = d * -t_0
	elif l <= -6.3e-267:
		tmp = d * math.sqrt((1.0 / (l * h)))
	elif l <= 2.75e-250:
		tmp = d * -math.sqrt(((1.0 / h) / l))
	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 = Float64(l * h) ^ -0.5
	tmp = 0.0
	if (l <= -6e-172)
		tmp = Float64(d * Float64(-t_0));
	elseif (l <= -6.3e-267)
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(l * h))));
	elseif (l <= 2.75e-250)
		tmp = Float64(d * Float64(-sqrt(Float64(Float64(1.0 / h) / l))));
	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 = (l * h) ^ -0.5;
	tmp = 0.0;
	if (l <= -6e-172)
		tmp = d * -t_0;
	elseif (l <= -6.3e-267)
		tmp = d * sqrt((1.0 / (l * h)));
	elseif (l <= 2.75e-250)
		tmp = d * -sqrt(((1.0 / h) / l));
	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[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]}, If[LessEqual[l, -6e-172], N[(d * (-t$95$0)), $MachinePrecision], If[LessEqual[l, -6.3e-267], N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 2.75e-250], N[(d * (-N[Sqrt[N[(N[(1.0 / h), $MachinePrecision] / l), $MachinePrecision]], $MachinePrecision])), $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 := {\left(\ell \cdot h\right)}^{-0.5}\\
\mathbf{if}\;\ell \leq -6 \cdot 10^{-172}:\\
\;\;\;\;d \cdot \left(-t\_0\right)\\

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

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

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -5.99999999999999967e-172 < l < -6.30000000000000042e-267

    1. Initial program 88.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. Add Preprocessing
    3. Taylor expanded in d around inf 45.4%

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

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

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

    if -6.30000000000000042e-267 < l < 2.75e-250

    1. Initial program 75.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. Add Preprocessing
    3. Taylor expanded in d around inf 15.7%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt28.7%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg28.6%

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

      \[\leadsto d \cdot \color{blue}{\left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]
    9. Taylor expanded in d around 0 28.7%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    10. Step-by-step derivation
      1. mul-1-neg28.7%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. distribute-rgt-neg-in28.7%

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

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

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

    if 2.75e-250 < l

    1. Initial program 62.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. Add Preprocessing
    3. Taylor expanded in d around inf 44.5%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 44.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{-172}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -6.3 \cdot 10^{-267}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{elif}\;\ell \leq 2.75 \cdot 10^{-250}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{\frac{1}{h}}{\ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 42.6% accurate, 2.7× 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(\ell \cdot h\right)}^{-0.5}\\ t_1 := d \cdot \left(-t\_0\right)\\ \mathbf{if}\;\ell \leq -4.4 \cdot 10^{-172}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -4.5 \cdot 10^{-270}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-249}:\\ \;\;\;\;t\_1\\ \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 (pow (* l h) -0.5)) (t_1 (* d (- t_0))))
   (if (<= l -4.4e-172)
     t_1
     (if (<= l -4.5e-270)
       (* d (sqrt (/ 1.0 (* l h))))
       (if (<= l 6.8e-249) t_1 (* 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 = pow((l * h), -0.5);
	double t_1 = d * -t_0;
	double tmp;
	if (l <= -4.4e-172) {
		tmp = t_1;
	} else if (l <= -4.5e-270) {
		tmp = d * sqrt((1.0 / (l * h)));
	} else if (l <= 6.8e-249) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_0 = (l * h) ** (-0.5d0)
    t_1 = d * -t_0
    if (l <= (-4.4d-172)) then
        tmp = t_1
    else if (l <= (-4.5d-270)) then
        tmp = d * sqrt((1.0d0 / (l * h)))
    else if (l <= 6.8d-249) then
        tmp = t_1
    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.pow((l * h), -0.5);
	double t_1 = d * -t_0;
	double tmp;
	if (l <= -4.4e-172) {
		tmp = t_1;
	} else if (l <= -4.5e-270) {
		tmp = d * Math.sqrt((1.0 / (l * h)));
	} else if (l <= 6.8e-249) {
		tmp = t_1;
	} 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.pow((l * h), -0.5)
	t_1 = d * -t_0
	tmp = 0
	if l <= -4.4e-172:
		tmp = t_1
	elif l <= -4.5e-270:
		tmp = d * math.sqrt((1.0 / (l * h)))
	elif l <= 6.8e-249:
		tmp = t_1
	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 = Float64(l * h) ^ -0.5
	t_1 = Float64(d * Float64(-t_0))
	tmp = 0.0
	if (l <= -4.4e-172)
		tmp = t_1;
	elseif (l <= -4.5e-270)
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(l * h))));
	elseif (l <= 6.8e-249)
		tmp = t_1;
	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 = (l * h) ^ -0.5;
	t_1 = d * -t_0;
	tmp = 0.0;
	if (l <= -4.4e-172)
		tmp = t_1;
	elseif (l <= -4.5e-270)
		tmp = d * sqrt((1.0 / (l * h)));
	elseif (l <= 6.8e-249)
		tmp = t_1;
	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[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]}, Block[{t$95$1 = N[(d * (-t$95$0)), $MachinePrecision]}, If[LessEqual[l, -4.4e-172], t$95$1, If[LessEqual[l, -4.5e-270], N[(d * N[Sqrt[N[(1.0 / N[(l * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 6.8e-249], t$95$1, 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 := {\left(\ell \cdot h\right)}^{-0.5}\\
t_1 := d \cdot \left(-t\_0\right)\\
\mathbf{if}\;\ell \leq -4.4 \cdot 10^{-172}:\\
\;\;\;\;t\_1\\

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

\mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-249}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.40000000000000018e-172 or -4.49999999999999998e-270 < l < 6.7999999999999996e-249

    1. Initial program 65.1%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 11.2%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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.8%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg44.4%

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

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

    if -4.40000000000000018e-172 < l < -4.49999999999999998e-270

    1. Initial program 88.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. Add Preprocessing
    3. Taylor expanded in d around inf 45.4%

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

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

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

    if 6.7999999999999996e-249 < l

    1. Initial program 62.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. Add Preprocessing
    3. Taylor expanded in d around inf 44.5%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 44.5%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.4 \cdot 10^{-172}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -4.5 \cdot 10^{-270}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \mathbf{elif}\;\ell \leq 6.8 \cdot 10^{-249}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 42.1% 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} t_0 := {\left(\ell \cdot h\right)}^{-0.5}\\ \mathbf{if}\;\ell \leq -3.2 \cdot 10^{-172}:\\ \;\;\;\;d \cdot \left(-t\_0\right)\\ \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 (pow (* l h) -0.5)))
   (if (<= l -3.2e-172) (* 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 = pow((l * h), -0.5);
	double tmp;
	if (l <= -3.2e-172) {
		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 = (l * h) ** (-0.5d0)
    if (l <= (-3.2d-172)) 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.pow((l * h), -0.5);
	double tmp;
	if (l <= -3.2e-172) {
		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.pow((l * h), -0.5)
	tmp = 0
	if l <= -3.2e-172:
		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 = Float64(l * h) ^ -0.5
	tmp = 0.0
	if (l <= -3.2e-172)
		tmp = Float64(d * Float64(-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 = (l * h) ^ -0.5;
	tmp = 0.0;
	if (l <= -3.2e-172)
		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[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]}, If[LessEqual[l, -3.2e-172], 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 := {\left(\ell \cdot h\right)}^{-0.5}\\
\mathbf{if}\;\ell \leq -3.2 \cdot 10^{-172}:\\
\;\;\;\;d \cdot \left(-t\_0\right)\\

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


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

    1. Initial program 61.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. Add Preprocessing
    3. Taylor expanded in d around inf 9.8%

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

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

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

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

        \[\leadsto d \cdot \color{blue}{\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-sqrt48.5%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left(-1 \cdot \color{blue}{{\left(h \cdot \ell\right)}^{-0.5}}\right) \]
      11. mul-1-neg49.3%

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

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

    if -3.2000000000000001e-172 < l

    1. Initial program 68.3%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf 40.0%

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
    6. Taylor expanded in l around 0 40.0%

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

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

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

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

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

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

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

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

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

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

Alternative 20: 25.9% 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(\ell \cdot h\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 (* l 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) {
	return d * pow((l * h), -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 * ((l * h) ** (-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((l * h), -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((l * h), -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(l * h) ^ -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 * ((l * h) ^ -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[(l * h), $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(\ell \cdot h\right)}^{-0.5}
\end{array}
Derivation
  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. Add Preprocessing
  3. Taylor expanded in d around inf 29.8%

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

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

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{\ell \cdot h}}} \]
  6. Taylor expanded in l around 0 29.8%

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

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

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

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

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

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

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

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

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

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

Reproduce

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