Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.5% → 89.5%
Time: 10.3s
Alternatives: 15
Speedup: 1.1×

Specification

?
\[\begin{array}{l} \\ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0, m, d, h, l, d_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)))))
end
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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 15 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: 80.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \end{array} \]
(FPCore (w0 M D h l d)
 :precision binary64
 (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))
double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * sqrt((1.0 - (pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0, m, d, h, l, d_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0
    real(8), intent (in) :: m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_1
    code = w0 * sqrt((1.0d0 - ((((m * d) / (2.0d0 * d_1)) ** 2.0d0) * (h / l))))
end function
public static double code(double w0, double M, double D, double h, double l, double d) {
	return w0 * Math.sqrt((1.0 - (Math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))));
}
def code(w0, M, D, h, l, d):
	return w0 * math.sqrt((1.0 - (math.pow(((M * D) / (2.0 * d)), 2.0) * (h / l))))
function code(w0, M, D, h, l, d)
	return Float64(w0 * sqrt(Float64(1.0 - Float64((Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0) * Float64(h / l)))))
end
function tmp = code(w0, M, D, h, l, d)
	tmp = w0 * sqrt((1.0 - ((((M * D) / (2.0 * d)) ^ 2.0) * (h / l))));
end
code[w0_, M_, D_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 89.5% accurate, 0.3× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := w0\_m \cdot \sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}}\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;\frac{D\_m \cdot \left(w0\_m \cdot \sqrt{-0.25 \cdot \frac{{M\_m}^{2} \cdot h}{d\_m \cdot \ell}}\right)}{\sqrt{d\_m}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0
         (*
          w0_m
          (sqrt (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)))))))
   (*
    w0_s
    (if (<= t_0 5e+307)
      t_0
      (if (<= t_0 INFINITY)
        (/
         (* D_m (* w0_m (sqrt (- (* 0.25 (/ (* (pow M_m 2.0) h) (* d_m l)))))))
         (sqrt d_m))
        (*
         w0_m
         (/
          (sqrt
           (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0))))
          (sqrt d_m))))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = w0_m * sqrt((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))));
	double tmp;
	if (t_0 <= 5e+307) {
		tmp = t_0;
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (D_m * (w0_m * sqrt(-(0.25 * ((pow(M_m, 2.0) * h) / (d_m * l)))))) / sqrt(d_m);
	} else {
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = w0_m * Math.sqrt((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))));
	double tmp;
	if (t_0 <= 5e+307) {
		tmp = t_0;
	} else if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = (D_m * (w0_m * Math.sqrt(-(0.25 * ((Math.pow(M_m, 2.0) * h) / (d_m * l)))))) / Math.sqrt(d_m);
	} else {
		tmp = w0_m * (Math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / Math.sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = w0_m * math.sqrt((1.0 - (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))))
	tmp = 0
	if t_0 <= 5e+307:
		tmp = t_0
	elif t_0 <= math.inf:
		tmp = (D_m * (w0_m * math.sqrt(-(0.25 * ((math.pow(M_m, 2.0) * h) / (d_m * l)))))) / math.sqrt(d_m)
	else:
		tmp = w0_m * (math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / math.sqrt(d_m))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(w0_m * sqrt(Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)))))
	tmp = 0.0
	if (t_0 <= 5e+307)
		tmp = t_0;
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(D_m * Float64(w0_m * sqrt(Float64(-Float64(0.25 * Float64(Float64((M_m ^ 2.0) * h) / Float64(d_m * l))))))) / sqrt(d_m));
	else
		tmp = Float64(w0_m * Float64(sqrt(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0)))) / sqrt(d_m)));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = w0_m * sqrt((1.0 - ((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l))));
	tmp = 0.0;
	if (t_0 <= 5e+307)
		tmp = t_0;
	elseif (t_0 <= Inf)
		tmp = (D_m * (w0_m * sqrt(-(0.25 * (((M_m ^ 2.0) * h) / (d_m * l)))))) / sqrt(d_m);
	else
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[t$95$0, 5e+307], t$95$0, If[LessEqual[t$95$0, Infinity], N[(N[(D$95$m * N[(w0$95$m * N[Sqrt[(-N[(0.25 * N[(N[(N[Power[M$95$m, 2.0], $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[(N[Sqrt[N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := w0\_m \cdot \sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}}\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t\_0\\

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

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 w0 (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))))) < 5e307

    1. Initial program 80.5%

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

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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

      \[\leadsto w0 \cdot \color{blue}{\frac{\sqrt{d - \left(M \cdot D\right) \cdot \frac{\frac{\left(M \cdot D\right) \cdot h}{d \cdot \ell}}{4}}}{\sqrt{d}}} \]
    5. Taylor expanded in D around inf

      \[\leadsto \color{blue}{\frac{D \cdot \left(w0 \cdot \sqrt{\mathsf{neg}\left(\frac{1}{4} \cdot \frac{{M}^{2} \cdot h}{d \cdot \ell}\right)}\right)}{\sqrt{d}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{D \cdot \left(w0 \cdot \sqrt{\mathsf{neg}\left(\frac{1}{4} \cdot \frac{{M}^{2} \cdot h}{d \cdot \ell}\right)}\right)}{\color{blue}{\sqrt{d}}} \]
    7. Applied rewrites21.8%

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

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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

      \[\leadsto w0 \cdot \color{blue}{\frac{\sqrt{d - \left(M \cdot D\right) \cdot \frac{\frac{\left(M \cdot D\right) \cdot h}{d \cdot \ell}}{4}}}{\sqrt{d}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 89.1% accurate, 0.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := w0\_m \cdot \sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}}\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 5 \cdot 10^{+304}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0
         (*
          w0_m
          (sqrt (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)))))))
   (*
    w0_s
    (if (<= t_0 5e+304)
      t_0
      (*
       w0_m
       (/
        (sqrt (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0))))
        (sqrt d_m)))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = w0_m * sqrt((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))));
	double tmp;
	if (t_0 <= 5e+304) {
		tmp = t_0;
	} else {
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = w0_m * sqrt((1.0d0 - ((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l))))
    if (t_0 <= 5d+304) then
        tmp = t_0
    else
        tmp = w0_m * (sqrt((d_m_1 - ((m_m * d_m) * ((((m_m * d_m) * h) / (d_m_1 * l)) / 4.0d0)))) / sqrt(d_m_1))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = w0_m * Math.sqrt((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))));
	double tmp;
	if (t_0 <= 5e+304) {
		tmp = t_0;
	} else {
		tmp = w0_m * (Math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / Math.sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = w0_m * math.sqrt((1.0 - (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l))))
	tmp = 0
	if t_0 <= 5e+304:
		tmp = t_0
	else:
		tmp = w0_m * (math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / math.sqrt(d_m))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(w0_m * sqrt(Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)))))
	tmp = 0.0
	if (t_0 <= 5e+304)
		tmp = t_0;
	else
		tmp = Float64(w0_m * Float64(sqrt(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0)))) / sqrt(d_m)));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = w0_m * sqrt((1.0 - ((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l))));
	tmp = 0.0;
	if (t_0 <= 5e+304)
		tmp = t_0;
	else
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[t$95$0, 5e+304], t$95$0, N[(w0$95$m * N[(N[Sqrt[N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := w0\_m \cdot \sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}}\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 w0 (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))))) < 4.9999999999999997e304

    1. Initial program 80.5%

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

    if 4.9999999999999997e304 < (*.f64 w0 (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)))))

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

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

Alternative 3: 88.8% accurate, 1.0× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{D\_m}{d\_m + d\_m} \cdot M\_m\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;d\_m \leq 10^{-25}:\\ \;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - t\_0 \cdot \frac{t\_0 \cdot h}{\ell}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* (/ D_m (+ d_m d_m)) M_m)))
   (*
    w0_s
    (if (<= d_m 1e-25)
      (*
       w0_m
       (/
        (sqrt (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0))))
        (sqrt d_m)))
      (* w0_m (sqrt (- 1.0 (* t_0 (/ (* t_0 h) l)))))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / (d_m + d_m)) * M_m;
	double tmp;
	if (d_m <= 1e-25) {
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	} else {
		tmp = w0_m * sqrt((1.0 - (t_0 * ((t_0 * h) / l))));
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (d_m / (d_m_1 + d_m_1)) * m_m
    if (d_m_1 <= 1d-25) then
        tmp = w0_m * (sqrt((d_m_1 - ((m_m * d_m) * ((((m_m * d_m) * h) / (d_m_1 * l)) / 4.0d0)))) / sqrt(d_m_1))
    else
        tmp = w0_m * sqrt((1.0d0 - (t_0 * ((t_0 * h) / l))))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / (d_m + d_m)) * M_m;
	double tmp;
	if (d_m <= 1e-25) {
		tmp = w0_m * (Math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / Math.sqrt(d_m));
	} else {
		tmp = w0_m * Math.sqrt((1.0 - (t_0 * ((t_0 * h) / l))));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = (D_m / (d_m + d_m)) * M_m
	tmp = 0
	if d_m <= 1e-25:
		tmp = w0_m * (math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / math.sqrt(d_m))
	else:
		tmp = w0_m * math.sqrt((1.0 - (t_0 * ((t_0 * h) / l))))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(D_m / Float64(d_m + d_m)) * M_m)
	tmp = 0.0
	if (d_m <= 1e-25)
		tmp = Float64(w0_m * Float64(sqrt(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0)))) / sqrt(d_m)));
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(t_0 * Float64(Float64(t_0 * h) / l)))));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = (D_m / (d_m + d_m)) * M_m;
	tmp = 0.0;
	if (d_m <= 1e-25)
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	else
		tmp = w0_m * sqrt((1.0 - (t_0 * ((t_0 * h) / l))));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(D$95$m / N[(d$95$m + d$95$m), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[d$95$m, 1e-25], N[(w0$95$m * N[(N[Sqrt[N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(t$95$0 * N[(N[(t$95$0 * h), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{D\_m}{d\_m + d\_m} \cdot M\_m\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;d\_m \leq 10^{-25}:\\
\;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - t\_0 \cdot \frac{t\_0 \cdot h}{\ell}}\\


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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

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

    if 1.00000000000000004e-25 < d

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      3. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      4. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)}} \]
      5. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}\right)} \]
      6. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{\color{blue}{M \cdot D}}{2 \cdot d}\right)} \]
      7. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{\color{blue}{2 \cdot d}}\right)} \]
      8. times-fracN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\left(\frac{M}{2} \cdot \frac{D}{d}\right)}\right)} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right) \cdot \frac{D}{d}\right)}} \]
      10. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right)\right) \cdot \frac{D}{d}}} \]
      11. lower-*.f64N/A

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot 0.25\right)\right)\right) \cdot \frac{D}{d}}} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right)\right) \cdot \frac{D}{d}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right)\right)} \cdot \frac{D}{d}} \]
      3. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h}{\ell} \cdot \left(\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{D}{d}\right)}} \]
      4. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h}{\ell}} \cdot \left(\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{D}{d}\right)} \]
      5. frac-2negN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\mathsf{neg}\left(h\right)}{\mathsf{neg}\left(\ell\right)}} \cdot \left(\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{D}{d}\right)} \]
      6. associate-*l/N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(\mathsf{neg}\left(h\right)\right) \cdot \left(\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{D}{d}\right)}{\mathsf{neg}\left(\ell\right)}}} \]
      7. associate-/l*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\mathsf{neg}\left(h\right)\right) \cdot \frac{\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{D}{d}}{\mathsf{neg}\left(\ell\right)}}} \]
    5. Applied rewrites87.9%

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

