Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 80.8% → 89.3%
Time: 10.7s
Alternatives: 12
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 12 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.8% 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.3% accurate, 1.0× speedup?

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

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


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

    1. Initial program 77.6%

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

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

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

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

    if 1.00000000000000004e36 < d

    1. Initial program 84.1%

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

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

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

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

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

Alternative 2: 87.7% accurate, 1.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ d_m = \left|d\right| \\ [w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\ \\ \begin{array}{l} t_0 := \frac{M\_m \cdot D}{d\_m + d\_m}\\ w0 \cdot \sqrt{1 - \frac{t\_0 \cdot \left(t\_0 \cdot h\right)}{\ell}} \end{array} \end{array} \]
M_m = (fabs.f64 M)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D h l d_m)
 :precision binary64
 (let* ((t_0 (/ (* M_m D) (+ d_m d_m))))
   (* w0 (sqrt (- 1.0 (/ (* t_0 (* t_0 h)) l))))))
M_m = fabs(M);
d_m = fabs(d);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d_m);
double code(double w0, double M_m, double D, double h, double l, double d_m) {
	double t_0 = (M_m * D) / (d_m + d_m);
	return w0 * sqrt((1.0 - ((t_0 * (t_0 * h)) / l)));
}
M_m =     private
d_m =     private
NOTE: w0, M_m, D, 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, m_m, d, h, l, d_m)
use fmin_fmax_functions
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m
    real(8) :: t_0
    t_0 = (m_m * d) / (d_m + d_m)
    code = w0 * sqrt((1.0d0 - ((t_0 * (t_0 * h)) / l)))
end function
M_m = Math.abs(M);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D && D < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D, double h, double l, double d_m) {
	double t_0 = (M_m * D) / (d_m + d_m);
	return w0 * Math.sqrt((1.0 - ((t_0 * (t_0 * h)) / l)));
}
M_m = math.fabs(M)
d_m = math.fabs(d)
[w0, M_m, D, h, l, d_m] = sort([w0, M_m, D, h, l, d_m])
def code(w0, M_m, D, h, l, d_m):
	t_0 = (M_m * D) / (d_m + d_m)
	return w0 * math.sqrt((1.0 - ((t_0 * (t_0 * h)) / l)))
M_m = abs(M)
d_m = abs(d)
w0, M_m, D, h, l, d_m = sort([w0, M_m, D, h, l, d_m])
function code(w0, M_m, D, h, l, d_m)
	t_0 = Float64(Float64(M_m * D) / Float64(d_m + d_m))
	return Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(t_0 * Float64(t_0 * h)) / l))))
end
M_m = abs(M);
d_m = abs(d);
w0, M_m, D, h, l, d_m = num2cell(sort([w0, M_m, D, h, l, d_m])){:}
function tmp = code(w0, M_m, D, h, l, d_m)
	t_0 = (M_m * D) / (d_m + d_m);
	tmp = w0 * sqrt((1.0 - ((t_0 * (t_0 * h)) / l)));
