Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.9% → 75.4%
Time: 46.3s
Alternatives: 26
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 26 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.9% 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: 75.4% accurate, 0.6× speedup?

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

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

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


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

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

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

        \[\leadsto \left(\color{blue}{{\left(\frac{d}{h}\right)}^{0.5}} \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) \]
      2. sqr-pow72.4%

        \[\leadsto \left(\color{blue}{\left({\left(\frac{d}{h}\right)}^{\left(\frac{0.5}{2}\right)} \cdot {\left(\frac{d}{h}\right)}^{\left(\frac{0.5}{2}\right)}\right)} \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. pow272.4%

        \[\leadsto \left(\color{blue}{{\left({\left(\frac{d}{h}\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2}} \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) \]
      4. metadata-eval72.4%

        \[\leadsto \left({\left({\left(\frac{d}{h}\right)}^{\color{blue}{0.25}}\right)}^{2} \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) \]
    4. Applied egg-rr72.4%

      \[\leadsto \left(\color{blue}{{\left({\left(\frac{d}{h}\right)}^{0.25}\right)}^{2}} \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) \]
    5. Taylor expanded in d around -inf 77.4%

      \[\leadsto \left({\color{blue}{\left(e^{0.25 \cdot \left(\log \left(\frac{-1}{h}\right) + -1 \cdot \log \left(\frac{-1}{d}\right)\right)}\right)}}^{2} \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) \]
    6. Step-by-step derivation
      1. distribute-lft-in77.4%

        \[\leadsto \left({\left(e^{\color{blue}{0.25 \cdot \log \left(\frac{-1}{h}\right) + 0.25 \cdot \left(-1 \cdot \log \left(\frac{-1}{d}\right)\right)}}\right)}^{2} \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) \]
      2. exp-sum77.9%

        \[\leadsto \left({\color{blue}{\left(e^{0.25 \cdot \log \left(\frac{-1}{h}\right)} \cdot e^{0.25 \cdot \left(-1 \cdot \log \left(\frac{-1}{d}\right)\right)}\right)}}^{2} \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. *-commutative77.9%

        \[\leadsto \left({\left(e^{\color{blue}{\log \left(\frac{-1}{h}\right) \cdot 0.25}} \cdot e^{0.25 \cdot \left(-1 \cdot \log \left(\frac{-1}{d}\right)\right)}\right)}^{2} \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) \]
      4. exp-to-pow78.7%

        \[\leadsto \left({\left(\color{blue}{{\left(\frac{-1}{h}\right)}^{0.25}} \cdot e^{0.25 \cdot \left(-1 \cdot \log \left(\frac{-1}{d}\right)\right)}\right)}^{2} \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) \]
      5. *-commutative78.7%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot e^{\color{blue}{\left(-1 \cdot \log \left(\frac{-1}{d}\right)\right) \cdot 0.25}}\right)}^{2} \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) \]
      6. *-commutative78.7%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot e^{\color{blue}{\left(\log \left(\frac{-1}{d}\right) \cdot -1\right)} \cdot 0.25}\right)}^{2} \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) \]
      7. associate-*l*78.7%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot e^{\color{blue}{\log \left(\frac{-1}{d}\right) \cdot \left(-1 \cdot 0.25\right)}}\right)}^{2} \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) \]
      8. metadata-eval78.7%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot e^{\log \left(\frac{-1}{d}\right) \cdot \color{blue}{-0.25}}\right)}^{2} \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) \]
      9. metadata-eval78.7%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot e^{\log \left(\frac{-1}{d}\right) \cdot \color{blue}{\left(0.25 \cdot -1\right)}}\right)}^{2} \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) \]
      10. exp-to-pow81.8%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot \color{blue}{{\left(\frac{-1}{d}\right)}^{\left(0.25 \cdot -1\right)}}\right)}^{2} \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) \]
      11. metadata-eval81.8%

        \[\leadsto \left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot {\left(\frac{-1}{d}\right)}^{\color{blue}{-0.25}}\right)}^{2} \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) \]
    7. Simplified81.8%

      \[\leadsto \left({\color{blue}{\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot {\left(\frac{-1}{d}\right)}^{-0.25}\right)}}^{2} \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) \]

    if -3.1999999999999999e-37 < d < 1.17999999999999995e-275

    1. Initial program 43.8%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in57.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\color{blue}{\left|{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}\right|} \cdot \left(-d\right)\right) \]
      7. metadata-eval57.4%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow57.4%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr57.4%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow57.4%

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

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

    if 1.17999999999999995e-275 < d

    1. Initial program 78.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.2 \cdot 10^{-37}:\\ \;\;\;\;\left({\left({\left(\frac{-1}{h}\right)}^{0.25} \cdot {\left(\frac{-1}{d}\right)}^{-0.25}\right)}^{2} \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)\\ \mathbf{elif}\;d \leq 1.18 \cdot 10^{-275}:\\ \;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{d}}{\sqrt{h}}\right) \cdot \left(1 - 0.5 \cdot \frac{h \cdot {\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right)}^{2}}{\ell}\right)\\ \end{array} \]

