Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.6% → 84.2%
Time: 27.2s
Alternatives: 23
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 23 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.6% 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: 84.2% accurate, 0.5× speedup?

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

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


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

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

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

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

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

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

    if -1.999999999999994e-310 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.3%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.3%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.4%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 83.5% accurate, 0.6× speedup?

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

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


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

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

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

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

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

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

    if -1.999999999999994e-310 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.3%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.3%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.4%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.6%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \frac{\color{blue}{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right) \cdot \left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}}{\ell}, 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
      2. *-un-lft-identity83.5%

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \left(\frac{\left(D \cdot M\right) \cdot \frac{0.5}{d}}{1} \cdot \frac{\color{blue}{\left(D \cdot M\right) \cdot \frac{0.5}{d}}}{\ell}\right), 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
    9. Applied egg-rr88.8%

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

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

Alternative 3: 83.9% accurate, 0.8× speedup?

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

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


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

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

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

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

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

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

    if -1.999999999999994e-310 < l

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.3%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.3%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.4%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.6%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \frac{\color{blue}{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right) \cdot \left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}}{\ell}, 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
      2. *-un-lft-identity83.5%

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \left(\frac{\left(D \cdot M\right) \cdot \frac{0.5}{d}}{1} \cdot \frac{\color{blue}{\left(D \cdot M\right) \cdot \frac{0.5}{d}}}{\ell}\right), 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
    9. Applied egg-rr88.8%

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

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

Alternative 4: 80.4% accurate, 0.8× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.45e-307 < l

    1. Initial program 60.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified60.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. Add Preprocessing
    4. Step-by-step derivation
      1. sub-neg60.0%

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.4%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.4%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.3%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div55.9%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times55.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.0%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.2%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \frac{\color{blue}{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right) \cdot \left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}}{\ell}, 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
      2. *-un-lft-identity82.9%

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

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

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

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

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

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

