Henrywood and Agarwal, Equation (12)

Percentage Accurate: 67.1% → 77.6%
Time: 8.5s
Alternatives: 15
Speedup: 1.7×

Specification

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 15 alternatives:

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

Initial Program: 67.1% accurate, 1.0× speedup?

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

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

Alternative 1: 77.6% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;h \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(d \cdot \left(-{\left(\ell \cdot h\right)}^{-0.5}\right)\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if h < -2.6e67

    1. Initial program 58.9%

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

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

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

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

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

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

    if -2.6e67 < h < -4.999999999999985e-310

    1. Initial program 71.6%

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

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

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

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

    if -4.999999999999985e-310 < h

    1. Initial program 67.5%

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

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

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

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

Alternative 2: 54.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+51}:\\ \;\;\;\;\left(\frac{\left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right) \cdot -1}{d} \cdot \sqrt{\frac{h}{\left(\ell \cdot \ell\right) \cdot \ell}}\right) \cdot -0.125\\ \mathbf{elif}\;t\_1 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot \left(-t\_0\right)}{h}\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (-
           1.0
           (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l))))))
   (if (<= t_1 -5e+51)
     (*
      (* (/ (* (* (* M D) (* M D)) -1.0) d) (sqrt (/ h (* (* l l) l))))
      -0.125)
     (if (<= t_1 1e+220)
       (* (sqrt (/ d h)) (sqrt (/ d l)))
       (if (<= t_1 INFINITY) (/ (* t_0 d) h) (/ (* d (- t_0)) h))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_1 <= -5e+51) {
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * sqrt((h / ((l * l) * l)))) * -0.125;
	} else if (t_1 <= 1e+220) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * -t_0) / h;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h / l));
	double t_1 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_1 <= -5e+51) {
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * Math.sqrt((h / ((l * l) * l)))) * -0.125;
	} else if (t_1 <= 1e+220) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * -t_0) / h;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((h / l))
	t_1 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	tmp = 0
	if t_1 <= -5e+51:
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * math.sqrt((h / ((l * l) * l)))) * -0.125
	elif t_1 <= 1e+220:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif t_1 <= math.inf:
		tmp = (t_0 * d) / h
	else:
		tmp = (d * -t_0) / h
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	tmp = 0.0
	if (t_1 <= -5e+51)
		tmp = Float64(Float64(Float64(Float64(Float64(Float64(M * D) * Float64(M * D)) * -1.0) / d) * sqrt(Float64(h / Float64(Float64(l * l) * l)))) * -0.125);
	elseif (t_1 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (t_1 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = Float64(Float64(d * Float64(-t_0)) / h);
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h / l));
	t_1 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	tmp = 0.0;
	if (t_1 <= -5e+51)
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * sqrt((h / ((l * l) * l)))) * -0.125;
	elseif (t_1 <= 1e+220)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (t_1 <= Inf)
		tmp = (t_0 * d) / h;
	else
		tmp = (d * -t_0) / h;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+51], N[(N[(N[(N[(N[(N[(M * D), $MachinePrecision] * N[(M * D), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision] / d), $MachinePrecision] * N[Sqrt[N[(h / N[(N[(l * l), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision], If[LessEqual[t$95$1, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], N[(N[(d * (-t$95$0)), $MachinePrecision] / h), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 10^{+220}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

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


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

    1. Initial program 85.9%

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

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

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

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

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

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

    1. Initial program 89.1%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    4. Applied rewrites81.5%

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.9%

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

Alternative 3: 53.0% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+51}:\\ \;\;\;\;\left(\left(\left(D \cdot D\right) \cdot \frac{\left(M \cdot M\right) \cdot -1}{d}\right) \cdot \sqrt{\frac{h}{\left(\ell \cdot \ell\right) \cdot \ell}}\right) \cdot -0.125\\ \mathbf{elif}\;t\_1 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot \left(-t\_0\right)}{h}\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (-
           1.0
           (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l))))))
   (if (<= t_1 -5e+51)
     (*
      (* (* (* D D) (/ (* (* M M) -1.0) d)) (sqrt (/ h (* (* l l) l))))
      -0.125)
     (if (<= t_1 1e+220)
       (* (sqrt (/ d h)) (sqrt (/ d l)))
       (if (<= t_1 INFINITY) (/ (* t_0 d) h) (/ (* d (- t_0)) h))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_1 <= -5e+51) {
		tmp = (((D * D) * (((M * M) * -1.0) / d)) * sqrt((h / ((l * l) * l)))) * -0.125;
	} else if (t_1 <= 1e+220) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * -t_0) / h;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h / l));
	double t_1 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_1 <= -5e+51) {
		tmp = (((D * D) * (((M * M) * -1.0) / d)) * Math.sqrt((h / ((l * l) * l)))) * -0.125;
	} else if (t_1 <= 1e+220) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * -t_0) / h;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((h / l))
	t_1 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	tmp = 0
	if t_1 <= -5e+51:
		tmp = (((D * D) * (((M * M) * -1.0) / d)) * math.sqrt((h / ((l * l) * l)))) * -0.125
	elif t_1 <= 1e+220:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif t_1 <= math.inf:
		tmp = (t_0 * d) / h
	else:
		tmp = (d * -t_0) / h
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	tmp = 0.0
	if (t_1 <= -5e+51)
		tmp = Float64(Float64(Float64(Float64(D * D) * Float64(Float64(Float64(M * M) * -1.0) / d)) * sqrt(Float64(h / Float64(Float64(l * l) * l)))) * -0.125);
	elseif (t_1 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (t_1 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = Float64(Float64(d * Float64(-t_0)) / h);
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h / l));
	t_1 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	tmp = 0.0;
	if (t_1 <= -5e+51)
		tmp = (((D * D) * (((M * M) * -1.0) / d)) * sqrt((h / ((l * l) * l)))) * -0.125;
	elseif (t_1 <= 1e+220)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (t_1 <= Inf)
		tmp = (t_0 * d) / h;
	else
		tmp = (d * -t_0) / h;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+51], N[(N[(N[(N[(D * D), $MachinePrecision] * N[(N[(N[(M * M), $MachinePrecision] * -1.0), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(h / N[(N[(l * l), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision], If[LessEqual[t$95$1, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], N[(N[(d * (-t$95$0)), $MachinePrecision] / h), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 10^{+220}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

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


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

    1. Initial program 85.9%

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

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

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

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

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

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

    1. Initial program 89.1%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    4. Applied rewrites81.5%

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.9%

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

Alternative 4: 52.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := -t\_0\\ t_2 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ \mathbf{if}\;t\_2 \leq -2 \cdot 10^{-78}:\\ \;\;\;\;\frac{\frac{\left(d \cdot d\right) \cdot t\_1}{d}}{h}\\ \mathbf{elif}\;t\_2 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;t\_2 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot t\_1}{h}\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1 (- t_0))
        (t_2
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (-
           1.0
           (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l))))))
   (if (<= t_2 -2e-78)
     (/ (/ (* (* d d) t_1) d) h)
     (if (<= t_2 1e+220)
       (* (sqrt (/ d h)) (sqrt (/ d l)))
       (if (<= t_2 INFINITY) (/ (* t_0 d) h) (/ (* d t_1) h))))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = -t_0;
	double t_2 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_2 <= -2e-78) {
		tmp = (((d * d) * t_1) / d) / h;
	} else if (t_2 <= 1e+220) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (t_2 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * t_1) / h;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h / l));
	double t_1 = -t_0;
	double t_2 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_2 <= -2e-78) {
		tmp = (((d * d) * t_1) / d) / h;
	} else if (t_2 <= 1e+220) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (t_2 <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (d * t_1) / h;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((h / l))
	t_1 = -t_0
	t_2 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	tmp = 0
	if t_2 <= -2e-78:
		tmp = (((d * d) * t_1) / d) / h
	elif t_2 <= 1e+220:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif t_2 <= math.inf:
		tmp = (t_0 * d) / h
	else:
		tmp = (d * t_1) / h
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(-t_0)
	t_2 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	tmp = 0.0
	if (t_2 <= -2e-78)
		tmp = Float64(Float64(Float64(Float64(d * d) * t_1) / d) / h);
	elseif (t_2 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (t_2 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = Float64(Float64(d * t_1) / h);
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h / l));
	t_1 = -t_0;
	t_2 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	tmp = 0.0;
	if (t_2 <= -2e-78)
		tmp = (((d * d) * t_1) / d) / h;
	elseif (t_2 <= 1e+220)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (t_2 <= Inf)
		tmp = (t_0 * d) / h;
	else
		tmp = (d * t_1) / h;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = (-t$95$0)}, Block[{t$95$2 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e-78], N[(N[(N[(N[(d * d), $MachinePrecision] * t$95$1), $MachinePrecision] / d), $MachinePrecision] / h), $MachinePrecision], If[LessEqual[t$95$2, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], N[(N[(d * t$95$1), $MachinePrecision] / h), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_2 \leq 10^{+220}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

\mathbf{elif}\;t\_2 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

\mathbf{else}:\\
\;\;\;\;\frac{d \cdot t\_1}{h}\\


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

    1. Initial program 86.6%

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

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

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

      \[\leadsto \frac{\frac{\frac{-1}{8} \cdot \left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \sqrt{\frac{{h}^{3}}{{\ell}^{3}}}\right) + {d}^{2} \cdot \sqrt{\frac{h}{\ell}}}{d}}{h} \]
    5. Applied rewrites54.7%

      \[\leadsto \frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot {\left(D \cdot M\right)}^{2}, -0.125, \sqrt{\frac{h}{\ell}} \cdot \left(d \cdot d\right)\right)}{d}}{h} \]
    6. Taylor expanded in l around -inf

      \[\leadsto \frac{\frac{\left({d}^{2} \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{d}}{h} \]
    7. Applied rewrites27.5%

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

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

    1. Initial program 88.6%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    4. Applied rewrites85.7%

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.9%

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

Alternative 5: 50.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ t_2 := \frac{d \cdot \left(-t\_0\right)}{h}\\ \mathbf{if}\;t\_1 \leq 2 \cdot 10^{-245}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
        (t_2 (/ (* d (- t_0)) h)))
   (if (<= t_1 2e-245)
     t_2
     (if (<= t_1 1e+220)
       (* (sqrt (/ d h)) (sqrt (/ d l)))
       (if (<= t_1 INFINITY) (/ (* t_0 d) h) t_2)))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_2 = (d * -t_0) / h;
	double tmp;
	if (t_1 <= 2e-245) {
		tmp = t_2;
	} else if (t_1 <= 1e+220) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = t_2;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h / l));
	double t_1 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_2 = (d * -t_0) / h;
	double tmp;
	if (t_1 <= 2e-245) {
		tmp = t_2;
	} else if (t_1 <= 1e+220) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((h / l))
	t_1 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	t_2 = (d * -t_0) / h
	tmp = 0
	if t_1 <= 2e-245:
		tmp = t_2
	elif t_1 <= 1e+220:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif t_1 <= math.inf:
		tmp = (t_0 * d) / h
	else:
		tmp = t_2
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	t_2 = Float64(Float64(d * Float64(-t_0)) / h)
	tmp = 0.0
	if (t_1 <= 2e-245)
		tmp = t_2;
	elseif (t_1 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (t_1 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h / l));
	t_1 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	t_2 = (d * -t_0) / h;
	tmp = 0.0;
	if (t_1 <= 2e-245)
		tmp = t_2;
	elseif (t_1 <= 1e+220)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (t_1 <= Inf)
		tmp = (t_0 * d) / h;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(d * (-t$95$0)), $MachinePrecision] / h), $MachinePrecision]}, If[LessEqual[t$95$1, 2e-245], t$95$2, If[LessEqual[t$95$1, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq 10^{+220}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l)))) < 1.9999999999999999e-245 or +inf.0 < (*.f64 (*.f64 (pow.f64 (/.f64 d h) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64))) (pow.f64 (/.f64 d l) (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)))) (-.f64 #s(literal 1 binary64) (*.f64 (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 2 binary64)) (pow.f64 (/.f64 (*.f64 M D) (*.f64 #s(literal 2 binary64) d)) #s(literal 2 binary64))) (/.f64 h l))))

    1. Initial program 55.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites22.2%

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

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

    1. Initial program 98.8%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    4. Applied rewrites98.1%

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

      \[\leadsto \frac{\sqrt{\frac{h}{\ell}} \cdot d}{h} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 6: 73.5% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ \mathbf{if}\;t\_1 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right) \cdot \left(M \cdot \frac{D}{2 \cdot d}\right)\right) \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right), -0.125, t\_0 \cdot \left(d \cdot d\right)\right)}{d}}{h}\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (-
           1.0
           (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l))))))
   (if (<= t_1 1e+220)
     (*
      (sqrt (/ d h))
      (*
       (sqrt (/ d l))
       (-
        1.0
        (* (/ h l) (* (* (* (/ D d) (* 0.5 M)) (* M (/ D (* 2.0 d)))) 0.5)))))
     (if (<= t_1 INFINITY)
       (/ (* t_0 d) h)
       (/
        (/
         (fma (* (pow (/ h l) 1.5) (* (* M D) (* M D))) -0.125 (* t_0 (* d d)))
         d)
        h)))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double tmp;
	if (t_1 <= 1e+220) {
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))));
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = (fma((pow((h / l), 1.5) * ((M * D) * (M * D))), -0.125, (t_0 * (d * d))) / d) / h;
	}
	return tmp;
}
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	tmp = 0.0
	if (t_1 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(D / d) * Float64(0.5 * M)) * Float64(M * Float64(D / Float64(2.0 * d)))) * 0.5)))));
	elseif (t_1 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = Float64(Float64(fma(Float64((Float64(h / l) ^ 1.5) * Float64(Float64(M * D) * Float64(M * D))), -0.125, Float64(t_0 * Float64(d * d))) / d) / h);
	end
	return tmp
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(D / d), $MachinePrecision] * N[(0.5 * M), $MachinePrecision]), $MachinePrecision] * N[(M * N[(D / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], N[(N[(N[(N[(N[Power[N[(h / l), $MachinePrecision], 1.5], $MachinePrecision] * N[(N[(M * D), $MachinePrecision] * N[(M * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.125 + N[(t$95$0 * N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] / h), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right), -0.125, t\_0 \cdot \left(d \cdot d\right)\right)}{d}}{h}\\


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\frac{\frac{-1}{8} \cdot \left(\left({D}^{2} \cdot {M}^{2}\right) \cdot \sqrt{\frac{{h}^{3}}{{\ell}^{3}}}\right) + {d}^{2} \cdot \sqrt{\frac{h}{\ell}}}{d}}{h} \]
    5. Applied rewrites26.6%

      \[\leadsto \frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot {\left(D \cdot M\right)}^{2}, -0.125, \sqrt{\frac{h}{\ell}} \cdot \left(d \cdot d\right)\right)}{d}}{h} \]
    6. Applied rewrites26.6%

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

Alternative 7: 71.9% accurate, 0.5× speedup?

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

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

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.9%

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

Alternative 8: 70.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ t_1 := \frac{D}{2 \cdot d}\\ t_2 := \sqrt{\frac{h}{\ell}}\\ \mathbf{if}\;t\_0 \leq 10^{+220}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\left(t\_1 \cdot M\right) \cdot M\right) \cdot t\_1\right) \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;t\_0 \leq \infty:\\ \;\;\;\;\frac{t\_2 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{d \cdot \left(-t\_2\right)}{h}\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
        (t_1 (/ D (* 2.0 d)))
        (t_2 (sqrt (/ h l))))
   (if (<= t_0 1e+220)
     (*
      (sqrt (/ d h))
      (* (sqrt (/ d l)) (- 1.0 (* (/ h l) (* (* (* (* t_1 M) M) t_1) 0.5)))))
     (if (<= t_0 INFINITY) (/ (* t_2 d) h) (/ (* d (- t_2)) h)))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_1 = D / (2.0 * d);
	double t_2 = sqrt((h / l));
	double tmp;
	if (t_0 <= 1e+220) {
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((t_1 * M) * M) * t_1) * 0.5))));
	} else if (t_0 <= ((double) INFINITY)) {
		tmp = (t_2 * d) / h;
	} else {
		tmp = (d * -t_2) / h;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_1 = D / (2.0 * d);
	double t_2 = Math.sqrt((h / l));
	double tmp;
	if (t_0 <= 1e+220) {
		tmp = Math.sqrt((d / h)) * (Math.sqrt((d / l)) * (1.0 - ((h / l) * ((((t_1 * M) * M) * t_1) * 0.5))));
	} else if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = (t_2 * d) / h;
	} else {
		tmp = (d * -t_2) / h;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	t_1 = D / (2.0 * d)
	t_2 = math.sqrt((h / l))
	tmp = 0
	if t_0 <= 1e+220:
		tmp = math.sqrt((d / h)) * (math.sqrt((d / l)) * (1.0 - ((h / l) * ((((t_1 * M) * M) * t_1) * 0.5))))
	elif t_0 <= math.inf:
		tmp = (t_2 * d) / h
	else:
		tmp = (d * -t_2) / h
	return tmp
function code(d, h, l, M, D)
	t_0 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	t_1 = Float64(D / Float64(2.0 * d))
	t_2 = sqrt(Float64(h / l))
	tmp = 0.0
	if (t_0 <= 1e+220)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(t_1 * M) * M) * t_1) * 0.5)))));
	elseif (t_0 <= Inf)
		tmp = Float64(Float64(t_2 * d) / h);
	else
		tmp = Float64(Float64(d * Float64(-t_2)) / h);
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	t_1 = D / (2.0 * d);
	t_2 = sqrt((h / l));
	tmp = 0.0;
	if (t_0 <= 1e+220)
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((t_1 * M) * M) * t_1) * 0.5))));
	elseif (t_0 <= Inf)
		tmp = (t_2 * d) / h;
	else
		tmp = (d * -t_2) / h;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(D / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 1e+220], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(t$95$1 * M), $MachinePrecision] * M), $MachinePrecision] * t$95$1), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, Infinity], N[(N[(t$95$2 * d), $MachinePrecision] / h), $MachinePrecision], N[(N[(d * (-t$95$2)), $MachinePrecision] / h), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_0 \leq \infty:\\
\;\;\;\;\frac{t\_2 \cdot d}{h}\\

\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \left(-t\_2\right)}{h}\\


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

    1. Initial program 87.6%

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

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

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

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

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

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

    1. Initial program 56.3%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites70.8%

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

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

    1. Initial program 0.0%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.9%

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