Alternative 2: 72.3% accurate, 0.8× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.7999999999999993e85 < d < -4.999999999999985e-310

    1. Initial program 56.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in65.8%

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}} \cdot \left(-d\right)\right) \]
      5. sqr-pow65.8%

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\color{blue}{\left|{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}\right|} \cdot \left(-d\right)\right) \]
      7. metadata-eval65.8%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow65.9%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr65.9%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow65.8%

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

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

    if -4.999999999999985e-310 < d < 7.4999999999999997e-236

    1. Initial program 16.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. Simplified14.6%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around 0 38.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-*l/38.0%

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

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

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

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

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

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

    if 7.4999999999999997e-236 < d

    1. Initial program 82.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. Simplified81.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.8 \cdot 10^{+85}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \frac{0.25 \cdot \left({\left(\frac{D}{d}\right)}^{2} \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{\ell}\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-236}:\\ \;\;\;\;-0.125 \cdot \frac{\left(M \cdot \left(M \cdot \left(D \cdot D\right)\right)\right) \cdot \sqrt{\frac{h}{{\ell}^{3}}}}{d}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \frac{h \cdot {\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right)}^{2}}{\ell}\right) \cdot \left(\sqrt{\frac{d}{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right)\\ \end{array} \]

Alternative 3: 74.0% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 55.5%

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

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

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

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

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

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

    if -2.60000000000000007e35 < h < -1.999999999999994e-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.3%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in81.7%

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

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

    if -1.999999999999994e-310 < h

    1. Initial program 74.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. Simplified73.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. Step-by-step derivation
      1. sqrt-div82.8%

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

      \[\leadsto \left(\color{blue}{\frac{\sqrt{d}}{\sqrt{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. Recombined 3 regimes into one program.
  4. Final simplification75.6%

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

Alternative 4: 75.0% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 55.5%

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

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

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

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

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

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

    if -1.95e35 < h < -1.999999999999994e-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.3%

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in81.7%

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

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

    if -1.999999999999994e-310 < h

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

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

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

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

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

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

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

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

Alternative 5: 71.1% accurate, 1.0× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.8000000000000001e-26 or 3.80000000000000024e-237 < d

    1. Initial program 78.0%

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

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

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

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

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

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

    if -2.8000000000000001e-26 < d < -4.999999999999985e-310

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in63.7%

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}} \cdot \left(-d\right)\right) \]
      5. sqr-pow63.7%

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow63.7%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr63.7%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow63.7%

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

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

    if -4.999999999999985e-310 < d < 3.80000000000000024e-237

    1. Initial program 16.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. Simplified14.6%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around 0 38.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-*l/38.0%

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

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

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

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

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

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

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

Alternative 6: 69.6% accurate, 1.0× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.1999999999999996e85 < d < -4.999999999999985e-310

    1. Initial program 56.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in65.8%

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\sqrt{\color{blue}{{\left(h \cdot \ell\right)}^{-1}}} \cdot \left(-d\right)\right) \]
      5. sqr-pow65.8%

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\color{blue}{\left|{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}\right|} \cdot \left(-d\right)\right) \]
      7. metadata-eval65.8%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow65.9%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr65.9%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow65.8%

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

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

    if -4.999999999999985e-310 < d < 1.14999999999999999e-235

    1. Initial program 16.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. Simplified14.6%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around 0 38.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-*l/38.0%

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

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

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

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

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

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

    if 1.14999999999999999e-235 < d

    1. Initial program 82.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. Simplified81.8%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -9.2 \cdot 10^{+85}:\\ \;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - 0.5 \cdot \frac{0.25 \cdot \left({\left(\frac{D}{d}\right)}^{2} \cdot \left(M \cdot \left(h \cdot M\right)\right)\right)}{\ell}\right)\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\right)\\ \mathbf{elif}\;d \leq 1.15 \cdot 10^{-235}:\\ \;\;\;\;-0.125 \cdot \frac{\left(M \cdot \left(M \cdot \left(D \cdot D\right)\right)\right) \cdot \sqrt{\frac{h}{{\ell}^{3}}}}{d}\\ \mathbf{else}:\\ \;\;\;\;\left(1 - 0.5 \cdot \frac{h \cdot {\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right)}^{2}}{\ell}\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \end{array} \]

Alternative 7: 69.1% accurate, 1.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;h \leq -1.48 \cdot 10^{+169} \lor \neg \left(h \leq -1.12 \cdot 10^{-304}\right):\\ \;\;\;\;\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (or (<= h -1.48e+169) (not (<= h -1.12e-304)))
   (*
    (- 1.0 (* 0.5 (* (pow (* (/ M 2.0) (/ D d)) 2.0) (/ h l))))
    (* (sqrt (/ d l)) (sqrt (/ d h))))
   (*
    (fma (/ h l) (* (pow (* D (/ M d)) 2.0) -0.125) 1.0)
    (* d (- (sqrt (/ 1.0 (* h l))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if ((h <= -1.48e+169) || !(h <= -1.12e-304)) {
		tmp = (1.0 - (0.5 * (pow(((M / 2.0) * (D / d)), 2.0) * (h / l)))) * (sqrt((d / l)) * sqrt((d / h)));
	} else {
		tmp = fma((h / l), (pow((D * (M / d)), 2.0) * -0.125), 1.0) * (d * -sqrt((1.0 / (h * l))));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if ((h <= -1.48e+169) || !(h <= -1.12e-304))
		tmp = Float64(Float64(1.0 - Float64(0.5 * Float64((Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0) * Float64(h / l)))) * Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))));
	else
		tmp = Float64(fma(Float64(h / l), Float64((Float64(D * Float64(M / d)) ^ 2.0) * -0.125), 1.0) * Float64(d * Float64(-sqrt(Float64(1.0 / Float64(h * l))))));
	end
	return tmp
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[Or[LessEqual[h, -1.48e+169], N[Not[LessEqual[h, -1.12e-304]], $MachinePrecision]], N[(N[(1.0 - N[(0.5 * N[(N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(D * N[(M / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * -0.125), $MachinePrecision] + 1.0), $MachinePrecision] * N[(d * (-N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq -1.48 \cdot 10^{+169} \lor \neg \left(h \leq -1.12 \cdot 10^{-304}\right):\\
\;\;\;\;\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < -1.48000000000000004e169 or -1.12000000000000006e-304 < h

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

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

    if -1.48000000000000004e169 < h < -1.12000000000000006e-304

    1. Initial program 66.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in78.0%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq -1.48 \cdot 10^{+169} \lor \neg \left(h \leq -1.12 \cdot 10^{-304}\right):\\ \;\;\;\;\left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right) \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\right)\\ \end{array} \]

Alternative 8: 65.6% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq 1.4 \cdot 10^{+86}:\\
\;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}} \cdot \mathsf{fma}\left(-0.125, \frac{h}{\ell} \cdot {\left(M \cdot \frac{D}{d}\right)}^{2}, 1\right)\\

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


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

    1. Initial program 62.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. Simplified61.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. Applied egg-rr14.9%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in66.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\color{blue}{\left|{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}\right|} \cdot \left(-d\right)\right) \]
      7. metadata-eval66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow66.3%

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

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

    if -3.50000000000000016e-245 < l < 1.40000000000000002e86

    1. Initial program 80.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. Simplified79.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.40000000000000002e86 < l

    1. Initial program 57.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot \left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \]
      6. fabs-sqr46.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)} \]
      7. sqr-pow46.6%

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

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

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

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

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

Alternative 9: 65.6% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq 1.2 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, -0.125 \cdot {\left(\frac{M \cdot D}{d}\right)}^{2}, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\

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


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

    1. Initial program 62.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. Simplified61.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. Applied egg-rr14.9%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in66.4%

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\color{blue}{\left|{\left(h \cdot \ell\right)}^{\left(\frac{-1}{2}\right)}\right|} \cdot \left(-d\right)\right) \]
      7. metadata-eval66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|{\left(h \cdot \ell\right)}^{\color{blue}{-0.5}}\right| \cdot \left(-d\right)\right) \]
      8. sqr-pow66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\left|\color{blue}{{\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)} \cdot {\left(h \cdot \ell\right)}^{\left(\frac{-0.5}{2}\right)}}\right| \cdot \left(-d\right)\right) \]
      9. fabs-sqr66.3%

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(\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)} \cdot \left(-d\right)\right) \]
      10. sqr-pow66.3%

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

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

    if -3.50000000000000016e-245 < l < 1.19999999999999999e82

    1. Initial program 80.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. Simplified78.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. Applied egg-rr20.9%

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

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

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

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

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

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

    if 1.19999999999999999e82 < l

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down61.0%

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

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

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