Alternative 5: 57.4% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{h}}{\ell}\right)\right)}\\

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

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


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

    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. Simplified65.4%

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

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

    if -3.80000000000000022e-189 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{h \cdot \ell}\right)\right)}} \]
      2. associate-/r*62.9%

        \[\leadsto d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{h}}{\ell}}\right)\right)} \]
    6. Applied egg-rr62.9%

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

    if -1.999999999999994e-310 < l < 1.35e153

    1. Initial program 68.9%

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

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

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod19.3%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative19.3%

        \[\leadsto \sqrt{\color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative19.3%

        \[\leadsto \sqrt{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right) \cdot \color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
      5. swap-sqr19.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e153 < l

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac56.1%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified56.0%

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

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

Alternative 6: 78.9% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 6.50000000000000028e-303

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

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

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

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

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

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

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

    if 6.50000000000000028e-303 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.9%

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

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

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

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

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

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

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

        \[\leadsto d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \frac{\color{blue}{\left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right) \cdot \left(D \cdot \left(M \cdot \frac{0.5}{d}\right)\right)}}{\ell}, 1\right)}{\sqrt{\ell} \cdot \sqrt{h}} \]
      2. *-un-lft-identity83.2%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq 6.5 \cdot 10^{-303}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;d \cdot \frac{\mathsf{fma}\left(-0.5, h \cdot \left(\left(\frac{0.5}{d} \cdot \left(M \cdot D\right)\right) \cdot \frac{\frac{0.5}{d} \cdot \left(M \cdot D\right)}{\ell}\right), 1\right)}{\sqrt{h} \cdot \sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 59.1% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{h}}{\ell}\right)\right)}\\

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


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

    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. Simplified65.4%

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

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

    if -4.69999999999999998e-188 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{h \cdot \ell}\right)\right)}} \]
      2. associate-/r*62.9%

        \[\leadsto d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{h}}{\ell}}\right)\right)} \]
    6. Applied egg-rr62.9%

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

    if -1.999999999999994e-310 < l

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.7%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.7%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.3%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.3%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.4%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 71.7% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 6.50000000000000028e-303

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

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

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

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

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

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

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

    if 6.50000000000000028e-303 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;h \leq 6.5 \cdot 10^{-303}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;\frac{d \cdot \mathsf{fma}\left(-0.5, \frac{h}{\frac{\ell}{{\left(\frac{0.5}{d} \cdot \left(M \cdot D\right)\right)}^{2}}}, 1\right)}{\sqrt{h \cdot \ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 70.7% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 1.1500000000000001e-301

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

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

    if 1.1500000000000001e-301 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 72.0% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 8.5e-303

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

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

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

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

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

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

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

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

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

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

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

    if 8.5e-303 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 71.1% accurate, 1.0× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if h < 6.50000000000000028e-303

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

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

    if 6.50000000000000028e-303 < h

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

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

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

        \[\leadsto \color{blue}{1 \cdot \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)} \]
      3. *-un-lft-identity51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      4. *-commutative51.8%

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      5. sqrt-div55.8%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{\ell}}} \cdot \sqrt{\frac{d}{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      6. sqrt-div56.4%

        \[\leadsto \frac{\sqrt{d}}{\sqrt{\ell}} \cdot \color{blue}{\frac{\sqrt{d}}{\sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      7. frac-times56.4%

        \[\leadsto \color{blue}{\frac{\sqrt{d} \cdot \sqrt{d}}{\sqrt{\ell} \cdot \sqrt{h}}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
      8. add-sqr-sqrt56.5%

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{\ell} \cdot \sqrt{h}} + \left(-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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right) \]
    5. Applied egg-rr69.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 49.3% accurate, 1.0× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.5200000000000001e-72

    1. Initial program 86.3%

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

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

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

    if -1.5200000000000001e-72 < d < -4.999999999999985e-310

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

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

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{h \cdot \ell}\right)\right)}} \]
      2. associate-/r*28.9%

        \[\leadsto d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{h}}{\ell}}\right)\right)} \]
    6. Applied egg-rr28.9%

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

    if -4.999999999999985e-310 < d < 6.39999999999999974e89

    1. Initial program 55.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. Simplified55.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. Add Preprocessing
    4. Taylor expanded in d around 0 39.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.39999999999999974e89 < d

    1. Initial program 74.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. Simplified74.2%

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

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

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

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

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

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

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

        \[\leadsto \frac{d}{\color{blue}{\sqrt{\ell \cdot h}}} \]
      7. *-commutative66.3%

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac73.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified73.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;d \leq -1.52 \cdot 10^{-72}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;d \leq -5 \cdot 10^{-310}:\\ \;\;\;\;d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{h}}{\ell}\right)\right)}\\ \mathbf{elif}\;d \leq 6.4 \cdot 10^{+89}:\\ \;\;\;\;-0.125 \cdot \frac{\frac{\sqrt{h} \cdot {\left(M \cdot D\right)}^{2}}{d}}{{\ell}^{1.5}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 45.1% accurate, 1.0× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\frac{1}{h}}{\ell}\right)\right)}\\

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


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

    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. Simplified65.4%

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

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

    if -6.4999999999999997e-190 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

        \[\leadsto d \cdot \sqrt{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{h \cdot \ell}\right)\right)}} \]
      2. associate-/r*62.9%

        \[\leadsto d \cdot \sqrt{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\frac{1}{h}}{\ell}}\right)\right)} \]
    6. Applied egg-rr62.9%

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

    if -1.999999999999994e-310 < l

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

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

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

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

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

        \[\leadsto d \cdot \frac{1}{\sqrt{\color{blue}{\ell \cdot h}}} \]
      4. sqrt-unprod41.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac41.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified41.2%

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

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

Alternative 14: 45.1% accurate, 1.1× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot \log \left(e^{{\left(h \cdot \ell\right)}^{-0.5}}\right)\\

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


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

    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. Simplified65.4%

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

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

    if -3.40000000000000027e-188 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

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

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

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

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

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

    if -1.999999999999994e-310 < l

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

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

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

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

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

        \[\leadsto d \cdot \frac{1}{\sqrt{\color{blue}{\ell \cdot h}}} \]
      4. sqrt-unprod41.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac41.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified41.2%

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

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

