
(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}
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(if (<= d -5.1e+120)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(if (<= d -2.15e-305)
(*
(* (sqrt (/ d l)) (/ (sqrt (- d)) (sqrt (- h))))
(-
1.0
(*
(* (* 0.5 (* D_m -0.5)) (/ M_m d))
(* (* (* M_m (/ -0.5 d)) D_m) (/ h l)))))
(*
(* (/ (sqrt d) (sqrt h)) (/ (sqrt d) (sqrt l)))
(-
1.0
(* (* (/ 1.0 2.0) (pow (/ (* M_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (sqrt((d / l)) * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else {
tmp = ((sqrt(d) / sqrt(h)) * (sqrt(d) / sqrt(l))) * (1.0 - (((1.0 / 2.0) * pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: tmp
if (d <= (-5.1d+120)) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else if (d <= (-2.15d-305)) then
tmp = (sqrt((d / l)) * (sqrt(-d) / sqrt(-h))) * (1.0d0 - (((0.5d0 * (d_m * (-0.5d0))) * (m_m / d)) * (((m_m * ((-0.5d0) / d)) * d_m) * (h / l))))
else
tmp = ((sqrt(d) / sqrt(h)) * (sqrt(d) / sqrt(l))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (Math.sqrt((d / l)) * (Math.sqrt(-d) / Math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else {
tmp = ((Math.sqrt(d) / Math.sqrt(h)) * (Math.sqrt(d) / Math.sqrt(l))) * (1.0 - (((1.0 / 2.0) * Math.pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): tmp = 0 if d <= -5.1e+120: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) elif d <= -2.15e-305: tmp = (math.sqrt((d / l)) * (math.sqrt(-d) / math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l)))) else: tmp = ((math.sqrt(d) / math.sqrt(h)) * (math.sqrt(d) / math.sqrt(l))) * (1.0 - (((1.0 / 2.0) * math.pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) tmp = 0.0 if (d <= -5.1e+120) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); elseif (d <= -2.15e-305) tmp = Float64(Float64(sqrt(Float64(d / l)) * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h)))) * Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(D_m * -0.5)) * Float64(M_m / d)) * Float64(Float64(Float64(M_m * Float64(-0.5 / d)) * D_m) * Float64(h / l))))); else tmp = Float64(Float64(Float64(sqrt(d) / sqrt(h)) * Float64(sqrt(d) / sqrt(l))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * (Float64(Float64(M_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
tmp = 0.0;
if (d <= -5.1e+120)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
elseif (d <= -2.15e-305)
tmp = (sqrt((d / l)) * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
else
tmp = ((sqrt(d) / sqrt(h)) * (sqrt(d) / sqrt(l))) * (1.0 - (((1.0 / 2.0) * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -5.1e+120], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.15e-305], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(0.5 * N[(D$95$m * -0.5), $MachinePrecision]), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(M$95$m * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision] * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.1 \cdot 10^{+120}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{elif}\;d \leq -2.15 \cdot 10^{-305}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - \left(\left(0.5 \cdot \left(D\_m \cdot -0.5\right)\right) \cdot \frac{M\_m}{d}\right) \cdot \left(\left(\left(M\_m \cdot \frac{-0.5}{d}\right) \cdot D\_m\right) \cdot \frac{h}{\ell}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{\sqrt{d}}{\sqrt{h}} \cdot \frac{\sqrt{d}}{\sqrt{\ell}}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot {\left(\frac{M\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
\end{array}
\end{array}
if d < -5.10000000000000027e120Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -5.10000000000000027e120 < d < -2.1500000000000001e-305Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f6438.6
Applied rewrites38.6%
if -2.1500000000000001e-305 < d Initial program 66.7%
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lift-/.f64N/A
sqrt-divN/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f64N/A
lower-unsound-sqrt.f6436.0
Applied rewrites36.0%
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
pow1/2N/A
lift-/.f64N/A
sqrt-divN/A
lower-unsound-sqrt.f64N/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f6440.6
Applied rewrites40.6%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(let* ((t_0 (sqrt (/ d l))))
(if (<= h -5e-310)
(*
(* t_0 (/ (sqrt (- d)) (sqrt (- h))))
(-
1.0
(*
(* (* 0.5 (* D_m -0.5)) (/ M_m d))
(* (* (* M_m (/ -0.5 d)) D_m) (/ h l)))))
(if (<= h 1.7e+113)
(*
(/ (* (sqrt (/ d h)) (- (sqrt d))) (- (sqrt l)))
(- 1.0 (* (* 0.5 (pow (/ (* M_m D_m) (* 2.0 d)) 2.0)) (/ h l))))
(if (<= h 2.3e+219)
(*
(* d (sqrt (/ 1.0 (* h l))))
(/ (- l (* (* (* (/ (* (* D_m D_m) M_m) (* d d)) 0.125) M_m) h)) l))
(*
(* t_0 (/ (sqrt d) (sqrt h)))
(-
1.0
(*
(*
(/ 1.0 2.0)
(* (* (* (/ D_m (+ d d)) M_m) (* D_m M_m)) (/ 0.5 d)))
(/ h l)))))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = sqrt((d / l));
double tmp;
if (h <= -5e-310) {
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else if (h <= 1.7e+113) {
tmp = ((sqrt((d / h)) * -sqrt(d)) / -sqrt(l)) * (1.0 - ((0.5 * pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
} else if (h <= 2.3e+219) {
tmp = (d * sqrt((1.0 / (h * l)))) * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
} else {
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((d / l))
if (h <= (-5d-310)) then
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0d0 - (((0.5d0 * (d_m * (-0.5d0))) * (m_m / d)) * (((m_m * ((-0.5d0) / d)) * d_m) * (h / l))))
else if (h <= 1.7d+113) then
tmp = ((sqrt((d / h)) * -sqrt(d)) / -sqrt(l)) * (1.0d0 - ((0.5d0 * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
else if (h <= 2.3d+219) then
tmp = (d * sqrt((1.0d0 / (h * l)))) * ((l - ((((((d_m * d_m) * m_m) / (d * d)) * 0.125d0) * m_m) * h)) / l)
else
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0d0 - (((1.0d0 / 2.0d0) * ((((d_m / (d + d)) * m_m) * (d_m * m_m)) * (0.5d0 / d))) * (h / l)))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = Math.sqrt((d / l));
double tmp;
if (h <= -5e-310) {
tmp = (t_0 * (Math.sqrt(-d) / Math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else if (h <= 1.7e+113) {
tmp = ((Math.sqrt((d / h)) * -Math.sqrt(d)) / -Math.sqrt(l)) * (1.0 - ((0.5 * Math.pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
} else if (h <= 2.3e+219) {
tmp = (d * Math.sqrt((1.0 / (h * l)))) * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
} else {
tmp = (t_0 * (Math.sqrt(d) / Math.sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): t_0 = math.sqrt((d / l)) tmp = 0 if h <= -5e-310: tmp = (t_0 * (math.sqrt(-d) / math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l)))) elif h <= 1.7e+113: tmp = ((math.sqrt((d / h)) * -math.sqrt(d)) / -math.sqrt(l)) * (1.0 - ((0.5 * math.pow(((M_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) elif h <= 2.3e+219: tmp = (d * math.sqrt((1.0 / (h * l)))) * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l) else: tmp = (t_0 * (math.sqrt(d) / math.sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l))) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) t_0 = sqrt(Float64(d / l)) tmp = 0.0 if (h <= -5e-310) tmp = Float64(Float64(t_0 * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h)))) * Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(D_m * -0.5)) * Float64(M_m / d)) * Float64(Float64(Float64(M_m * Float64(-0.5 / d)) * D_m) * Float64(h / l))))); elseif (h <= 1.7e+113) tmp = Float64(Float64(Float64(sqrt(Float64(d / h)) * Float64(-sqrt(d))) / Float64(-sqrt(l))) * Float64(1.0 - Float64(Float64(0.5 * (Float64(Float64(M_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))); elseif (h <= 2.3e+219) tmp = Float64(Float64(d * sqrt(Float64(1.0 / Float64(h * l)))) * Float64(Float64(l - Float64(Float64(Float64(Float64(Float64(Float64(D_m * D_m) * M_m) / Float64(d * d)) * 0.125) * M_m) * h)) / l)); else tmp = Float64(Float64(t_0 * Float64(sqrt(d) / sqrt(h))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * Float64(Float64(Float64(Float64(D_m / Float64(d + d)) * M_m) * Float64(D_m * M_m)) * Float64(0.5 / d))) * Float64(h / l)))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = sqrt((d / l));
tmp = 0.0;
if (h <= -5e-310)
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
elseif (h <= 1.7e+113)
tmp = ((sqrt((d / h)) * -sqrt(d)) / -sqrt(l)) * (1.0 - ((0.5 * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
elseif (h <= 2.3e+219)
tmp = (d * sqrt((1.0 / (h * l)))) * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
else
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, -5e-310], N[(N[(t$95$0 * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(0.5 * N[(D$95$m * -0.5), $MachinePrecision]), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(M$95$m * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 1.7e+113], N[(N[(N[(N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision] * (-N[Sqrt[d], $MachinePrecision])), $MachinePrecision] / (-N[Sqrt[l], $MachinePrecision])), $MachinePrecision] * N[(1.0 - N[(N[(0.5 * N[Power[N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[h, 2.3e+219], N[(N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(l - N[(N[(N[(N[(N[(N[(D$95$m * D$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] * M$95$m), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[(N[(D$95$m / N[(d + d), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision] * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;h \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - \left(\left(0.5 \cdot \left(D\_m \cdot -0.5\right)\right) \cdot \frac{M\_m}{d}\right) \cdot \left(\left(\left(M\_m \cdot \frac{-0.5}{d}\right) \cdot D\_m\right) \cdot \frac{h}{\ell}\right)\right)\\
\mathbf{elif}\;h \leq 1.7 \cdot 10^{+113}:\\
\;\;\;\;\frac{\sqrt{\frac{d}{h}} \cdot \left(-\sqrt{d}\right)}{-\sqrt{\ell}} \cdot \left(1 - \left(0.5 \cdot {\left(\frac{M\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
\mathbf{elif}\;h \leq 2.3 \cdot 10^{+219}:\\
\;\;\;\;\left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right) \cdot \frac{\ell - \left(\left(\frac{\left(D\_m \cdot D\_m\right) \cdot M\_m}{d \cdot d} \cdot 0.125\right) \cdot M\_m\right) \cdot h}{\ell}\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot \left(\left(\left(\frac{D\_m}{d + d} \cdot M\_m\right) \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{0.5}{d}\right)\right) \cdot \frac{h}{\ell}\right)\\
\end{array}
\end{array}
if h < -4.999999999999985e-310Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f6438.6
Applied rewrites38.6%
if -4.999999999999985e-310 < h < 1.70000000000000009e113Initial program 66.7%
lift-/.f64N/A
mult-flipN/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f6466.7
Applied rewrites66.7%
lift-*.f64N/A
lift-pow.f64N/A
lift-pow.f64N/A
pow-prod-downN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
mult-flipN/A
lift-/.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
pow1/2N/A
lift-/.f64N/A
sqrt-undivN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
frac-2negN/A
associate-*r/N/A
lower-/.f64N/A
Applied rewrites36.0%
lift-/.f64N/A
metadata-eval36.0
Applied rewrites36.0%
if 1.70000000000000009e113 < h < 2.3000000000000001e219Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6427.8
Applied rewrites27.8%
if 2.3000000000000001e219 < h Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
mult-flipN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-/.f64N/A
lower-/.f6465.0
lift-/.f64N/A
metadata-eval65.0
Applied rewrites65.0%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-unsound-sqrt.f64N/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f6437.3
Applied rewrites37.3%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(let* ((t_0 (sqrt (/ d l))) (t_1 (* (* (* M_m (/ -0.5 d)) D_m) (/ h l))))
(if (<= d -5.1e+120)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(if (<= d -2.15e-305)
(*
(* t_0 (/ (sqrt (- d)) (sqrt (- h))))
(- 1.0 (* (* (* 0.5 (* D_m -0.5)) (/ M_m d)) t_1)))
(if (<= d 6.9e-193)
(*
(* (sqrt (/ d (* h l))) (sqrt d))
(-
1.0
(*
(*
(/ 1.0 2.0)
(* (* (* (/ D_m (+ d d)) M_m) (* D_m M_m)) (/ 0.5 d)))
(/ h l))))
(*
(* t_0 (sqrt (/ d h)))
(- 1.0 (* (* (/ M_m d) (* -0.25 D_m)) t_1))))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = sqrt((d / l));
double t_1 = ((M_m * (-0.5 / d)) * D_m) * (h / l);
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * t_1));
} else if (d <= 6.9e-193) {
tmp = (sqrt((d / (h * l))) * sqrt(d)) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
} else {
tmp = (t_0 * sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * t_1));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = sqrt((d / l))
t_1 = ((m_m * ((-0.5d0) / d)) * d_m) * (h / l)
if (d <= (-5.1d+120)) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else if (d <= (-2.15d-305)) then
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0d0 - (((0.5d0 * (d_m * (-0.5d0))) * (m_m / d)) * t_1))
else if (d <= 6.9d-193) then
tmp = (sqrt((d / (h * l))) * sqrt(d)) * (1.0d0 - (((1.0d0 / 2.0d0) * ((((d_m / (d + d)) * m_m) * (d_m * m_m)) * (0.5d0 / d))) * (h / l)))
else
tmp = (t_0 * sqrt((d / h))) * (1.0d0 - (((m_m / d) * ((-0.25d0) * d_m)) * t_1))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = Math.sqrt((d / l));
double t_1 = ((M_m * (-0.5 / d)) * D_m) * (h / l);
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (t_0 * (Math.sqrt(-d) / Math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * t_1));
} else if (d <= 6.9e-193) {
tmp = (Math.sqrt((d / (h * l))) * Math.sqrt(d)) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
} else {
tmp = (t_0 * Math.sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * t_1));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): t_0 = math.sqrt((d / l)) t_1 = ((M_m * (-0.5 / d)) * D_m) * (h / l) tmp = 0 if d <= -5.1e+120: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) elif d <= -2.15e-305: tmp = (t_0 * (math.sqrt(-d) / math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * t_1)) elif d <= 6.9e-193: tmp = (math.sqrt((d / (h * l))) * math.sqrt(d)) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l))) else: tmp = (t_0 * math.sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * t_1)) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) t_0 = sqrt(Float64(d / l)) t_1 = Float64(Float64(Float64(M_m * Float64(-0.5 / d)) * D_m) * Float64(h / l)) tmp = 0.0 if (d <= -5.1e+120) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); elseif (d <= -2.15e-305) tmp = Float64(Float64(t_0 * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h)))) * Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(D_m * -0.5)) * Float64(M_m / d)) * t_1))); elseif (d <= 6.9e-193) tmp = Float64(Float64(sqrt(Float64(d / Float64(h * l))) * sqrt(d)) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * Float64(Float64(Float64(Float64(D_m / Float64(d + d)) * M_m) * Float64(D_m * M_m)) * Float64(0.5 / d))) * Float64(h / l)))); else tmp = Float64(Float64(t_0 * sqrt(Float64(d / h))) * Float64(1.0 - Float64(Float64(Float64(M_m / d) * Float64(-0.25 * D_m)) * t_1))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = sqrt((d / l));
t_1 = ((M_m * (-0.5 / d)) * D_m) * (h / l);
tmp = 0.0;
if (d <= -5.1e+120)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
elseif (d <= -2.15e-305)
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * t_1));
elseif (d <= 6.9e-193)
tmp = (sqrt((d / (h * l))) * sqrt(d)) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
else
tmp = (t_0 * sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * t_1));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(M$95$m * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[d, -5.1e+120], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.15e-305], N[(N[(t$95$0 * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(0.5 * N[(D$95$m * -0.5), $MachinePrecision]), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 6.9e-193], N[(N[(N[Sqrt[N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[d], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[(N[(D$95$m / N[(d + d), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision] * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(M$95$m / d), $MachinePrecision] * N[(-0.25 * D$95$m), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
t_1 := \left(\left(M\_m \cdot \frac{-0.5}{d}\right) \cdot D\_m\right) \cdot \frac{h}{\ell}\\
\mathbf{if}\;d \leq -5.1 \cdot 10^{+120}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{elif}\;d \leq -2.15 \cdot 10^{-305}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - \left(\left(0.5 \cdot \left(D\_m \cdot -0.5\right)\right) \cdot \frac{M\_m}{d}\right) \cdot t\_1\right)\\
\mathbf{elif}\;d \leq 6.9 \cdot 10^{-193}:\\
\;\;\;\;\left(\sqrt{\frac{d}{h \cdot \ell}} \cdot \sqrt{d}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot \left(\left(\left(\frac{D\_m}{d + d} \cdot M\_m\right) \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{0.5}{d}\right)\right) \cdot \frac{h}{\ell}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - \left(\frac{M\_m}{d} \cdot \left(-0.25 \cdot D\_m\right)\right) \cdot t\_1\right)\\
\end{array}
\end{array}
if d < -5.10000000000000027e120Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -5.10000000000000027e120 < d < -2.1500000000000001e-305Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f6438.6
Applied rewrites38.6%
if -2.1500000000000001e-305 < d < 6.8999999999999998e-193Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
mult-flipN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-/.f64N/A
lower-/.f6465.0
lift-/.f64N/A
metadata-eval65.0
Applied rewrites65.0%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lift-*.f64N/A
associate-*l/N/A
lift-/.f64N/A
sqrt-prodN/A
lower-unsound-sqrt.f64N/A
lower-unsound-*.f64N/A
lower-unsound-sqrt.f6431.9
lift-*.f64N/A
*-commutativeN/A
lift-*.f6431.9
Applied rewrites31.9%
if 6.8999999999999998e-193 < d Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6468.4
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
metadata-eval68.4
Applied rewrites68.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(let* ((t_0 (sqrt (/ d l))))
(if (<= d -5.1e+120)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(if (<= d -2.15e-305)
(*
(* t_0 (/ (sqrt (- d)) (sqrt (- h))))
(-
1.0
(*
(* (* 0.5 (* D_m -0.5)) (/ M_m d))
(* (* (* M_m (/ -0.5 d)) D_m) (/ h l)))))
(*
(* t_0 (/ (sqrt d) (sqrt h)))
(-
1.0
(*
(* (/ 1.0 2.0) (* (* (* (/ D_m (+ d d)) M_m) (* D_m M_m)) (/ 0.5 d)))
(/ h l))))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = sqrt((d / l));
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else {
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((d / l))
if (d <= (-5.1d+120)) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else if (d <= (-2.15d-305)) then
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0d0 - (((0.5d0 * (d_m * (-0.5d0))) * (m_m / d)) * (((m_m * ((-0.5d0) / d)) * d_m) * (h / l))))
else
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0d0 - (((1.0d0 / 2.0d0) * ((((d_m / (d + d)) * m_m) * (d_m * m_m)) * (0.5d0 / d))) * (h / l)))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = Math.sqrt((d / l));
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else if (d <= -2.15e-305) {
tmp = (t_0 * (Math.sqrt(-d) / Math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
} else {
tmp = (t_0 * (Math.sqrt(d) / Math.sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): t_0 = math.sqrt((d / l)) tmp = 0 if d <= -5.1e+120: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) elif d <= -2.15e-305: tmp = (t_0 * (math.sqrt(-d) / math.sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l)))) else: tmp = (t_0 * (math.sqrt(d) / math.sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l))) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) t_0 = sqrt(Float64(d / l)) tmp = 0.0 if (d <= -5.1e+120) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); elseif (d <= -2.15e-305) tmp = Float64(Float64(t_0 * Float64(sqrt(Float64(-d)) / sqrt(Float64(-h)))) * Float64(1.0 - Float64(Float64(Float64(0.5 * Float64(D_m * -0.5)) * Float64(M_m / d)) * Float64(Float64(Float64(M_m * Float64(-0.5 / d)) * D_m) * Float64(h / l))))); else tmp = Float64(Float64(t_0 * Float64(sqrt(d) / sqrt(h))) * Float64(1.0 - Float64(Float64(Float64(1.0 / 2.0) * Float64(Float64(Float64(Float64(D_m / Float64(d + d)) * M_m) * Float64(D_m * M_m)) * Float64(0.5 / d))) * Float64(h / l)))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = sqrt((d / l));
tmp = 0.0;
if (d <= -5.1e+120)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
elseif (d <= -2.15e-305)
tmp = (t_0 * (sqrt(-d) / sqrt(-h))) * (1.0 - (((0.5 * (D_m * -0.5)) * (M_m / d)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
else
tmp = (t_0 * (sqrt(d) / sqrt(h))) * (1.0 - (((1.0 / 2.0) * ((((D_m / (d + d)) * M_m) * (D_m * M_m)) * (0.5 / d))) * (h / l)));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[d, -5.1e+120], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, -2.15e-305], N[(N[(t$95$0 * N[(N[Sqrt[(-d)], $MachinePrecision] / N[Sqrt[(-h)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(0.5 * N[(D$95$m * -0.5), $MachinePrecision]), $MachinePrecision] * N[(M$95$m / d), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(M$95$m * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * N[(N[Sqrt[d], $MachinePrecision] / N[Sqrt[h], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[(N[(D$95$m / N[(d + d), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision] * N[(D$95$m * M$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.5 / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;d \leq -5.1 \cdot 10^{+120}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{elif}\;d \leq -2.15 \cdot 10^{-305}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{-d}}{\sqrt{-h}}\right) \cdot \left(1 - \left(\left(0.5 \cdot \left(D\_m \cdot -0.5\right)\right) \cdot \frac{M\_m}{d}\right) \cdot \left(\left(\left(M\_m \cdot \frac{-0.5}{d}\right) \cdot D\_m\right) \cdot \frac{h}{\ell}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot \frac{\sqrt{d}}{\sqrt{h}}\right) \cdot \left(1 - \left(\frac{1}{2} \cdot \left(\left(\left(\frac{D\_m}{d + d} \cdot M\_m\right) \cdot \left(D\_m \cdot M\_m\right)\right) \cdot \frac{0.5}{d}\right)\right) \cdot \frac{h}{\ell}\right)\\
\end{array}
\end{array}
if d < -5.10000000000000027e120Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -5.10000000000000027e120 < d < -2.1500000000000001e-305Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-sqrt.f64N/A
lift-/.f64N/A
frac-2negN/A
sqrt-divN/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f64N/A
lower-unsound-sqrt.f64N/A
lower-neg.f6438.6
Applied rewrites38.6%
if -2.1500000000000001e-305 < d Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
mult-flipN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
count-2-revN/A
lower-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lift-/.f64N/A
lower-/.f6465.0
lift-/.f64N/A
metadata-eval65.0
Applied rewrites65.0%
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
lower-unsound-sqrt.f64N/A
lower-unsound-/.f64N/A
lower-unsound-sqrt.f6437.3
Applied rewrites37.3%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(if (<= d -5.1e+120)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(*
(* (sqrt (/ d l)) (sqrt (/ d h)))
(-
1.0
(* (* (/ M_m d) (* -0.25 D_m)) (* (* (* M_m (/ -0.5 d)) D_m) (/ h l)))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else {
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: tmp
if (d <= (-5.1d+120)) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0d0 - (((m_m / d) * ((-0.25d0) * d_m)) * (((m_m * ((-0.5d0) / d)) * d_m) * (h / l))))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -5.1e+120) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else {
tmp = (Math.sqrt((d / l)) * Math.sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): tmp = 0 if d <= -5.1e+120: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) else: tmp = (math.sqrt((d / l)) * math.sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * (((M_m * (-0.5 / d)) * D_m) * (h / l)))) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) tmp = 0.0 if (d <= -5.1e+120) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); else tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * Float64(1.0 - Float64(Float64(Float64(M_m / d) * Float64(-0.25 * D_m)) * Float64(Float64(Float64(M_m * Float64(-0.5 / d)) * D_m) * Float64(h / l))))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
tmp = 0.0;
if (d <= -5.1e+120)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
else
tmp = (sqrt((d / l)) * sqrt((d / h))) * (1.0 - (((M_m / d) * (-0.25 * D_m)) * (((M_m * (-0.5 / d)) * D_m) * (h / l))));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -5.1e+120], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[(N[(N[(M$95$m / d), $MachinePrecision] * N[(-0.25 * D$95$m), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(M$95$m * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * D$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -5.1 \cdot 10^{+120}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \left(1 - \left(\frac{M\_m}{d} \cdot \left(-0.25 \cdot D\_m\right)\right) \cdot \left(\left(\left(M\_m \cdot \frac{-0.5}{d}\right) \cdot D\_m\right) \cdot \frac{h}{\ell}\right)\right)\\
\end{array}
\end{array}
if d < -5.10000000000000027e120Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -5.10000000000000027e120 < d Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6468.4
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
metadata-eval68.4
Applied rewrites68.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(if (<= d -4.35e+167)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(*
(*
(-
1.0
(* (/ (* M_m (* (* (* (/ -0.5 d) M_m) D_m) h)) (* d l)) (* -0.25 D_m)))
(sqrt (/ d h)))
(sqrt (/ d l)))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -4.35e+167) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else {
tmp = ((1.0 - (((M_m * ((((-0.5 / d) * M_m) * D_m) * h)) / (d * l)) * (-0.25 * D_m))) * sqrt((d / h))) * sqrt((d / l));
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: tmp
if (d <= (-4.35d+167)) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else
tmp = ((1.0d0 - (((m_m * (((((-0.5d0) / d) * m_m) * d_m) * h)) / (d * l)) * ((-0.25d0) * d_m))) * sqrt((d / h))) * sqrt((d / l))
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -4.35e+167) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else {
tmp = ((1.0 - (((M_m * ((((-0.5 / d) * M_m) * D_m) * h)) / (d * l)) * (-0.25 * D_m))) * Math.sqrt((d / h))) * Math.sqrt((d / l));
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): tmp = 0 if d <= -4.35e+167: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) else: tmp = ((1.0 - (((M_m * ((((-0.5 / d) * M_m) * D_m) * h)) / (d * l)) * (-0.25 * D_m))) * math.sqrt((d / h))) * math.sqrt((d / l)) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) tmp = 0.0 if (d <= -4.35e+167) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); else tmp = Float64(Float64(Float64(1.0 - Float64(Float64(Float64(M_m * Float64(Float64(Float64(Float64(-0.5 / d) * M_m) * D_m) * h)) / Float64(d * l)) * Float64(-0.25 * D_m))) * sqrt(Float64(d / h))) * sqrt(Float64(d / l))); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
tmp = 0.0;
if (d <= -4.35e+167)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
else
tmp = ((1.0 - (((M_m * ((((-0.5 / d) * M_m) * D_m) * h)) / (d * l)) * (-0.25 * D_m))) * sqrt((d / h))) * sqrt((d / l));
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -4.35e+167], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 - N[(N[(N[(M$95$m * N[(N[(N[(N[(-0.5 / d), $MachinePrecision] * M$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision] * N[(-0.25 * D$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.35 \cdot 10^{+167}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(1 - \frac{M\_m \cdot \left(\left(\left(\frac{-0.5}{d} \cdot M\_m\right) \cdot D\_m\right) \cdot h\right)}{d \cdot \ell} \cdot \left(-0.25 \cdot D\_m\right)\right) \cdot \sqrt{\frac{d}{h}}\right) \cdot \sqrt{\frac{d}{\ell}}\\
\end{array}
\end{array}
if d < -4.3499999999999999e167Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -4.3499999999999999e167 < d Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Applied rewrites66.6%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(if (<= d -1.02e+120)
(* -1.0 (* d (sqrt (/ 1.0 (* h l)))))
(if (<= d 1.6e+117)
(*
(* (sqrt (/ d l)) (sqrt (/ d h)))
(fma
(* (* (/ (* (* (* M_m M_m) D_m) D_m) d) 0.25) (/ -0.5 d))
(/ h l)
1.0))
(/ (* d (sqrt (/ 1.0 h))) (sqrt l)))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (d <= -1.02e+120) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else if (d <= 1.6e+117) {
tmp = (sqrt((d / l)) * sqrt((d / h))) * fma(((((((M_m * M_m) * D_m) * D_m) / d) * 0.25) * (-0.5 / d)), (h / l), 1.0);
} else {
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
}
return tmp;
}
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) tmp = 0.0 if (d <= -1.02e+120) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); elseif (d <= 1.6e+117) tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * fma(Float64(Float64(Float64(Float64(Float64(Float64(M_m * M_m) * D_m) * D_m) / d) * 0.25) * Float64(-0.5 / d)), Float64(h / l), 1.0)); else tmp = Float64(Float64(d * sqrt(Float64(1.0 / h))) / sqrt(l)); end return tmp end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[d, -1.02e+120], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[d, 1.6e+117], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(N[(N[(N[(M$95$m * M$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] / d), $MachinePrecision] * 0.25), $MachinePrecision] * N[(-0.5 / d), $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(d * N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.02 \cdot 10^{+120}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{+117}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot \mathsf{fma}\left(\left(\frac{\left(\left(M\_m \cdot M\_m\right) \cdot D\_m\right) \cdot D\_m}{d} \cdot 0.25\right) \cdot \frac{-0.5}{d}, \frac{h}{\ell}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\
\end{array}
\end{array}
if d < -1.01999999999999997e120Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if -1.01999999999999997e120 < d < 1.60000000000000002e117Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites61.3%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
Applied rewrites59.9%
if 1.60000000000000002e117 < d Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites19.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6424.7
Applied rewrites24.7%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))
(t_1 (* (sqrt (/ d l)) (sqrt (/ d h)))))
(if (<= t_0 -1e-146)
(*
t_1
(-
1.0
(/ (* (* (* (* (* (/ D_m (+ d d)) M_m) M_m) D_m) 0.25) h) (* d l))))
(if (<= t_0 1e+283) (* t_1 1.0) (* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = sqrt((d / l)) * sqrt((d / h));
double tmp;
if (t_0 <= -1e-146) {
tmp = t_1 * (1.0 - (((((((D_m / (d + d)) * M_m) * M_m) * D_m) * 0.25) * h) / (d * l)));
} else if (t_0 <= 1e+283) {
tmp = t_1 * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
t_1 = sqrt((d / l)) * sqrt((d / h))
if (t_0 <= (-1d-146)) then
tmp = t_1 * (1.0d0 - (((((((d_m / (d + d)) * m_m) * m_m) * d_m) * 0.25d0) * h) / (d * l)))
else if (t_0 <= 1d+283) then
tmp = t_1 * 1.0d0
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = Math.sqrt((d / l)) * Math.sqrt((d / h));
double tmp;
if (t_0 <= -1e-146) {
tmp = t_1 * (1.0 - (((((((D_m / (d + d)) * M_m) * M_m) * D_m) * 0.25) * h) / (d * l)));
} else if (t_0 <= 1e+283) {
tmp = t_1 * 1.0;
} else {
tmp = Math.sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): 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_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) t_1 = math.sqrt((d / l)) * math.sqrt((d / h)) tmp = 0 if t_0 <= -1e-146: tmp = t_1 * (1.0 - (((((((D_m / (d + d)) * M_m) * M_m) * D_m) * 0.25) * h) / (d * l))) elif t_0 <= 1e+283: tmp = t_1 * 1.0 else: tmp = math.sqrt(((d / (h * l)) * d)) * (l / l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) t_1 = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(t_1 * Float64(1.0 - Float64(Float64(Float64(Float64(Float64(Float64(Float64(D_m / Float64(d + d)) * M_m) * M_m) * D_m) * 0.25) * h) / Float64(d * l)))); elseif (t_0 <= 1e+283) tmp = Float64(t_1 * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
t_1 = sqrt((d / l)) * sqrt((d / h));
tmp = 0.0;
if (t_0 <= -1e-146)
tmp = t_1 * (1.0 - (((((((D_m / (d + d)) * M_m) * M_m) * D_m) * 0.25) * h) / (d * l)));
elseif (t_0 <= 1e+283)
tmp = t_1 * 1.0;
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(t$95$1 * N[(1.0 - N[(N[(N[(N[(N[(N[(N[(D$95$m / N[(d + d), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] * 0.25), $MachinePrecision] * h), $MachinePrecision] / N[(d * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(t$95$1 * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
t_1 := \sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;t\_1 \cdot \left(1 - \frac{\left(\left(\left(\left(\frac{D\_m}{d + d} \cdot M\_m\right) \cdot M\_m\right) \cdot D\_m\right) \cdot 0.25\right) \cdot h}{d \cdot \ell}\right)\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;t\_1 \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites61.3%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites63.9%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))
(t_1 (* (sqrt (/ d l)) (sqrt (/ d h)))))
(if (<= t_0 -1e-146)
(*
t_1
(fma
-0.5
(/ (* (* (* (* M_m M_m) D_m) D_m) h) (* (* 4.0 (* d d)) l))
1.0))
(if (<= t_0 1e+283) (* t_1 1.0) (* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = sqrt((d / l)) * sqrt((d / h));
double tmp;
if (t_0 <= -1e-146) {
tmp = t_1 * fma(-0.5, (((((M_m * M_m) * D_m) * D_m) * h) / ((4.0 * (d * d)) * l)), 1.0);
} else if (t_0 <= 1e+283) {
tmp = t_1 * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) t_1 = Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(t_1 * fma(-0.5, Float64(Float64(Float64(Float64(Float64(M_m * M_m) * D_m) * D_m) * h) / Float64(Float64(4.0 * Float64(d * d)) * l)), 1.0)); elseif (t_0 <= 1e+283) tmp = Float64(t_1 * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(t$95$1 * N[(-0.5 * N[(N[(N[(N[(N[(M$95$m * M$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] * D$95$m), $MachinePrecision] * h), $MachinePrecision] / N[(N[(4.0 * N[(d * d), $MachinePrecision]), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(t$95$1 * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
t_1 := \sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;t\_1 \cdot \mathsf{fma}\left(-0.5, \frac{\left(\left(\left(M\_m \cdot M\_m\right) \cdot D\_m\right) \cdot D\_m\right) \cdot h}{\left(4 \cdot \left(d \cdot d\right)\right) \cdot \ell}, 1\right)\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;t\_1 \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites50.8%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))
(t_1 (sqrt (/ d l)))
(t_2 (sqrt (/ d h))))
(if (<= t_0 -1e-146)
(*
(*
(- 1.0 (* (* (* (/ (* (* D_m D_m) M_m) (* d d)) 0.125) M_m) (/ h l)))
t_1)
t_2)
(if (<= t_0 1e+283)
(* (* t_1 t_2) 1.0)
(* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = sqrt((d / l));
double t_2 = sqrt((d / h));
double tmp;
if (t_0 <= -1e-146) {
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
} else if (t_0 <= 1e+283) {
tmp = (t_1 * t_2) * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
t_1 = sqrt((d / l))
t_2 = sqrt((d / h))
if (t_0 <= (-1d-146)) then
tmp = ((1.0d0 - ((((((d_m * d_m) * m_m) / (d * d)) * 0.125d0) * m_m) * (h / l))) * t_1) * t_2
else if (t_0 <= 1d+283) then
tmp = (t_1 * t_2) * 1.0d0
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = Math.sqrt((d / l));
double t_2 = Math.sqrt((d / h));
double tmp;
if (t_0 <= -1e-146) {
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
} else if (t_0 <= 1e+283) {
tmp = (t_1 * t_2) * 1.0;
} else {
tmp = Math.sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): 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_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) t_1 = math.sqrt((d / l)) t_2 = math.sqrt((d / h)) tmp = 0 if t_0 <= -1e-146: tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2 elif t_0 <= 1e+283: tmp = (t_1 * t_2) * 1.0 else: tmp = math.sqrt(((d / (h * l)) * d)) * (l / l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) t_1 = sqrt(Float64(d / l)) t_2 = sqrt(Float64(d / h)) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(Float64(Float64(1.0 - Float64(Float64(Float64(Float64(Float64(Float64(D_m * D_m) * M_m) / Float64(d * d)) * 0.125) * M_m) * Float64(h / l))) * t_1) * t_2); elseif (t_0 <= 1e+283) tmp = Float64(Float64(t_1 * t_2) * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
t_1 = sqrt((d / l));
t_2 = sqrt((d / h));
tmp = 0.0;
if (t_0 <= -1e-146)
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
elseif (t_0 <= 1e+283)
tmp = (t_1 * t_2) * 1.0;
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(N[(N[(1.0 - N[(N[(N[(N[(N[(N[(D$95$m * D$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] * M$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(N[(t$95$1 * t$95$2), $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
t_1 := \sqrt{\frac{d}{\ell}}\\
t_2 := \sqrt{\frac{d}{h}}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;\left(\left(1 - \left(\left(\frac{\left(D\_m \cdot D\_m\right) \cdot M\_m}{d \cdot d} \cdot 0.125\right) \cdot M\_m\right) \cdot \frac{h}{\ell}\right) \cdot t\_1\right) \cdot t\_2\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;\left(t\_1 \cdot t\_2\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites47.2%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))
(t_1 (sqrt (/ d h)))
(t_2 (sqrt (/ d l))))
(if (<= t_0 -1e-146)
(*
(*
(- 1.0 (* (* (* (/ (* (* D_m D_m) M_m) (* d d)) 0.125) M_m) (/ h l)))
t_1)
t_2)
(if (<= t_0 1e+283)
(* (* t_2 t_1) 1.0)
(* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = sqrt((d / h));
double t_2 = sqrt((d / l));
double tmp;
if (t_0 <= -1e-146) {
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
} else if (t_0 <= 1e+283) {
tmp = (t_2 * t_1) * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
t_1 = sqrt((d / h))
t_2 = sqrt((d / l))
if (t_0 <= (-1d-146)) then
tmp = ((1.0d0 - ((((((d_m * d_m) * m_m) / (d * d)) * 0.125d0) * m_m) * (h / l))) * t_1) * t_2
else if (t_0 <= 1d+283) then
tmp = (t_2 * t_1) * 1.0d0
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = Math.sqrt((d / h));
double t_2 = Math.sqrt((d / l));
double tmp;
if (t_0 <= -1e-146) {
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
} else if (t_0 <= 1e+283) {
tmp = (t_2 * t_1) * 1.0;
} else {
tmp = Math.sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): 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_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) t_1 = math.sqrt((d / h)) t_2 = math.sqrt((d / l)) tmp = 0 if t_0 <= -1e-146: tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2 elif t_0 <= 1e+283: tmp = (t_2 * t_1) * 1.0 else: tmp = math.sqrt(((d / (h * l)) * d)) * (l / l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) t_1 = sqrt(Float64(d / h)) t_2 = sqrt(Float64(d / l)) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(Float64(Float64(1.0 - Float64(Float64(Float64(Float64(Float64(Float64(D_m * D_m) * M_m) / Float64(d * d)) * 0.125) * M_m) * Float64(h / l))) * t_1) * t_2); elseif (t_0 <= 1e+283) tmp = Float64(Float64(t_2 * t_1) * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
t_1 = sqrt((d / h));
t_2 = sqrt((d / l));
tmp = 0.0;
if (t_0 <= -1e-146)
tmp = ((1.0 - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * (h / l))) * t_1) * t_2;
elseif (t_0 <= 1e+283)
tmp = (t_2 * t_1) * 1.0;
else
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(N[(N[(1.0 - N[(N[(N[(N[(N[(N[(D$95$m * D$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] * M$95$m), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(N[(t$95$2 * t$95$1), $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
t_1 := \sqrt{\frac{d}{h}}\\
t_2 := \sqrt{\frac{d}{\ell}}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;\left(\left(1 - \left(\left(\frac{\left(D\_m \cdot D\_m\right) \cdot M\_m}{d \cdot d} \cdot 0.125\right) \cdot M\_m\right) \cdot \frac{h}{\ell}\right) \cdot t\_1\right) \cdot t\_2\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;\left(t\_2 \cdot t\_1\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites47.3%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l))))))
(if (<= t_0 -1e-146)
(*
(fma
(* (* (* (* M_m D_m) (* M_m D_m)) (/ 0.25 (* (* d d) l))) h)
-0.5
1.0)
(sqrt (* (/ d (* l h)) d)))
(if (<= t_0 1e+283)
(* (* (sqrt (/ d l)) (sqrt (/ d h))) 1.0)
(* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double tmp;
if (t_0 <= -1e-146) {
tmp = fma(((((M_m * D_m) * (M_m * D_m)) * (0.25 / ((d * d) * l))) * h), -0.5, 1.0) * sqrt(((d / (l * h)) * d));
} else if (t_0 <= 1e+283) {
tmp = (sqrt((d / l)) * sqrt((d / h))) * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(fma(Float64(Float64(Float64(Float64(M_m * D_m) * Float64(M_m * D_m)) * Float64(0.25 / Float64(Float64(d * d) * l))) * h), -0.5, 1.0) * sqrt(Float64(Float64(d / Float64(l * h)) * d))); elseif (t_0 <= 1e+283) tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(N[(N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(M$95$m * D$95$m), $MachinePrecision]), $MachinePrecision] * N[(0.25 / N[(N[(d * d), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * h), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sqrt[N[(N[(d / N[(l * h), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(\left(M\_m \cdot D\_m\right) \cdot \left(M\_m \cdot D\_m\right)\right) \cdot \frac{0.25}{\left(d \cdot d\right) \cdot \ell}\right) \cdot h, -0.5, 1\right) \cdot \sqrt{\frac{d}{\ell \cdot h} \cdot d}\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
Applied rewrites35.6%
Applied rewrites37.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
lift-*.f64N/A
lift-*.f64N/A
lower-*.f6444.0
lift-*.f64N/A
*-commutativeN/A
lift-*.f6444.0
lift-*.f64N/A
*-commutativeN/A
lift-*.f6444.0
Applied rewrites44.0%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l))))))
(if (<= t_0 -1e-146)
(*
(fma
(* (* (* M_m D_m) (* D_m (* (/ 0.25 (* (* d d) l)) M_m))) h)
-0.5
1.0)
(sqrt (* (/ d (* l h)) d)))
(if (<= t_0 1e+283)
(* (* (sqrt (/ d l)) (sqrt (/ d h))) 1.0)
(* (sqrt (* (/ d (* h l)) d)) (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double tmp;
if (t_0 <= -1e-146) {
tmp = fma((((M_m * D_m) * (D_m * ((0.25 / ((d * d) * l)) * M_m))) * h), -0.5, 1.0) * sqrt(((d / (l * h)) * d));
} else if (t_0 <= 1e+283) {
tmp = (sqrt((d / l)) * sqrt((d / h))) * 1.0;
} else {
tmp = sqrt(((d / (h * l)) * d)) * (l / l);
}
return tmp;
}
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) tmp = 0.0 if (t_0 <= -1e-146) tmp = Float64(fma(Float64(Float64(Float64(M_m * D_m) * Float64(D_m * Float64(Float64(0.25 / Float64(Float64(d * d) * l)) * M_m))) * h), -0.5, 1.0) * sqrt(Float64(Float64(d / Float64(l * h)) * d))); elseif (t_0 <= 1e+283) tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * 1.0); else tmp = Float64(sqrt(Float64(Float64(d / Float64(h * l)) * d)) * Float64(l / l)); end return tmp end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-146], N[(N[(N[(N[(N[(M$95$m * D$95$m), $MachinePrecision] * N[(D$95$m * N[(N[(0.25 / N[(N[(d * d), $MachinePrecision] * l), $MachinePrecision]), $MachinePrecision] * M$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * h), $MachinePrecision] * -0.5 + 1.0), $MachinePrecision] * N[Sqrt[N[(N[(d / N[(l * h), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision], N[(N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision] * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-146}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(M\_m \cdot D\_m\right) \cdot \left(D\_m \cdot \left(\frac{0.25}{\left(d \cdot d\right) \cdot \ell} \cdot M\_m\right)\right)\right) \cdot h, -0.5, 1\right) \cdot \sqrt{\frac{d}{\ell \cdot h} \cdot d}\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{d}{h \cdot \ell} \cdot d} \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.00000000000000003e-146Initial program 66.7%
Applied rewrites35.6%
Applied rewrites37.7%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6445.6
Applied rewrites45.6%
if -1.00000000000000003e-146 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
: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_m D_m) (* 2.0 d)) 2.0)) (/ h l)))))
(t_1 (sqrt (* (/ d (* h l)) d))))
(if (<= t_0 -2e-67)
(*
t_1
(/ (- l (* (* (* (* D_m (/ (* M_m D_m) (* d d))) 0.125) M_m) h)) l))
(if (<= t_0 1e+283)
(* (* (sqrt (/ d l)) (sqrt (/ d h))) 1.0)
(* t_1 (/ l l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = sqrt(((d / (h * l)) * d));
double tmp;
if (t_0 <= -2e-67) {
tmp = t_1 * ((l - ((((D_m * ((M_m * D_m) / (d * d))) * 0.125) * M_m) * h)) / l);
} else if (t_0 <= 1e+283) {
tmp = (sqrt((d / l)) * sqrt((d / h))) * 1.0;
} else {
tmp = t_1 * (l / l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (((d / h) ** (1.0d0 / 2.0d0)) * ((d / l) ** (1.0d0 / 2.0d0))) * (1.0d0 - (((1.0d0 / 2.0d0) * (((m_m * d_m) / (2.0d0 * d)) ** 2.0d0)) * (h / l)))
t_1 = sqrt(((d / (h * l)) * d))
if (t_0 <= (-2d-67)) then
tmp = t_1 * ((l - ((((d_m * ((m_m * d_m) / (d * d))) * 0.125d0) * m_m) * h)) / l)
else if (t_0 <= 1d+283) then
tmp = (sqrt((d / l)) * sqrt((d / h))) * 1.0d0
else
tmp = t_1 * (l / l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
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_m * D_m) / (2.0 * d)), 2.0)) * (h / l)));
double t_1 = Math.sqrt(((d / (h * l)) * d));
double tmp;
if (t_0 <= -2e-67) {
tmp = t_1 * ((l - ((((D_m * ((M_m * D_m) / (d * d))) * 0.125) * M_m) * h)) / l);
} else if (t_0 <= 1e+283) {
tmp = (Math.sqrt((d / l)) * Math.sqrt((d / h))) * 1.0;
} else {
tmp = t_1 * (l / l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): 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_m * D_m) / (2.0 * d)), 2.0)) * (h / l))) t_1 = math.sqrt(((d / (h * l)) * d)) tmp = 0 if t_0 <= -2e-67: tmp = t_1 * ((l - ((((D_m * ((M_m * D_m) / (d * d))) * 0.125) * M_m) * h)) / l) elif t_0 <= 1e+283: tmp = (math.sqrt((d / l)) * math.sqrt((d / h))) * 1.0 else: tmp = t_1 * (l / l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) 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_m * D_m) / Float64(2.0 * d)) ^ 2.0)) * Float64(h / l)))) t_1 = sqrt(Float64(Float64(d / Float64(h * l)) * d)) tmp = 0.0 if (t_0 <= -2e-67) tmp = Float64(t_1 * Float64(Float64(l - Float64(Float64(Float64(Float64(D_m * Float64(Float64(M_m * D_m) / Float64(d * d))) * 0.125) * M_m) * h)) / l)); elseif (t_0 <= 1e+283) tmp = Float64(Float64(sqrt(Float64(d / l)) * sqrt(Float64(d / h))) * 1.0); else tmp = Float64(t_1 * Float64(l / l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = (((d / h) ^ (1.0 / 2.0)) * ((d / l) ^ (1.0 / 2.0))) * (1.0 - (((1.0 / 2.0) * (((M_m * D_m) / (2.0 * d)) ^ 2.0)) * (h / l)));
t_1 = sqrt(((d / (h * l)) * d));
tmp = 0.0;
if (t_0 <= -2e-67)
tmp = t_1 * ((l - ((((D_m * ((M_m * D_m) / (d * d))) * 0.125) * M_m) * h)) / l);
elseif (t_0 <= 1e+283)
tmp = (sqrt((d / l)) * sqrt((d / h))) * 1.0;
else
tmp = t_1 * (l / l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := 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$95$m * D$95$m), $MachinePrecision] / N[(2.0 * d), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(h / l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(d / N[(h * l), $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, -2e-67], N[(t$95$1 * N[(N[(l - N[(N[(N[(N[(D$95$m * N[(N[(M$95$m * D$95$m), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] * M$95$m), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+283], N[(N[(N[Sqrt[N[(d / l), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(d / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision], N[(t$95$1 * N[(l / l), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\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\_m \cdot D\_m}{2 \cdot d}\right)}^{2}\right) \cdot \frac{h}{\ell}\right)\\
t_1 := \sqrt{\frac{d}{h \cdot \ell} \cdot d}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-67}:\\
\;\;\;\;t\_1 \cdot \frac{\ell - \left(\left(\left(D\_m \cdot \frac{M\_m \cdot D\_m}{d \cdot d}\right) \cdot 0.125\right) \cdot M\_m\right) \cdot h}{\ell}\\
\mathbf{elif}\;t\_0 \leq 10^{+283}:\\
\;\;\;\;\left(\sqrt{\frac{d}{\ell}} \cdot \sqrt{\frac{d}{h}}\right) \cdot 1\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \frac{\ell}{\ell}\\
\end{array}
\end{array}
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.99999999999999989e-67Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6445.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6445.4
Applied rewrites45.4%
if -1.99999999999999989e-67 < (*.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)))) < 9.99999999999999955e282Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
Applied rewrites68.4%
Taylor expanded in d around inf
Applied rewrites38.9%
if 9.99999999999999955e282 < (*.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)))) Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around inf
Applied rewrites29.4%
M_m = (fabs.f64 M)
D_m = (fabs.f64 D)
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
(FPCore (d h l M_m D_m)
:precision binary64
(let* ((t_0 (* d (sqrt (/ 1.0 (* h l))))))
(if (<= l 1.4e-305)
(* -1.0 t_0)
(if (<= l 6.2e+82)
(*
t_0
(/ (- l (* (* (* (/ (* (* D_m D_m) M_m) (* d d)) 0.125) M_m) h)) l))
(/ (* d (sqrt (/ 1.0 h))) (sqrt l))))))M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = d * sqrt((1.0 / (h * l)));
double tmp;
if (l <= 1.4e-305) {
tmp = -1.0 * t_0;
} else if (l <= 6.2e+82) {
tmp = t_0 * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
} else {
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: t_0
real(8) :: tmp
t_0 = d * sqrt((1.0d0 / (h * l)))
if (l <= 1.4d-305) then
tmp = (-1.0d0) * t_0
else if (l <= 6.2d+82) then
tmp = t_0 * ((l - ((((((d_m * d_m) * m_m) / (d * d)) * 0.125d0) * m_m) * h)) / l)
else
tmp = (d * sqrt((1.0d0 / h))) / sqrt(l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double t_0 = d * Math.sqrt((1.0 / (h * l)));
double tmp;
if (l <= 1.4e-305) {
tmp = -1.0 * t_0;
} else if (l <= 6.2e+82) {
tmp = t_0 * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
} else {
tmp = (d * Math.sqrt((1.0 / h))) / Math.sqrt(l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): t_0 = d * math.sqrt((1.0 / (h * l))) tmp = 0 if l <= 1.4e-305: tmp = -1.0 * t_0 elif l <= 6.2e+82: tmp = t_0 * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l) else: tmp = (d * math.sqrt((1.0 / h))) / math.sqrt(l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) t_0 = Float64(d * sqrt(Float64(1.0 / Float64(h * l)))) tmp = 0.0 if (l <= 1.4e-305) tmp = Float64(-1.0 * t_0); elseif (l <= 6.2e+82) tmp = Float64(t_0 * Float64(Float64(l - Float64(Float64(Float64(Float64(Float64(Float64(D_m * D_m) * M_m) / Float64(d * d)) * 0.125) * M_m) * h)) / l)); else tmp = Float64(Float64(d * sqrt(Float64(1.0 / h))) / sqrt(l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
t_0 = d * sqrt((1.0 / (h * l)));
tmp = 0.0;
if (l <= 1.4e-305)
tmp = -1.0 * t_0;
elseif (l <= 6.2e+82)
tmp = t_0 * ((l - ((((((D_m * D_m) * M_m) / (d * d)) * 0.125) * M_m) * h)) / l);
else
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision]
D_m = N[Abs[D], $MachinePrecision]
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
code[d_, h_, l_, M$95$m_, D$95$m_] := Block[{t$95$0 = N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, 1.4e-305], N[(-1.0 * t$95$0), $MachinePrecision], If[LessEqual[l, 6.2e+82], N[(t$95$0 * N[(N[(l - N[(N[(N[(N[(N[(N[(D$95$m * D$95$m), $MachinePrecision] * M$95$m), $MachinePrecision] / N[(d * d), $MachinePrecision]), $MachinePrecision] * 0.125), $MachinePrecision] * M$95$m), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision] / l), $MachinePrecision]), $MachinePrecision], N[(N[(d * N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
t_0 := d \cdot \sqrt{\frac{1}{h \cdot \ell}}\\
\mathbf{if}\;\ell \leq 1.4 \cdot 10^{-305}:\\
\;\;\;\;-1 \cdot t\_0\\
\mathbf{elif}\;\ell \leq 6.2 \cdot 10^{+82}:\\
\;\;\;\;t\_0 \cdot \frac{\ell - \left(\left(\frac{\left(D\_m \cdot D\_m\right) \cdot M\_m}{d \cdot d} \cdot 0.125\right) \cdot M\_m\right) \cdot h}{\ell}\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\
\end{array}
\end{array}
if l < 1.40000000000000007e-305Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if 1.40000000000000007e-305 < l < 6.20000000000000065e82Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6427.8
Applied rewrites27.8%
if 6.20000000000000065e82 < l Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites19.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6424.7
Applied rewrites24.7%
M_m = (fabs.f64 M) D_m = (fabs.f64 D) NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. (FPCore (d h l M_m D_m) :precision binary64 (if (<= h 2.3e-297) (* -1.0 (* d (sqrt (/ 1.0 (* h l))))) (/ (* d (sqrt (/ 1.0 h))) (sqrt l))))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (h <= 2.3e-297) {
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
} else {
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
}
return tmp;
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
real(8) :: tmp
if (h <= 2.3d-297) then
tmp = (-1.0d0) * (d * sqrt((1.0d0 / (h * l))))
else
tmp = (d * sqrt((1.0d0 / h))) / sqrt(l)
end if
code = tmp
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
double tmp;
if (h <= 2.3e-297) {
tmp = -1.0 * (d * Math.sqrt((1.0 / (h * l))));
} else {
tmp = (d * Math.sqrt((1.0 / h))) / Math.sqrt(l);
}
return tmp;
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): tmp = 0 if h <= 2.3e-297: tmp = -1.0 * (d * math.sqrt((1.0 / (h * l)))) else: tmp = (d * math.sqrt((1.0 / h))) / math.sqrt(l) return tmp
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) tmp = 0.0 if (h <= 2.3e-297) tmp = Float64(-1.0 * Float64(d * sqrt(Float64(1.0 / Float64(h * l))))); else tmp = Float64(Float64(d * sqrt(Float64(1.0 / h))) / sqrt(l)); end return tmp end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp_2 = code(d, h, l, M_m, D_m)
tmp = 0.0;
if (h <= 2.3e-297)
tmp = -1.0 * (d * sqrt((1.0 / (h * l))));
else
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
end
tmp_2 = tmp;
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := If[LessEqual[h, 2.3e-297], N[(-1.0 * N[(d * N[Sqrt[N[(1.0 / N[(h * l), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(d * N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\begin{array}{l}
\mathbf{if}\;h \leq 2.3 \cdot 10^{-297}:\\
\;\;\;\;-1 \cdot \left(d \cdot \sqrt{\frac{1}{h \cdot \ell}}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{d \cdot \sqrt{\frac{1}{h}}}{\sqrt{\ell}}\\
\end{array}
\end{array}
if h < 2.2999999999999999e-297Initial program 66.7%
Applied rewrites42.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites39.1%
Taylor expanded in d around -inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-*.f6425.5
Applied rewrites25.5%
if 2.2999999999999999e-297 < h Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites19.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6424.7
Applied rewrites24.7%
M_m = (fabs.f64 M) D_m = (fabs.f64 D) NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. (FPCore (d h l M_m D_m) :precision binary64 (/ (* d (sqrt (/ 1.0 h))) (sqrt l)))
M_m = fabs(M);
D_m = fabs(D);
assert(d < h && h < l && l < M_m && M_m < D_m);
double code(double d, double h, double l, double M_m, double D_m) {
return (d * sqrt((1.0 / h))) / sqrt(l);
}
M_m = private
D_m = private
NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(d, h, l, m_m, d_m)
use fmin_fmax_functions
real(8), intent (in) :: d
real(8), intent (in) :: h
real(8), intent (in) :: l
real(8), intent (in) :: m_m
real(8), intent (in) :: d_m
code = (d * sqrt((1.0d0 / h))) / sqrt(l)
end function
M_m = Math.abs(M);
D_m = Math.abs(D);
assert d < h && h < l && l < M_m && M_m < D_m;
public static double code(double d, double h, double l, double M_m, double D_m) {
return (d * Math.sqrt((1.0 / h))) / Math.sqrt(l);
}
M_m = math.fabs(M) D_m = math.fabs(D) [d, h, l, M_m, D_m] = sort([d, h, l, M_m, D_m]) def code(d, h, l, M_m, D_m): return (d * math.sqrt((1.0 / h))) / math.sqrt(l)
M_m = abs(M) D_m = abs(D) d, h, l, M_m, D_m = sort([d, h, l, M_m, D_m]) function code(d, h, l, M_m, D_m) return Float64(Float64(d * sqrt(Float64(1.0 / h))) / sqrt(l)) end
M_m = abs(M);
D_m = abs(D);
d, h, l, M_m, D_m = num2cell(sort([d, h, l, M_m, D_m])){:}
function tmp = code(d, h, l, M_m, D_m)
tmp = (d * sqrt((1.0 / h))) / sqrt(l);
end
M_m = N[Abs[M], $MachinePrecision] D_m = N[Abs[D], $MachinePrecision] NOTE: d, h, l, M_m, and D_m should be sorted in increasing order before calling this function. code[d_, h_, l_, M$95$m_, D$95$m_] := N[(N[(d * N[Sqrt[N[(1.0 / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[l], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
M_m = \left|M\right|
\\
D_m = \left|D\right|
\\
[d, h, l, M_m, D_m] = \mathsf{sort}([d, h, l, M_m, D_m])\\
\\
\frac{d \cdot \sqrt{\frac{1}{h}}}{\sqrt{\ell}}
\end{array}
Initial program 66.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
lift-pow.f64N/A
lift-/.f64N/A
metadata-evalN/A
unpow1/2N/A
lower-sqrt.f6466.7
Applied rewrites66.7%
lift-pow.f64N/A
unpow2N/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
lift-/.f64N/A
frac-2negN/A
distribute-frac-negN/A
sqr-negN/A
lower-*.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval66.7
Applied rewrites66.7%
Applied rewrites19.9%
Taylor expanded in d around inf
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-sqrt.f6424.7
Applied rewrites24.7%
herbie shell --seed 2025164
(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)))))