Alternative 4: 88.3% accurate, 0.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{D\_m}{d\_m} \cdot M\_m\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{t\_0 \cdot t\_0}{4} \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* (/ D_m d_m) M_m)))
   (*
    w0_s
    (if (<=
         (sqrt (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l))))
         1e+140)
      (* w0_m (sqrt (- 1.0 (* (/ (* t_0 t_0) 4.0) (/ h l)))))
      (*
       w0_m
       (/
        (sqrt (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0))))
        (sqrt d_m)))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / d_m) * M_m;
	double tmp;
	if (sqrt((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	} else {
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (d_m / d_m_1) * m_m
    if (sqrt((1.0d0 - ((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)))) <= 1d+140) then
        tmp = w0_m * sqrt((1.0d0 - (((t_0 * t_0) / 4.0d0) * (h / l))))
    else
        tmp = w0_m * (sqrt((d_m_1 - ((m_m * d_m) * ((((m_m * d_m) * h) / (d_m_1 * l)) / 4.0d0)))) / sqrt(d_m_1))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / d_m) * M_m;
	double tmp;
	if (Math.sqrt((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * Math.sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	} else {
		tmp = w0_m * (Math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / Math.sqrt(d_m));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = (D_m / d_m) * M_m
	tmp = 0
	if math.sqrt((1.0 - (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140:
		tmp = w0_m * math.sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))))
	else:
		tmp = w0_m * (math.sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / math.sqrt(d_m))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(D_m / d_m) * M_m)
	tmp = 0.0
	if (sqrt(Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)))) <= 1e+140)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(t_0 * t_0) / 4.0) * Float64(h / l)))));
	else
		tmp = Float64(w0_m * Float64(sqrt(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0)))) / sqrt(d_m)));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = (D_m / d_m) * M_m;
	tmp = 0.0;
	if (sqrt((1.0 - ((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)))) <= 1e+140)
		tmp = w0_m * sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	else
		tmp = w0_m * (sqrt((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0)))) / sqrt(d_m));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(D$95$m / d$95$m), $MachinePrecision] * M$95$m), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1e+140], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] / 4.0), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[(N[Sqrt[N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{D\_m}{d\_m} \cdot M\_m\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \frac{t\_0 \cdot t\_0}{4} \cdot \frac{h}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \frac{\sqrt{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}}{\sqrt{d\_m}}\\


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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-pow.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      4. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{M \cdot D}{\color{blue}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{M \cdot D}{\color{blue}{d \cdot 2}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      6. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{M \cdot D}{d}}{2}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      7. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}\right) \cdot \frac{h}{\ell}} \]
      8. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \frac{M \cdot D}{\color{blue}{2 \cdot d}}\right) \cdot \frac{h}{\ell}} \]
      9. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \frac{M \cdot D}{\color{blue}{d \cdot 2}}\right) \cdot \frac{h}{\ell}} \]
      10. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \color{blue}{\frac{\frac{M \cdot D}{d}}{2}}\right) \cdot \frac{h}{\ell}} \]
      11. frac-timesN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot 2}} \cdot \frac{h}{\ell}} \]
      12. metadata-evalN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \color{blue}{\left(1 + 1\right)}} \cdot \frac{h}{\ell}} \]
      13. cosh-0-revN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \left(\color{blue}{\cosh 0} + 1\right)} \cdot \frac{h}{\ell}} \]
      14. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \left(\cosh 0 + 1\right)}} \cdot \frac{h}{\ell}} \]
    3. Applied rewrites79.9%

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

    if 1.00000000000000006e140 < (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))))

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

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

Alternative 5: 87.0% accurate, 0.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{D\_m}{d\_m} \cdot M\_m\\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{t\_0 \cdot t\_0}{4} \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{\frac{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}{d\_m}}\\ \end{array} \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (let* ((t_0 (* (/ D_m d_m) M_m)))
   (*
    w0_s
    (if (<=
         (sqrt (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l))))
         1e+140)
      (* w0_m (sqrt (- 1.0 (* (/ (* t_0 t_0) 4.0) (/ h l)))))
      (*
       w0_m
       (sqrt
        (/
         (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0)))
         d_m)))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / d_m) * M_m;
	double tmp;
	if (sqrt((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	} else {
		tmp = w0_m * sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (d_m / d_m_1) * m_m
    if (sqrt((1.0d0 - ((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)))) <= 1d+140) then
        tmp = w0_m * sqrt((1.0d0 - (((t_0 * t_0) / 4.0d0) * (h / l))))
    else
        tmp = w0_m * sqrt(((d_m_1 - ((m_m * d_m) * ((((m_m * d_m) * h) / (d_m_1 * l)) / 4.0d0))) / d_m_1))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double t_0 = (D_m / d_m) * M_m;
	double tmp;
	if (Math.sqrt((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * Math.sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	} else {
		tmp = w0_m * Math.sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	t_0 = (D_m / d_m) * M_m
	tmp = 0
	if math.sqrt((1.0 - (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140:
		tmp = w0_m * math.sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))))
	else:
		tmp = w0_m * math.sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = Float64(Float64(D_m / d_m) * M_m)
	tmp = 0.0
	if (sqrt(Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)))) <= 1e+140)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(t_0 * t_0) / 4.0) * Float64(h / l)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0))) / d_m)));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	t_0 = (D_m / d_m) * M_m;
	tmp = 0.0;
	if (sqrt((1.0 - ((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)))) <= 1e+140)
		tmp = w0_m * sqrt((1.0 - (((t_0 * t_0) / 4.0) * (h / l))));
	else
		tmp = w0_m * sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(D$95$m / d$95$m), $MachinePrecision] * M$95$m), $MachinePrecision]}, N[(w0$95$s * If[LessEqual[N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1e+140], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] / 4.0), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{D\_m}{d\_m} \cdot M\_m\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \frac{t\_0 \cdot t\_0}{4} \cdot \frac{h}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \sqrt{\frac{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}{d\_m}}\\


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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-pow.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      4. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{M \cdot D}{\color{blue}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{M \cdot D}{\color{blue}{d \cdot 2}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      6. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{M \cdot D}{d}}{2}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      7. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}\right) \cdot \frac{h}{\ell}} \]
      8. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \frac{M \cdot D}{\color{blue}{2 \cdot d}}\right) \cdot \frac{h}{\ell}} \]
      9. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \frac{M \cdot D}{\color{blue}{d \cdot 2}}\right) \cdot \frac{h}{\ell}} \]
      10. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{M \cdot D}{d}}{2} \cdot \color{blue}{\frac{\frac{M \cdot D}{d}}{2}}\right) \cdot \frac{h}{\ell}} \]
      11. frac-timesN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot 2}} \cdot \frac{h}{\ell}} \]
      12. metadata-evalN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \color{blue}{\left(1 + 1\right)}} \cdot \frac{h}{\ell}} \]
      13. cosh-0-revN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \left(\color{blue}{\cosh 0} + 1\right)} \cdot \frac{h}{\ell}} \]
      14. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\frac{M \cdot D}{d} \cdot \frac{M \cdot D}{d}}{2 \cdot \left(\cosh 0 + 1\right)}} \cdot \frac{h}{\ell}} \]
    3. Applied rewrites79.9%

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

    if 1.00000000000000006e140 < (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))))

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

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