Alternative 15: 44.0% accurate, 1.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.3 \cdot 10^{-190}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{d}{\sqrt{h \cdot \ell}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (if (<= l -4.3e-190)
   (* (sqrt (/ d l)) (sqrt (/ d h)))
   (if (<= l -2e-310)
     (log1p (expm1 (/ d (sqrt (* h l)))))
     (/ (/ d (sqrt h)) (sqrt l)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -4.3e-190) {
		tmp = sqrt((d / l)) * sqrt((d / h));
	} else if (l <= -2e-310) {
		tmp = log1p(expm1((d / sqrt((h * l)))));
	} else {
		tmp = (d / sqrt(h)) / sqrt(l);
	}
	return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double tmp;
	if (l <= -4.3e-190) {
		tmp = Math.sqrt((d / l)) * Math.sqrt((d / h));
	} else if (l <= -2e-310) {
		tmp = Math.log1p(Math.expm1((d / Math.sqrt((h * l)))));
	} else {
		tmp = (d / Math.sqrt(h)) / Math.sqrt(l);
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	tmp = 0
	if l <= -4.3e-190:
		tmp = math.sqrt((d / l)) * math.sqrt((d / h))
	elif l <= -2e-310:
		tmp = math.log1p(math.expm1((d / math.sqrt((h * l)))))
	else:
		tmp = (d / math.sqrt(h)) / math.sqrt(l)
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	tmp = 0.0
	if (l <= -4.3e-190)
		tmp = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h)));
	elseif (l <= -2e-310)
		tmp = log1p(expm1(Float64(d / sqrt(Float64(h * l)))));
	else
		tmp = Float64(Float64(d / sqrt(h)) / sqrt(l));
	end
	return tmp
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[l, -4.3e-190], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -2e-310], N[Log[1 + N[(Exp[N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision], N[(N[(d / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.3 \cdot 10^{-190}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{d}{\sqrt{h \cdot \ell}}\right)\right)\\

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


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

    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. Simplified65.4%

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

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

    if -4.3e-190 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

        \[\leadsto \color{blue}{{d}^{1}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      2. metadata-eval27.1%

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

        \[\leadsto \color{blue}{\sqrt{{d}^{2}}} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      4. sqrt-prod5.2%

        \[\leadsto \color{blue}{\sqrt{{d}^{2} \cdot \frac{1}{h \cdot \ell}}} \]
      5. div-inv5.2%

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

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

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

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

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{{d}^{\color{blue}{1}}}{\sqrt{h \cdot \ell}}\right)\right) \]
      10. pow154.9%

        \[\leadsto \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\color{blue}{d}}{\sqrt{h \cdot \ell}}\right)\right) \]
    6. Applied egg-rr54.9%

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

    if -1.999999999999994e-310 < l

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

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

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

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

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

        \[\leadsto d \cdot \frac{1}{\sqrt{\color{blue}{\ell \cdot h}}} \]
      4. sqrt-unprod41.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac41.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified41.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.3 \cdot 10^{-190}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{d}{\sqrt{h \cdot \ell}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 44.5% accurate, 1.5× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\

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


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

    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. Simplified65.4%

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

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

    if -3.7000000000000002e-190 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\frac{1}{h \cdot \ell}\right)}^{1.5}}} \]
    9. Step-by-step derivation
      1. pow1/331.0%

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

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

        \[\leadsto d \cdot {\left(\frac{1}{h \cdot \ell}\right)}^{\color{blue}{0.5}} \]
      4. pow1/227.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(\left(h \cdot \ell\right) \cdot \left(h \cdot \ell\right)\right)}}^{-0.25} \]
      2. *-commutative35.1%

        \[\leadsto d \cdot {\left(\left(h \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot h\right)}\right)}^{-0.25} \]
      3. associate-*r*46.9%

        \[\leadsto d \cdot {\color{blue}{\left(\left(\left(h \cdot \ell\right) \cdot \ell\right) \cdot h\right)}}^{-0.25} \]
      4. *-commutative46.9%

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

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

    if -1.999999999999994e-310 < l

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

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

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

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

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

        \[\leadsto d \cdot \frac{1}{\sqrt{\color{blue}{\ell \cdot h}}} \]
      4. sqrt-unprod41.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac41.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified41.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.7 \cdot 10^{-190}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 46.2% accurate, 1.5× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\