end
M_m = N[Abs[M], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D_, h_, l_, d$95$m_] := Block[{t$95$0 = N[(N[(M$95$m * D), $MachinePrecision] / N[(d$95$m + d$95$m), $MachinePrecision]), $MachinePrecision]}, N[(w0 * N[Sqrt[N[(1.0 - N[(N[(t$95$0 * N[(t$95$0 * h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\
\\
\begin{array}{l}
t_0 := \frac{M\_m \cdot D}{d\_m + d\_m}\\
w0 \cdot \sqrt{1 - \frac{t\_0 \cdot \left(t\_0 \cdot h\right)}{\ell}}
\end{array}
\end{array}
Derivation
  1. Initial program 80.8%

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

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

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

Alternative 3: 86.8% accurate, 0.5× speedup?

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

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


\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))))) < 1.9999999999999999e305

    1. Initial program 92.7%

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

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

    if 1.9999999999999999e305 < (*.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 34.9%

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

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

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

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

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

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

Alternative 4: 86.7% accurate, 0.5× speedup?

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

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


\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))))) < 1.9999999999999999e305

    1. Initial program 92.7%

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

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

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

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

    if 1.9999999999999999e305 < (*.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 34.9%

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

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

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

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

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

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

Alternative 5: 85.8% accurate, 1.1× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ d_m = \left|d\right| \\ [w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\ \\ w0 \cdot \sqrt{1 - \frac{M\_m \cdot D}{d\_m + d\_m} \cdot \frac{\frac{\left(M\_m \cdot D\right) \cdot h}{d\_m + d\_m}}{\ell}} \end{array} \]
M_m = (fabs.f64 M)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D h l d_m)
 :precision binary64
 (*
  w0
  (sqrt
   (-
    1.0
    (* (/ (* M_m D) (+ d_m d_m)) (/ (/ (* (* M_m D) h) (+ d_m d_m)) l))))))
M_m = fabs(M);
d_m = fabs(d);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d_m);
double code(double w0, double M_m, double D, double h, double l, double d_m) {
	return w0 * sqrt((1.0 - (((M_m * D) / (d_m + d_m)) * ((((M_m * D) * h) / (d_m + d_m)) / l))));
}
M_m =     private
d_m =     private
NOTE: w0, M_m, D, 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, m_m, d, h, l, d_m)
use fmin_fmax_functions
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m
    code = w0 * sqrt((1.0d0 - (((m_m * d) / (d_m + d_m)) * ((((m_m * d) * h) / (d_m + d_m)) / l))))
end function
M_m = Math.abs(M);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D && D < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D, double h, double l, double d_m) {
	return w0 * Math.sqrt((1.0 - (((M_m * D) / (d_m + d_m)) * ((((M_m * D) * h) / (d_m + d_m)) / l))));
}
M_m = math.fabs(M)
d_m = math.fabs(d)
[w0, M_m, D, h, l, d_m] = sort([w0, M_m, D, h, l, d_m])
def code(w0, M_m, D, h, l, d_m):
	return w0 * math.sqrt((1.0 - (((M_m * D) / (d_m + d_m)) * ((((M_m * D) * h) / (d_m + d_m)) / l))))
M_m = abs(M)
d_m = abs(d)
w0, M_m, D, h, l, d_m = sort([w0, M_m, D, h, l, d_m])
function code(w0, M_m, D, h, l, d_m)
	return Float64(w0 * sqrt(Float64(1.0 - Float64(Float64(Float64(M_m * D) / Float64(d_m + d_m)) * Float64(Float64(Float64(Float64(M_m * D) * h) / Float64(d_m + d_m)) / l)))))
end
M_m = abs(M);
d_m = abs(d);
w0, M_m, D, h, l, d_m = num2cell(sort([w0, M_m, D, h, l, d_m])){:}
function tmp = code(w0, M_m, D, h, l, d_m)
	tmp = w0 * sqrt((1.0 - (((M_m * D) / (d_m + d_m)) * ((((M_m * D) * h) / (d_m + d_m)) / l))));