Alternative 9: 47.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{\frac{h}{\ell}}\\ t_1 := \left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\ t_2 := \frac{d \cdot \left(-t\_0\right)}{h}\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{-78}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq \infty:\\ \;\;\;\;\frac{t\_0 \cdot d}{h}\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (let* ((t_0 (sqrt (/ h l)))
        (t_1
         (*
          (* (pow (/ d h) (/ 1.0 2.0)) (pow (/ d l) (/ 1.0 2.0)))
          (- 1.0 (* (* (/ 1.0 2.0) (pow (/ (* M D) (* 2.0 d)) 2.0)) (/ h l)))))
        (t_2 (/ (* d (- t_0)) h)))
   (if (<= t_1 -2e-78) t_2 (if (<= t_1 INFINITY) (/ (* t_0 d) h) t_2))))
double code(double d, double h, double l, double M, double D) {
	double t_0 = sqrt((h / l));
	double t_1 = (pow((d / h), (1.0 / 2.0)) * pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_2 = (d * -t_0) / h;
	double tmp;
	if (t_1 <= -2e-78) {
		tmp = t_2;
	} else if (t_1 <= ((double) INFINITY)) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = t_2;
	}
	return tmp;
}
public static double code(double d, double h, double l, double M, double D) {
	double t_0 = Math.sqrt((h / l));
	double t_1 = (Math.pow((d / h), (1.0 / 2.0)) * Math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)));
	double t_2 = (d * -t_0) / h;
	double tmp;
	if (t_1 <= -2e-78) {
		tmp = t_2;
	} else if (t_1 <= Double.POSITIVE_INFINITY) {
		tmp = (t_0 * d) / h;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(d, h, l, M, D):
	t_0 = math.sqrt((h / l))
	t_1 = (math.pow((d / h), (1.0 / 2.0)) * math.pow((d / l), (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * math.pow(((M * D) / (2.0 * d)), 2.0)) * (h / l)))
	t_2 = (d * -t_0) / h
	tmp = 0
	if t_1 <= -2e-78:
		tmp = t_2
	elif t_1 <= math.inf:
		tmp = (t_0 * d) / h
	else:
		tmp = t_2
	return tmp
function code(d, h, l, M, D)
	t_0 = sqrt(Float64(h / l))
	t_1 = Float64(Float64((Float64(d / h) ^ Float64(1.0 / 2.0)) * (Float64(d / l) ^ Float64(1.0 / 2.0))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M * D) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l))))
	t_2 = Float64(Float64(d * Float64(-t_0)) / h)
	tmp = 0.0
	if (t_1 <= -2e-78)
		tmp = t_2;
	elseif (t_1 <= Inf)
		tmp = Float64(Float64(t_0 * d) / h);
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	t_0 = sqrt((h / l));
	t_1 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M * D) / (2.0 * d)) ^ 2.0)) * (h / l)));
	t_2 = (d * -t_0) / h;
	tmp = 0.0;
	if (t_1 <= -2e-78)
		tmp = t_2;
	elseif (t_1 <= Inf)
		tmp = (t_0 * d) / h;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := Block[{t$95$0 = N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Power[N[(d / h), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[(d / l), $MachinePrecision], N[(1.0 / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M * D), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(d * (-t$95$0)), $MachinePrecision] / h), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-78], t$95$2, If[LessEqual[t$95$1, Infinity], N[(N[(t$95$0 * d), $MachinePrecision] / h), $MachinePrecision], t$95$2]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


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

    1. Initial program 55.8%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites20.8%

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

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

    1. Initial program 78.7%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites74.8%

      \[\leadsto \frac{\sqrt{\frac{h}{\ell}} \cdot d}{h} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 10: 41.0% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left({\left(\frac{d}{h}\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(\frac{d}{\ell}\right)}^{\left(\frac{1}{2}\right)}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M \cdot D}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right) \leq 2 \cdot 10^{-245}:\\
\;\;\;\;\sqrt{\frac{\frac{1}{\ell}}{h}} \cdot d\\

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


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

    1. Initial program 80.0%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    3. Applied rewrites17.3%

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

      \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot d \]
    5. Applied rewrites17.3%

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

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

    1. Initial program 58.6%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites56.6%

      \[\leadsto \frac{\sqrt{\frac{h}{\ell}} \cdot d}{h} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 75.0% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -7.5 \cdot 10^{-119}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right) \cdot \left(M \cdot \frac{D}{2 \cdot d}\right)\right) \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;d \leq 1.9 \cdot 10^{-160}:\\ \;\;\;\;\frac{\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \frac{{\left(D \cdot M\right)}^{2}}{d}\right) \cdot -0.125}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(\frac{\sqrt{d}}{\sqrt{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -7.5e-119)
   (*
    (sqrt (/ d h))
    (*
     (sqrt (/ d l))
     (-
      1.0
      (* (/ h l) (* (* (* (/ D d) (* 0.5 M)) (* M (/ D (* 2.0 d)))) 0.5)))))
   (if (<= d 1.9e-160)
     (/ (* (* (pow (/ h l) 1.5) (/ (pow (* D M) 2.0) d)) -0.125) h)
     (*
      (/ (sqrt d) (sqrt h))
      (*
       (/ (sqrt d) (sqrt l))
       (- 1.0 (* (/ h l) (* (pow (* (/ M 2.0) (/ D d)) 2.0) 0.5))))))))
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -7.5e-119) {
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))));
	} else if (d <= 1.9e-160) {
		tmp = ((pow((h / l), 1.5) * (pow((D * M), 2.0) / d)) * -0.125) / h;
	} else {
		tmp = (sqrt(d) / sqrt(h)) * ((sqrt(d) / sqrt(l)) * (1.0 - ((h / l) * (pow(((M / 2.0) * (D / d)), 2.0) * 0.5))));
	}
	return tmp;
}
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(d, h, l, m, d_1)
use fmin_fmax_functions
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (d <= (-7.5d-119)) then
        tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0d0 - ((h / l) * ((((d_1 / d) * (0.5d0 * m)) * (m * (d_1 / (2.0d0 * d)))) * 0.5d0))))
    else if (d <= 1.9d-160) then
        tmp = ((((h / l) ** 1.5d0) * (((d_1 * m) ** 2.0d0) / d)) * (-0.125d0)) / h
    else
        tmp = (sqrt(d) / sqrt(h)) * ((sqrt(d) / sqrt(l)) * (1.0d0 - ((h / l) * ((((m / 2.0d0) * (d_1 / d)) ** 2.0d0) * 0.5d0))))
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -7.5e-119) {
		tmp = Math.sqrt((d / h)) * (Math.sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))));
	} else if (d <= 1.9e-160) {
		tmp = ((Math.pow((h / l), 1.5) * (Math.pow((D * M), 2.0) / d)) * -0.125) / h;
	} else {
		tmp = (Math.sqrt(d) / Math.sqrt(h)) * ((Math.sqrt(d) / Math.sqrt(l)) * (1.0 - ((h / l) * (Math.pow(((M / 2.0) * (D / d)), 2.0) * 0.5))));
	}
	return tmp;
}
def code(d, h, l, M, D):
	tmp = 0
	if d <= -7.5e-119:
		tmp = math.sqrt((d / h)) * (math.sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))))
	elif d <= 1.9e-160:
		tmp = ((math.pow((h / l), 1.5) * (math.pow((D * M), 2.0) / d)) * -0.125) / h
	else:
		tmp = (math.sqrt(d) / math.sqrt(h)) * ((math.sqrt(d) / math.sqrt(l)) * (1.0 - ((h / l) * (math.pow(((M / 2.0) * (D / d)), 2.0) * 0.5))))
	return tmp
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -7.5e-119)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(D / d) * Float64(0.5 * M)) * Float64(M * Float64(D / Float64(2.0 * d)))) * 0.5)))));
	elseif (d <= 1.9e-160)
		tmp = Float64(Float64(Float64((Float64(h / l) ^ 1.5) * Float64((Float64(D * M) ^ 2.0) / d)) * -0.125) / h);
	else
		tmp = Float64(Float64(sqrt(d) / sqrt(h)) * Float64(Float64(sqrt(d) / sqrt(l)) * Float64(1.0 - Float64(Float64(h / l) * Float64((Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0) * 0.5)))));
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -7.5e-119)
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))));
	elseif (d <= 1.9e-160)
		tmp = ((((h / l) ^ 1.5) * (((D * M) ^ 2.0) / d)) * -0.125) / h;
	else
		tmp = (sqrt(d) / sqrt(h)) * ((sqrt(d) / sqrt(l)) * (1.0 - ((h / l) * ((((M / 2.0) * (D / d)) ^ 2.0) * 0.5))));
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -7.5e-119], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(D / d), $MachinePrecision] * N[(0.5 * M), $MachinePrecision]), $MachinePrecision] * N[(M * N[(D / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.9e-160], N[(N[(N[(N[Power[N[(h / l), $MachinePrecision], 1.5], $MachinePrecision] * N[(N[Power[N[(D * M), $MachinePrecision], 2.0], $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision] / h), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.5 \cdot 10^{-119}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right) \cdot \left(M \cdot \frac{D}{2 \cdot d}\right)\right) \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;d \leq 1.9 \cdot 10^{-160}:\\
\;\;\;\;\frac{\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \frac{{\left(D \cdot M\right)}^{2}}{d}\right) \cdot -0.125}{h}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -7.50000000000000044e-119

    1. Initial program 76.2%

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

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

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

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

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

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

    if -7.50000000000000044e-119 < d < 1.8999999999999999e-160

    1. Initial program 45.6%

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

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

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

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

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

    if 1.8999999999999999e-160 < d

    1. Initial program 74.4%

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

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

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

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

Alternative 12: 75.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -2.5 \cdot 10^{-27}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right) \cdot \left(M \cdot \frac{D}{2 \cdot d}\right)\right) \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right), -0.125, \sqrt{\frac{h}{\ell}} \cdot \left(d \cdot d\right)\right)}{d}}{h}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{d}}{\sqrt{h}} \cdot \left(\frac{\sqrt{d}}{\sqrt{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left({\left(\frac{M}{2} \cdot \frac{D}{d}\right)}^{2} \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -2.5e-27)
   (*
    (sqrt (/ d h))
    (*
     (sqrt (/ d l))
     (-
      1.0
      (* (/ h l) (* (* (* (/ D d) (* 0.5 M)) (* M (/ D (* 2.0 d)))) 0.5)))))
   (if (<= d -1e-309)
     (/
      (/
       (fma
        (* (pow (/ h l) 1.5) (* (* M D) (* M D)))
        -0.125
        (* (sqrt (/ h l)) (* d d)))
       d)
      h)
     (*
      (/ (sqrt d) (sqrt h))
      (*
       (/ (sqrt d) (sqrt l))
       (- 1.0 (* (/ h l) (* (pow (* (/ M 2.0) (/ D d)) 2.0) 0.5))))))))
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -2.5e-27) {
		tmp = sqrt((d / h)) * (sqrt((d / l)) * (1.0 - ((h / l) * ((((D / d) * (0.5 * M)) * (M * (D / (2.0 * d)))) * 0.5))));
	} else if (d <= -1e-309) {
		tmp = (fma((pow((h / l), 1.5) * ((M * D) * (M * D))), -0.125, (sqrt((h / l)) * (d * d))) / d) / h;
	} else {
		tmp = (sqrt(d) / sqrt(h)) * ((sqrt(d) / sqrt(l)) * (1.0 - ((h / l) * (pow(((M / 2.0) * (D / d)), 2.0) * 0.5))));
	}
	return tmp;
}
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -2.5e-27)
		tmp = Float64(sqrt(Float64(d / h)) * Float64(sqrt(Float64(d / l)) * Float64(1.0 - Float64(Float64(h / l) * Float64(Float64(Float64(Float64(D / d) * Float64(0.5 * M)) * Float64(M * Float64(D / Float64(2.0 * d)))) * 0.5)))));
	elseif (d <= -1e-309)
		tmp = Float64(Float64(fma(Float64((Float64(h / l) ^ 1.5) * Float64(Float64(M * D) * Float64(M * D))), -0.125, Float64(sqrt(Float64(h / l)) * Float64(d * d))) / d) / h);
	else
		tmp = Float64(Float64(sqrt(d) / sqrt(h)) * Float64(Float64(sqrt(d) / sqrt(l)) * Float64(1.0 - Float64(Float64(h / l) * Float64((Float64(Float64(M / 2.0) * Float64(D / d)) ^ 2.0) * 0.5)))));
	end
	return tmp