Alternative 10: 65.5% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq 5.8 \cdot 10^{+82}:\\
\;\;\;\;\mathsf{fma}\left(\frac{h}{\ell}, -0.125 \cdot {\left(\frac{M \cdot D}{d}\right)}^{2}, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\

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


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

    1. Initial program 62.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. Simplified61.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. Applied egg-rr14.9%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \left(-\color{blue}{\sqrt{\frac{1}{h \cdot \ell}} \cdot d}\right) \]
      3. distribute-rgt-neg-in66.4%

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

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

    if -4.8e-245 < l < 5.8000000000000003e82

    1. Initial program 80.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. Simplified78.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. Applied egg-rr20.9%

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

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

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

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

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

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

    if 5.8000000000000003e82 < l

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down61.0%

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

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

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

Alternative 11: 60.8% accurate, 1.4× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if D < 1.8000000000000001e142

    1. Initial program 68.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.8000000000000001e142 < D

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

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

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

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

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

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

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

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

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

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

Alternative 12: 46.2% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;d \leq -5.2 \cdot 10^{-142}:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -3.90000000000000019e34 or -2.1e-54 < d < -5.1999999999999999e-142

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.90000000000000019e34 < d < -2.1e-54

    1. Initial program 99.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. Simplified99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*68.0%

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

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

    if -5.1999999999999999e-142 < d < 7.6999999999999997e-261

    1. Initial program 41.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. Simplified40.6%

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

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

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

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

        \[\leadsto d \cdot \sqrt[3]{\frac{1}{h \cdot \ell} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}}} \]
      4. metadata-eval20.5%

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

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

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

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

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

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

    if 7.6999999999999997e-261 < d < 1.30000000000000002e-17

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.30000000000000002e-17 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down71.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.9 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -2.1 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq -5.2 \cdot 10^{-142}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 7.7 \cdot 10^{-261}:\\ \;\;\;\;d \cdot \sqrt[3]{\frac{1}{\left(h \cdot \ell\right) \cdot \sqrt{h \cdot \ell}}}\\ \mathbf{elif}\;d \leq 1.3 \cdot 10^{-17}:\\ \;\;\;\;-0.125 \cdot \frac{D \cdot \left(D \cdot \left(M \cdot M\right)\right)}{\frac{d}{\sqrt{\frac{h}{{\ell}^{3}}}}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({h}^{-0.5} \cdot {\ell}^{-0.5}\right)\\ \end{array} \]

Alternative 13: 48.7% accurate, 1.5× speedup?

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

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

\mathbf{elif}\;d \leq -4.1 \cdot 10^{-141}:\\
\;\;\;\;t_0\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if d < -9.99999999999999946e33 or -4.19999999999999955e-53 < d < -4.10000000000000002e-141

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.99999999999999946e33 < d < -4.19999999999999955e-53

    1. Initial program 99.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. Simplified99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*68.0%

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

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

    if -4.10000000000000002e-141 < d < 2.60000000000000012e-282

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.60000000000000012e-282 < d < 3.20000000000000023e-16

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.20000000000000023e-16 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down71.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -4.2 \cdot 10^{-53}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq -4.1 \cdot 10^{-141}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 2.6 \cdot 10^{-282}:\\ \;\;\;\;d \cdot \sqrt[3]{\frac{1}{\left(h \cdot \ell\right) \cdot \sqrt{h \cdot \ell}}}\\ \mathbf{elif}\;d \leq 3.2 \cdot 10^{-16}:\\ \;\;\;\;-0.125 \cdot \frac{D \cdot \left(D \cdot \left(M \cdot M\right)\right)}{\frac{d}{\frac{\sqrt{h}}{{\ell}^{1.5}}}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({h}^{-0.5} \cdot {\ell}^{-0.5}\right)\\ \end{array} \]

Alternative 14: 58.3% accurate, 1.5× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.6000000000000003e-94 < l < 2.99999999999999989e82

    1. Initial program 76.2%

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

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

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

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

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

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

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

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

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

    if 2.99999999999999989e82 < l

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down61.0%

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

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

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

Alternative 15: 58.2% accurate, 1.5× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -6.99999999999999996e-94 < l < 5.99999999999999978e82

    1. Initial program 76.2%

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

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

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

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

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

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

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

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

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

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

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

    if 5.99999999999999978e82 < l

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down61.0%

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

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

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

