Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.7% → 83.7%
Time: 28.4s
Alternatives: 19
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 19 alternatives:

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

Initial Program: 66.7% 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: 83.7% accurate, 0.6× speedup?

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

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


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

    1. Initial program 67.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{-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}}{\frac{\ell}{h}}\right)\right) \]
      9. add-sqr-sqrt69.2%

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

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

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < l

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 69.8% accurate, 0.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])\\ \\ \begin{array}{l} t_0 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right)\\ t_1 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-227}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot t\_1\right)\\ \mathbf{elif}\;t\_0 \leq 0:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{\ell}{d}}} \cdot \left(1 + \left(-0.5 \cdot \frac{h}{\ell}\right) \cdot {\left(\left(M\_m \cdot 0.5\right) \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;\left({M\_m}^{2} \cdot \frac{\sqrt{\frac{h}{{\ell}^{3}}}}{d}\right) \cdot \left(-0.125 \cdot {D\_m}^{2}\right)\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* D_m M_m) (* d 2.0)) 2.0))))))
        (t_1 (sqrt (/ d h))))
   (if (<= t_0 -2e-227)
     (*
      (sqrt (/ d l))
      (* (+ 1.0 (/ (* -0.5 (pow (* D_m (/ M_m (* d 2.0))) 2.0)) (/ l h))) t_1))
     (if (<= t_0 0.0)
       (* d (pow (* l h) -0.5))
       (if (<= t_0 INFINITY)
         (*
          (/ t_1 (sqrt (/ l d)))
          (+ 1.0 (* (* -0.5 (/ h l)) (pow (* (* M_m 0.5) (/ D_m d)) 2.0))))
         (*
          (* (pow M_m 2.0) (/ (sqrt (/ h (pow l 3.0))) d))
          (* -0.125 (pow D_m 2.0))))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((D_m * M_m) / (d * 2.0)), 2.0))));
	double t_1 = sqrt((d / h));
	double tmp;
	if (t_0 <= -2e-227) {
		tmp = sqrt((d / l)) * ((1.0 + ((-0.5 * pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1);
	} else if (t_0 <= 0.0) {
		tmp = d * pow((l * h), -0.5);
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (t_1 / sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * pow(((M_m * 0.5) * (D_m / d)), 2.0)));
	} else {
		tmp = (pow(M_m, 2.0) * (sqrt((h / pow(l, 3.0))) / d)) * (-0.125 * pow(D_m, 2.0));
	}
	return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((D_m * M_m) / (d * 2.0)), 2.0))));
	double t_1 = Math.sqrt((d / h));
	double tmp;
	if (t_0 <= -2e-227) {
		tmp = Math.sqrt((d / l)) * ((1.0 + ((-0.5 * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1);
	} else if (t_0 <= 0.0) {
		tmp = d * Math.pow((l * h), -0.5);
	} else if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = (t_1 / Math.sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * Math.pow(((M_m * 0.5) * (D_m / d)), 2.0)));
	} else {
		tmp = (Math.pow(M_m, 2.0) * (Math.sqrt((h / Math.pow(l, 3.0))) / d)) * (-0.125 * Math.pow(D_m, 2.0));
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((D_m * M_m) / (d * 2.0)), 2.0))))
	t_1 = math.sqrt((d / h))
	tmp = 0
	if t_0 <= -2e-227:
		tmp = math.sqrt((d / l)) * ((1.0 + ((-0.5 * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1)
	elif t_0 <= 0.0:
		tmp = d * math.pow((l * h), -0.5)
	elif t_0 <= math.inf:
		tmp = (t_1 / math.sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * math.pow(((M_m * 0.5) * (D_m / d)), 2.0)))
	else:
		tmp = (math.pow(M_m, 2.0) * (math.sqrt((h / math.pow(l, 3.0))) / d)) * (-0.125 * math.pow(D_m, 2.0))
	return tmp
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	t_0 = Float64(Float64((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(D_m * M_m) / Float64(d * 2.0)) ^ 2.0)))))
	t_1 = sqrt(Float64(d / h))
	tmp = 0.0
	if (t_0 <= -2e-227)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(Float64(-0.5 * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / Float64(l / h))) * t_1));
	elseif (t_0 <= 0.0)
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(t_1 / sqrt(Float64(l / d))) * Float64(1.0 + Float64(Float64(-0.5 * Float64(h / l)) * (Float64(Float64(M_m * 0.5) * Float64(D_m / d)) ^ 2.0))));
	else
		tmp = Float64(Float64((M_m ^ 2.0) * Float64(sqrt(Float64(h / (l ^ 3.0))) / d)) * Float64(-0.125 * (D_m ^ 2.0)));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((D_m * M_m) / (d * 2.0)) ^ 2.0))));
	t_1 = sqrt((d / h));
	tmp = 0.0;
	if (t_0 <= -2e-227)
		tmp = sqrt((d / l)) * ((1.0 + ((-0.5 * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / (l / h))) * t_1);
	elseif (t_0 <= 0.0)
		tmp = d * ((l * h) ^ -0.5);
	elseif (t_0 <= Inf)
		tmp = (t_1 / sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * (((M_m * 0.5) * (D_m / d)) ^ 2.0)));
	else
		tmp = ((M_m ^ 2.0) * (sqrt((h / (l ^ 3.0))) / d)) * (-0.125 * (D_m ^ 2.0));
	end
	tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(D$95$m * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -2e-227], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(N[(-0.5 * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(t$95$1 / N[Sqrt[N[(l / d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(-0.5 * N[(h / l), $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(M$95$m * 0.5), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[M$95$m, 2.0], $MachinePrecision] * N[(N[Sqrt[N[(h / N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] * N[(-0.125 * N[Power[D$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right)\\
t_1 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-227}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot t\_1\right)\\

\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < -1.99999999999999989e-227

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999989e-227 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < 0.0

    1. Initial program 24.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. Simplified24.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 54.5%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}} \]
      4. *-commutative54.5%

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

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

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

    if 0.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < +inf.0

    1. Initial program 89.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. Simplified89.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. clear-num89.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\color{blue}{\frac{1}{\frac{\ell}{d}}}}\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-div89.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\ell}{d}}}}\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. metadata-eval89.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l))))

    1. Initial program 0.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. Simplified0.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 19.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 69.8% accurate, 0.3× 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({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right)\\ t_1 := \sqrt{\frac{d}{h}}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-227}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot t\_1\right)\\ \mathbf{elif}\;t\_0 \leq 0:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{\ell}{d}}} \cdot \left(1 + \left(-0.5 \cdot \frac{h}{\ell}\right) \cdot {\left(\left(M\_m \cdot 0.5\right) \cdot \frac{D\_m}{d}\right)}^{2}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left({\left(\ell \cdot h\right)}^{2}\right)}^{-0.25}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
 :precision binary64
 (let* ((t_0
         (*
          (* (pow (/ d h) 0.5) (pow (/ d l) 0.5))
          (- 1.0 (* (/ h l) (* 0.5 (pow (/ (* D_m M_m) (* d 2.0)) 2.0))))))
        (t_1 (sqrt (/ d h))))
   (if (<= t_0 -2e-227)
     (*
      (sqrt (/ d l))
      (* (+ 1.0 (/ (* -0.5 (pow (* D_m (/ M_m (* d 2.0))) 2.0)) (/ l h))) t_1))
     (if (<= t_0 0.0)
       (* d (pow (* l h) -0.5))
       (if (<= t_0 INFINITY)
         (*
          (/ t_1 (sqrt (/ l d)))
          (+ 1.0 (* (* -0.5 (/ h l)) (pow (* (* M_m 0.5) (/ D_m d)) 2.0))))
         (* d (pow (pow (* l h) 2.0) -0.25)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (pow((d / h), 0.5) * pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * pow(((D_m * M_m) / (d * 2.0)), 2.0))));
	double t_1 = sqrt((d / h));
	double tmp;
	if (t_0 <= -2e-227) {
		tmp = sqrt((d / l)) * ((1.0 + ((-0.5 * pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1);
	} else if (t_0 <= 0.0) {
		tmp = d * pow((l * h), -0.5);
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (t_1 / sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * pow(((M_m * 0.5) * (D_m / d)), 2.0)));
	} else {
		tmp = d * pow(pow((l * h), 2.0), -0.25);
	}
	return tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	double t_0 = (Math.pow((d / h), 0.5) * Math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * Math.pow(((D_m * M_m) / (d * 2.0)), 2.0))));
	double t_1 = Math.sqrt((d / h));
	double tmp;
	if (t_0 <= -2e-227) {
		tmp = Math.sqrt((d / l)) * ((1.0 + ((-0.5 * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1);
	} else if (t_0 <= 0.0) {
		tmp = d * Math.pow((l * h), -0.5);
	} else if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = (t_1 / Math.sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * Math.pow(((M_m * 0.5) * (D_m / d)), 2.0)));
	} else {
		tmp = d * Math.pow(Math.pow((l * h), 2.0), -0.25);
	}
	return tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	t_0 = (math.pow((d / h), 0.5) * math.pow((d / l), 0.5)) * (1.0 - ((h / l) * (0.5 * math.pow(((D_m * M_m) / (d * 2.0)), 2.0))))
	t_1 = math.sqrt((d / h))
	tmp = 0
	if t_0 <= -2e-227:
		tmp = math.sqrt((d / l)) * ((1.0 + ((-0.5 * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * t_1)
	elif t_0 <= 0.0:
		tmp = d * math.pow((l * h), -0.5)
	elif t_0 <= math.inf:
		tmp = (t_1 / math.sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * math.pow(((M_m * 0.5) * (D_m / d)), 2.0)))
	else:
		tmp = d * math.pow(math.pow((l * h), 2.0), -0.25)
	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((Float64(d / h) ^ 0.5) * (Float64(d / l) ^ 0.5)) * Float64(1.0 - Float64(Float64(h / l) * Float64(0.5 * (Float64(Float64(D_m * M_m) / Float64(d * 2.0)) ^ 2.0)))))
	t_1 = sqrt(Float64(d / h))
	tmp = 0.0
	if (t_0 <= -2e-227)
		tmp = Float64(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(Float64(-0.5 * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / Float64(l / h))) * t_1));
	elseif (t_0 <= 0.0)
		tmp = Float64(d * (Float64(l * h) ^ -0.5));
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(t_1 / sqrt(Float64(l / d))) * Float64(1.0 + Float64(Float64(-0.5 * Float64(h / l)) * (Float64(Float64(M_m * 0.5) * Float64(D_m / d)) ^ 2.0))));
	else
		tmp = Float64(d * ((Float64(l * h) ^ 2.0) ^ -0.25));
	end
	return tmp
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
	t_0 = (((d / h) ^ 0.5) * ((d / l) ^ 0.5)) * (1.0 - ((h / l) * (0.5 * (((D_m * M_m) / (d * 2.0)) ^ 2.0))));
	t_1 = sqrt((d / h));
	tmp = 0.0;
	if (t_0 <= -2e-227)
		tmp = sqrt((d / l)) * ((1.0 + ((-0.5 * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / (l / h))) * t_1);
	elseif (t_0 <= 0.0)
		tmp = d * ((l * h) ^ -0.5);
	elseif (t_0 <= Inf)
		tmp = (t_1 / sqrt((l / d))) * (1.0 + ((-0.5 * (h / l)) * (((M_m * 0.5) * (D_m / d)) ^ 2.0)));
	else
		tmp = d * (((l * h) ^ 2.0) ^ -0.25);
	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[(N[(N[Power[N[(d / h), $MachinePrecision], 0.5], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], 0.5], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(0.5 * N[Power[N[(N[(D$95$m * M$95$m), $MachinePrecision] / N[(d * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -2e-227], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(N[(-0.5 * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(t$95$1 / N[Sqrt[N[(l / d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(-0.5 * N[(h / l), $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(M$95$m * 0.5), $MachinePrecision] * N[(D$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d * N[Power[N[Power[N[(l * h), $MachinePrecision], 2.0], $MachinePrecision], -0.25], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \left({\left(\frac{d}{h}\right)}^{0.5} \cdot {\left(\frac{d}{\ell}\right)}^{0.5}\right) \cdot \left(1 - \frac{h}{\ell} \cdot \left(0.5 \cdot {\left(\frac{D\_m \cdot M\_m}{d \cdot 2}\right)}^{2}\right)\right)\\
t_1 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-227}:\\
\;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot t\_1\right)\\

\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < -1.99999999999999989e-227

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999989e-227 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < 0.0

    1. Initial program 24.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. Simplified24.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 54.5%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}} \]
      4. *-commutative54.5%

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

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

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

    if 0.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < +inf.0

    1. Initial program 89.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. Simplified89.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. clear-num89.1%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\color{blue}{\frac{1}{\frac{\ell}{d}}}}\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-div89.8%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\ell}{d}}}}\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. metadata-eval89.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if +inf.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l))))

    1. Initial program 0.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. Simplified0.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 11.3%

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

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

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

        \[\leadsto d \cdot \mathsf{expm1}\left(\mathsf{log1p}\left({\color{blue}{\left({\left(h \cdot \ell\right)}^{-1}\right)}}^{0.5}\right)\right) \]
      4. pow-pow11.1%

        \[\leadsto d \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}}\right)\right) \]
      5. *-commutative11.1%

        \[\leadsto d \cdot \mathsf{expm1}\left(\mathsf{log1p}\left({\color{blue}{\left(\ell \cdot h\right)}}^{\left(-1 \cdot 0.5\right)}\right)\right) \]
      6. metadata-eval11.1%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 81.0% accurate, 0.8× speedup?

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

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


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

    1. Initial program 67.6%

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

      \[\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/69.2%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{1}{\frac{\ell}{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)}}\right)\right) \]
      7. sqrt-prod39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \sqrt{\color{blue}{\frac{1}{\frac{\ell}{d}}}}\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-div68.5%

        \[\leadsto \left(\sqrt{\frac{d}{h}} \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{\ell}{d}}}}\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. metadata-eval68.5%

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 81.3% accurate, 0.8× speedup?

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

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


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

    1. Initial program 67.6%

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

      \[\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/69.2%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{1}{\frac{\ell}{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)}}\right)\right) \]
      7. sqrt-prod39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 81.5% accurate, 0.8× speedup?

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

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


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

    1. Initial program 67.6%

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

      \[\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/69.2%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{1}{\frac{\ell}{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)}}\right)\right) \]
      7. sqrt-prod39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{\color{blue}{M \cdot D}}{d} \cdot \frac{D \cdot M}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
      10. *-commutative68.6%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{M \cdot D}{d} \cdot \frac{\color{blue}{M \cdot D}}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
      11. unpow268.6%

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < l

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

    1. Initial program 67.6%

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

      \[\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/69.2%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{1}{\frac{\ell}{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)}}\right)\right) \]
      7. sqrt-prod39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{\color{blue}{M \cdot D}}{d} \cdot \frac{D \cdot M}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
      10. *-commutative68.6%

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{M \cdot D}{d} \cdot \frac{\color{blue}{M \cdot D}}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
      11. unpow268.6%

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

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

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

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

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < l

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 75.8% accurate, 0.8× speedup?

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

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


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

    1. Initial program 67.6%

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

      \[\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/69.2%

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

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

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

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

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

        \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + \frac{1}{\frac{\ell}{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)}}\right)\right) \]
      7. sqrt-prod39.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 58.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified58.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-neg58.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-in48.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-identity48.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. sqrt-div48.9%

        \[\leadsto \color{blue}{\frac{\sqrt{d}}{\sqrt{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) \]
      5. sqrt-div56.4%

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

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

        \[\leadsto \frac{\color{blue}{d}}{\sqrt{h} \cdot \sqrt{\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) \]
    5. Applied egg-rr68.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 66.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])\\ \\ \sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot \sqrt{\frac{d}{h}}\right) \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
 (*
  (sqrt (/ d l))
  (*
   (+ 1.0 (/ (* -0.5 (pow (* D_m (/ M_m (* d 2.0))) 2.0)) (/ l h)))
   (sqrt (/ d h)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return sqrt((d / l)) * ((1.0 + ((-0.5 * pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * sqrt((d / h)));
}
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 = sqrt((d / l)) * ((1.0d0 + (((-0.5d0) * ((d_m * (m_m / (d * 2.0d0))) ** 2.0d0)) / (l / h))) * sqrt((d / h)))
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 Math.sqrt((d / l)) * ((1.0 + ((-0.5 * Math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * Math.sqrt((d / h)));
}
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 math.sqrt((d / l)) * ((1.0 + ((-0.5 * math.pow((D_m * (M_m / (d * 2.0))), 2.0)) / (l / h))) * math.sqrt((d / h)))
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(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(Float64(-0.5 * (Float64(D_m * Float64(M_m / Float64(d * 2.0))) ^ 2.0)) / Float64(l / h))) * sqrt(Float64(d / h))))
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 = sqrt((d / l)) * ((1.0 + ((-0.5 * ((D_m * (M_m / (d * 2.0))) ^ 2.0)) / (l / h))) * sqrt((d / h)));
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[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(N[(-0.5 * N[Power[N[(D$95$m * N[(M$95$m / N[(d * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[(l / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + \frac{-0.5 \cdot {\left(D\_m \cdot \frac{M\_m}{d \cdot 2}\right)}^{2}}{\frac{\ell}{h}}\right) \cdot \sqrt{\frac{d}{h}}\right)
\end{array}
Derivation
  1. Initial program 63.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. Simplified63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 66.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])\\ \\ \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + -0.125 \cdot \left(\frac{h}{\ell} \cdot {\left(D\_m \cdot \frac{M\_m}{d}\right)}^{2}\right)\right)\right) \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
 (*
  (sqrt (/ d l))
  (*
   (sqrt (/ d h))
   (+ 1.0 (* -0.125 (* (/ h l) (pow (* D_m (/ M_m d)) 2.0)))))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return sqrt((d / l)) * (sqrt((d / h)) * (1.0 + (-0.125 * ((h / l) * pow((D_m * (M_m / d)), 2.0)))));
}
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 = sqrt((d / l)) * (sqrt((d / h)) * (1.0d0 + ((-0.125d0) * ((h / l) * ((d_m * (m_m / d)) ** 2.0d0)))))
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 Math.sqrt((d / l)) * (Math.sqrt((d / h)) * (1.0 + (-0.125 * ((h / l) * Math.pow((D_m * (M_m / d)), 2.0)))));
}
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 math.sqrt((d / l)) * (math.sqrt((d / h)) * (1.0 + (-0.125 * ((h / l) * math.pow((D_m * (M_m / d)), 2.0)))))
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(sqrt(Float64(d / l)) * Float64(sqrt(Float64(d / h)) * Float64(1.0 + Float64(-0.125 * Float64(Float64(h / l) * (Float64(D_m * Float64(M_m / d)) ^ 2.0))))))
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 = sqrt((d / l)) * (sqrt((d / h)) * (1.0 + (-0.125 * ((h / l) * ((D_m * (M_m / d)) ^ 2.0)))));
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[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-0.125 * N[(N[(h / l), $MachinePrecision] * N[Power[N[(D$95$m * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $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])\\
\\
\sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + -0.125 \cdot \left(\frac{h}{\ell} \cdot {\left(D\_m \cdot \frac{M\_m}{d}\right)}^{2}\right)\right)\right)
\end{array}
Derivation
  1. Initial program 63.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. Simplified63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 68.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])\\ \\ \sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + h \cdot \left({\left(D\_m \cdot \frac{M\_m}{d}\right)}^{2} \cdot \frac{-0.125}{\ell}\right)\right) \cdot \sqrt{\frac{d}{h}}\right) \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
 (*
  (sqrt (/ d l))
  (*
   (+ 1.0 (* h (* (pow (* D_m (/ M_m d)) 2.0) (/ -0.125 l))))
   (sqrt (/ d h)))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return sqrt((d / l)) * ((1.0 + (h * (pow((D_m * (M_m / d)), 2.0) * (-0.125 / l)))) * sqrt((d / h)));
}
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 = sqrt((d / l)) * ((1.0d0 + (h * (((d_m * (m_m / d)) ** 2.0d0) * ((-0.125d0) / l)))) * sqrt((d / h)))
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 Math.sqrt((d / l)) * ((1.0 + (h * (Math.pow((D_m * (M_m / d)), 2.0) * (-0.125 / l)))) * Math.sqrt((d / h)));
}
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 math.sqrt((d / l)) * ((1.0 + (h * (math.pow((D_m * (M_m / d)), 2.0) * (-0.125 / l)))) * math.sqrt((d / h)))
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(sqrt(Float64(d / l)) * Float64(Float64(1.0 + Float64(h * Float64((Float64(D_m * Float64(M_m / d)) ^ 2.0) * Float64(-0.125 / l)))) * sqrt(Float64(d / h))))
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 = sqrt((d / l)) * ((1.0 + (h * (((D_m * (M_m / d)) ^ 2.0) * (-0.125 / l)))) * sqrt((d / h)));
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[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + N[(h * N[(N[Power[N[(D$95$m * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.125 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\sqrt{\frac{d}{\ell}} \cdot \left(\left(1 + h \cdot \left({\left(D\_m \cdot \frac{M\_m}{d}\right)}^{2} \cdot \frac{-0.125}{\ell}\right)\right) \cdot \sqrt{\frac{d}{h}}\right)
\end{array}
Derivation
  1. Initial program 63.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. Simplified63.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{\color{blue}{M \cdot D}}{d} \cdot \frac{D \cdot M}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
    10. *-commutative63.6%

      \[\leadsto \sqrt{\frac{d}{\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left(\left(\frac{M \cdot D}{d} \cdot \frac{\color{blue}{M \cdot D}}{d}\right) \cdot \frac{-0.125}{\ell}\right)\right)\right) \]
    11. unpow263.6%

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

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

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

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

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

Alternative 12: 59.4% accurate, 1.4× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 1.60000000000000001e42

    1. Initial program 65.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.60000000000000001e42 < l

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 45.9% accurate, 1.6× speedup?

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

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


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

    1. Initial program 67.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified68.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 l around -inf 0.0%

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

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

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

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

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

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

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

    if 4.3999999999999998e-286 < l

    1. Initial program 58.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. Simplified57.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 39.3%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}} \]
      4. *-commutative39.3%

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

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

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

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

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

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

Alternative 14: 42.1% accurate, 2.9× speedup?

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

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


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

    1. Initial program 67.8%

      \[\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \]
    2. Simplified68.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 l around -inf 0.0%

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

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

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

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

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

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

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

    if 1.06e-283 < l

    1. Initial program 58.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. Simplified57.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 39.3%

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

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

Alternative 15: 37.5% accurate, 3.0× speedup?

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.10000000000000004e-169 < d

    1. Initial program 54.2%

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

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

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

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

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

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

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

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

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

Alternative 16: 42.3% accurate, 3.0× speedup?

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

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


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

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.4000000000000001e-284 < l

    1. Initial program 58.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. Simplified57.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 39.3%

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

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

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

        \[\leadsto d \cdot \color{blue}{{\left(h \cdot \ell\right)}^{\left(-1 \cdot 0.5\right)}} \]
      4. *-commutative39.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 4.4 \cdot 10^{-284}:\\ \;\;\;\;d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;d \cdot {\left(\ell \cdot h\right)}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 42.2% accurate, 3.0× speedup?

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

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


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

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.68000000000000001e-279 < l

    1. Initial program 58.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. Simplified57.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 39.3%

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

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

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

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


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

    1. Initial program 67.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto d \cdot \color{blue}{\left(-{\left(h \cdot \ell\right)}^{-0.5}\right)} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt48.4%

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

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

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

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

      \[\leadsto d \cdot \left(-\color{blue}{{\left(\sqrt{\ell \cdot h}\right)}^{-0.5} \cdot {\left(\sqrt{\ell \cdot h}\right)}^{-0.5}}\right) \]
    10. Step-by-step derivation
      1. pow-sqr48.4%

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

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

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

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

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

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

    if 5.39999999999999964e-282 < l

    1. Initial program 58.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. Simplified57.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 39.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 5.4 \cdot 10^{-282}:\\ \;\;\;\;d \cdot \frac{-1}{\sqrt{\ell \cdot h}}\\ \mathbf{else}:\\ \;\;\;\;d \cdot \sqrt{\frac{1}{\ell \cdot h}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 26.0% accurate, 3.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ [d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\ \\ d \cdot {\left(\ell \cdot h\right)}^{-0.5} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m) :precision binary64 (* d (pow (* l h) -0.5)))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
	return d * pow((l * h), -0.5);
}
M_m = abs(m)
D_m = abs(d)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
real(8) function code(d, h, l, m_m, d_m)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    code = d * ((l * h) ** (-0.5d0))
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
	return d * Math.pow((l * h), -0.5);
}
M_m = math.fabs(M)
D_m = math.fabs(D)
[d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m])
def code(d, h, l, M_m, D_m):
	return d * math.pow((l * h), -0.5)
M_m = abs(M)
D_m = abs(D)
d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m])
function code(d, h, l, M_m, D_m)
	return Float64(d * (Float64(l * h) ^ -0.5))
end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
	tmp = d * ((l * h) ^ -0.5);
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := N[(d * N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
d \cdot {\left(\ell \cdot h\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 63.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. Simplified62.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.4%

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

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

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

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

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

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

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

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

Reproduce

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