end
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -2.5e-27], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[(N[(N[(D / d), $MachinePrecision] * N[(0.5 * M), $MachinePrecision]), $MachinePrecision] * N[(M * N[(D / N[(2.0 * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-309], N[(N[(N[(N[(N[Power[N[(h / l), $MachinePrecision], 1.5], $MachinePrecision] * N[(N[(M * D), $MachinePrecision] * N[(M * D), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.125 + N[(N[Sqrt[N[(h / l), $MachinePrecision]], $MachinePrecision] * N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision] / h), $MachinePrecision], N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(h / l), $MachinePrecision] * N[(N[Power[N[(N[(M / 2.0), $MachinePrecision] * N[(D / d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.5 \cdot 10^{-27}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \left(\sqrt{\frac{d}{\ell}} \cdot \left(1 - \frac{h}{\ell} \cdot \left(\left(\left(\frac{D}{d} \cdot \left(0.5 \cdot M\right)\right) \cdot \left(M \cdot \frac{D}{2 \cdot d}\right)\right) \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;d \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot \left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right), -0.125, \sqrt{\frac{h}{\ell}} \cdot \left(d \cdot d\right)\right)}{d}}{h}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -2.5000000000000001e-27

    1. Initial program 76.8%

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

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

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

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

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

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

    if -2.5000000000000001e-27 < d < -1.000000000000002e-309

    1. Initial program 54.5%

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

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

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

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

      \[\leadsto \frac{\frac{\mathsf{fma}\left({\left(\frac{h}{\ell}\right)}^{1.5} \cdot {\left(D \cdot M\right)}^{2}, -0.125, \sqrt{\frac{h}{\ell}} \cdot \left(d \cdot d\right)\right)}{d}}{h} \]
    6. Applied rewrites54.1%

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

    if -1.000000000000002e-309 < d

    1. Initial program 67.5%

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

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

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

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

Alternative 13: 52.3% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;d \leq -1.05 \cdot 10^{+126}:\\ \;\;\;\;\left(-{\left(\ell \cdot h\right)}^{-0.5}\right) \cdot d\\ \mathbf{elif}\;d \leq -1.45 \cdot 10^{-31}:\\ \;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\ \mathbf{elif}\;d \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\left(\frac{\left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right) \cdot -1}{d} \cdot \sqrt{\frac{h}{\left(\ell \cdot \ell\right) \cdot \ell}}\right) \cdot -0.125\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{\ell} \cdot \sqrt{h}} \cdot d\\ \end{array} \end{array} \]
(FPCore (d h l M D)
 :precision binary64
 (if (<= d -1.05e+126)
   (* (- (pow (* l h) -0.5)) d)
   (if (<= d -1.45e-31)
     (* (sqrt (/ d h)) (sqrt (/ d l)))
     (if (<= d -1e-309)
       (*
        (* (/ (* (* (* M D) (* M D)) -1.0) d) (sqrt (/ h (* (* l l) l))))
        -0.125)
       (* (/ 1.0 (* (sqrt l) (sqrt h))) d)))))
double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -1.05e+126) {
		tmp = -pow((l * h), -0.5) * d;
	} else if (d <= -1.45e-31) {
		tmp = sqrt((d / h)) * sqrt((d / l));
	} else if (d <= -1e-309) {
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * sqrt((h / ((l * l) * l)))) * -0.125;
	} else {
		tmp = (1.0 / (sqrt(l) * sqrt(h))) * d;
	}
	return tmp;
}
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(d, h, l, m, d_1)
use fmin_fmax_functions
    real(8), intent (in) :: d
    real(8), intent (in) :: h
    real(8), intent (in) :: l
    real(8), intent (in) :: m
    real(8), intent (in) :: d_1
    real(8) :: tmp
    if (d <= (-1.05d+126)) then
        tmp = -((l * h) ** (-0.5d0)) * d
    else if (d <= (-1.45d-31)) then
        tmp = sqrt((d / h)) * sqrt((d / l))
    else if (d <= (-1d-309)) then
        tmp = (((((m * d_1) * (m * d_1)) * (-1.0d0)) / d) * sqrt((h / ((l * l) * l)))) * (-0.125d0)
    else
        tmp = (1.0d0 / (sqrt(l) * sqrt(h))) * d
    end if
    code = tmp
end function
public static double code(double d, double h, double l, double M, double D) {
	double tmp;
	if (d <= -1.05e+126) {
		tmp = -Math.pow((l * h), -0.5) * d;
	} else if (d <= -1.45e-31) {
		tmp = Math.sqrt((d / h)) * Math.sqrt((d / l));
	} else if (d <= -1e-309) {
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * Math.sqrt((h / ((l * l) * l)))) * -0.125;
	} else {
		tmp = (1.0 / (Math.sqrt(l) * Math.sqrt(h))) * d;
	}
	return tmp;
}
def code(d, h, l, M, D):
	tmp = 0
	if d <= -1.05e+126:
		tmp = -math.pow((l * h), -0.5) * d
	elif d <= -1.45e-31:
		tmp = math.sqrt((d / h)) * math.sqrt((d / l))
	elif d <= -1e-309:
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * math.sqrt((h / ((l * l) * l)))) * -0.125
	else:
		tmp = (1.0 / (math.sqrt(l) * math.sqrt(h))) * d
	return tmp
function code(d, h, l, M, D)
	tmp = 0.0
	if (d <= -1.05e+126)
		tmp = Float64(Float64(-(Float64(l * h) ^ -0.5)) * d);
	elseif (d <= -1.45e-31)
		tmp = Float64(sqrt(Float64(d / h)) * sqrt(Float64(d / l)));
	elseif (d <= -1e-309)
		tmp = Float64(Float64(Float64(Float64(Float64(Float64(M * D) * Float64(M * D)) * -1.0) / d) * sqrt(Float64(h / Float64(Float64(l * l) * l)))) * -0.125);
	else
		tmp = Float64(Float64(1.0 / Float64(sqrt(l) * sqrt(h))) * d);
	end
	return tmp
end
function tmp_2 = code(d, h, l, M, D)
	tmp = 0.0;
	if (d <= -1.05e+126)
		tmp = -((l * h) ^ -0.5) * d;
	elseif (d <= -1.45e-31)
		tmp = sqrt((d / h)) * sqrt((d / l));
	elseif (d <= -1e-309)
		tmp = (((((M * D) * (M * D)) * -1.0) / d) * sqrt((h / ((l * l) * l)))) * -0.125;
	else
		tmp = (1.0 / (sqrt(l) * sqrt(h))) * d;
	end
	tmp_2 = tmp;
end
code[d_, h_, l_, M_, D_] := If[LessEqual[d, -1.05e+126], N[((-N[Power[N[(l * h), $MachinePrecision], -0.5], $MachinePrecision]) * d), $MachinePrecision], If[LessEqual[d, -1.45e-31], N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -1e-309], N[(N[(N[(N[(N[(N[(M * D), $MachinePrecision] * N[(M * D), $MachinePrecision]), $MachinePrecision] * -1.0), $MachinePrecision] / d), $MachinePrecision] * N[Sqrt[N[(h / N[(N[(l * l), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * -0.125), $MachinePrecision], N[(N[(1.0 / N[(N[Sqrt[l], $MachinePrecision] * N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.05 \cdot 10^{+126}:\\
\;\;\;\;\left(-{\left(\ell \cdot h\right)}^{-0.5}\right) \cdot d\\

\mathbf{elif}\;d \leq -1.45 \cdot 10^{-31}:\\
\;\;\;\;\sqrt{\frac{d}{h}} \cdot \sqrt{\frac{d}{\ell}}\\

\mathbf{elif}\;d \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\left(\frac{\left(\left(M \cdot D\right) \cdot \left(M \cdot D\right)\right) \cdot -1}{d} \cdot \sqrt{\frac{h}{\left(\ell \cdot \ell\right) \cdot \ell}}\right) \cdot -0.125\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if d < -1.05e126

    1. Initial program 74.1%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    3. Applied rewrites6.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\ell \cdot h\right)}^{-1}} \cdot d} \]
    4. Taylor expanded in h around -inf

      \[\leadsto \left(\sqrt{\frac{1}{h \cdot \ell}} \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot d \]
    5. Applied rewrites66.2%

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

    if -1.05e126 < d < -1.45e-31

    1. Initial program 79.9%

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

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

      \[\leadsto \sqrt{\frac{d}{h}} \cdot \color{blue}{\sqrt{\frac{d}{\ell}}} \]
    4. Applied rewrites48.4%

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

    if -1.45e-31 < d < -1.000000000000002e-309

    1. Initial program 54.1%

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

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

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

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

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

    if -1.000000000000002e-309 < d

    1. Initial program 67.5%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    3. Applied rewrites44.4%

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

      \[\leadsto \frac{1}{\sqrt{\ell \cdot h}} \cdot d \]
    5. Applied rewrites52.4%

      \[\leadsto \frac{1}{\sqrt{\ell} \cdot \sqrt{h}} \cdot d \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 14: 43.4% accurate, 7.7× speedup?

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

\\
\begin{array}{l}
t_0 := \sqrt{\frac{h}{\ell}}\\
\mathbf{if}\;d \leq -5.6 \cdot 10^{-108}:\\
\;\;\;\;\frac{t\_0 \cdot d}{h}\\

\mathbf{elif}\;d \leq 7 \cdot 10^{-122}:\\
\;\;\;\;\frac{d \cdot \left(-t\_0\right)}{h}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if d < -5.6e-108

    1. Initial program 76.5%

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

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

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

      \[\leadsto \frac{d \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites46.9%

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

    if -5.6e-108 < d < 7.0000000000000003e-122

    1. Initial program 46.9%

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

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

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

      \[\leadsto \frac{\left(d \cdot {\left(\sqrt{-1}\right)}^{2}\right) \cdot \sqrt{\frac{h}{\ell}}}{h} \]
    5. Applied rewrites17.7%

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

    if 7.0000000000000003e-122 < d

    1. Initial program 76.0%

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

      \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
    3. Applied rewrites52.7%

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

      \[\leadsto \frac{1}{\sqrt{\ell \cdot h}} \cdot d \]
    5. Applied rewrites62.7%

      \[\leadsto \frac{1}{\sqrt{\ell} \cdot \sqrt{h}} \cdot d \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 15: 27.4% accurate, 12.9× speedup?

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

\\
\sqrt{\frac{1}{\ell \cdot h}} \cdot d
\end{array}
Derivation
  1. Initial program 67.1%

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

    \[\leadsto \color{blue}{d \cdot \sqrt{\frac{1}{h \cdot \ell}}} \]
  3. Applied rewrites27.4%

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

    \[\leadsto \sqrt{\frac{1}{\ell \cdot h}} \cdot d \]
  5. Add Preprocessing

Reproduce

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