Alternative 6: 86.7% accurate, 0.5× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{\frac{0.25}{d\_m} \cdot \left(M\_m \cdot D\_m\right)}{d\_m} \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{\frac{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}{d\_m}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (*
  w0_s
  (if (<=
       (sqrt (- 1.0 (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l))))
       1e+140)
    (*
     w0_m
     (sqrt
      (-
       1.0
       (* (* (/ (* (/ 0.25 d_m) (* M_m D_m)) d_m) (* D_m M_m)) (/ h l)))))
    (*
     w0_m
     (sqrt
      (/
       (- d_m (* (* M_m D_m) (/ (/ (* (* M_m D_m) h) (* d_m l)) 4.0)))
       d_m))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if (sqrt((1.0 - (pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	} else {
		tmp = w0_m * sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if (sqrt((1.0d0 - ((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)))) <= 1d+140) then
        tmp = w0_m * sqrt((1.0d0 - (((((0.25d0 / d_m_1) * (m_m * d_m)) / d_m_1) * (d_m * m_m)) * (h / l))))
    else
        tmp = w0_m * sqrt(((d_m_1 - ((m_m * d_m) * ((((m_m * d_m) * h) / (d_m_1 * l)) / 4.0d0))) / d_m_1))
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if (Math.sqrt((1.0 - (Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140) {
		tmp = w0_m * Math.sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	} else {
		tmp = w0_m * Math.sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	tmp = 0
	if math.sqrt((1.0 - (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)))) <= 1e+140:
		tmp = w0_m * math.sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))))
	else:
		tmp = w0_m * math.sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m))
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (sqrt(Float64(1.0 - Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)))) <= 1e+140)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(Float64(Float64(0.25 / d_m) * Float64(M_m * D_m)) / d_m) * Float64(D_m * M_m)) * Float64(h / l)))));
	else
		tmp = Float64(w0_m * sqrt(Float64(Float64(d_m - Float64(Float64(M_m * D_m) * Float64(Float64(Float64(Float64(M_m * D_m) * h) / Float64(d_m * l)) / 4.0))) / d_m)));
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if (sqrt((1.0 - ((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)))) <= 1e+140)
		tmp = w0_m * sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	else
		tmp = w0_m * sqrt(((d_m - ((M_m * D_m) * ((((M_m * D_m) * h) / (d_m * l)) / 4.0))) / d_m));
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[Sqrt[N[(1.0 - N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1e+140], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(N[(N[(0.25 / d$95$m), $MachinePrecision] * N[(M$95$m * D$95$m), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(N[(d$95$m - N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;\sqrt{1 - {\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell}} \leq 10^{+140}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{\frac{0.25}{d\_m} \cdot \left(M\_m \cdot D\_m\right)}{d\_m} \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{h}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \sqrt{\frac{d\_m - \left(M\_m \cdot D\_m\right) \cdot \frac{\frac{\left(M\_m \cdot D\_m\right) \cdot h}{d\_m \cdot \ell}}{4}}{d\_m}}\\


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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-pow.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      4. mult-flipN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\left(M \cdot D\right) \cdot \frac{1}{2 \cdot d}\right)} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(M \cdot D\right) \cdot \left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)\right)} \cdot \frac{h}{\ell}} \]
      6. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(M \cdot D\right)\right)} \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{0.25}{d \cdot d} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right)} \cdot \frac{h}{\ell}} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{\frac{1}{4}}{d \cdot d} \cdot \left(D \cdot M\right)\right)} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      2. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{1}{4}}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      3. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\frac{\frac{1}{4}}{\color{blue}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      4. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{\frac{1}{4}}{d}}{d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l/N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      6. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      8. lower-/.f6479.1

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{0.25}{d}} \cdot \left(D \cdot M\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      9. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(M \cdot D\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      11. lower-*.f6479.1

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

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

    if 1.00000000000000006e140 < (sqrt.f64 (-.f64 #s(literal 1 binary64) (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))))

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

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

Alternative 7: 85.8% accurate, 0.9× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;M\_m \cdot D\_m \leq 5 \cdot 10^{-84}:\\ \;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\ \mathbf{elif}\;M\_m \cdot D\_m \leq 10^{+36}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(M\_m \cdot D\_m\right) \cdot h, \frac{M\_m \cdot D\_m}{\left(-4 \cdot \left(\ell \cdot d\_m\right)\right) \cdot d\_m}, 1\right)} \cdot w0\_m\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot \left(\frac{D\_m}{d\_m} \cdot \left(\left(M\_m \cdot M\_m\right) \cdot 0.25\right)\right)\right) \cdot \frac{D\_m}{d\_m}}\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (*
  w0_s
  (if (<= (* M_m D_m) 5e-84)
    (*
     w0_m
     (sqrt
      (fma (/ -0.25 d_m) (* (/ (* M_m D_m) d_m) (* (* (/ M_m l) h) D_m)) 1.0)))
    (if (<= (* M_m D_m) 1e+36)
      (*
       (sqrt
        (fma (* (* M_m D_m) h) (/ (* M_m D_m) (* (* -4.0 (* l d_m)) d_m)) 1.0))
       w0_m)
      (*
       w0_m
       (sqrt
        (-
         1.0
         (*
          (* (/ h l) (* (/ D_m d_m) (* (* M_m M_m) 0.25)))
          (/ D_m d_m)))))))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((M_m * D_m) <= 5e-84) {
		tmp = w0_m * sqrt(fma((-0.25 / d_m), (((M_m * D_m) / d_m) * (((M_m / l) * h) * D_m)), 1.0));
	} else if ((M_m * D_m) <= 1e+36) {
		tmp = sqrt(fma(((M_m * D_m) * h), ((M_m * D_m) / ((-4.0 * (l * d_m)) * d_m)), 1.0)) * w0_m;
	} else {
		tmp = w0_m * sqrt((1.0 - (((h / l) * ((D_m / d_m) * ((M_m * M_m) * 0.25))) * (D_m / d_m))));
	}
	return w0_s * tmp;
}
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64(M_m * D_m) <= 5e-84)
		tmp = Float64(w0_m * sqrt(fma(Float64(-0.25 / d_m), Float64(Float64(Float64(M_m * D_m) / d_m) * Float64(Float64(Float64(M_m / l) * h) * D_m)), 1.0)));
	elseif (Float64(M_m * D_m) <= 1e+36)
		tmp = Float64(sqrt(fma(Float64(Float64(M_m * D_m) * h), Float64(Float64(M_m * D_m) / Float64(Float64(-4.0 * Float64(l * d_m)) * d_m)), 1.0)) * w0_m);
	else
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(h / l) * Float64(Float64(D_m / d_m) * Float64(Float64(M_m * M_m) * 0.25))) * Float64(D_m / d_m)))));
	end
	return Float64(w0_s * tmp)
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(M$95$m * D$95$m), $MachinePrecision], 5e-84], N[(w0$95$m * N[Sqrt[N[(N[(-0.25 / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m / l), $MachinePrecision] * h), $MachinePrecision] * D$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(M$95$m * D$95$m), $MachinePrecision], 1e+36], N[(N[Sqrt[N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] * N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(N[(-4.0 * N[(l * d$95$m), $MachinePrecision]), $MachinePrecision] * d$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0$95$m), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(h / l), $MachinePrecision] * N[(N[(D$95$m / d$95$m), $MachinePrecision] * N[(N[(M$95$m * M$95$m), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(D$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;M\_m \cdot D\_m \leq 5 \cdot 10^{-84}:\\
\;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\

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

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{h}{\ell} \cdot \left(\frac{D\_m}{d\_m} \cdot \left(\left(M\_m \cdot M\_m\right) \cdot 0.25\right)\right)\right) \cdot \frac{D\_m}{d\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 M D) < 5.0000000000000002e-84

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-pow.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      4. mult-flipN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\left(M \cdot D\right) \cdot \frac{1}{2 \cdot d}\right)} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(M \cdot D\right) \cdot \left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)\right)} \cdot \frac{h}{\ell}} \]
      6. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(M \cdot D\right)\right)} \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{0.25}{d \cdot d} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right)} \cdot \frac{h}{\ell}} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{\frac{1}{4}}{d \cdot d} \cdot \left(D \cdot M\right)\right)} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      2. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{1}{4}}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      3. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\frac{\frac{1}{4}}{\color{blue}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      4. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{\frac{1}{4}}{d}}{d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l/N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      6. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      8. lower-/.f6479.1

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{0.25}{d}} \cdot \left(D \cdot M\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      9. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(M \cdot D\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      11. lower-*.f6479.1

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

      \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{0.25}{d} \cdot \left(M \cdot D\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
    6. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}}} \]
      2. sub-negate-revN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} - 1\right)\right)}} \]
      3. sub-flipN/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\color{blue}{\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
      4. metadata-evalN/A

        \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \color{blue}{-1}\right)\right)} \]
      5. distribute-neg-outN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) + \left(\mathsf{neg}\left(-1\right)\right)}} \]
    7. Applied rewrites83.8%

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

    if 5.0000000000000002e-84 < (*.f64 M D) < 1.00000000000000004e36

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
      4. +-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
      5. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
      6. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
      7. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
      8. distribute-rgt-neg-inN/A

        \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
      11. lower-fma.f64N/A

        \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
    3. Applied rewrites84.5%

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

      \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\left(D \cdot \frac{h}{d \cdot \ell}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0} \]
    5. Applied rewrites78.9%

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

    if 1.00000000000000004e36 < (*.f64 M D)

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
      2. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      3. lift-pow.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
      4. unpow2N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)}} \]
      5. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}\right)} \]
      6. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{\color{blue}{M \cdot D}}{2 \cdot d}\right)} \]
      7. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{\color{blue}{2 \cdot d}}\right)} \]
      8. times-fracN/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\left(\frac{M}{2} \cdot \frac{D}{d}\right)}\right)} \]
      9. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right) \cdot \frac{D}{d}\right)}} \]
      10. associate-*r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right)\right) \cdot \frac{D}{d}}} \]
      11. lower-*.f64N/A

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot 0.25\right)\right)\right) \cdot \frac{D}{d}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 85.4% accurate, 0.6× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -1 \cdot 10^{-7}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{\frac{0.25}{d\_m} \cdot \left(M\_m \cdot D\_m\right)}{d\_m} \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{h}{\ell}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot 1\\ \end{array} \end{array} \]
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
d_m = (fabs.f64 d)
w0\_m = (fabs.f64 w0)
w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0_s w0_m M_m D_m h l d_m)
 :precision binary64
 (*
  w0_s
  (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -1e-7)
    (*
     w0_m
     (sqrt
      (-
       1.0
       (* (* (/ (* (/ 0.25 d_m) (* M_m D_m)) d_m) (* D_m M_m)) (/ h l)))))
    (* w0_m 1.0))))
M_m = fabs(M);
D_m = fabs(D);
d_m = fabs(d);
w0\_m = fabs(w0);
w0\_s = copysign(1.0, w0);
assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e-7) {
		tmp = w0_m * sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	} else {
		tmp = w0_m * 1.0;
	}
	return w0_s * tmp;
}
M_m =     private
D_m =     private
d_m =     private
w0\_m =     private
w0\_s =     private
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
use fmin_fmax_functions
    real(8), intent (in) :: w0_s
    real(8), intent (in) :: w0_m
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d_m
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m_1
    real(8) :: tmp
    if (((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)) <= (-1d-7)) then
        tmp = w0_m * sqrt((1.0d0 - (((((0.25d0 / d_m_1) * (m_m * d_m)) / d_m_1) * (d_m * m_m)) * (h / l))))
    else
        tmp = w0_m * 1.0d0
    end if
    code = w0_s * tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