\;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\

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


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

    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. 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. Add Preprocessing
    4. Taylor expanded in d around inf 3.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{d}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      6. add-sqr-sqrt0.0%

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

        \[\leadsto \color{blue}{\sqrt{\frac{d}{\sqrt{\ell} \cdot \sqrt{h}} \cdot \frac{d}{\sqrt{\ell} \cdot \sqrt{h}}}} \]
      8. rem-sqrt-square0.0%

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

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

        \[\leadsto \left|\frac{d}{\sqrt{\color{blue}{h \cdot \ell}}}\right| \]
    6. Applied egg-rr46.2%

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

    if -3.30000000000000019e-190 < l < -1.999999999999994e-310

    1. Initial program 83.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. Simplified79.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. Add Preprocessing
    4. Taylor expanded in d around inf 27.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\frac{1}{h \cdot \ell}\right)}^{1.5}}} \]
    9. Step-by-step derivation
      1. pow1/331.0%

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

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

        \[\leadsto d \cdot {\left(\frac{1}{h \cdot \ell}\right)}^{\color{blue}{0.5}} \]
      4. pow1/227.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(\left(h \cdot \ell\right) \cdot \left(h \cdot \ell\right)\right)}}^{-0.25} \]
      2. *-commutative35.1%

        \[\leadsto d \cdot {\left(\left(h \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot h\right)}\right)}^{-0.25} \]
      3. associate-*r*46.9%

        \[\leadsto d \cdot {\color{blue}{\left(\left(\left(h \cdot \ell\right) \cdot \ell\right) \cdot h\right)}}^{-0.25} \]
      4. *-commutative46.9%

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

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

    if -1.999999999999994e-310 < l

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

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

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

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

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

        \[\leadsto d \cdot \frac{1}{\sqrt{\color{blue}{\ell \cdot h}}} \]
      4. sqrt-unprod41.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot d}{\color{blue}{\sqrt{\ell} \cdot \sqrt{h}}} \]
      4. times-frac41.2%

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{d}{\sqrt{h}}}}{\sqrt{\ell}} \]
    10. Simplified41.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.3 \cdot 10^{-190}:\\ \;\;\;\;\left|\frac{d}{\sqrt{h \cdot \ell}}\right|\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-310}:\\ \;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{d}{\sqrt{h}}}{\sqrt{\ell}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 43.8% accurate, 1.6× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if M < 5.8e9

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\frac{d}{\color{blue}{\sqrt{\ell \cdot h}}}\right| \]
      10. *-commutative48.3%

        \[\leadsto \left|\frac{d}{\sqrt{\color{blue}{h \cdot \ell}}}\right| \]
    6. Applied egg-rr48.3%

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

    if 5.8e9 < M

    1. Initial program 61.4%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in16.3%

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

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

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

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

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

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

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

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

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

Alternative 19: 43.4% accurate, 2.8× speedup?

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

