Henrywood and Agarwal, Equation (12)

Percentage Accurate: 66.1% → 74.3%
Time: 2.4min
Alternatives: 4
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 4 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.1% 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: 74.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\\ \mathbf{if}\;d \leq -1 \cdot 10^{-310}:\\ \;\;\;\;\frac{\sqrt{-d}}{\sqrt{-\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{d}{\ell}} \cdot \left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (+ 1.0 (* h (* (pow (/ (* M 0.5) (/ d D)) 2.0) (/ -0.5 l))))))
   (if (<= d -1e-310)
     (* (/ (sqrt (- d)) (sqrt (- l))) (* (sqrt (/ d h)) t_0))
     (* (sqrt (/ d l)) (* t_0 (/ (sqrt d) (sqrt h)))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = 1.0 + (h * (pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)));
	double tmp;
	if (d <= -1e-310) {
		tmp = (sqrt(-d) / sqrt(-l)) * (sqrt((d / h)) * t_0);
	} else {
		tmp = sqrt((d / l)) * (t_0 * (sqrt(d) / sqrt(h)));
	}
	return tmp;
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 + (h * ((((m * 0.5d0) / (d / d_1)) ** 2.0d0) * ((-0.5d0) / l)))
    if (d <= (-1d-310)) then
        tmp = (sqrt(-d) / sqrt(-l)) * (sqrt((d / h)) * t_0)
    else
        tmp = sqrt((d / l)) * (t_0 * (sqrt(d) / sqrt(h)))
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = 1.0 + (h * (Math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)));
	double tmp;
	if (d <= -1e-310) {
		tmp = (Math.sqrt(-d) / Math.sqrt(-l)) * (Math.sqrt((d / h)) * t_0);
	} else {
		tmp = Math.sqrt((d / l)) * (t_0 * (Math.sqrt(d) / Math.sqrt(h)));
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = 1.0 + (h * (math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)))
	tmp = 0
	if d <= -1e-310:
		tmp = (math.sqrt(-d) / math.sqrt(-l)) * (math.sqrt((d / h)) * t_0)
	else:
		tmp = math.sqrt((d / l)) * (t_0 * (math.sqrt(d) / math.sqrt(h)))
	return tmp
