
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
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(x, y, z, t, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
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(x, y, z, t, a)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a): return ((x * y) - (z * t)) / a
function code(x, y, z, t, a) return Float64(Float64(Float64(x * y) - Float64(z * t)) / a) end
function tmp = code(x, y, z, t, a) tmp = ((x * y) - (z * t)) / a; end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(*
a_s
(if (<= a_m 50000000000.0)
(/ (fma (- z) t (* y x)) a_m)
(fma (/ x a_m) y (* (- z) (/ t a_m))))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if (a_m <= 50000000000.0) {
tmp = fma(-z, t, (y * x)) / a_m;
} else {
tmp = fma((x / a_m), y, (-z * (t / a_m)));
}
return a_s * tmp;
}
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) tmp = 0.0 if (a_m <= 50000000000.0) tmp = Float64(fma(Float64(-z), t, Float64(y * x)) / a_m); else tmp = fma(Float64(x / a_m), y, Float64(Float64(-z) * Float64(t / a_m))); end return Float64(a_s * tmp) end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 50000000000.0], N[(N[((-z) * t + N[(y * x), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(x / a$95$m), $MachinePrecision] * y + N[((-z) * N[(t / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 50000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(-z, t, y \cdot x\right)}{a\_m}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{a\_m}, y, \left(-z\right) \cdot \frac{t}{a\_m}\right)\\
\end{array}
\end{array}
if a < 5e10Initial program 98.1%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
if 5e10 < a Initial program 84.0%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(*
a_s
(if (<= a_m 1900000000000.0)
(/ (fma (- z) t (* y x)) a_m)
(- (* (/ x a_m) y) (* (/ z a_m) t)))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if (a_m <= 1900000000000.0) {
tmp = fma(-z, t, (y * x)) / a_m;
} else {
tmp = ((x / a_m) * y) - ((z / a_m) * t);
}
return a_s * tmp;
}
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) tmp = 0.0 if (a_m <= 1900000000000.0) tmp = Float64(fma(Float64(-z), t, Float64(y * x)) / a_m); else tmp = Float64(Float64(Float64(x / a_m) * y) - Float64(Float64(z / a_m) * t)); end return Float64(a_s * tmp) end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 1900000000000.0], N[(N[((-z) * t + N[(y * x), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision] - N[(N[(z / a$95$m), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 1900000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(-z, t, y \cdot x\right)}{a\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{a\_m} \cdot y - \frac{z}{a\_m} \cdot t\\
\end{array}
\end{array}
if a < 1.9e12Initial program 98.0%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
if 1.9e12 < a Initial program 83.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6491.9
Applied rewrites91.9%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-/.f64N/A
distribute-lft-neg-inN/A
associate-*l/N/A
mul-1-negN/A
associate-*l/N/A
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-/.f6492.3
Applied rewrites92.3%
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(*
a_s
(if (<= a_m 50000000000.0)
(/ (fma (- z) t (* y x)) a_m)
(- (* (/ x a_m) y) (* (/ t a_m) z)))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if (a_m <= 50000000000.0) {
tmp = fma(-z, t, (y * x)) / a_m;
} else {
tmp = ((x / a_m) * y) - ((t / a_m) * z);
}
return a_s * tmp;
}
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) tmp = 0.0 if (a_m <= 50000000000.0) tmp = Float64(fma(Float64(-z), t, Float64(y * x)) / a_m); else tmp = Float64(Float64(Float64(x / a_m) * y) - Float64(Float64(t / a_m) * z)); end return Float64(a_s * tmp) end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 50000000000.0], N[(N[((-z) * t + N[(y * x), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision] - N[(N[(t / a$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 50000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(-z, t, y \cdot x\right)}{a\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{a\_m} \cdot y - \frac{t}{a\_m} \cdot z\\
\end{array}
\end{array}
if a < 5e10Initial program 98.1%
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower--.f64N/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
associate-*r*N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
if 5e10 < a Initial program 84.0%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6492.0
Applied rewrites92.0%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6491.9
Applied rewrites91.9%
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(let* ((t_1 (* (/ z (- a_m)) t)))
(*
a_s
(if (<= (* z t) (- INFINITY))
t_1
(if (<= (* z t) 1e+307) (/ (- (* x y) (* z t)) a_m) t_1)))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double t_1 = (z / -a_m) * t;
double tmp;
if ((z * t) <= -((double) INFINITY)) {
tmp = t_1;
} else if ((z * t) <= 1e+307) {
tmp = ((x * y) - (z * t)) / a_m;
} else {
tmp = t_1;
}
return a_s * tmp;
}
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
double t_1 = (z / -a_m) * t;
double tmp;
if ((z * t) <= -Double.POSITIVE_INFINITY) {
tmp = t_1;
} else if ((z * t) <= 1e+307) {
tmp = ((x * y) - (z * t)) / a_m;
} else {
tmp = t_1;
}
return a_s * tmp;
}
a\_m = math.fabs(a) a\_s = math.copysign(1.0, a) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) def code(a_s, x, y, z, t, a_m): t_1 = (z / -a_m) * t tmp = 0 if (z * t) <= -math.inf: tmp = t_1 elif (z * t) <= 1e+307: tmp = ((x * y) - (z * t)) / a_m else: tmp = t_1 return a_s * tmp
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) t_1 = Float64(Float64(z / Float64(-a_m)) * t) tmp = 0.0 if (Float64(z * t) <= Float64(-Inf)) tmp = t_1; elseif (Float64(z * t) <= 1e+307) tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a_m); else tmp = t_1; end return Float64(a_s * tmp) end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
t_1 = (z / -a_m) * t;
tmp = 0.0;
if ((z * t) <= -Inf)
tmp = t_1;
elseif ((z * t) <= 1e+307)
tmp = ((x * y) - (z * t)) / a_m;
else
tmp = t_1;
end
tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(z / (-a$95$m)), $MachinePrecision] * t), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(z * t), $MachinePrecision], (-Infinity)], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 1e+307], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \frac{z}{-a\_m} \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot t \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 10^{+307}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a\_m}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
\end{array}
if (*.f64 z t) < -inf.0 or 9.99999999999999986e306 < (*.f64 z t) Initial program 66.6%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6492.9
Applied rewrites92.9%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6489.6
Applied rewrites89.6%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-/.f64N/A
distribute-lft-neg-inN/A
associate-*l/N/A
mul-1-negN/A
associate-*l/N/A
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-/.f6489.6
Applied rewrites89.6%
Taylor expanded in x around 0
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
lift-neg.f64N/A
lower-/.f6496.1
Applied rewrites96.1%
if -inf.0 < (*.f64 z t) < 9.99999999999999986e306Initial program 95.3%
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(*
a_s
(if (<= (* z t) -5e+143)
(* (/ z (- a_m)) t)
(if (<= (* z t) 5e-64) (* (/ x a_m) y) (* (- z) (/ t a_m))))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if ((z * t) <= -5e+143) {
tmp = (z / -a_m) * t;
} else if ((z * t) <= 5e-64) {
tmp = (x / a_m) * y;
} else {
tmp = -z * (t / a_m);
}
return a_s * tmp;
}
a\_m = private
a\_s = private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
real(8), intent (in) :: a_s
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a_m
real(8) :: tmp
if ((z * t) <= (-5d+143)) then
tmp = (z / -a_m) * t
else if ((z * t) <= 5d-64) then
tmp = (x / a_m) * y
else
tmp = -z * (t / a_m)
end if
code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if ((z * t) <= -5e+143) {
tmp = (z / -a_m) * t;
} else if ((z * t) <= 5e-64) {
tmp = (x / a_m) * y;
} else {
tmp = -z * (t / a_m);
}
return a_s * tmp;
}
a\_m = math.fabs(a) a\_s = math.copysign(1.0, a) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) def code(a_s, x, y, z, t, a_m): tmp = 0 if (z * t) <= -5e+143: tmp = (z / -a_m) * t elif (z * t) <= 5e-64: tmp = (x / a_m) * y else: tmp = -z * (t / a_m) return a_s * tmp
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) tmp = 0.0 if (Float64(z * t) <= -5e+143) tmp = Float64(Float64(z / Float64(-a_m)) * t); elseif (Float64(z * t) <= 5e-64) tmp = Float64(Float64(x / a_m) * y); else tmp = Float64(Float64(-z) * Float64(t / a_m)); end return Float64(a_s * tmp) end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
tmp = 0.0;
if ((z * t) <= -5e+143)
tmp = (z / -a_m) * t;
elseif ((z * t) <= 5e-64)
tmp = (x / a_m) * y;
else
tmp = -z * (t / a_m);
end
tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[N[(z * t), $MachinePrecision], -5e+143], N[(N[(z / (-a$95$m)), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e-64], N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision], N[((-z) * N[(t / a$95$m), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+143}:\\
\;\;\;\;\frac{z}{-a\_m} \cdot t\\
\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{-64}:\\
\;\;\;\;\frac{x}{a\_m} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(-z\right) \cdot \frac{t}{a\_m}\\
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000012e143Initial program 82.5%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6491.2
Applied rewrites91.2%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6488.9
Applied rewrites88.9%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-/.f64N/A
distribute-lft-neg-inN/A
associate-*l/N/A
mul-1-negN/A
associate-*l/N/A
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-/.f6489.5
Applied rewrites89.5%
Taylor expanded in x around 0
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
lift-neg.f64N/A
lower-/.f6487.0
Applied rewrites87.0%
if -5.00000000000000012e143 < (*.f64 z t) < 5.00000000000000033e-64Initial program 94.9%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.0
Applied rewrites88.0%
Taylor expanded in x around inf
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
div-subN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6470.1
Applied rewrites70.1%
if 5.00000000000000033e-64 < (*.f64 z t) Initial program 89.5%
Taylor expanded in x around 0
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6468.6
Applied rewrites68.6%
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
:precision binary64
(let* ((t_1 (* (/ z (- a_m)) t)))
(*
a_s
(if (<= (* z t) -5e+143)
t_1
(if (<= (* z t) 2e+95) (* (/ x a_m) y) t_1)))))a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double t_1 = (z / -a_m) * t;
double tmp;
if ((z * t) <= -5e+143) {
tmp = t_1;
} else if ((z * t) <= 2e+95) {
tmp = (x / a_m) * y;
} else {
tmp = t_1;
}
return a_s * tmp;
}
a\_m = private
a\_s = private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
real(8), intent (in) :: a_s
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a_m
real(8) :: t_1
real(8) :: tmp
t_1 = (z / -a_m) * t
if ((z * t) <= (-5d+143)) then
tmp = t_1
else if ((z * t) <= 2d+95) then
tmp = (x / a_m) * y
else
tmp = t_1
end if
code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
double t_1 = (z / -a_m) * t;
double tmp;
if ((z * t) <= -5e+143) {
tmp = t_1;
} else if ((z * t) <= 2e+95) {
tmp = (x / a_m) * y;
} else {
tmp = t_1;
}
return a_s * tmp;
}
a\_m = math.fabs(a) a\_s = math.copysign(1.0, a) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) def code(a_s, x, y, z, t, a_m): t_1 = (z / -a_m) * t tmp = 0 if (z * t) <= -5e+143: tmp = t_1 elif (z * t) <= 2e+95: tmp = (x / a_m) * y else: tmp = t_1 return a_s * tmp
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) t_1 = Float64(Float64(z / Float64(-a_m)) * t) tmp = 0.0 if (Float64(z * t) <= -5e+143) tmp = t_1; elseif (Float64(z * t) <= 2e+95) tmp = Float64(Float64(x / a_m) * y); else tmp = t_1; end return Float64(a_s * tmp) end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
t_1 = (z / -a_m) * t;
tmp = 0.0;
if ((z * t) <= -5e+143)
tmp = t_1;
elseif ((z * t) <= 2e+95)
tmp = (x / a_m) * y;
else
tmp = t_1;
end
tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(z / (-a$95$m)), $MachinePrecision] * t), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(z * t), $MachinePrecision], -5e+143], t$95$1, If[LessEqual[N[(z * t), $MachinePrecision], 2e+95], N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \frac{z}{-a\_m} \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+143}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+95}:\\
\;\;\;\;\frac{x}{a\_m} \cdot y\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
\end{array}
if (*.f64 z t) < -5.00000000000000012e143 or 2.00000000000000004e95 < (*.f64 z t) Initial program 83.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6490.6
Applied rewrites90.6%
lift-/.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
*-commutativeN/A
lower--.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6488.5
Applied rewrites88.5%
lift--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
lift-/.f64N/A
distribute-lft-neg-inN/A
associate-*l/N/A
mul-1-negN/A
associate-*l/N/A
mul-1-negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
fp-cancel-sub-signN/A
lower--.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lower-*.f64N/A
lower-/.f6489.6
Applied rewrites89.6%
Taylor expanded in x around 0
mul-1-negN/A
associate-/l*N/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-*.f64N/A
mul-1-negN/A
distribute-neg-frac2N/A
lift-neg.f64N/A
lower-/.f6485.5
Applied rewrites85.5%
if -5.00000000000000012e143 < (*.f64 z t) < 2.00000000000000004e95Initial program 95.2%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6487.2
Applied rewrites87.2%
Taylor expanded in x around inf
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
div-subN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6465.6
Applied rewrites65.6%
a\_m = (fabs.f64 a) a\_s = (copysign.f64 #s(literal 1 binary64) a) NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function. NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function. (FPCore (a_s x y z t a_m) :precision binary64 (* a_s (if (<= t 1.2e-143) (* (/ x a_m) y) (* (/ y a_m) x))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if (t <= 1.2e-143) {
tmp = (x / a_m) * y;
} else {
tmp = (y / a_m) * x;
}
return a_s * tmp;
}
a\_m = private
a\_s = private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
real(8), intent (in) :: a_s
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a_m
real(8) :: tmp
if (t <= 1.2d-143) then
tmp = (x / a_m) * y
else
tmp = (y / a_m) * x
end if
code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
double tmp;
if (t <= 1.2e-143) {
tmp = (x / a_m) * y;
} else {
tmp = (y / a_m) * x;
}
return a_s * tmp;
}
a\_m = math.fabs(a) a\_s = math.copysign(1.0, a) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) def code(a_s, x, y, z, t, a_m): tmp = 0 if t <= 1.2e-143: tmp = (x / a_m) * y else: tmp = (y / a_m) * x return a_s * tmp
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) tmp = 0.0 if (t <= 1.2e-143) tmp = Float64(Float64(x / a_m) * y); else tmp = Float64(Float64(y / a_m) * x); end return Float64(a_s * tmp) end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
tmp = 0.0;
if (t <= 1.2e-143)
tmp = (x / a_m) * y;
else
tmp = (y / a_m) * x;
end
tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[t, 1.2e-143], N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision], N[(N[(y / a$95$m), $MachinePrecision] * x), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t \leq 1.2 \cdot 10^{-143}:\\
\;\;\;\;\frac{x}{a\_m} \cdot y\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{a\_m} \cdot x\\
\end{array}
\end{array}
if t < 1.1999999999999999e-143Initial program 92.8%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6489.0
Applied rewrites89.0%
Taylor expanded in x around inf
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
div-subN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6460.6
Applied rewrites60.6%
if 1.1999999999999999e-143 < t Initial program 90.5%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6487.8
Applied rewrites87.8%
Taylor expanded in x around inf
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
div-subN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6445.5
Applied rewrites45.5%
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
associate-/l*N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f6445.8
Applied rewrites45.8%
a\_m = (fabs.f64 a) a\_s = (copysign.f64 #s(literal 1 binary64) a) NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function. NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function. (FPCore (a_s x y z t a_m) :precision binary64 (* a_s (* (/ x a_m) y)))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
return a_s * ((x / a_m) * y);
}
a\_m = private
a\_s = private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
real(8), intent (in) :: a_s
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a_m
code = a_s * ((x / a_m) * y)
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
return a_s * ((x / a_m) * y);
}
a\_m = math.fabs(a) a\_s = math.copysign(1.0, a) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) [x, y, z, t, a_m] = sort([x, y, z, t, a_m]) def code(a_s, x, y, z, t, a_m): return a_s * ((x / a_m) * y)
a\_m = abs(a) a\_s = copysign(1.0, a) x, y, z, t, a_m = sort([x, y, z, t, a_m]) x, y, z, t, a_m = sort([x, y, z, t, a_m]) function code(a_s, x, y, z, t, a_m) return Float64(a_s * Float64(Float64(x / a_m) * y)) end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp = code(a_s, x, y, z, t, a_m)
tmp = a_s * ((x / a_m) * y);
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * N[(N[(x / a$95$m), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \left(\frac{x}{a\_m} \cdot y\right)
\end{array}
Initial program 91.4%
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift--.f64N/A
fp-cancel-sub-sign-invN/A
div-addN/A
associate-*l/N/A
distribute-lft-neg-inN/A
*-commutativeN/A
mul-1-negN/A
associate-*r/N/A
lower-fma.f64N/A
lower-/.f64N/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f6488.3
Applied rewrites88.3%
Taylor expanded in x around inf
fp-cancel-sub-signN/A
associate-*l/N/A
associate-*r/N/A
div-subN/A
associate-*l/N/A
lower-*.f64N/A
lift-/.f6451.6
Applied rewrites51.6%
herbie shell --seed 2025112
(FPCore (x y z t a)
:name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
:precision binary64
(/ (- (* x y) (* z t)) a))