\mathbf{elif}\;\ell \leq -2 \cdot 10^{-307}:\\
\;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\

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


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

    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. 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. Add Preprocessing
    4. Taylor expanded in d around inf 3.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      5. distribute-lft-neg-in45.9%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in45.9%

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

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

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

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

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

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

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

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

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

    if -3.7000000000000002e-190 < l < -1.99999999999999982e-307

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    5. Step-by-step derivation
      1. add-cbrt-cube32.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. pow1/332.3%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d \cdot \color{blue}{\sqrt[3]{{\left(\frac{1}{h \cdot \ell}\right)}^{1.5}}} \]
    9. Step-by-step derivation
      1. pow1/332.3%

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

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

        \[\leadsto d \cdot {\left(\frac{1}{h \cdot \ell}\right)}^{\color{blue}{0.5}} \]
      4. pow1/228.2%

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

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

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

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

        \[\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)} \]
      9. pow-prod-down36.5%

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

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

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

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

        \[\leadsto d \cdot {\color{blue}{\left(\left(h \cdot \ell\right) \cdot \left(h \cdot \ell\right)\right)}}^{-0.25} \]
      2. *-commutative36.5%

        \[\leadsto d \cdot {\left(\left(h \cdot \ell\right) \cdot \color{blue}{\left(\ell \cdot h\right)}\right)}^{-0.25} \]
      3. associate-*r*48.8%

        \[\leadsto d \cdot {\color{blue}{\left(\left(\left(h \cdot \ell\right) \cdot \ell\right) \cdot h\right)}}^{-0.25} \]
      4. *-commutative48.8%

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

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

    if -1.99999999999999982e-307 < l

    1. Initial program 60.7%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified60.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. Add Preprocessing
    4. Step-by-step derivation
      1. add-sqr-sqrt27.4%

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod23.7%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative23.7%

        \[\leadsto \sqrt{\color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative23.7%

        \[\leadsto \sqrt{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right) \cdot \color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
      5. swap-sqr23.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.7 \cdot 10^{-190}:\\ \;\;\;\;d \cdot \left(-{\left(h \cdot \ell\right)}^{-0.5}\right)\\ \mathbf{elif}\;\ell \leq -2 \cdot 10^{-307}:\\ \;\;\;\;d \cdot {\left(h \cdot \left(\ell \cdot \left(h \cdot \ell\right)\right)\right)}^{-0.25}\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(h \cdot \ell\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 41.6% accurate, 3.0× speedup?

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

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


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

    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. 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. Add Preprocessing
    4. Taylor expanded in d around inf 3.6%

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      5. distribute-lft-neg-in45.9%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in45.9%

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

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

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

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

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

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

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

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

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

    if -3.2000000000000001e-190 < l

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

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 21: 42.9% accurate, 3.0× speedup?

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

    1. Initial program 76.8%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(-d\right)} \cdot \sqrt{\frac{1}{h \cdot \ell}} \]
      5. distribute-lft-neg-in42.0%

        \[\leadsto \color{blue}{-d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
      6. distribute-rgt-neg-in42.0%

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

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

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

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

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

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

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

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

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

    if -5.09999999999999971e-263 < d

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

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

        \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
      2. sqrt-unprod22.2%

        \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
      3. *-commutative22.2%

        \[\leadsto \sqrt{\color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
      4. *-commutative22.2%

        \[\leadsto \sqrt{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right) \cdot \color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
      5. swap-sqr22.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 22: 26.1% accurate, 3.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ d \cdot {\left(h \cdot \ell\right)}^{-0.5} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m) :precision binary64 (* d (pow (* h l) -0.5)))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return d * pow((h * l), -0.5);
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    code = d * ((h * l) ** (-0.5d0))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	return d * Math.pow((h * l), -0.5);
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	return d * math.pow((h * l), -0.5)
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	return Float64(d * (Float64(h * l) ^ -0.5))
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
	tmp = d * ((h * l) ^ -0.5);
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := N[(d * N[Power[N[(h * l), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
d \cdot {\left(h \cdot \ell\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 65.1%

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

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

      \[\leadsto \color{blue}{\sqrt{\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)} \cdot \sqrt{\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)}} \]
    2. sqrt-unprod28.3%

      \[\leadsto \color{blue}{\sqrt{\left(\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)\right) \cdot \left(\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)\right)}} \]
    3. *-commutative28.3%

      \[\leadsto \sqrt{\color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)} \cdot \left(\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)\right)} \]
    4. *-commutative28.3%

      \[\leadsto \sqrt{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right) \cdot \color{blue}{\left(\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}{h}} \cdot \sqrt{\frac{d}{\ell}}\right)\right)}} \]
    5. swap-sqr28.3%

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

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

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

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

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

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

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

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

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

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

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

Alternative 23: 26.1% accurate, 3.2× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ \frac{d}{\sqrt{h \cdot \ell}} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m) :precision binary64 (/ d (sqrt (* h l))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return d / sqrt((h * l));
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    code = d / sqrt((h * l))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	return d / Math.sqrt((h * l));
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	return d / math.sqrt((h * l))
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	return Float64(d / sqrt(Float64(h * l)))
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
	tmp = d / sqrt((h * l));
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := N[(d / N[Sqrt[N[(h * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\frac{d}{\sqrt{h \cdot \ell}}
\end{array}
Derivation
  1. Initial program 65.1%

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

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

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

      \[\leadsto d \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{h \cdot \ell}}} \]
    2. metadata-eval24.9%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{d}{\sqrt{h \cdot \ell}}} \]
  7. Add Preprocessing

Reproduce

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