d_m = Math.abs(d);
w0\_m = Math.abs(w0);
w0\_s = Math.copySign(1.0, w0);
assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
	double tmp;
	if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e-7) {
		tmp = w0_m * Math.sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	} else {
		tmp = w0_m * 1.0;
	}
	return w0_s * tmp;
}
M_m = math.fabs(M)
D_m = math.fabs(D)
d_m = math.fabs(d)
w0\_m = math.fabs(w0)
w0\_s = math.copysign(1.0, w0)
[w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
	tmp = 0
	if (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e-7:
		tmp = w0_m * math.sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))))
	else:
		tmp = w0_m * 1.0
	return w0_s * tmp
M_m = abs(M)
D_m = abs(D)
d_m = abs(d)
w0\_m = abs(w0)
w0\_s = copysign(1.0, w0)
w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0
	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -1e-7)
		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(Float64(Float64(0.25 / d_m) * Float64(M_m * D_m)) / d_m) * Float64(D_m * M_m)) * Float64(h / l)))));
	else
		tmp = Float64(w0_m * 1.0);
	end
	return Float64(w0_s * tmp)
end
M_m = abs(M);
D_m = abs(D);
d_m = abs(d);
w0\_m = abs(w0);
w0\_s = sign(w0) * abs(1.0);
w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
	tmp = 0.0;
	if (((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)) <= -1e-7)
		tmp = w0_m * sqrt((1.0 - (((((0.25 / d_m) * (M_m * D_m)) / d_m) * (D_m * M_m)) * (h / l))));
	else
		tmp = w0_m * 1.0;
	end
	tmp_2 = w0_s * tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