end
M_m = N[Abs[M], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D_, h_, l_, d$95$m_] := N[(w0 * N[Sqrt[N[(1.0 - N[(N[(N[(M$95$m * D), $MachinePrecision] / N[(d$95$m + d$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(M$95$m * D), $MachinePrecision] * h), $MachinePrecision] / N[(d$95$m + d$95$m), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\
\\
w0 \cdot \sqrt{1 - \frac{M\_m \cdot D}{d\_m + d\_m} \cdot \frac{\frac{\left(M\_m \cdot D\right) \cdot h}{d\_m + d\_m}}{\ell}}
\end{array}
Derivation
  1. Initial program 80.8%

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

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

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

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

Alternative 6: 83.9% accurate, 0.5× speedup?

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

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


\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

    1. Initial program 100.0%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites99.7%

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

    if 1 < (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 52.4%

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

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

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

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

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

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

Alternative 7: 83.6% accurate, 0.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < -1.99999999999999996e-12

    1. Initial program 65.3%

      \[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 \sqrt{1 - \color{blue}{\left(\frac{1}{4} \cdot \frac{{D}^{2} \cdot {M}^{2}}{{d}^{2}}\right)} \cdot \frac{h}{\ell}} \]
    3. Applied rewrites41.3%

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

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

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

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

    1. Initial program 88.2%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites96.2%

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

Alternative 8: 82.0% accurate, 0.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < -1.99999999999999996e-12

    1. Initial program 65.3%

      \[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 \sqrt{1 - \color{blue}{\left(\frac{1}{4} \cdot \frac{{D}^{2} \cdot {M}^{2}}{{d}^{2}}\right)} \cdot \frac{h}{\ell}} \]
    3. Applied rewrites41.3%

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

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

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

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

    1. Initial program 88.2%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites96.2%

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

Alternative 9: 79.6% accurate, 0.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < -1.99999999999999996e-12

    1. Initial program 65.3%

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

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

      \[\leadsto w0 \cdot \mathsf{fma}\left(\frac{\left(\left(M \cdot M\right) \cdot h\right) \cdot \left(D \cdot D\right)}{d \cdot \left(d \cdot \ell\right)}, -0.125, 1\right) \]
    5. Applied rewrites43.3%

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

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

    1. Initial program 88.2%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites96.2%

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

Alternative 10: 79.3% accurate, 0.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < -2.0000000000000001e209

    1. Initial program 57.9%

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

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

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

      \[\leadsto w0 \cdot \frac{-0.125 \cdot \left(\left(\left(M \cdot M\right) \cdot h\right) \cdot \left(D \cdot D\right)\right)}{\color{blue}{\left(d \cdot d\right) \cdot \ell}} \]
    6. Applied rewrites42.7%

      \[\leadsto w0 \cdot \left(\frac{\left(\left(M \cdot M\right) \cdot h\right) \cdot \left(D \cdot D\right)}{\left(d \cdot d\right) \cdot \ell} \cdot -0.125\right) \]
    7. Applied rewrites51.5%

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

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

    1. Initial program 89.0%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites89.6%

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

Alternative 11: 79.0% accurate, 0.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;w0\\


\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)) < -2.0000000000000001e209

    1. Initial program 57.9%

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

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

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

      \[\leadsto w0 \cdot \frac{-0.125 \cdot \left(\left(\left(M \cdot M\right) \cdot h\right) \cdot \left(D \cdot D\right)\right)}{\color{blue}{\left(d \cdot d\right) \cdot \ell}} \]
    6. Applied rewrites42.7%

      \[\leadsto w0 \cdot \left(\frac{\left(\left(M \cdot M\right) \cdot h\right) \cdot \left(D \cdot D\right)}{\left(d \cdot d\right) \cdot \ell} \cdot -0.125\right) \]
    7. Applied rewrites49.1%

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

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

    1. Initial program 89.0%

      \[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 \color{blue}{w0} \]
    3. Applied rewrites89.6%

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

Alternative 12: 67.3% accurate, 39.8× speedup?

\[\begin{array}{l} M_m = \left|M\right| \\ d_m = \left|d\right| \\ [w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\ \\ w0 \end{array} \]
M_m = (fabs.f64 M)
d_m = (fabs.f64 d)
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
(FPCore (w0 M_m D h l d_m) :precision binary64 w0)
M_m = fabs(M);
d_m = fabs(d);
assert(w0 < M_m && M_m < D && D < h && h < l && l < d_m);
double code(double w0, double M_m, double D, double h, double l, double d_m) {
	return w0;
}
M_m =     private
d_m =     private
NOTE: w0, M_m, D, 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, m_m, d, h, l, d_m)
use fmin_fmax_functions
    real(8), intent (in) :: w0
    real(8), intent (in) :: m_m
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: d_m
    code = w0
end function
M_m = Math.abs(M);
d_m = Math.abs(d);
assert w0 < M_m && M_m < D && D < h && h < l && l < d_m;
public static double code(double w0, double M_m, double D, double h, double l, double d_m) {
	return w0;
}
M_m = math.fabs(M)
d_m = math.fabs(d)
[w0, M_m, D, h, l, d_m] = sort([w0, M_m, D, h, l, d_m])
def code(w0, M_m, D, h, l, d_m):
	return w0
M_m = abs(M)
d_m = abs(d)
w0, M_m, D, h, l, d_m = sort([w0, M_m, D, h, l, d_m])
function code(w0, M_m, D, h, l, d_m)
	return w0
end
M_m = abs(M);
d_m = abs(d);
w0, M_m, D, h, l, d_m = num2cell(sort([w0, M_m, D, h, l, d_m])){:}
function tmp = code(w0, M_m, D, h, l, d_m)
	tmp = w0;
end
M_m = N[Abs[M], $MachinePrecision]
d_m = N[Abs[d], $MachinePrecision]
NOTE: w0, M_m, D, h, l, and d_m should be sorted in increasing order before calling this function.
code[w0_, M$95$m_, D_, h_, l_, d$95$m_] := w0
\begin{array}{l}
M_m = \left|M\right|
\\
d_m = \left|d\right|
\\
[w0, M_m, D, h, l, d_m] = \mathsf{sort}([w0, M_m, D, h, l, d_m])\\
\\
w0
\end{array}
Derivation
  1. Initial program 80.8%

    \[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 \color{blue}{w0} \]
  3. Applied rewrites67.3%

    \[\leadsto \color{blue}{w0} \]
  4. Add Preprocessing

Reproduce

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