Henrywood and Agarwal, Equation (9a)

Percentage Accurate: 81.5% → 88.5%
Time: 7.9s
Alternatives: 14
Speedup: 2.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}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 14 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: 81.5% accurate, 1.0× speedup?

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

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

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

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

Alternative 1: 88.5% accurate, 0.7× speedup?

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

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


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

    1. Initial program 86.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        1. Initial program 52.9%

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

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

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

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

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

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

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

              Alternative 2: 82.2% accurate, 0.4× speedup?

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

                1. Initial program 56.3%

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

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

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

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

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

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

                      1. Initial program 99.4%

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

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

                          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                        2. Step-by-step derivation
                          1. Applied rewrites33.7%

                            \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot M\right) \cdot \left(M \cdot h\right)}{\color{blue}{\left(d \cdot d\right) \cdot \ell}}} \]
                          2. Step-by-step derivation
                            1. Applied rewrites48.4%

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

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

                            1. Initial program 90.6%

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

                              \[\leadsto \color{blue}{w0} \]
                            4. Step-by-step derivation
                              1. Applied rewrites96.5%

                                \[\leadsto \color{blue}{w0} \]
                            5. Recombined 3 regimes into one program.
                            6. Final simplification82.4%

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

                            Alternative 3: 82.5% accurate, 0.4× speedup?

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

                              1. Initial program 56.3%

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

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

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

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

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

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

                                    1. Initial program 99.4%

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

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

                                        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites33.7%

                                          \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot M\right) \cdot \left(M \cdot h\right)}{\color{blue}{\left(d \cdot d\right) \cdot \ell}}} \]
                                        2. Step-by-step derivation
                                          1. Applied rewrites34.1%

                                            \[\leadsto w0 \cdot \sqrt{1 - \frac{\left(0.25 \cdot D\right) \cdot \left(D \cdot \left(\left(M \cdot M\right) \cdot h\right)\right)}{\color{blue}{\left(d \cdot d\right)} \cdot \ell}} \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites49.3%

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

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

                                            1. Initial program 90.6%

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

                                              \[\leadsto \color{blue}{w0} \]
                                            4. Step-by-step derivation
                                              1. Applied rewrites96.5%

                                                \[\leadsto \color{blue}{w0} \]
                                            5. Recombined 3 regimes into one program.
                                            6. Final simplification82.4%

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

                                            Alternative 4: 82.5% accurate, 0.4× speedup?

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

                                              1. Initial program 56.3%

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

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

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

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

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

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

                                                    1. Initial program 99.4%

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

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

                                                        \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                                                      2. Step-by-step derivation
                                                        1. Applied rewrites33.7%

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

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

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

                                                            \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{-1}{4} \cdot \frac{{D}^{2} \cdot {M}^{2}}{{d}^{2} \cdot \ell}, h, 1\right)} \]
                                                          3. Step-by-step derivation
                                                            1. Applied rewrites58.4%

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

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

                                                            1. Initial program 90.6%

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

                                                              \[\leadsto \color{blue}{w0} \]
                                                            4. Step-by-step derivation
                                                              1. Applied rewrites96.5%

                                                                \[\leadsto \color{blue}{w0} \]
                                                            5. Recombined 3 regimes into one program.
                                                            6. Final simplification83.1%

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

                                                            Alternative 5: 81.6% accurate, 0.4× speedup?

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

                                                              1. Initial program 57.0%

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

                                                                  \[\leadsto w0 \cdot \color{blue}{\mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), \frac{h}{d \cdot d} \cdot \frac{M \cdot M}{\ell}, 1\right)} \]
                                                                2. Step-by-step derivation
                                                                  1. Applied rewrites46.2%

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

                                                                    \[\leadsto w0 \cdot \left(h \cdot \color{blue}{\left(\frac{-1}{8} \cdot \frac{{D}^{2} \cdot {M}^{2}}{{d}^{2} \cdot \ell} + \frac{1}{h}\right)}\right) \]
                                                                  3. Step-by-step derivation
                                                                    1. Applied rewrites55.4%

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

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

                                                                    1. Initial program 99.6%

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

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

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

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

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

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

                                                                            \[\leadsto w0 \cdot \sqrt{\frac{-1}{4} \cdot \frac{{D}^{2} \cdot \left({M}^{2} \cdot h\right)}{\color{blue}{{d}^{2} \cdot \ell}}} \]
                                                                          3. Step-by-step derivation
                                                                            1. Applied rewrites22.8%

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

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

                                                                            1. Initial program 90.8%

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

                                                                              \[\leadsto \color{blue}{w0} \]
                                                                            4. Step-by-step derivation
                                                                              1. Applied rewrites94.9%

                                                                                \[\leadsto \color{blue}{w0} \]
                                                                            5. Recombined 3 regimes into one program.
                                                                            6. Final simplification80.4%

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

                                                                            Alternative 6: 83.9% accurate, 0.7× speedup?

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

                                                                              1. Initial program 65.4%

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

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

                                                                                  \[\leadsto w0 \cdot \sqrt{\color{blue}{\left(-0.25 \cdot \left(D \cdot D\right)\right) \cdot \left(\frac{h}{d \cdot d} \cdot \frac{M \cdot M}{\ell}\right)}} \]
                                                                                2. Step-by-step derivation
                                                                                  1. Applied rewrites42.9%

                                                                                    \[\leadsto w0 \cdot \sqrt{\left(-0.25 \cdot \left(D \cdot D\right)\right) \cdot \left(\frac{M \cdot M}{d} \cdot \color{blue}{\frac{\frac{h}{\ell}}{d}}\right)} \]
                                                                                  2. Step-by-step derivation
                                                                                    1. Applied rewrites53.3%

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

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

                                                                                    1. Initial program 90.6%

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

                                                                                      \[\leadsto \color{blue}{w0} \]
                                                                                    4. Step-by-step derivation
                                                                                      1. Applied rewrites96.3%

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

                                                                                    Alternative 7: 84.5% accurate, 0.7× speedup?

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

                                                                                      1. Initial program 65.8%

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

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

                                                                                          \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                                                                                        2. Step-by-step derivation
                                                                                          1. Applied rewrites42.8%

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

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

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

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

                                                                                            1. Initial program 90.6%

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

                                                                                              \[\leadsto \color{blue}{w0} \]
                                                                                            4. Step-by-step derivation
                                                                                              1. Applied rewrites96.5%

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

                                                                                            Alternative 8: 83.2% accurate, 0.7× speedup?

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

                                                                                              1. Initial program 64.2%

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

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

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

                                                                                                    \[\leadsto w0 \cdot \sqrt{\left(-0.25 \cdot \left(D \cdot D\right)\right) \cdot \left(\frac{M \cdot M}{d} \cdot \color{blue}{\frac{\frac{h}{\ell}}{d}}\right)} \]
                                                                                                  2. Step-by-step derivation
                                                                                                    1. Applied rewrites53.2%

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

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

                                                                                                    1. Initial program 90.8%

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

                                                                                                      \[\leadsto \color{blue}{w0} \]
                                                                                                    4. Step-by-step derivation
                                                                                                      1. Applied rewrites94.9%

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

                                                                                                    Alternative 9: 80.6% accurate, 0.8× speedup?

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

                                                                                                      1. Initial program 65.8%

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

                                                                                                          \[\leadsto w0 \cdot \color{blue}{\mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), \frac{h}{d \cdot d} \cdot \frac{M \cdot M}{\ell}, 1\right)} \]
                                                                                                        2. Step-by-step derivation
                                                                                                          1. Applied rewrites38.1%

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

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

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

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

                                                                                                            1. Initial program 90.6%

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

                                                                                                              \[\leadsto \color{blue}{w0} \]
                                                                                                            4. Step-by-step derivation
                                                                                                              1. Applied rewrites96.5%

                                                                                                                \[\leadsto \color{blue}{w0} \]
                                                                                                            5. Recombined 2 regimes into one program.
                                                                                                            6. Final simplification80.0%

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

                                                                                                            Alternative 10: 79.9% accurate, 0.8× speedup?

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

                                                                                                              1. Initial program 59.9%

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

                                                                                                                  \[\leadsto w0 \cdot \color{blue}{\mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), \frac{h}{d \cdot d} \cdot \frac{M \cdot M}{\ell}, 1\right)} \]
                                                                                                                2. Step-by-step derivation
                                                                                                                  1. Applied rewrites40.6%

                                                                                                                    \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), M \cdot \color{blue}{\frac{M \cdot h}{\left(d \cdot d\right) \cdot \ell}}, 1\right) \]
                                                                                                                  2. Step-by-step derivation
                                                                                                                    1. Applied rewrites42.1%

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

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

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

                                                                                                                      1. Initial program 91.2%

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

                                                                                                                        \[\leadsto \color{blue}{w0} \]
                                                                                                                      4. Step-by-step derivation
                                                                                                                        1. Applied rewrites90.5%

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

                                                                                                                      Alternative 11: 79.4% accurate, 0.8× speedup?

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

                                                                                                                        1. Initial program 59.9%

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

                                                                                                                            \[\leadsto w0 \cdot \color{blue}{\mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), \frac{h}{d \cdot d} \cdot \frac{M \cdot M}{\ell}, 1\right)} \]
                                                                                                                          2. Step-by-step derivation
                                                                                                                            1. Applied rewrites40.6%

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

                                                                                                                                \[\leadsto w0 \cdot \mathsf{fma}\left(-0.125 \cdot \left(D \cdot D\right), \frac{\left(\frac{h}{d} \cdot M\right) \cdot M}{\color{blue}{d \cdot \ell}}, 1\right) \]
                                                                                                                              2. 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) \]
                                                                                                                              3. Step-by-step derivation
                                                                                                                                1. Applied rewrites43.5%

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

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

                                                                                                                                1. Initial program 91.2%

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

                                                                                                                                  \[\leadsto \color{blue}{w0} \]
                                                                                                                                4. Step-by-step derivation
                                                                                                                                  1. Applied rewrites90.5%

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

                                                                                                                                Alternative 12: 85.4% accurate, 1.5× speedup?

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

                                                                                                                                  1. Initial program 85.8%

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

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

                                                                                                                                      \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                                                                                                                                    2. Step-by-step derivation
                                                                                                                                      1. Applied rewrites60.3%

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

                                                                                                                                        \[\leadsto w0 \cdot \sqrt{h \cdot \color{blue}{\left(\frac{1}{h} - \frac{1}{4} \cdot \frac{{D}^{2} \cdot {M}^{2}}{{d}^{2} \cdot \ell}\right)}} \]
                                                                                                                                      3. Step-by-step derivation
                                                                                                                                        1. Applied rewrites80.8%

                                                                                                                                          \[\leadsto w0 \cdot \sqrt{\mathsf{fma}\left(\frac{-0.25}{d} \cdot \frac{\left(M \cdot D\right) \cdot \left(M \cdot D\right)}{d \cdot \ell}, \color{blue}{h}, 1\right)} \]
                                                                                                                                        2. Step-by-step derivation
                                                                                                                                          1. Applied rewrites84.7%

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

                                                                                                                                          if 5.00000000000000011e63 < (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d))

                                                                                                                                          1. Initial program 64.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                                                                          Alternative 13: 84.4% accurate, 2.1× speedup?

                                                                                                                                          \[\begin{array}{l} D_m = \left|D\right| \\ M_m = \left|M\right| \\ [w0, M_m, D_m, h, l, d] = \mathsf{sort}([w0, M_m, D_m, h, l, d])\\ \\ w0 \cdot \sqrt{\mathsf{fma}\left(\left(\frac{-0.25}{d} \cdot \left(D\_m \cdot \frac{M\_m}{d}\right)\right) \cdot \left(D\_m \cdot \frac{M\_m}{\ell}\right), h, 1\right)} \end{array} \]
                                                                                                                                          D_m = (fabs.f64 D)
                                                                                                                                          M_m = (fabs.f64 M)
                                                                                                                                          NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
                                                                                                                                          (FPCore (w0 M_m D_m h l d)
                                                                                                                                           :precision binary64
                                                                                                                                           (*
                                                                                                                                            w0
                                                                                                                                            (sqrt (fma (* (* (/ -0.25 d) (* D_m (/ M_m d))) (* D_m (/ M_m l))) h 1.0))))
                                                                                                                                          D_m = fabs(D);
                                                                                                                                          M_m = fabs(M);
                                                                                                                                          assert(w0 < M_m && M_m < D_m && D_m < h && h < l && l < d);
                                                                                                                                          double code(double w0, double M_m, double D_m, double h, double l, double d) {
                                                                                                                                          	return w0 * sqrt(fma((((-0.25 / d) * (D_m * (M_m / d))) * (D_m * (M_m / l))), h, 1.0));
                                                                                                                                          }
                                                                                                                                          
                                                                                                                                          D_m = abs(D)
                                                                                                                                          M_m = abs(M)
                                                                                                                                          w0, M_m, D_m, h, l, d = sort([w0, M_m, D_m, h, l, d])
                                                                                                                                          function code(w0, M_m, D_m, h, l, d)
                                                                                                                                          	return Float64(w0 * sqrt(fma(Float64(Float64(Float64(-0.25 / d) * Float64(D_m * Float64(M_m / d))) * Float64(D_m * Float64(M_m / l))), h, 1.0)))
                                                                                                                                          end
                                                                                                                                          
                                                                                                                                          D_m = N[Abs[D], $MachinePrecision]
                                                                                                                                          M_m = N[Abs[M], $MachinePrecision]
                                                                                                                                          NOTE: w0, M_m, D_m, h, l, and d should be sorted in increasing order before calling this function.
                                                                                                                                          code[w0_, M$95$m_, D$95$m_, h_, l_, d_] := N[(w0 * N[Sqrt[N[(N[(N[(N[(-0.25 / d), $MachinePrecision] * N[(D$95$m * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(D$95$m * N[(M$95$m / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * h + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
                                                                                                                                          
                                                                                                                                          \begin{array}{l}
                                                                                                                                          D_m = \left|D\right|
                                                                                                                                          \\
                                                                                                                                          M_m = \left|M\right|
                                                                                                                                          \\
                                                                                                                                          [w0, M_m, D_m, h, l, d] = \mathsf{sort}([w0, M_m, D_m, h, l, d])\\
                                                                                                                                          \\
                                                                                                                                          w0 \cdot \sqrt{\mathsf{fma}\left(\left(\frac{-0.25}{d} \cdot \left(D\_m \cdot \frac{M\_m}{d}\right)\right) \cdot \left(D\_m \cdot \frac{M\_m}{\ell}\right), h, 1\right)}
                                                                                                                                          \end{array}
                                                                                                                                          
                                                                                                                                          Derivation
                                                                                                                                          1. Initial program 82.3%

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

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

                                                                                                                                              \[\leadsto w0 \cdot \sqrt{\color{blue}{1 - \frac{\left(0.25 \cdot \left(D \cdot D\right)\right) \cdot \frac{\left(M \cdot M\right) \cdot h}{\ell}}{d \cdot d}}} \]
                                                                                                                                            2. Step-by-step derivation
                                                                                                                                              1. Applied rewrites59.4%

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

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

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

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

                                                                                                                                                  Alternative 14: 68.0% accurate, 157.0× speedup?

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

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

                                                                                                                                                    \[\leadsto \color{blue}{w0} \]
                                                                                                                                                  4. Step-by-step derivation
                                                                                                                                                    1. Applied rewrites66.2%

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

                                                                                                                                                    Reproduce

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