w0\_m = N[Abs[w0], $MachinePrecision]
w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -1e-7], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(N[(N[(0.25 / d$95$m), $MachinePrecision] * N[(M$95$m * D$95$m), $MachinePrecision]), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * 1.0), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
d_m = \left|d\right|
\\
w0\_m = \left|w0\right|
\\
w0\_s = \mathsf{copysign}\left(1, w0\right)
\\
[w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
\\
w0\_s \cdot \begin{array}{l}
\mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -1 \cdot 10^{-7}:\\
\;\;\;\;w0\_m \cdot \sqrt{1 - \left(\frac{\frac{0.25}{d\_m} \cdot \left(M\_m \cdot D\_m\right)}{d\_m} \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{h}{\ell}}\\

\mathbf{else}:\\
\;\;\;\;w0\_m \cdot 1\\


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

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Step-by-step derivation
      1. lift-pow.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
      3. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      4. mult-flipN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\left(M \cdot D\right) \cdot \frac{1}{2 \cdot d}\right)} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(M \cdot D\right) \cdot \left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)\right)} \cdot \frac{h}{\ell}} \]
      6. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(M \cdot D\right)\right)} \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

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

      \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{0.25}{d \cdot d} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right)} \cdot \frac{h}{\ell}} \]
    4. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{\frac{1}{4}}{d \cdot d} \cdot \left(D \cdot M\right)\right)} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      2. lift-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{1}{4}}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      3. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\frac{\frac{1}{4}}{\color{blue}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      4. associate-/r*N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{\frac{1}{4}}{d}}{d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      5. associate-*l/N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      6. lower-/.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      7. lower-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      8. lower-/.f6479.1

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{0.25}{d}} \cdot \left(D \cdot M\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      9. lift-*.f64N/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      10. *-commutativeN/A

        \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(M \cdot D\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      11. lower-*.f6479.1

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

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

    if -9.9999999999999995e-8 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

    1. Initial program 80.5%

      \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
    2. Taylor expanded in M around 0

      \[\leadsto w0 \cdot \color{blue}{1} \]
    3. Step-by-step derivation
      1. Applied rewrites67.7%

        \[\leadsto w0 \cdot \color{blue}{1} \]
    4. Recombined 2 regimes into one program.
    5. Add Preprocessing

    Alternative 9: 85.4% accurate, 0.6× speedup?

    \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq 5 \cdot 10^{-124}:\\ \;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{\left(\left(\left(M\_m \cdot M\_m\right) \cdot 0.25\right) \cdot D\_m\right) \cdot h}{d\_m \cdot \ell} \cdot \frac{D\_m}{d\_m}}\\ \end{array} \end{array} \]
    M_m = (fabs.f64 M)
    D_m = (fabs.f64 D)
    d_m = (fabs.f64 d)
    w0\_m = (fabs.f64 w0)
    w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    (FPCore (w0_s w0_m M_m D_m h l d_m)
     :precision binary64
     (*
      w0_s
      (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) 5e-124)
        (*
         w0_m
         (sqrt
          (fma (/ -0.25 d_m) (* (/ (* M_m D_m) d_m) (* (* (/ M_m l) h) D_m)) 1.0)))
        (*
         w0_m
         (sqrt
          (-
           1.0
           (* (/ (* (* (* (* M_m M_m) 0.25) D_m) h) (* d_m l)) (/ D_m d_m))))))))
    M_m = fabs(M);
    D_m = fabs(D);
    d_m = fabs(d);
    w0\_m = fabs(w0);
    w0\_s = copysign(1.0, w0);
    assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
    double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
    	double tmp;
    	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= 5e-124) {
    		tmp = w0_m * sqrt(fma((-0.25 / d_m), (((M_m * D_m) / d_m) * (((M_m / l) * h) * D_m)), 1.0));
    	} else {
    		tmp = w0_m * sqrt((1.0 - ((((((M_m * M_m) * 0.25) * D_m) * h) / (d_m * l)) * (D_m / d_m))));
    	}
    	return w0_s * tmp;
    }
    
    M_m = abs(M)
    D_m = abs(D)
    d_m = abs(d)
    w0\_m = abs(w0)
    w0\_s = copysign(1.0, w0)
    w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
    function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
    	tmp = 0.0
    	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= 5e-124)
    		tmp = Float64(w0_m * sqrt(fma(Float64(-0.25 / d_m), Float64(Float64(Float64(M_m * D_m) / d_m) * Float64(Float64(Float64(M_m / l) * h) * D_m)), 1.0)));
    	else
    		tmp = Float64(w0_m * sqrt(Float64(1.0 - Float64(Float64(Float64(Float64(Float64(Float64(M_m * M_m) * 0.25) * D_m) * h) / Float64(d_m * l)) * Float64(D_m / d_m)))));
    	end
    	return Float64(w0_s * tmp)
    end
    
    M_m = N[Abs[M], $MachinePrecision]
    D_m = N[Abs[D], $MachinePrecision]
    d_m = N[Abs[d], $MachinePrecision]
    w0\_m = N[Abs[w0], $MachinePrecision]
    w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], 5e-124], N[(w0$95$m * N[Sqrt[N[(N[(-0.25 / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m / l), $MachinePrecision] * h), $MachinePrecision] * D$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(w0$95$m * N[Sqrt[N[(1.0 - N[(N[(N[(N[(N[(N[(M$95$m * M$95$m), $MachinePrecision] * 0.25), $MachinePrecision] * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m * l), $MachinePrecision]), $MachinePrecision] * N[(D$95$m / d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    M_m = \left|M\right|
    \\
    D_m = \left|D\right|
    \\
    d_m = \left|d\right|
    \\
    w0\_m = \left|w0\right|
    \\
    w0\_s = \mathsf{copysign}\left(1, w0\right)
    \\
    [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
    \\
    w0\_s \cdot \begin{array}{l}
    \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq 5 \cdot 10^{-124}:\\
    \;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;w0\_m \cdot \sqrt{1 - \frac{\left(\left(\left(M\_m \cdot M\_m\right) \cdot 0.25\right) \cdot D\_m\right) \cdot h}{d\_m \cdot \ell} \cdot \frac{D\_m}{d\_m}}\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < 5.0000000000000003e-124

      1. Initial program 80.5%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Step-by-step derivation
        1. lift-pow.f64N/A

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

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
        3. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
        4. mult-flipN/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\left(M \cdot D\right) \cdot \frac{1}{2 \cdot d}\right)} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
        5. associate-*l*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(M \cdot D\right) \cdot \left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)\right)} \cdot \frac{h}{\ell}} \]
        6. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(M \cdot D\right)\right)} \cdot \frac{h}{\ell}} \]
        7. lower-*.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{0.25}{d \cdot d} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right)} \cdot \frac{h}{\ell}} \]
      4. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{\frac{1}{4}}{d \cdot d} \cdot \left(D \cdot M\right)\right)} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        2. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{1}{4}}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        3. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\frac{\frac{1}{4}}{\color{blue}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        4. associate-/r*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{\frac{1}{4}}{d}}{d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        5. associate-*l/N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        6. lower-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        7. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        8. lower-/.f6479.1

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{0.25}{d}} \cdot \left(D \cdot M\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        9. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        10. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(M \cdot D\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        11. lower-*.f6479.1

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

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{0.25}{d} \cdot \left(M \cdot D\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      6. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}}} \]
        2. sub-negate-revN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} - 1\right)\right)}} \]
        3. sub-flipN/A

          \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\color{blue}{\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
        4. metadata-evalN/A

          \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \color{blue}{-1}\right)\right)} \]
        5. distribute-neg-outN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) + \left(\mathsf{neg}\left(-1\right)\right)}} \]
      7. Applied rewrites83.8%

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

      if 5.0000000000000003e-124 < (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l))

      1. Initial program 80.5%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
        2. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{h}{\ell} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
        3. lift-pow.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}} \]
        4. unpow2N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)}} \]
        5. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\frac{M \cdot D}{2 \cdot d}}\right)} \]
        6. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{\color{blue}{M \cdot D}}{2 \cdot d}\right)} \]
        7. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{\color{blue}{2 \cdot d}}\right)} \]
        8. times-fracN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \color{blue}{\left(\frac{M}{2} \cdot \frac{D}{d}\right)}\right)} \]
        9. associate-*r*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{h}{\ell} \cdot \color{blue}{\left(\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right) \cdot \frac{D}{d}\right)}} \]
        10. associate-*r*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M}{2}\right)\right) \cdot \frac{D}{d}}} \]
        11. lower-*.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot 0.25\right)\right)\right) \cdot \frac{D}{d}}} \]
      4. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{h}{\ell} \cdot \left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right)\right)} \cdot \frac{D}{d}} \]
        2. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{h}{\ell}\right)} \cdot \frac{D}{d}} \]
        3. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{D}{d} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right)} \cdot \frac{h}{\ell}\right) \cdot \frac{D}{d}} \]
        4. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{D}{d}} \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot \frac{h}{\ell}\right) \cdot \frac{D}{d}} \]
        5. associate-*l/N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)}{d}} \cdot \frac{h}{\ell}\right) \cdot \frac{D}{d}} \]
        6. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)}{d} \cdot \color{blue}{\frac{h}{\ell}}\right) \cdot \frac{D}{d}} \]
        7. frac-timesN/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot h}{d \cdot \ell}} \cdot \frac{D}{d}} \]
        8. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot h}{\color{blue}{\ell \cdot d}} \cdot \frac{D}{d}} \]
        9. lower-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot h}{\ell \cdot d}} \cdot \frac{D}{d}} \]
        10. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\left(D \cdot \left(\left(M \cdot M\right) \cdot \frac{1}{4}\right)\right) \cdot h}}{\ell \cdot d} \cdot \frac{D}{d}} \]
        11. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\left(\left(\left(M \cdot M\right) \cdot \frac{1}{4}\right) \cdot D\right)} \cdot h}{\ell \cdot d} \cdot \frac{D}{d}} \]
        12. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\color{blue}{\left(\left(\left(M \cdot M\right) \cdot \frac{1}{4}\right) \cdot D\right)} \cdot h}{\ell \cdot d} \cdot \frac{D}{d}} \]
        13. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(\left(\left(M \cdot M\right) \cdot \frac{1}{4}\right) \cdot D\right) \cdot h}{\color{blue}{d \cdot \ell}} \cdot \frac{D}{d}} \]
        14. lower-*.f6478.3

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\frac{\left(\left(\left(M \cdot M\right) \cdot 0.25\right) \cdot D\right) \cdot h}{d \cdot \ell}} \cdot \frac{D}{d}} \]
    3. Recombined 2 regimes into one program.
    4. Add Preprocessing

    Alternative 10: 84.2% accurate, 1.1× speedup?

    \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;M\_m \leq 2 \cdot 10^{-122}:\\ \;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(\left(h \cdot \frac{D\_m}{\ell \cdot d\_m}\right) \cdot \left(M\_m \cdot M\_m\right)\right) \cdot -0.25, \frac{D\_m}{d\_m}, 1\right)} \cdot w0\_m\\ \end{array} \end{array} \]
    M_m = (fabs.f64 M)
    D_m = (fabs.f64 D)
    d_m = (fabs.f64 d)
    w0\_m = (fabs.f64 w0)
    w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    (FPCore (w0_s w0_m M_m D_m h l d_m)
     :precision binary64
     (*
      w0_s
      (if (<= M_m 2e-122)
        (*
         w0_m
         (sqrt
          (fma (/ -0.25 d_m) (* (/ (* M_m D_m) d_m) (* (* (/ M_m l) h) D_m)) 1.0)))
        (*
         (sqrt
          (fma (* (* (* h (/ D_m (* l d_m))) (* M_m M_m)) -0.25) (/ D_m d_m) 1.0))
         w0_m))))
    M_m = fabs(M);
    D_m = fabs(D);
    d_m = fabs(d);
    w0\_m = fabs(w0);
    w0\_s = copysign(1.0, w0);
    assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
    double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
    	double tmp;
    	if (M_m <= 2e-122) {
    		tmp = w0_m * sqrt(fma((-0.25 / d_m), (((M_m * D_m) / d_m) * (((M_m / l) * h) * D_m)), 1.0));
    	} else {
    		tmp = sqrt(fma((((h * (D_m / (l * d_m))) * (M_m * M_m)) * -0.25), (D_m / d_m), 1.0)) * w0_m;
    	}
    	return w0_s * tmp;
    }
    
    M_m = abs(M)
    D_m = abs(D)
    d_m = abs(d)
    w0\_m = abs(w0)
    w0\_s = copysign(1.0, w0)
    w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
    function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
    	tmp = 0.0
    	if (M_m <= 2e-122)
    		tmp = Float64(w0_m * sqrt(fma(Float64(-0.25 / d_m), Float64(Float64(Float64(M_m * D_m) / d_m) * Float64(Float64(Float64(M_m / l) * h) * D_m)), 1.0)));
    	else
    		tmp = Float64(sqrt(fma(Float64(Float64(Float64(h * Float64(D_m / Float64(l * d_m))) * Float64(M_m * M_m)) * -0.25), Float64(D_m / d_m), 1.0)) * w0_m);
    	end
    	return Float64(w0_s * tmp)
    end
    
    M_m = N[Abs[M], $MachinePrecision]
    D_m = N[Abs[D], $MachinePrecision]
    d_m = N[Abs[d], $MachinePrecision]
    w0\_m = N[Abs[w0], $MachinePrecision]
    w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[M$95$m, 2e-122], N[(w0$95$m * N[Sqrt[N[(N[(-0.25 / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] / d$95$m), $MachinePrecision] * N[(N[(N[(M$95$m / l), $MachinePrecision] * h), $MachinePrecision] * D$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[(N[(N[(h * N[(D$95$m / N[(l * d$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(M$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision] * N[(D$95$m / d$95$m), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0$95$m), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    M_m = \left|M\right|
    \\
    D_m = \left|D\right|
    \\
    d_m = \left|d\right|
    \\
    w0\_m = \left|w0\right|
    \\
    w0\_s = \mathsf{copysign}\left(1, w0\right)
    \\
    [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
    \\
    w0\_s \cdot \begin{array}{l}
    \mathbf{if}\;M\_m \leq 2 \cdot 10^{-122}:\\
    \;\;\;\;w0\_m \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d\_m}, \frac{M\_m \cdot D\_m}{d\_m} \cdot \left(\left(\frac{M\_m}{\ell} \cdot h\right) \cdot D\_m\right), 1\right)}\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{\mathsf{fma}\left(\left(\left(h \cdot \frac{D\_m}{\ell \cdot d\_m}\right) \cdot \left(M\_m \cdot M\_m\right)\right) \cdot -0.25, \frac{D\_m}{d\_m}, 1\right)} \cdot w0\_m\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if M < 2.00000000000000012e-122

      1. Initial program 80.5%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Step-by-step derivation
        1. lift-pow.f64N/A

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

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)} \cdot \frac{h}{\ell}} \]
        3. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{M \cdot D}{2 \cdot d}} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
        4. mult-flipN/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\left(M \cdot D\right) \cdot \frac{1}{2 \cdot d}\right)} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \frac{h}{\ell}} \]
        5. associate-*l*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(M \cdot D\right) \cdot \left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right)\right)} \cdot \frac{h}{\ell}} \]
        6. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{1}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(M \cdot D\right)\right)} \cdot \frac{h}{\ell}} \]
        7. lower-*.f64N/A

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

        \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{\left(\left(\frac{0.25}{d \cdot d} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right)} \cdot \frac{h}{\ell}} \]
      4. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\left(\frac{\frac{1}{4}}{d \cdot d} \cdot \left(D \cdot M\right)\right)} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        2. lift-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{1}{4}}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        3. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\frac{\frac{1}{4}}{\color{blue}{d \cdot d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        4. associate-/r*N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\left(\color{blue}{\frac{\frac{\frac{1}{4}}{d}}{d}} \cdot \left(D \cdot M\right)\right) \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        5. associate-*l/N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        6. lower-/.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        7. lower-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{\frac{1}{4}}{d} \cdot \left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        8. lower-/.f6479.1

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\color{blue}{\frac{0.25}{d}} \cdot \left(D \cdot M\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        9. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(D \cdot M\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        10. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \color{blue}{\left(M \cdot D\right)}}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
        11. lower-*.f6479.1

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

        \[\leadsto w0 \cdot \sqrt{1 - \left(\color{blue}{\frac{\frac{0.25}{d} \cdot \left(M \cdot D\right)}{d}} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}} \]
      6. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}}} \]
        2. sub-negate-revN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} - 1\right)\right)}} \]
        3. sub-flipN/A

          \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\color{blue}{\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \left(\mathsf{neg}\left(1\right)\right)\right)}\right)} \]
        4. metadata-evalN/A

          \[\leadsto w0 \cdot \sqrt{\mathsf{neg}\left(\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell} + \color{blue}{-1}\right)\right)} \]
        5. distribute-neg-outN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left(\left(\frac{\frac{\frac{1}{4}}{d} \cdot \left(M \cdot D\right)}{d} \cdot \left(D \cdot M\right)\right) \cdot \frac{h}{\ell}\right)\right) + \left(\mathsf{neg}\left(-1\right)\right)}} \]
      7. Applied rewrites83.8%

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

      if 2.00000000000000012e-122 < M

      1. Initial program 80.5%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Step-by-step derivation
        1. lift--.f64N/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
        2. lift-*.f64N/A

          \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
        3. fp-cancel-sub-sign-invN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
        4. +-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
        5. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
        6. lift-pow.f64N/A

          \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
        7. unpow2N/A

          \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
        8. distribute-rgt-neg-inN/A

          \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
        9. associate-*r*N/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
        10. *-commutativeN/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
        11. lower-fma.f64N/A

          \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
      3. Applied rewrites84.5%

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

        \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\left(D \cdot \frac{h}{d \cdot \ell}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0} \]
      5. Step-by-step derivation
        1. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\color{blue}{\left(D \cdot \frac{h}{d \cdot \ell}\right)} \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        2. *-commutativeN/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\color{blue}{\left(\frac{h}{d \cdot \ell} \cdot D\right)} \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        3. lift-/.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\left(\color{blue}{\frac{h}{d \cdot \ell}} \cdot D\right) \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        4. associate-*l/N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\color{blue}{\frac{h \cdot D}{d \cdot \ell}} \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        5. associate-/l*N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\color{blue}{\left(h \cdot \frac{D}{d \cdot \ell}\right)} \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        6. lower-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\color{blue}{\left(h \cdot \frac{D}{d \cdot \ell}\right)} \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        7. lower-/.f6476.8

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\left(h \cdot \color{blue}{\frac{D}{d \cdot \ell}}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0 \]
        8. lift-*.f64N/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\left(h \cdot \frac{D}{\color{blue}{d \cdot \ell}}\right) \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        9. *-commutativeN/A

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\left(h \cdot \frac{D}{\color{blue}{\ell \cdot d}}\right) \cdot \left(M \cdot M\right)\right) \cdot \frac{-1}{4}, \frac{D}{d}, 1\right)} \cdot w0 \]
        10. lower-*.f6476.8

          \[\leadsto \sqrt{\mathsf{fma}\left(\left(\left(h \cdot \frac{D}{\color{blue}{\ell \cdot d}}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0 \]
      6. Applied rewrites76.8%

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

    Alternative 11: 82.7% accurate, 1.1× speedup?

    \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;D\_m \leq 1.65 \cdot 10^{-5}:\\ \;\;\;\;w0\_m \cdot 1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\left(M\_m \cdot D\_m\right) \cdot h, \frac{M\_m \cdot D\_m}{\left(-4 \cdot \left(\ell \cdot d\_m\right)\right) \cdot d\_m}, 1\right)} \cdot w0\_m\\ \end{array} \end{array} \]
    M_m = (fabs.f64 M)
    D_m = (fabs.f64 D)
    d_m = (fabs.f64 d)
    w0\_m = (fabs.f64 w0)
    w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    (FPCore (w0_s w0_m M_m D_m h l d_m)
     :precision binary64
     (*
      w0_s
      (if (<= D_m 1.65e-5)
        (* w0_m 1.0)
        (*
         (sqrt
          (fma (* (* M_m D_m) h) (/ (* M_m D_m) (* (* -4.0 (* l d_m)) d_m)) 1.0))
         w0_m))))
    M_m = fabs(M);
    D_m = fabs(D);
    d_m = fabs(d);
    w0\_m = fabs(w0);
    w0\_s = copysign(1.0, w0);
    assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
    double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
    	double tmp;
    	if (D_m <= 1.65e-5) {
    		tmp = w0_m * 1.0;
    	} else {
    		tmp = sqrt(fma(((M_m * D_m) * h), ((M_m * D_m) / ((-4.0 * (l * d_m)) * d_m)), 1.0)) * w0_m;
    	}
    	return w0_s * tmp;
    }
    
    M_m = abs(M)
    D_m = abs(D)
    d_m = abs(d)
    w0\_m = abs(w0)
    w0\_s = copysign(1.0, w0)
    w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
    function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
    	tmp = 0.0
    	if (D_m <= 1.65e-5)
    		tmp = Float64(w0_m * 1.0);
    	else
    		tmp = Float64(sqrt(fma(Float64(Float64(M_m * D_m) * h), Float64(Float64(M_m * D_m) / Float64(Float64(-4.0 * Float64(l * d_m)) * d_m)), 1.0)) * w0_m);
    	end
    	return Float64(w0_s * tmp)
    end
    
    M_m = N[Abs[M], $MachinePrecision]
    D_m = N[Abs[D], $MachinePrecision]
    d_m = N[Abs[d], $MachinePrecision]
    w0\_m = N[Abs[w0], $MachinePrecision]
    w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
    NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
    code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[D$95$m, 1.65e-5], N[(w0$95$m * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * h), $MachinePrecision] * N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(N[(-4.0 * N[(l * d$95$m), $MachinePrecision]), $MachinePrecision] * d$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0$95$m), $MachinePrecision]]), $MachinePrecision]
    
    \begin{array}{l}
    M_m = \left|M\right|
    \\
    D_m = \left|D\right|
    \\
    d_m = \left|d\right|
    \\
    w0\_m = \left|w0\right|
    \\
    w0\_s = \mathsf{copysign}\left(1, w0\right)
    \\
    [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
    \\
    w0\_s \cdot \begin{array}{l}
    \mathbf{if}\;D\_m \leq 1.65 \cdot 10^{-5}:\\
    \;\;\;\;w0\_m \cdot 1\\
    
    \mathbf{else}:\\
    \;\;\;\;\sqrt{\mathsf{fma}\left(\left(M\_m \cdot D\_m\right) \cdot h, \frac{M\_m \cdot D\_m}{\left(-4 \cdot \left(\ell \cdot d\_m\right)\right) \cdot d\_m}, 1\right)} \cdot w0\_m\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if D < 1.6500000000000001e-5

      1. Initial program 80.5%

        \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
      2. Taylor expanded in M around 0

        \[\leadsto w0 \cdot \color{blue}{1} \]
      3. Step-by-step derivation
        1. Applied rewrites67.7%

          \[\leadsto w0 \cdot \color{blue}{1} \]

        if 1.6500000000000001e-5 < D

        1. Initial program 80.5%

          \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
        2. Step-by-step derivation
          1. lift--.f64N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
          2. lift-*.f64N/A

            \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
          3. fp-cancel-sub-sign-invN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
          4. +-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
          5. *-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
          6. lift-pow.f64N/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
          7. unpow2N/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
          8. distribute-rgt-neg-inN/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
          9. associate-*r*N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
          10. *-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
          11. lower-fma.f64N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
        3. Applied rewrites84.5%

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

          \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\left(D \cdot \frac{h}{d \cdot \ell}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0} \]
        5. Applied rewrites78.9%

          \[\leadsto \sqrt{\color{blue}{\mathsf{fma}\left(\left(M \cdot D\right) \cdot h, \frac{M \cdot D}{\left(-4 \cdot \left(\ell \cdot d\right)\right) \cdot d}, 1\right)}} \cdot w0 \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 12: 81.0% accurate, 0.6× speedup?

      \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -0.04:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(M\_m, \frac{\left(\left(D\_m \cdot D\_m\right) \cdot M\_m\right) \cdot h}{\left(-4 \cdot \left(\ell \cdot d\_m\right)\right) \cdot d\_m}, 1\right)} \cdot w0\_m\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot 1\\ \end{array} \end{array} \]
      M_m = (fabs.f64 M)
      D_m = (fabs.f64 D)
      d_m = (fabs.f64 d)
      w0\_m = (fabs.f64 w0)
      w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
      NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
      (FPCore (w0_s w0_m M_m D_m h l d_m)
       :precision binary64
       (*
        w0_s
        (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -0.04)
          (*
           (sqrt
            (fma M_m (/ (* (* (* D_m D_m) M_m) h) (* (* -4.0 (* l d_m)) d_m)) 1.0))
           w0_m)
          (* w0_m 1.0))))
      M_m = fabs(M);
      D_m = fabs(D);
      d_m = fabs(d);
      w0\_m = fabs(w0);
      w0\_s = copysign(1.0, w0);
      assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
      double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
      	double tmp;
      	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -0.04) {
      		tmp = sqrt(fma(M_m, ((((D_m * D_m) * M_m) * h) / ((-4.0 * (l * d_m)) * d_m)), 1.0)) * w0_m;
      	} else {
      		tmp = w0_m * 1.0;
      	}
      	return w0_s * tmp;
      }
      
      M_m = abs(M)
      D_m = abs(D)
      d_m = abs(d)
      w0\_m = abs(w0)
      w0\_s = copysign(1.0, w0)
      w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
      function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
      	tmp = 0.0
      	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -0.04)
      		tmp = Float64(sqrt(fma(M_m, Float64(Float64(Float64(Float64(D_m * D_m) * M_m) * h) / Float64(Float64(-4.0 * Float64(l * d_m)) * d_m)), 1.0)) * w0_m);
      	else
      		tmp = Float64(w0_m * 1.0);
      	end
      	return Float64(w0_s * tmp)
      end
      
      M_m = N[Abs[M], $MachinePrecision]
      D_m = N[Abs[D], $MachinePrecision]
      d_m = N[Abs[d], $MachinePrecision]
      w0\_m = N[Abs[w0], $MachinePrecision]
      w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
      NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
      code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -0.04], N[(N[Sqrt[N[(M$95$m * N[(N[(N[(N[(D$95$m * D$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(N[(-4.0 * N[(l * d$95$m), $MachinePrecision]), $MachinePrecision] * d$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] * w0$95$m), $MachinePrecision], N[(w0$95$m * 1.0), $MachinePrecision]]), $MachinePrecision]
      
      \begin{array}{l}
      M_m = \left|M\right|
      \\
      D_m = \left|D\right|
      \\
      d_m = \left|d\right|
      \\
      w0\_m = \left|w0\right|
      \\
      w0\_s = \mathsf{copysign}\left(1, w0\right)
      \\
      [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
      \\
      w0\_s \cdot \begin{array}{l}
      \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -0.04:\\
      \;\;\;\;\sqrt{\mathsf{fma}\left(M\_m, \frac{\left(\left(D\_m \cdot D\_m\right) \cdot M\_m\right) \cdot h}{\left(-4 \cdot \left(\ell \cdot d\_m\right)\right) \cdot d\_m}, 1\right)} \cdot w0\_m\\
      
      \mathbf{else}:\\
      \;\;\;\;w0\_m \cdot 1\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -0.0400000000000000008

        1. Initial program 80.5%

          \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
        2. Step-by-step derivation
          1. lift--.f64N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
          2. lift-*.f64N/A

            \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
          3. fp-cancel-sub-sign-invN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
          4. +-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
          5. *-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
          6. lift-pow.f64N/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
          7. unpow2N/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
          8. distribute-rgt-neg-inN/A

            \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
          9. associate-*r*N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
          10. *-commutativeN/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
          11. lower-fma.f64N/A

            \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
        3. Applied rewrites84.5%

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

          \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\left(D \cdot \frac{h}{d \cdot \ell}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0} \]
        5. Applied rewrites61.6%

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

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

        1. Initial program 80.5%

          \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
        2. Taylor expanded in M around 0

          \[\leadsto w0 \cdot \color{blue}{1} \]
        3. Step-by-step derivation
          1. Applied rewrites67.7%

            \[\leadsto w0 \cdot \color{blue}{1} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 13: 79.1% accurate, 0.6× speedup?

        \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -0.04:\\ \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{D\_m \cdot \left(\left(M\_m \cdot M\_m\right) \cdot \left(h \cdot D\_m\right)\right)}{\left(d\_m \cdot d\_m\right) \cdot \ell}, -0.25, 1\right)} \cdot w0\_m\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot 1\\ \end{array} \end{array} \]
        M_m = (fabs.f64 M)
        D_m = (fabs.f64 D)
        d_m = (fabs.f64 d)
        w0\_m = (fabs.f64 w0)
        w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
        NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
        (FPCore (w0_s w0_m M_m D_m h l d_m)
         :precision binary64
         (*
          w0_s
          (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -0.04)
            (*
             (sqrt
              (fma (/ (* D_m (* (* M_m M_m) (* h D_m))) (* (* d_m d_m) l)) -0.25 1.0))
             w0_m)
            (* w0_m 1.0))))
        M_m = fabs(M);
        D_m = fabs(D);
        d_m = fabs(d);
        w0\_m = fabs(w0);
        w0\_s = copysign(1.0, w0);
        assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
        double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
        	double tmp;
        	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -0.04) {
        		tmp = sqrt(fma(((D_m * ((M_m * M_m) * (h * D_m))) / ((d_m * d_m) * l)), -0.25, 1.0)) * w0_m;
        	} else {
        		tmp = w0_m * 1.0;
        	}
        	return w0_s * tmp;
        }
        
        M_m = abs(M)
        D_m = abs(D)
        d_m = abs(d)
        w0\_m = abs(w0)
        w0\_s = copysign(1.0, w0)
        w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
        function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
        	tmp = 0.0
        	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -0.04)
        		tmp = Float64(sqrt(fma(Float64(Float64(D_m * Float64(Float64(M_m * M_m) * Float64(h * D_m))) / Float64(Float64(d_m * d_m) * l)), -0.25, 1.0)) * w0_m);
        	else
        		tmp = Float64(w0_m * 1.0);
        	end
        	return Float64(w0_s * tmp)
        end
        
        M_m = N[Abs[M], $MachinePrecision]
        D_m = N[Abs[D], $MachinePrecision]
        d_m = N[Abs[d], $MachinePrecision]
        w0\_m = N[Abs[w0], $MachinePrecision]
        w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
        NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
        code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -0.04], N[(N[Sqrt[N[(N[(N[(D$95$m * N[(N[(M$95$m * M$95$m), $MachinePrecision] * N[(h * D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(d$95$m * d$95$m), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision] * -0.25 + 1.0), $MachinePrecision]], $MachinePrecision] * w0$95$m), $MachinePrecision], N[(w0$95$m * 1.0), $MachinePrecision]]), $MachinePrecision]
        
        \begin{array}{l}
        M_m = \left|M\right|
        \\
        D_m = \left|D\right|
        \\
        d_m = \left|d\right|
        \\
        w0\_m = \left|w0\right|
        \\
        w0\_s = \mathsf{copysign}\left(1, w0\right)
        \\
        [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
        \\
        w0\_s \cdot \begin{array}{l}
        \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -0.04:\\
        \;\;\;\;\sqrt{\mathsf{fma}\left(\frac{D\_m \cdot \left(\left(M\_m \cdot M\_m\right) \cdot \left(h \cdot D\_m\right)\right)}{\left(d\_m \cdot d\_m\right) \cdot \ell}, -0.25, 1\right)} \cdot w0\_m\\
        
        \mathbf{else}:\\
        \;\;\;\;w0\_m \cdot 1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -0.0400000000000000008

          1. Initial program 80.5%

            \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
          2. Step-by-step derivation
            1. lift--.f64N/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
            2. lift-*.f64N/A

              \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
            3. fp-cancel-sub-sign-invN/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
            4. +-commutativeN/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
            5. *-commutativeN/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
            6. lift-pow.f64N/A

              \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
            7. unpow2N/A

              \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
            8. distribute-rgt-neg-inN/A

              \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
            9. associate-*r*N/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
            10. *-commutativeN/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
            11. lower-fma.f64N/A

              \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
          3. Applied rewrites84.5%

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

            \[\leadsto \color{blue}{\sqrt{\mathsf{fma}\left(\left(\left(D \cdot \frac{h}{d \cdot \ell}\right) \cdot \left(M \cdot M\right)\right) \cdot -0.25, \frac{D}{d}, 1\right)} \cdot w0} \]
          5. Applied rewrites65.2%

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

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

          1. Initial program 80.5%

            \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
          2. Taylor expanded in M around 0

            \[\leadsto w0 \cdot \color{blue}{1} \]
          3. Step-by-step derivation
            1. Applied rewrites67.7%

              \[\leadsto w0 \cdot \color{blue}{1} \]
          4. Recombined 2 regimes into one program.
          5. Add Preprocessing

          Alternative 14: 73.3% accurate, 0.7× speedup?

          \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \begin{array}{l} \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -1 \cdot 10^{+277}:\\ \;\;\;\;w0\_m \cdot \frac{d\_m \cdot \sqrt{\sqrt{\frac{1}{d\_m} \cdot \frac{1}{d\_m}}}}{\sqrt{d\_m}}\\ \mathbf{else}:\\ \;\;\;\;w0\_m \cdot 1\\ \end{array} \end{array} \]
          M_m = (fabs.f64 M)
          D_m = (fabs.f64 D)
          d_m = (fabs.f64 d)
          w0\_m = (fabs.f64 w0)
          w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
          NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
          (FPCore (w0_s w0_m M_m D_m h l d_m)
           :precision binary64
           (*
            w0_s
            (if (<= (* (pow (/ (* M_m D_m) (* 2.0 d_m)) 2.0) (/ h l)) -1e+277)
              (* w0_m (/ (* d_m (sqrt (sqrt (* (/ 1.0 d_m) (/ 1.0 d_m))))) (sqrt d_m)))
              (* w0_m 1.0))))
          M_m = fabs(M);
          D_m = fabs(D);
          d_m = fabs(d);
          w0\_m = fabs(w0);
          w0\_s = copysign(1.0, w0);
          assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
          double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
          	double tmp;
          	if ((pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e+277) {
          		tmp = w0_m * ((d_m * sqrt(sqrt(((1.0 / d_m) * (1.0 / d_m))))) / sqrt(d_m));
          	} else {
          		tmp = w0_m * 1.0;
          	}
          	return w0_s * tmp;
          }
          
          M_m =     private
          D_m =     private
          d_m =     private
          w0\_m =     private
          w0\_s =     private
          NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
          use fmin_fmax_functions
              real(8), intent (in) :: w0_s
              real(8), intent (in) :: w0_m
              real(8), intent (in) :: m_m
              real(8), intent (in) :: d_m
              real(8), intent (in) :: h
              real(8), intent (in) :: l
              real(8), intent (in) :: d_m_1
              real(8) :: tmp
              if (((((m_m * d_m) / (2.0d0 * d_m_1)) ** 2.0d0) * (h / l)) <= (-1d+277)) then
                  tmp = w0_m * ((d_m_1 * sqrt(sqrt(((1.0d0 / d_m_1) * (1.0d0 / d_m_1))))) / sqrt(d_m_1))
              else
                  tmp = w0_m * 1.0d0
              end if
              code = w0_s * tmp
          end function
          
          M_m = Math.abs(M);
          D_m = Math.abs(D);
          d_m = Math.abs(d);
          w0\_m = Math.abs(w0);
          w0\_s = Math.copySign(1.0, w0);
          assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
          public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
          	double tmp;
          	if ((Math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e+277) {
          		tmp = w0_m * ((d_m * Math.sqrt(Math.sqrt(((1.0 / d_m) * (1.0 / d_m))))) / Math.sqrt(d_m));
          	} else {
          		tmp = w0_m * 1.0;
          	}
          	return w0_s * tmp;
          }
          
          M_m = math.fabs(M)
          D_m = math.fabs(D)
          d_m = math.fabs(d)
          w0\_m = math.fabs(w0)
          w0\_s = math.copysign(1.0, w0)
          [w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
          def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
          	tmp = 0
          	if (math.pow(((M_m * D_m) / (2.0 * d_m)), 2.0) * (h / l)) <= -1e+277:
          		tmp = w0_m * ((d_m * math.sqrt(math.sqrt(((1.0 / d_m) * (1.0 / d_m))))) / math.sqrt(d_m))
          	else:
          		tmp = w0_m * 1.0
          	return w0_s * tmp
          
          M_m = abs(M)
          D_m = abs(D)
          d_m = abs(d)
          w0\_m = abs(w0)
          w0\_s = copysign(1.0, w0)
          w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
          function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
          	tmp = 0.0
          	if (Float64((Float64(Float64(M_m * D_m) / Float64(2.0 * d_m)) ^ 2.0) * Float64(h / l)) <= -1e+277)
          		tmp = Float64(w0_m * Float64(Float64(d_m * sqrt(sqrt(Float64(Float64(1.0 / d_m) * Float64(1.0 / d_m))))) / sqrt(d_m)));
          	else
          		tmp = Float64(w0_m * 1.0);
          	end
          	return Float64(w0_s * tmp)
          end
          
          M_m = abs(M);
          D_m = abs(D);
          d_m = abs(d);
          w0\_m = abs(w0);
          w0\_s = sign(w0) * abs(1.0);
          w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
          function tmp_2 = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
          	tmp = 0.0;
          	if (((((M_m * D_m) / (2.0 * d_m)) ^ 2.0) * (h / l)) <= -1e+277)
          		tmp = w0_m * ((d_m * sqrt(sqrt(((1.0 / d_m) * (1.0 / d_m))))) / sqrt(d_m));
          	else
          		tmp = w0_m * 1.0;
          	end
          	tmp_2 = w0_s * tmp;
          end
          
          M_m = N[Abs[M], $MachinePrecision]
          D_m = N[Abs[D], $MachinePrecision]
          d_m = N[Abs[d], $MachinePrecision]
          w0\_m = N[Abs[w0], $MachinePrecision]
          w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
          NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
          code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * If[LessEqual[N[(N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision], -1e+277], N[(w0$95$m * N[(N[(d$95$m * N[Sqrt[N[Sqrt[N[(N[(1.0 / d$95$m), $MachinePrecision] * N[(1.0 / d$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[d$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(w0$95$m * 1.0), $MachinePrecision]]), $MachinePrecision]
          
          \begin{array}{l}
          M_m = \left|M\right|
          \\
          D_m = \left|D\right|
          \\
          d_m = \left|d\right|
          \\
          w0\_m = \left|w0\right|
          \\
          w0\_s = \mathsf{copysign}\left(1, w0\right)
          \\
          [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
          \\
          w0\_s \cdot \begin{array}{l}
          \mathbf{if}\;{\left(\frac{M\_m \cdot D\_m}{2 \cdot d\_m}\right)}^{2} \cdot \frac{h}{\ell} \leq -1 \cdot 10^{+277}:\\
          \;\;\;\;w0\_m \cdot \frac{d\_m \cdot \sqrt{\sqrt{\frac{1}{d\_m} \cdot \frac{1}{d\_m}}}}{\sqrt{d\_m}}\\
          
          \mathbf{else}:\\
          \;\;\;\;w0\_m \cdot 1\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (*.f64 (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64)) (/.f64 h l)) < -1e277

            1. Initial program 80.5%

              \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
            2. Step-by-step derivation
              1. lift--.f64N/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
              2. lift-*.f64N/A

                \[\leadsto w0 \cdot \sqrt{1 - \color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}}} \]
              3. fp-cancel-sub-sign-invN/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{1 + \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell}}} \]
              4. +-commutativeN/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right) \cdot \frac{h}{\ell} + 1}} \]
              5. *-commutativeN/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left({\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right)\right)} + 1} \]
              6. lift-pow.f64N/A

                \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}}\right)\right) + 1} \]
              7. unpow2N/A

                \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \left(\mathsf{neg}\left(\color{blue}{\frac{M \cdot D}{2 \cdot d} \cdot \frac{M \cdot D}{2 \cdot d}}\right)\right) + 1} \]
              8. distribute-rgt-neg-inN/A

                \[\leadsto w0 \cdot \sqrt{\frac{h}{\ell} \cdot \color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)\right)} + 1} \]
              9. associate-*r*N/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{h}{\ell} \cdot \frac{M \cdot D}{2 \cdot d}\right) \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right)} + 1} \]
              10. *-commutativeN/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}\right)} \cdot \left(\mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right)\right) + 1} \]
              11. lower-fma.f64N/A

                \[\leadsto w0 \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\frac{M \cdot D}{2 \cdot d} \cdot \frac{h}{\ell}, \mathsf{neg}\left(\frac{M \cdot D}{2 \cdot d}\right), 1\right)}} \]
            3. Applied rewrites84.5%

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

              \[\leadsto w0 \cdot \color{blue}{\frac{\sqrt{d - \left(M \cdot D\right) \cdot \frac{\frac{\left(M \cdot D\right) \cdot h}{d \cdot \ell}}{4}}}{\sqrt{d}}} \]
            5. Taylor expanded in d around inf

              \[\leadsto w0 \cdot \frac{\color{blue}{d \cdot \sqrt{\frac{1}{d}}}}{\sqrt{d}} \]
            6. Step-by-step derivation
              1. lower-*.f64N/A

                \[\leadsto w0 \cdot \frac{d \cdot \color{blue}{\sqrt{\frac{1}{d}}}}{\sqrt{d}} \]
              2. lower-sqrt.f64N/A

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\frac{1}{d}}}{\sqrt{d}} \]
              3. lower-/.f6467.3

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\frac{1}{d}}}{\sqrt{d}} \]
            7. Applied rewrites67.3%

              \[\leadsto w0 \cdot \frac{\color{blue}{d \cdot \sqrt{\frac{1}{d}}}}{\sqrt{d}} \]
            8. Step-by-step derivation
              1. rem-square-sqrtN/A

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\sqrt{\frac{1}{d}} \cdot \sqrt{\frac{1}{d}}}}{\sqrt{d}} \]
              2. sqrt-unprodN/A

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\sqrt{\frac{1}{d} \cdot \frac{1}{d}}}}{\sqrt{d}} \]
              3. lower-sqrt.f64N/A

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\sqrt{\frac{1}{d} \cdot \frac{1}{d}}}}{\sqrt{d}} \]
              4. lower-*.f6443.1

                \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\sqrt{\frac{1}{d} \cdot \frac{1}{d}}}}{\sqrt{d}} \]
            9. Applied rewrites43.1%

              \[\leadsto w0 \cdot \frac{d \cdot \sqrt{\sqrt{\frac{1}{d} \cdot \frac{1}{d}}}}{\sqrt{d}} \]

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

            1. Initial program 80.5%

              \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
            2. Taylor expanded in M around 0

              \[\leadsto w0 \cdot \color{blue}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites67.7%

                \[\leadsto w0 \cdot \color{blue}{1} \]
            4. Recombined 2 regimes into one program.
            5. Add Preprocessing

            Alternative 15: 67.7% accurate, 10.1× speedup?

            \[\begin{array}{l} M_m = \left|M\right| \\ D_m = \left|D\right| \\ d_m = \left|d\right| \\ w0\_m = \left|w0\right| \\ w0\_s = \mathsf{copysign}\left(1, w0\right) \\ [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\ \\ w0\_s \cdot \left(w0\_m \cdot 1\right) \end{array} \]
            M_m = (fabs.f64 M)
            D_m = (fabs.f64 D)
            d_m = (fabs.f64 d)
            w0\_m = (fabs.f64 w0)
            w0\_s = (copysign.f64 #s(literal 1 binary64) w0)
            NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
            (FPCore (w0_s w0_m M_m D_m h l d_m) :precision binary64 (* w0_s (* w0_m 1.0)))
            M_m = fabs(M);
            D_m = fabs(D);
            d_m = fabs(d);
            w0\_m = fabs(w0);
            w0\_s = copysign(1.0, w0);
            assert(w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m);
            double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
            	return w0_s * (w0_m * 1.0);
            }
            
            M_m =     private
            D_m =     private
            d_m =     private
            w0\_m =     private
            w0\_s =     private
            NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
            module fmin_fmax_functions
                implicit none
                private
                public fmax
                public fmin
            
                interface fmax
                    module procedure fmax88
                    module procedure fmax44
                    module procedure fmax84
                    module procedure fmax48
                end interface
                interface fmin
                    module procedure fmin88
                    module procedure fmin44
                    module procedure fmin84
                    module procedure fmin48
                end interface
            contains
                real(8) function fmax88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(4) function fmax44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                end function
                real(8) function fmax84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmax48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                end function
                real(8) function fmin88(x, y) result (res)
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(4) function fmin44(x, y) result (res)
                    real(4), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                end function
                real(8) function fmin84(x, y) result(res)
                    real(8), intent (in) :: x
                    real(4), intent (in) :: y
                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                end function
                real(8) function fmin48(x, y) result(res)
                    real(4), intent (in) :: x
                    real(8), intent (in) :: y
                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                end function
            end module
            
            real(8) function code(w0_s, w0_m, m_m, d_m, h, l, d_m_1)
            use fmin_fmax_functions
                real(8), intent (in) :: w0_s
                real(8), intent (in) :: w0_m
                real(8), intent (in) :: m_m
                real(8), intent (in) :: d_m
                real(8), intent (in) :: h
                real(8), intent (in) :: l
                real(8), intent (in) :: d_m_1
                code = w0_s * (w0_m * 1.0d0)
            end function
            
            M_m = Math.abs(M);
            D_m = Math.abs(D);
            d_m = Math.abs(d);
            w0\_m = Math.abs(w0);
            w0\_s = Math.copySign(1.0, w0);
            assert w0_m < M_m && M_m < D_m && D_m < h && h < l && l < d_m;
            public static double code(double w0_s, double w0_m, double M_m, double D_m, double h, double l, double d_m) {
            	return w0_s * (w0_m * 1.0);
            }
            
            M_m = math.fabs(M)
            D_m = math.fabs(D)
            d_m = math.fabs(d)
            w0\_m = math.fabs(w0)
            w0\_s = math.copysign(1.0, w0)
            [w0_m, M_m, D_m, h, l, d_m] = sort([w0_m, M_m, D_m, h, l, d_m])
            def code(w0_s, w0_m, M_m, D_m, h, l, d_m):
            	return w0_s * (w0_m * 1.0)
            
            M_m = abs(M)
            D_m = abs(D)
            d_m = abs(d)
            w0\_m = abs(w0)
            w0\_s = copysign(1.0, w0)
            w0_m, M_m, D_m, h, l, d_m = sort([w0_m, M_m, D_m, h, l, d_m])
            function code(w0_s, w0_m, M_m, D_m, h, l, d_m)
            	return Float64(w0_s * Float64(w0_m * 1.0))
            end
            
            M_m = abs(M);
            D_m = abs(D);
            d_m = abs(d);
            w0\_m = abs(w0);
            w0\_s = sign(w0) * abs(1.0);
            w0_m, M_m, D_m, h, l, d_m = num2cell(sort([w0_m, M_m, D_m, h, l, d_m])){:}
            function tmp = code(w0_s, w0_m, M_m, D_m, h, l, d_m)
            	tmp = w0_s * (w0_m * 1.0);
            end
            
            M_m = N[Abs[M], $MachinePrecision]
            D_m = N[Abs[D], $MachinePrecision]
            d_m = N[Abs[d], $MachinePrecision]
            w0\_m = N[Abs[w0], $MachinePrecision]
            w0\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[w0]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
            NOTE: w0_m, M_m, D_m, h, l, and d_m should be sorted in increasing order before calling this function.
            code[w0$95$s_, w0$95$m_, M$95$m_, D$95$m_, h_, l_, d$95$m_] := N[(w0$95$s * N[(w0$95$m * 1.0), $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            M_m = \left|M\right|
            \\
            D_m = \left|D\right|
            \\
            d_m = \left|d\right|
            \\
            w0\_m = \left|w0\right|
            \\
            w0\_s = \mathsf{copysign}\left(1, w0\right)
            \\
            [w0_m, M_m, D_m, h, l, d_m] = \mathsf{sort}([w0_m, M_m, D_m, h, l, d_m])\\
            \\
            w0\_s \cdot \left(w0\_m \cdot 1\right)
            \end{array}
            
            Derivation
            1. Initial program 80.5%

              \[w0 \cdot \sqrt{1 - {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2} \cdot \frac{h}{\ell}} \]
            2. Taylor expanded in M around 0

              \[\leadsto w0 \cdot \color{blue}{1} \]
            3. Step-by-step derivation
              1. Applied rewrites67.7%

                \[\leadsto w0 \cdot \color{blue}{1} \]
              2. Add Preprocessing

              Reproduce

              ?
              herbie shell --seed 2025152 
              (FPCore (w0 M D h l d)
                :name "Henrywood and Agarwal, Equation (9a)"
                :precision binary64
                (* w0 (sqrt (- 1.0 (* (pow (/ (* M D) (* 2.0 d)) 2.0) (/ h l))))))