Alternative 16: 52.0% accurate, 1.5× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 9.5999999999999993e-24

    1. Initial program 70.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. Simplified70.1%

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

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

    if 9.5999999999999993e-24 < M

    1. Initial program 59.7%

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

      \[\leadsto \color{blue}{\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. Applied egg-rr12.8%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\frac{D \cdot D}{\color{blue}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      6. times-frac22.8%

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\left(\color{blue}{\left(\frac{D}{d} \cdot \frac{D}{d}\right)} \cdot \left(M \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. unswap-sqr30.0%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\left(\left(\frac{D}{d} \cdot M\right) \cdot \left(\frac{D}{d} \cdot M\right)\right)} \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      11. associate-/r/30.0%

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

        \[\leadsto \left(-0.125 \cdot \left(\left(\color{blue}{\frac{D \cdot M}{d}} \cdot \left(\frac{D}{d} \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      13. associate-*r/30.0%

        \[\leadsto \left(-0.125 \cdot \left(\left(\color{blue}{\left(D \cdot \frac{M}{d}\right)} \cdot \left(\frac{D}{d} \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      14. associate-/r/30.0%

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

        \[\leadsto \left(-0.125 \cdot \left(\left(\left(D \cdot \frac{M}{d}\right) \cdot \color{blue}{\frac{D \cdot M}{d}}\right) \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      16. associate-*r/29.9%

        \[\leadsto \left(-0.125 \cdot \left(\left(\left(D \cdot \frac{M}{d}\right) \cdot \color{blue}{\left(D \cdot \frac{M}{d}\right)}\right) \cdot \frac{h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      17. unpow229.9%

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

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

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

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

Alternative 17: 44.2% accurate, 1.5× speedup?

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

\mathbf{elif}\;d \leq -8.8 \cdot 10^{-57}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -3.25 \cdot 10^{-142}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq 1.95 \cdot 10^{-16}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.9000000000000001e34 or -8.79999999999999994e-57 < d < -3.25000000000000013e-142

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9000000000000001e34 < d < -8.79999999999999994e-57 or 1.2e-241 < d < 1.94999999999999989e-16

    1. Initial program 80.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.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. Applied egg-rr6.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\left(\frac{D}{d} \cdot \frac{D}{d}\right)} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      9. times-frac46.9%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*51.5%

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

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

    if -3.25000000000000013e-142 < d < 1.2e-241

    1. Initial program 37.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. Simplified36.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(0.5 + 1\right)}}}} \]
      4. metadata-eval16.7%

        \[\leadsto \frac{d}{\sqrt[3]{{\left(h \cdot \ell\right)}^{\color{blue}{1.5}}}} \]
    11. Simplified16.7%

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

    if 1.94999999999999989e-16 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{d \cdot {\left(h \cdot \ell\right)}^{-0.5}} \]
    8. Step-by-step derivation
      1. unpow-prod-down71.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.9 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -8.8 \cdot 10^{-57}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq -3.25 \cdot 10^{-142}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 1.2 \cdot 10^{-241}:\\ \;\;\;\;\frac{d}{\sqrt[3]{{\left(h \cdot \ell\right)}^{1.5}}}\\ \mathbf{elif}\;d \leq 1.95 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \left({h}^{-0.5} \cdot {\ell}^{-0.5}\right)\\ \end{array} \]

Alternative 18: 44.2% accurate, 1.5× speedup?

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

\mathbf{elif}\;d \leq -1.55 \cdot 10^{-51}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq -1.02 \cdot 10^{-143}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;d \leq 2.1 \cdot 10^{-15}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -3.99999999999999978e34 or -1.5499999999999999e-51 < d < -1.02e-143

    1. Initial program 62.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.99999999999999978e34 < d < -1.5499999999999999e-51 or 7.5e-243 < d < 2.09999999999999981e-15

    1. Initial program 80.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.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. Applied egg-rr6.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\left(\frac{D}{d} \cdot \frac{D}{d}\right)} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      9. times-frac46.9%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*51.5%

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

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

    if -1.02e-143 < d < 7.5e-243

    1. Initial program 37.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. Simplified36.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\sqrt[3]{\color{blue}{{\left(h \cdot \ell\right)}^{\left(0.5 + 1\right)}}}} \]
      4. metadata-eval16.7%

        \[\leadsto \frac{d}{\sqrt[3]{{\left(h \cdot \ell\right)}^{\color{blue}{1.5}}}} \]
    11. Simplified16.7%

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

    if 2.09999999999999981e-15 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -1.55 \cdot 10^{-51}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq -1.02 \cdot 10^{-143}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 7.5 \cdot 10^{-243}:\\ \;\;\;\;\frac{d}{\sqrt[3]{{\left(h \cdot \ell\right)}^{1.5}}}\\ \mathbf{elif}\;d \leq 2.1 \cdot 10^{-15}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 19: 43.9% accurate, 1.6× speedup?

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

\mathbf{elif}\;d \leq -1.75 \cdot 10^{-56}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 1.25 \cdot 10^{-225}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq 3.1 \cdot 10^{-16}:\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -1.40000000000000004e34 or -1.7499999999999999e-56 < d < 1.25e-225

    1. Initial program 51.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. Simplified50.7%

      \[\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. Applied egg-rr13.6%

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

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

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

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

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

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

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

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

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

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

    if -1.40000000000000004e34 < d < -1.7499999999999999e-56 or 1.25e-225 < d < 3.1000000000000001e-16

    1. Initial program 86.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. Simplified86.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*54.2%

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

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

    if 3.1000000000000001e-16 < d

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.4 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -1.75 \cdot 10^{-56}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq 1.25 \cdot 10^{-225}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 3.1 \cdot 10^{-16}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]

Alternative 20: 47.9% accurate, 1.6× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;M \leq 5.4 \cdot 10^{-13}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= M 5.4e-13)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (*
    (sqrt (* (/ d l) (/ d h)))
    (* -0.125 (* (/ (* D D) (* d d)) (/ (* h (* M M)) l))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (M <= 5.4e-13) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else {
		tmp = sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * ((h * (M * M)) / l)));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (m <= 5.4d-13) then
        tmp = sqrt((d / l)) * sqrt((d / h))
    else
        tmp = sqrt(((d / l) * (d / h))) * ((-0.125d0) * (((d_1 * d_1) / (d * d)) * ((h * (m * m)) / l)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (M <= 5.4e-13) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else {
		tmp = Math.sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * ((h * (M * M)) / l)));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if M <= 5.4e-13:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	else:
		tmp = math.sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * ((h * (M * M)) / l)))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (M <= 5.4e-13)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	else
		tmp = Float64(sqrt(Float64(Float64(d / l) * Float64(d / h))) * Float64(-0.125 * Float64(Float64(Float64(D * D) / Float64(d * d)) * Float64(Float64(h * Float64(M * M)) / l))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (M <= 5.4e-13)
		tmp = sqrt((d / l)) * sqrt((d / h));
	else
		tmp = sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * ((h * (M * M)) / l)));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[M, 5.4e-13], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-0.125 * N[(N[(N[(D * D), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * N[(N[(h * N[(M * M), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;M \leq 5.4 \cdot 10^{-13}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 5.40000000000000021e-13

    1. Initial program 70.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. Simplified69.7%

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

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

    if 5.40000000000000021e-13 < M

    1. Initial program 60.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-0.125 \cdot \left(\left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \color{blue}{\frac{{M}^{2}}{\frac{\ell}{h}}}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. unpow223.2%

        \[\leadsto \left(-0.125 \cdot \left(\left(\frac{D}{d} \cdot \frac{D}{d}\right) \cdot \frac{\color{blue}{M \cdot M}}{\frac{\ell}{h}}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      11. times-frac17.1%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \frac{M \cdot M}{\frac{\ell}{h}}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      12. unpow217.1%

        \[\leadsto \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{\color{blue}{{M}^{2}}}{\frac{\ell}{h}}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      13. associate-/l*16.6%

        \[\leadsto \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \color{blue}{\frac{{M}^{2} \cdot h}{\ell}}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
    9. Simplified16.6%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)} \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification34.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;M \leq 5.4 \cdot 10^{-13}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \frac{h \cdot \left(M \cdot M\right)}{\ell}\right)\right)\\ \end{array} \]

Alternative 21: 41.0% accurate, 2.5× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ t_1 := d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{if}\;d \leq -4.1 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{-49}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;d \leq 5.3 \cdot 10^{-225}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0
         (*
          (sqrt (* (/ d l) (/ d h)))
          (* -0.125 (* (/ (* D D) (* d d)) (* M (* M (/ h l)))))))
        (t_1 (* d (- (sqrt (/ 1.0 (* h l)))))))
   (if (<= d -4.1e+34)
     t_1
     (if (<= d -3.8e-49)
       t_0
       (if (<= d 5.3e-225)
         t_1
         (if (<= d 1.9e-15) t_0 (/ d (sqrt (* h l)))))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * (M * (M * (h / l)))));
	double t_1 = d * -sqrt((1.0 / (h * l)));
	double tmp;
	if (d <= -4.1e+34) {
		tmp = t_1;
	} else if (d <= -3.8e-49) {
		tmp = t_0;
	} else if (d <= 5.3e-225) {
		tmp = t_1;
	} else if (d <= 1.9e-15) {
		tmp = t_0;
	} else {
		tmp = d / sqrt((h * l));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sqrt(((d / l) * (d / h))) * ((-0.125d0) * (((d_1 * d_1) / (d * d)) * (m * (m * (h / l)))))
    t_1 = d * -sqrt((1.0d0 / (h * l)))
    if (d <= (-4.1d+34)) then
        tmp = t_1
    else if (d <= (-3.8d-49)) then
        tmp = t_0
    else if (d <= 5.3d-225) then
        tmp = t_1
    else if (d <= 1.9d-15) then
        tmp = t_0
    else
        tmp = d / sqrt((h * l))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * (M * (M * (h / l)))));
	double t_1 = d * -Math.sqrt((1.0 / (h * l)));
	double tmp;
	if (d <= -4.1e+34) {
		tmp = t_1;
	} else if (d <= -3.8e-49) {
		tmp = t_0;
	} else if (d <= 5.3e-225) {
		tmp = t_1;
	} else if (d <= 1.9e-15) {
		tmp = t_0;
	} else {
		tmp = d / Math.sqrt((h * l));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * (M * (M * (h / l)))))
	t_1 = d * -math.sqrt((1.0 / (h * l)))
	tmp = 0
	if d <= -4.1e+34:
		tmp = t_1
	elif d <= -3.8e-49:
		tmp = t_0
	elif d <= 5.3e-225:
		tmp = t_1
	elif d <= 1.9e-15:
		tmp = t_0
	else:
		tmp = d / math.sqrt((h * l))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = Float64(sqrt(Float64(Float64(d / l) * Float64(d / h))) * Float64(-0.125 * Float64(Float64(Float64(D * D) / Float64(d * d)) * Float64(M * Float64(M * Float64(h / l))))))
	t_1 = Float64(d * Float64(-sqrt(Float64(1.0 / Float64(h * l)))))
	tmp = 0.0
	if (d <= -4.1e+34)
		tmp = t_1;
	elseif (d <= -3.8e-49)
		tmp = t_0;
	elseif (d <= 5.3e-225)
		tmp = t_1;
	elseif (d <= 1.9e-15)
		tmp = t_0;
	else
		tmp = Float64(d / sqrt(Float64(h * l)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt(((d / l) * (d / h))) * (-0.125 * (((D * D) / (d * d)) * (M * (M * (h / l)))));
	t_1 = d * -sqrt((1.0 / (h * l)));
	tmp = 0.0;
	if (d <= -4.1e+34)
		tmp = t_1;
	elseif (d <= -3.8e-49)
		tmp = t_0;
	elseif (d <= 5.3e-225)
		tmp = t_1;
	elseif (d <= 1.9e-15)
		tmp = t_0;
	else
		tmp = d / sqrt((h * l));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-0.125 * N[(N[(N[(D * D), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * N[(M * N[(M * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(d * (-N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]}, If[LessEqual[d, -4.1e+34], t$95$1, If[LessEqual[d, -3.8e-49], t$95$0, If[LessEqual[d, 5.3e-225], t$95$1, If[LessEqual[d, 1.9e-15], t$95$0, N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\
t_1 := d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{if}\;d \leq -4.1 \cdot 10^{+34}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq -3.8 \cdot 10^{-49}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;d \leq 5.3 \cdot 10^{-225}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;d \leq 1.9 \cdot 10^{-15}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -4.0999999999999998e34 or -3.7999999999999997e-49 < d < 5.30000000000000005e-225

    1. Initial program 51.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. Simplified50.7%

      \[\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. Applied egg-rr13.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def19.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\right)} \]
      2. expm1-log1p34.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)} \]
      3. *-commutative34.9%

        \[\leadsto \color{blue}{\left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
    5. Simplified35.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    6. Taylor expanded in D around 0 35.7%

      \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2} \cdot -0.125, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
    7. Taylor expanded in d around -inf 39.2%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    8. Step-by-step derivation
      1. associate-*r*39.2%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg39.2%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    9. Simplified39.2%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if -4.0999999999999998e34 < d < -3.7999999999999997e-49 or 5.30000000000000005e-225 < d < 1.9000000000000001e-15

    1. Initial program 86.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. Simplified86.0%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr7.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def18.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\right)} \]
      2. expm1-log1p74.0%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)} \]
      3. *-commutative74.0%

        \[\leadsto \color{blue}{\left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
    5. Simplified72.3%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    6. Taylor expanded in h around inf 47.3%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{{d}^{2} \cdot \ell}\right)} \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
    7. Step-by-step derivation
      1. times-frac45.6%

        \[\leadsto \left(-0.125 \cdot \color{blue}{\left(\frac{{D}^{2}}{{d}^{2}} \cdot \frac{{M}^{2} \cdot h}{\ell}\right)}\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      2. unpow245.6%

        \[\leadsto \left(-0.125 \cdot \left(\frac{\color{blue}{D \cdot D}}{{d}^{2}} \cdot \frac{{M}^{2} \cdot h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      3. unpow245.6%

        \[\leadsto \left(-0.125 \cdot \left(\frac{D \cdot D}{\color{blue}{d \cdot d}} \cdot \frac{{M}^{2} \cdot h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      4. times-frac46.3%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\left(\frac{D}{d} \cdot \frac{D}{d}\right)} \cdot \frac{{M}^{2} \cdot h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      5. unpow246.3%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{{\left(\frac{D}{d}\right)}^{2}} \cdot \frac{{M}^{2} \cdot h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      6. unpow246.3%

        \[\leadsto \left(-0.125 \cdot \left({\left(\frac{D}{d}\right)}^{2} \cdot \frac{\color{blue}{\left(M \cdot M\right)} \cdot h}{\ell}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      7. associate-*r/49.4%

        \[\leadsto \left(-0.125 \cdot \left({\left(\frac{D}{d}\right)}^{2} \cdot \color{blue}{\left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      8. unpow249.4%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\left(\frac{D}{d} \cdot \frac{D}{d}\right)} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      9. times-frac49.1%

        \[\leadsto \left(-0.125 \cdot \left(\color{blue}{\frac{D \cdot D}{d \cdot d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{h}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
      10. associate-*l*54.2%

        \[\leadsto \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \color{blue}{\left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)}\right)\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
    8. Simplified54.2%

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)} \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]

    if 1.9000000000000001e-15 < d

    1. Initial program 88.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. Simplified86.3%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 61.8%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. pow161.8%

        \[\leadsto \color{blue}{{\left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{1}} \]
      2. sqrt-div61.7%

        \[\leadsto {\left(d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}}\right)}^{1} \]
      3. metadata-eval61.7%

        \[\leadsto {\left(d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}}\right)}^{1} \]
    5. Applied egg-rr61.7%

      \[\leadsto \color{blue}{{\left(d \cdot \frac{1}{\sqrt{h \cdot \ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow161.7%

        \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{h \cdot \ell}}} \]
      2. associate-*r/61.8%

        \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{h \cdot \ell}}} \]
      3. *-rgt-identity61.8%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h \cdot \ell}} \]
    7. Simplified61.8%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification47.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -4.1 \cdot 10^{+34}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq -3.8 \cdot 10^{-49}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{elif}\;d \leq 5.3 \cdot 10^{-225}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-15}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \cdot \left(-0.125 \cdot \left(\frac{D \cdot D}{d \cdot d} \cdot \left(M \cdot \left(M \cdot \frac{h}{\ell}\right)\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 22: 41.4% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} t_0 := \sqrt{\frac{1}{h \cdot \ell}}\\ \mathbf{if}\;\ell \leq 1.95 \cdot 10^{-144}:\\ \;\;\;\;d \cdot \left(-t_0\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot t_0\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ 1.0 (* h l)))))
   (if (<= l 1.95e-144) (* d (- t_0)) (* d t_0))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((1.0 / (h * l)));
	double tmp;
	if (l <= 1.95e-144) {
		tmp = d * -t_0;
	} else {
		tmp = d * t_0;
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((1.0d0 / (h * l)))
    if (l <= 1.95d-144) then
        tmp = d * -t_0
    else
        tmp = d * t_0
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((1.0 / (h * l)));
	double tmp;
	if (l <= 1.95e-144) {
		tmp = d * -t_0;
	} else {
		tmp = d * t_0;
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	t_0 = math.sqrt((1.0 / (h * l)))
	tmp = 0
	if l <= 1.95e-144:
		tmp = d * -t_0
	else:
		tmp = d * t_0
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(1.0 / Float64(h * l)))
	tmp = 0.0
	if (l <= 1.95e-144)
		tmp = Float64(d * Float64(-t_0));
	else
		tmp = Float64(d * t_0);
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((1.0 / (h * l)));
	tmp = 0.0;
	if (l <= 1.95e-144)
		tmp = d * -t_0;
	else
		tmp = d * t_0;
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, 1.95e-144], N[(d * (-t$95$0)), $MachinePrecision], N[(d * t$95$0), $MachinePrecision]]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{h \cdot \ell}}\\
\mathbf{if}\;\ell \leq 1.95 \cdot 10^{-144}:\\
\;\;\;\;d \cdot \left(-t_0\right)\\

\mathbf{else}:\\
\;\;\;\;d \cdot t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.95000000000000007e-144

    1. Initial program 65.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. Simplified64.1%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Applied egg-rr15.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)} - 1} \]
    4. Step-by-step derivation
      1. expm1-def20.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)\right)\right)} \]
      2. expm1-log1p49.5%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}} \cdot \left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right)} \]
      3. *-commutative49.5%

        \[\leadsto \color{blue}{\left(1 + -0.5 \cdot \left(\frac{h}{\ell} \cdot {\left(\left(M \cdot 0.5\right) \cdot \frac{D}{d}\right)}^{2}\right)\right) \cdot \sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
    5. Simplified50.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{h}{\ell}, {\left(D \cdot \frac{M}{d}\right)}^{2} \cdot -0.125, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}} \]
    6. Taylor expanded in D around 0 50.6%

      \[\leadsto \mathsf{fma}\left(\frac{h}{\ell}, {\color{blue}{\left(\frac{D \cdot M}{d}\right)}}^{2} \cdot -0.125, 1\right) \cdot \sqrt{\frac{d}{\ell} \cdot \frac{d}{h}} \]
    7. Taylor expanded in d around -inf 38.8%

      \[\leadsto \color{blue}{-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)} \]
    8. Step-by-step derivation
      1. associate-*r*38.8%

        \[\leadsto \color{blue}{\left(-1 \cdot d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      2. mul-1-neg38.8%

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
    9. Simplified38.8%

      \[\leadsto \color{blue}{\left(-d\right) \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]

    if 1.95000000000000007e-144 < l

    1. Initial program 72.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. Simplified72.2%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 44.6%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification40.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 1.95 \cdot 10^{-144}:\\ \;\;\;\;d \cdot \left(-\sqrt{\frac{1}{h \cdot \ell}}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \end{array} \]

Alternative 23: 37.9% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -6.5 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -6.5e-131) (sqrt (* (/ d l) (/ d h))) (/ d (sqrt (* h l)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -6.5e-131) {
		tmp = sqrt(((d / l) * (d / h)));
	} else {
		tmp = d / sqrt((h * l));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (d <= (-6.5d-131)) then
        tmp = sqrt(((d / l) * (d / h)))
    else
        tmp = d / sqrt((h * l))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -6.5e-131) {
		tmp = Math.sqrt(((d / l) * (d / h)));
	} else {
		tmp = d / Math.sqrt((h * l));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -6.5e-131:
		tmp = math.sqrt(((d / l) * (d / h)))
	else:
		tmp = d / math.sqrt((h * l))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -6.5e-131)
		tmp = sqrt(Float64(Float64(d / l) * Float64(d / h)));
	else
		tmp = Float64(d / sqrt(Float64(h * l)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -6.5e-131)
		tmp = sqrt(((d / l) * (d / h)));
	else
		tmp = d / sqrt((h * l));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -6.5e-131], N[Sqrt[N[(N[(d / l), $MachinePrecision] * N[(d / h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.5 \cdot 10^{-131}:\\
\;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -6.5000000000000002e-131

    1. Initial program 67.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. Simplified67.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \frac{M}{\frac{d}{D}}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 43.5%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. pow143.5%

        \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot 1\right)\right)}^{1}} \]
      2. *-rgt-identity43.5%

        \[\leadsto {\left(\sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}}\right)}^{1} \]
      3. *-commutative43.5%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)}}^{1} \]
      4. sqrt-unprod30.9%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}}^{1} \]
    5. Applied egg-rr30.9%

      \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow130.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
    7. Simplified30.9%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]

    if -6.5000000000000002e-131 < d

    1. Initial program 68.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. Simplified67.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 32.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. pow132.2%

        \[\leadsto \color{blue}{{\left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{1}} \]
      2. sqrt-div32.2%

        \[\leadsto {\left(d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}}\right)}^{1} \]
      3. metadata-eval32.2%

        \[\leadsto {\left(d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}}\right)}^{1} \]
    5. Applied egg-rr32.2%

      \[\leadsto \color{blue}{{\left(d \cdot \frac{1}{\sqrt{h \cdot \ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow132.2%

        \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{h \cdot \ell}}} \]
      2. associate-*r/32.2%

        \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{h \cdot \ell}}} \]
      3. *-rgt-identity32.2%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h \cdot \ell}} \]
    7. Simplified32.2%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -6.5 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{\frac{d}{\ell} \cdot \frac{d}{h}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 24: 37.9% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -3.7 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -3.7e-131) (sqrt (/ d (/ h (/ d l)))) (/ d (sqrt (* h l)))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -3.7e-131) {
		tmp = sqrt((d / (h / (d / l))));
	} else {
		tmp = d / sqrt((h * l));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (d <= (-3.7d-131)) then
        tmp = sqrt((d / (h / (d / l))))
    else
        tmp = d / sqrt((h * l))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -3.7e-131) {
		tmp = Math.sqrt((d / (h / (d / l))));
	} else {
		tmp = d / Math.sqrt((h * l));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -3.7e-131:
		tmp = math.sqrt((d / (h / (d / l))))
	else:
		tmp = d / math.sqrt((h * l))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -3.7e-131)
		tmp = sqrt(Float64(d / Float64(h / Float64(d / l))));
	else
		tmp = Float64(d / sqrt(Float64(h * l)));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -3.7e-131)
		tmp = sqrt((d / (h / (d / l))));
	else
		tmp = d / sqrt((h * l));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -3.7e-131], N[Sqrt[N[(d / N[(h / N[(d / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.7 \cdot 10^{-131}:\\
\;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.7000000000000002e-131

    1. Initial program 67.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. Simplified67.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \frac{M}{\frac{d}{D}}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 43.5%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. pow143.5%

        \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot 1\right)\right)}^{1}} \]
      2. *-rgt-identity43.5%

        \[\leadsto {\left(\sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}}\right)}^{1} \]
      3. *-commutative43.5%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)}}^{1} \]
      4. sqrt-unprod30.9%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}}^{1} \]
    5. Applied egg-rr30.9%

      \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow130.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
      2. associate-*l/27.4%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot \frac{d}{\ell}}{h}}} \]
      3. associate-/l*31.1%

        \[\leadsto \sqrt{\color{blue}{\frac{d}{\frac{h}{\frac{d}{\ell}}}}} \]
    7. Simplified31.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}} \]

    if -3.7000000000000002e-131 < d

    1. Initial program 68.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. Simplified67.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 32.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    4. Step-by-step derivation
      1. pow132.2%

        \[\leadsto \color{blue}{{\left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{1}} \]
      2. sqrt-div32.2%

        \[\leadsto {\left(d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}}\right)}^{1} \]
      3. metadata-eval32.2%

        \[\leadsto {\left(d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}}\right)}^{1} \]
    5. Applied egg-rr32.2%

      \[\leadsto \color{blue}{{\left(d \cdot \frac{1}{\sqrt{h \cdot \ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow132.2%

        \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{h \cdot \ell}}} \]
      2. associate-*r/32.2%

        \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{h \cdot \ell}}} \]
      3. *-rgt-identity32.2%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h \cdot \ell}} \]
    7. Simplified32.2%

      \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.7 \cdot 10^{-131}:\\ \;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{d}{\sqrt{h \cdot \ell}}\\ \end{array} \]