function code(d, h, l, M, D)
	t_0 = Float64(1.0 + Float64(h * Float64((Float64(Float64(M * 0.5) / Float64(d / D)) ^ 2.0) * Float64(-0.5 / l))))
	tmp = 0.0
	if (d <= -1e-310)
		tmp = Float64(Float64(sqrt(Float64(-d)) / sqrt(Float64(-l))) * Float64(sqrt(Float64(d / h)) * t_0));
	else
		tmp = Float64(sqrt(Float64(d / l)) * Float64(t_0 * Float64(sqrt(d) / sqrt(h))));
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = 1.0 + (h * ((((M * 0.5) / (d / D)) ^ 2.0) * (-0.5 / l)));
	tmp = 0.0;
	if (d <= -1e-310)
		tmp = (sqrt(-d) / sqrt(-l)) * (sqrt((d / h)) * t_0);
	else
		tmp = sqrt((d / l)) * (t_0 * (sqrt(d) / sqrt(h)));
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(1.0 + N[(h * N[(N[Power[N[(N[(M * 0.5), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -1e-310], N[(N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-l)], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\\
\mathbf{if}\;d \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{\sqrt{-d}}{\sqrt{-\ell}} \cdot \left(\sqrt{\frac{d}{h}} \cdot t\_0\right)\\

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


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

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

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

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

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

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

        \[\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. associate-/r*71.6%

        \[\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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
      6. associate-*r/70.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.999999999999969e-311 < d

    1. Initial program 65.3%

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

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

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

        \[\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-inv65.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. *-commutative65.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. associate-/r*65.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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
      6. associate-*r/64.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 74.4% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{\ell}}\\ \mathbf{if}\;h \leq -4 \cdot 10^{-311}:\\ \;\;\;\;\left(t\_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(\left(1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\right) \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ d l))))
   (if (<= h -4e-311)
     (*
      (* t_0 (/ (sqrt (- d)) (sqrt (- h))))
      (- 1.0 (* 0.5 (* (pow (* (/ M 2.0) (/ D d)) 2.0) (/ h l)))))
     (*
      t_0
      (*
       (+ 1.0 (* h (* (pow (/ (* M 0.5) (/ d D)) 2.0) (/ -0.5 l))))
       (/ (sqrt d) (sqrt h)))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((d / l));
	double tmp;
	if (h <= -4e-311) {
		tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (0.5 * (pow(((M / 2.0) * (D / d)), 2.0) * (h / l))));
	} else {
		tmp = t_0 * ((1.0 + (h * (pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)))) * (sqrt(d) / sqrt(h)));
	}
	return tmp;
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((d / l))
    if (h <= (-4d-311)) then
        tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0d0 - (0.5d0 * ((((m / 2.0d0) * (d_1 / d)) ** 2.0d0) * (h / l))))
    else
        tmp = t_0 * ((1.0d0 + (h * ((((m * 0.5d0) / (d / d_1)) ** 2.0d0) * ((-0.5d0) / l)))) * (sqrt(d) / sqrt(h)))
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((d / l));
	double tmp;
	if (h <= -4e-311) {
		tmp = (t_0 * (Math.sqrt(-d) / Math.sqrt(-h))) * (1.0 - (0.5 * (Math.pow(((M / 2.0) * (D / d)), 2.0) * (h / l))));
	} else {
		tmp = t_0 * ((1.0 + (h * (Math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)))) * (Math.sqrt(d) / Math.sqrt(h)));
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((d / l))
	tmp = 0
	if h <= -4e-311:
		tmp = (t_0 * (math.sqrt(-d) / math.sqrt(-h))) * (1.0 - (0.5 * (math.pow(((M / 2.0) * (D / d)), 2.0) * (h / l))))
	else:
		tmp = t_0 * ((1.0 + (h * (math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)))) * (math.sqrt(d) / math.sqrt(h)))
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(d / l))
	tmp = 0.0
	if (h <= -4e-311)
		tmp = Float64(Float64(t_0 * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h)))) * Float64(1.0 - Float64(0.5 * Float64((Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0) * Float64(h / l)))));
	else
		tmp = Float64(t_0 * Float64(Float64(1.0 + Float64(h * Float64((Float64(Float64(M * 0.5) / Float64(d / D)) ^ 2.0) * Float64(-0.5 / l)))) * Float64(sqrt(d) / sqrt(h))));
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((d / l));
	tmp = 0.0;
	if (h <= -4e-311)
		tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (0.5 * ((((M / 2.0) * (D / d)) ^ 2.0) * (h / l))));
	else
		tmp = t_0 * ((1.0 + (h * ((((M * 0.5) / (d / D)) ^ 2.0) * (-0.5 / l)))) * (sqrt(d) / sqrt(h)));
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, -4e-311], N[(N[(t$95$0 * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(0.5 * N[(N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(1.0 + N[(h * N[(N[Power[N[(N[(M * 0.5), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;h \leq -4 \cdot 10^{-311}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - 0.5 \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot \frac{h}{\ell}\right)\right)\\

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


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

    1. Initial program 70.2%

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

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

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

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

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

    if -3.99999999999979e-311 < h

    1. Initial program 65.4%

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

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

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

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

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

        \[\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. associate-/r*65.3%

        \[\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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
      6. associate-*r/64.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 71.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{d}{\ell}}\\ t_1 := 1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\\ \mathbf{if}\;d \leq -4 \cdot 10^{-309}:\\ \;\;\;\;\left(\sqrt{\frac{d}{h}} \cdot t\_1\right) \cdot t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_0 \cdot \left(t\_1 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right)\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ d l)))
        (t_1 (+ 1.0 (* h (* (pow (/ (* M 0.5) (/ d D)) 2.0) (/ -0.5 l))))))
   (if (<= d -4e-309)
     (* (* (sqrt (/ d h)) t_1) t_0)
     (* t_0 (* t_1 (/ (sqrt d) (sqrt h)))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((d / l));
	double t_1 = 1.0 + (h * (pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)));
	double tmp;
	if (d <= -4e-309) {
		tmp = (sqrt((d / h)) * t_1) * t_0;
	} else {
		tmp = t_0 * (t_1 * (sqrt(d) / sqrt(h)));
	}
	return tmp;
}
real(8) function code(d, h, l, m, d_1)
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = sqrt((d / l))
    t_1 = 1.0d0 + (h * ((((m * 0.5d0) / (d / d_1)) ** 2.0d0) * ((-0.5d0) / l)))
    if (d <= (-4d-309)) then
        tmp = (sqrt((d / h)) * t_1) * t_0
    else
        tmp = t_0 * (t_1 * (sqrt(d) / sqrt(h)))
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((d / l));
	double t_1 = 1.0 + (h * (Math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)));
	double tmp;
	if (d <= -4e-309) {
		tmp = (Math.sqrt((d / h)) * t_1) * t_0;
	} else {
		tmp = t_0 * (t_1 * (Math.sqrt(d) / Math.sqrt(h)));
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((d / l))
	t_1 = 1.0 + (h * (math.pow(((M * 0.5) / (d / D)), 2.0) * (-0.5 / l)))
	tmp = 0
	if d <= -4e-309:
		tmp = (math.sqrt((d / h)) * t_1) * t_0
	else:
		tmp = t_0 * (t_1 * (math.sqrt(d) / math.sqrt(h)))
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(d / l))
	t_1 = Float64(1.0 + Float64(h * Float64((Float64(Float64(M * 0.5) / Float64(d / D)) ^ 2.0) * Float64(-0.5 / l))))
	tmp = 0.0
	if (d <= -4e-309)
		tmp = Float64(Float64(sqrt(Float64(d / h)) * t_1) * t_0);
	else
		tmp = Float64(t_0 * Float64(t_1 * Float64(sqrt(d) / sqrt(h))));
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((d / l));
	t_1 = 1.0 + (h * ((((M * 0.5) / (d / D)) ^ 2.0) * (-0.5 / l)));
	tmp = 0.0;
	if (d <= -4e-309)
		tmp = (sqrt((d / h)) * t_1) * t_0;
	else
		tmp = t_0 * (t_1 * (sqrt(d) / sqrt(h)));
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(h * N[(N[Power[N[(N[(M * 0.5), $MachinePrecision] / N[(d / D), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(-0.5 / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -4e-309], N[(N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$0), $MachinePrecision], N[(t$95$0 * N[(t$95$1 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
t_1 := 1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\\
\mathbf{if}\;d \leq -4 \cdot 10^{-309}:\\
\;\;\;\;\left(\sqrt{\frac{d}{h}} \cdot t\_1\right) \cdot t\_0\\

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


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

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

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

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

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

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

        \[\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. associate-/r*71.6%

        \[\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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
      6. associate-*r/70.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.9999999999999977e-309 < d

    1. Initial program 65.3%

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

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

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

        \[\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-inv65.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. *-commutative65.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. associate-/r*65.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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
      6. associate-*r/64.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 67.5% accurate, 1.0× speedup?

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

\\
\left(\sqrt{\frac{d}{h}} \cdot \left(1 + h \cdot \left({\left(\frac{M \cdot 0.5}{\frac{d}{D}}\right)}^{2} \cdot \frac{-0.5}{\ell}\right)\right)\right) \cdot \sqrt{\frac{d}{\ell}}
\end{array}
Derivation
  1. Initial program 67.8%

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

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

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

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

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

      \[\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. associate-/r*68.5%

      \[\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}{2 \cdot d}}\right)}^{2}}{\frac{\ell}{h}}\right)\right) \]
    6. associate-*r/67.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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