Alternative 25: 38.0% accurate, 3.0× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{-133}:\\ \;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \end{array} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -3.1e-133) (sqrt (/ d (/ h (/ d l)))) (* d (sqrt (/ 1.0 (* h l))))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -3.1e-133) {
		tmp = sqrt((d / (h / (d / l))));
	} else {
		tmp = d * sqrt((1.0 / (h * l)));
	}
	return tmp;
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (d <= (-3.1d-133)) then
        tmp = sqrt((d / (h / (d / l))))
    else
        tmp = d * sqrt((1.0d0 / (h * l)))
    end if
    code = tmp
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -3.1e-133) {
		tmp = Math.sqrt((d / (h / (d / l))));
	} else {
		tmp = d * Math.sqrt((1.0 / (h * l)));
	}
	return tmp;
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	tmp = 0
	if d <= -3.1e-133:
		tmp = math.sqrt((d / (h / (d / l))))
	else:
		tmp = d * math.sqrt((1.0 / (h * l)))
	return tmp
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -3.1e-133)
		tmp = sqrt(Float64(d / Float64(h / Float64(d / l))));
	else
		tmp = Float64(d * sqrt(Float64(1.0 / Float64(h * l))));
	end
	return tmp
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -3.1e-133)
		tmp = sqrt((d / (h / (d / l))));
	else
		tmp = d * sqrt((1.0 / (h * l)));
	end
	tmp_2 = tmp;
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -3.1e-133], N[Sqrt[N[(d / N[(h / N[(d / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.1 \cdot 10^{-133}:\\
\;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\

\mathbf{else}:\\
\;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if d < -3.10000000000000016e-133

    1. Initial program 67.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. Simplified67.2%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \mathsf{fma}\left({\left(0.5 \cdot \frac{M}{\frac{d}{D}}\right)}^{2}, -0.5 \cdot \frac{h}{\ell}, 1\right)\right)} \]
    3. Taylor expanded in M around 0 43.5%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{1}\right) \]
    4. Step-by-step derivation
      1. pow143.5%

        \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot 1\right)\right)}^{1}} \]
      2. *-rgt-identity43.5%

        \[\leadsto {\left(\sqrt{\frac{d}{\ell}} \cdot \color{blue}{\sqrt{\frac{d}{h}}}\right)}^{1} \]
      3. *-commutative43.5%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)}}^{1} \]
      4. sqrt-unprod30.9%

        \[\leadsto {\color{blue}{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}}^{1} \]
    5. Applied egg-rr30.9%

      \[\leadsto \color{blue}{{\left(\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}\right)}^{1}} \]
    6. Step-by-step derivation
      1. unpow130.9%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h} \cdot \frac{d}{\ell}}} \]
      2. associate-*l/27.4%

        \[\leadsto \sqrt{\color{blue}{\frac{d \cdot \frac{d}{\ell}}{h}}} \]
      3. associate-/l*31.1%

        \[\leadsto \sqrt{\color{blue}{\frac{d}{\frac{h}{\frac{d}{\ell}}}}} \]
    7. Simplified31.1%

      \[\leadsto \color{blue}{\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}} \]

    if -3.10000000000000016e-133 < d

    1. Initial program 68.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. Simplified67.4%

      \[\leadsto \color{blue}{\left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)} \]
    3. Taylor expanded in d around inf 32.2%

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification31.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -3.1 \cdot 10^{-133}:\\ \;\;\;\;\sqrt{\frac{d}{\frac{h}{\frac{d}{\ell}}}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\ \end{array} \]

Alternative 26: 25.9% accurate, 3.2× speedup?

\[\begin{array}{l} M = |M|\\ D = |D|\\ [M, D] = \mathsf{sort}([M, D])\\ \\ \frac{d}{\sqrt{h \cdot \ell}} \end{array} \]
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
(FPCore (d h l M D) :precision binary64 (/ d (sqrt (* h l))))
M = abs(M);
D = abs(D);
assert(M < D);
double code(double d, double h, double l, double M, double D) {
	return d / sqrt((h * l));
}
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    code = d / sqrt((h * l))
end function
M = Math.abs(M);
D = Math.abs(D);
assert M < D;
public static double code(double d, double h, double l, double M, double D) {
	return d / Math.sqrt((h * l));
}
M = abs(M)
D = abs(D)
[M, D] = sort([M, D])
def code(d, h, l, M, D):
	return d / math.sqrt((h * l))
M = abs(M)
D = abs(D)
M, D = sort([M, D])
function code(d, h, l, M, D)
	return Float64(d / sqrt(Float64(h * l)))
end
M = abs(M)
D = abs(D)
M, D = num2cell(sort([M, D])){:}
function tmp = code(d, h, l, M, D)
	tmp = d / sqrt((h * l));
end
NOTE: M should be positive before calling this function
NOTE: D should be positive before calling this function
NOTE: M and D should be sorted in increasing order before calling this function.
code[d_, h_, l_, M_, D_] := N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M = |M|\\
D = |D|\\
[M, D] = \mathsf{sort}([M, D])\\
\\
\frac{d}{\sqrt{h \cdot \ell}}
\end{array}
Derivation
  1. Initial program 67.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. Simplified66.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. Taylor expanded in d around inf 22.4%

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  4. Step-by-step derivation
    1. pow122.4%

      \[\leadsto \color{blue}{{\left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)}^{1}} \]
    2. sqrt-div22.4%

      \[\leadsto {\left(d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}}\right)}^{1} \]
    3. metadata-eval22.4%

      \[\leadsto {\left(d \cdot \frac{\color{blue}{1}}{\sqrt{h \cdot \ell}}\right)}^{1} \]
  5. Applied egg-rr22.4%

    \[\leadsto \color{blue}{{\left(d \cdot \frac{1}{\sqrt{h \cdot \ell}}\right)}^{1}} \]
  6. Step-by-step derivation
    1. unpow122.4%

      \[\leadsto \color{blue}{d \cdot \frac{1}{\sqrt{h \cdot \ell}}} \]
    2. associate-*r/22.4%

      \[\leadsto \color{blue}{\frac{d \cdot 1}{\sqrt{h \cdot \ell}}} \]
    3. *-rgt-identity22.4%

      \[\leadsto \frac{\color{blue}{d}}{\sqrt{h \cdot \ell}} \]
  7. Simplified22.4%

    \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  8. Final simplification22.4%

    \[\leadsto \frac{d}{\sqrt{h \cdot \ell}} \]

Reproduce

?
herbie shell --seed 2023279 
(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)))))