
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))
double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
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)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (1.0d0 / x) / (y * (1.0d0 + (z * z)))
end function
public static double code(double x, double y, double z) {
return (1.0 / x) / (y * (1.0 + (z * z)));
}
def code(x, y, z): return (1.0 / x) / (y * (1.0 + (z * z)))
function code(x, y, z) return Float64(Float64(1.0 / x) / Float64(y * Float64(1.0 + Float64(z * z)))) end
function tmp = code(x, y, z) tmp = (1.0 / x) / (y * (1.0 + (z * z))); end
code[x_, y_, z_] := N[(N[(1.0 / x), $MachinePrecision] / N[(y * N[(1.0 + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\end{array}
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= z_m 2.05e+41)
(/ (/ 1.0 x_m) (fma (* y_m z_m) z_m y_m))
(/ (/ 1.0 (* (* z_m x_m) z_m)) y_m)))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if (z_m <= 2.05e+41) {
tmp = (1.0 / x_m) / fma((y_m * z_m), z_m, y_m);
} else {
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
}
return y_s * (x_s * tmp);
}
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (z_m <= 2.05e+41) tmp = Float64(Float64(1.0 / x_m) / fma(Float64(y_m * z_m), z_m, y_m)); else tmp = Float64(Float64(1.0 / Float64(Float64(z_m * x_m) * z_m)) / y_m); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[z$95$m, 2.05e+41], N[(N[(1.0 / x$95$m), $MachinePrecision] / N[(N[(y$95$m * z$95$m), $MachinePrecision] * z$95$m + y$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(z$95$m * x$95$m), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 2.05 \cdot 10^{+41}:\\
\;\;\;\;\frac{\frac{1}{x\_m}}{\mathsf{fma}\left(y\_m \cdot z\_m, z\_m, y\_m\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(z\_m \cdot x\_m\right) \cdot z\_m}}{y\_m}\\
\end{array}\right)
\end{array}
if z < 2.0500000000000002e41Initial program 88.2%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
pow2N/A
associate-*r*N/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f6490.5
Applied rewrites90.5%
if 2.0500000000000002e41 < z Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
lft-mult-inverseN/A
pow2N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
pow2N/A
rgt-mult-inverseN/A
lower-fma.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6458.9
Applied rewrites58.9%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= z_m 32000000000.0)
(/ 1.0 (* (fma (* z_m z_m) y_m y_m) x_m))
(/ (/ 1.0 (* (* z_m x_m) z_m)) y_m)))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if (z_m <= 32000000000.0) {
tmp = 1.0 / (fma((z_m * z_m), y_m, y_m) * x_m);
} else {
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
}
return y_s * (x_s * tmp);
}
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (z_m <= 32000000000.0) tmp = Float64(1.0 / Float64(fma(Float64(z_m * z_m), y_m, y_m) * x_m)); else tmp = Float64(Float64(1.0 / Float64(Float64(z_m * x_m) * z_m)) / y_m); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[z$95$m, 32000000000.0], N[(1.0 / N[(N[(N[(z$95$m * z$95$m), $MachinePrecision] * y$95$m + y$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(z$95$m * x$95$m), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 32000000000:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(z\_m \cdot z\_m, y\_m, y\_m\right) \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(z\_m \cdot x\_m\right) \cdot z\_m}}{y\_m}\\
\end{array}\right)
\end{array}
if z < 3.2e10Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.0%
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
distribute-lft1-inN/A
lower-fma.f64N/A
pow2N/A
lift-*.f6488.0
Applied rewrites88.0%
if 3.2e10 < z Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
lft-mult-inverseN/A
pow2N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
pow2N/A
rgt-mult-inverseN/A
lower-fma.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6458.9
Applied rewrites58.9%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= z_m 32000000000.0)
(/ 1.0 (* (* (fma z_m z_m 1.0) y_m) x_m))
(/ (/ 1.0 (* (* z_m x_m) z_m)) y_m)))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if (z_m <= 32000000000.0) {
tmp = 1.0 / ((fma(z_m, z_m, 1.0) * y_m) * x_m);
} else {
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
}
return y_s * (x_s * tmp);
}
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (z_m <= 32000000000.0) tmp = Float64(1.0 / Float64(Float64(fma(z_m, z_m, 1.0) * y_m) * x_m)); else tmp = Float64(Float64(1.0 / Float64(Float64(z_m * x_m) * z_m)) / y_m); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[z$95$m, 32000000000.0], N[(1.0 / N[(N[(N[(z$95$m * z$95$m + 1.0), $MachinePrecision] * y$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(N[(z$95$m * x$95$m), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 32000000000:\\
\;\;\;\;\frac{1}{\left(\mathsf{fma}\left(z\_m, z\_m, 1\right) \cdot y\_m\right) \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(z\_m \cdot x\_m\right) \cdot z\_m}}{y\_m}\\
\end{array}\right)
\end{array}
if z < 3.2e10Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.0%
if 3.2e10 < z Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
lft-mult-inverseN/A
pow2N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
pow2N/A
rgt-mult-inverseN/A
lower-fma.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6458.9
Applied rewrites58.9%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= z_m 0.88)
(/ (/ (- 1.0 (* z_m z_m)) y_m) x_m)
(/ (/ 1.0 (* (* z_m x_m) z_m)) y_m)))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if (z_m <= 0.88) {
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
} else {
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
}
return y_s * (x_s * tmp);
}
z_m = private
x\_m = private
x\_s = private
y\_m = private
y\_s = private
NOTE: x_m, y_m, and z_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(y_s, x_s, x_m, y_m, z_m)
use fmin_fmax_functions
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if (z_m <= 0.88d0) then
tmp = ((1.0d0 - (z_m * z_m)) / y_m) / x_m
else
tmp = (1.0d0 / ((z_m * x_m) * z_m)) / y_m
end if
code = y_s * (x_s * tmp)
end function
z_m = Math.abs(z);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
assert x_m < y_m && y_m < z_m;
public static double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if (z_m <= 0.88) {
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
} else {
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
}
return y_s * (x_s * tmp);
}
z_m = math.fabs(z) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) [x_m, y_m, z_m] = sort([x_m, y_m, z_m]) def code(y_s, x_s, x_m, y_m, z_m): tmp = 0 if z_m <= 0.88: tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m else: tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m return y_s * (x_s * tmp)
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (z_m <= 0.88) tmp = Float64(Float64(Float64(1.0 - Float64(z_m * z_m)) / y_m) / x_m); else tmp = Float64(Float64(1.0 / Float64(Float64(z_m * x_m) * z_m)) / y_m); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = abs(z);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(y_s, x_s, x_m, y_m, z_m)
tmp = 0.0;
if (z_m <= 0.88)
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
else
tmp = (1.0 / ((z_m * x_m) * z_m)) / y_m;
end
tmp_2 = y_s * (x_s * tmp);
end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[z$95$m, 0.88], N[(N[(N[(1.0 - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision] / x$95$m), $MachinePrecision], N[(N[(1.0 / N[(N[(z$95$m * x$95$m), $MachinePrecision] * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;z\_m \leq 0.88:\\
\;\;\;\;\frac{\frac{1 - z\_m \cdot z\_m}{y\_m}}{x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(z\_m \cdot x\_m\right) \cdot z\_m}}{y\_m}\\
\end{array}\right)
\end{array}
if z < 0.880000000000000004Initial program 88.2%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift--.f64N/A
lift-*.f6450.4
Applied rewrites50.4%
if 0.880000000000000004 < z Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift-/.f64N/A
lft-mult-inverseN/A
pow2N/A
*-lft-identityN/A
distribute-rgt-inN/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
pow2N/A
rgt-mult-inverseN/A
lower-fma.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6452.5
Applied rewrites52.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6458.9
Applied rewrites58.9%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= (+ 1.0 (* z_m z_m)) 2.0)
(/ (/ (- 1.0 (* z_m z_m)) y_m) x_m)
(/ 1.0 (* (* (* z_m z_m) x_m) y_m))))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
} else {
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
}
return y_s * (x_s * tmp);
}
z_m = private
x\_m = private
x\_s = private
y\_m = private
y\_s = private
NOTE: x_m, y_m, and z_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(y_s, x_s, x_m, y_m, z_m)
use fmin_fmax_functions
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if ((1.0d0 + (z_m * z_m)) <= 2.0d0) then
tmp = ((1.0d0 - (z_m * z_m)) / y_m) / x_m
else
tmp = 1.0d0 / (((z_m * z_m) * x_m) * y_m)
end if
code = y_s * (x_s * tmp)
end function
z_m = Math.abs(z);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
assert x_m < y_m && y_m < z_m;
public static double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
} else {
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
}
return y_s * (x_s * tmp);
}
z_m = math.fabs(z) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) [x_m, y_m, z_m] = sort([x_m, y_m, z_m]) def code(y_s, x_s, x_m, y_m, z_m): tmp = 0 if (1.0 + (z_m * z_m)) <= 2.0: tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m else: tmp = 1.0 / (((z_m * z_m) * x_m) * y_m) return y_s * (x_s * tmp)
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (Float64(1.0 + Float64(z_m * z_m)) <= 2.0) tmp = Float64(Float64(Float64(1.0 - Float64(z_m * z_m)) / y_m) / x_m); else tmp = Float64(1.0 / Float64(Float64(Float64(z_m * z_m) * x_m) * y_m)); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = abs(z);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(y_s, x_s, x_m, y_m, z_m)
tmp = 0.0;
if ((1.0 + (z_m * z_m)) <= 2.0)
tmp = ((1.0 - (z_m * z_m)) / y_m) / x_m;
else
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
end
tmp_2 = y_s * (x_s * tmp);
end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[N[(1.0 + N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(N[(1.0 - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / y$95$m), $MachinePrecision] / x$95$m), $MachinePrecision], N[(1.0 / N[(N[(N[(z$95$m * z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;1 + z\_m \cdot z\_m \leq 2:\\
\;\;\;\;\frac{\frac{1 - z\_m \cdot z\_m}{y\_m}}{x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(z\_m \cdot z\_m\right) \cdot x\_m\right) \cdot y\_m}\\
\end{array}\right)
\end{array}
if (+.f64 #s(literal 1 binary64) (*.f64 z z)) < 2Initial program 88.2%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lift--.f64N/A
lift-*.f6450.4
Applied rewrites50.4%
if 2 < (+.f64 #s(literal 1 binary64) (*.f64 z z)) Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
pow2N/A
associate-*r*N/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6494.4
Applied rewrites94.4%
Taylor expanded in z around inf
associate-*l*N/A
pow2N/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6452.4
Applied rewrites52.4%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= (+ 1.0 (* z_m z_m)) 2.0)
(/ (- 1.0 (* z_m z_m)) (* y_m x_m))
(/ 1.0 (* (* (* z_m z_m) x_m) y_m))))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
} else {
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
}
return y_s * (x_s * tmp);
}
z_m = private
x\_m = private
x\_s = private
y\_m = private
y\_s = private
NOTE: x_m, y_m, and z_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(y_s, x_s, x_m, y_m, z_m)
use fmin_fmax_functions
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if ((1.0d0 + (z_m * z_m)) <= 2.0d0) then
tmp = (1.0d0 - (z_m * z_m)) / (y_m * x_m)
else
tmp = 1.0d0 / (((z_m * z_m) * x_m) * y_m)
end if
code = y_s * (x_s * tmp)
end function
z_m = Math.abs(z);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
assert x_m < y_m && y_m < z_m;
public static double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
} else {
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
}
return y_s * (x_s * tmp);
}
z_m = math.fabs(z) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) [x_m, y_m, z_m] = sort([x_m, y_m, z_m]) def code(y_s, x_s, x_m, y_m, z_m): tmp = 0 if (1.0 + (z_m * z_m)) <= 2.0: tmp = (1.0 - (z_m * z_m)) / (y_m * x_m) else: tmp = 1.0 / (((z_m * z_m) * x_m) * y_m) return y_s * (x_s * tmp)
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (Float64(1.0 + Float64(z_m * z_m)) <= 2.0) tmp = Float64(Float64(1.0 - Float64(z_m * z_m)) / Float64(y_m * x_m)); else tmp = Float64(1.0 / Float64(Float64(Float64(z_m * z_m) * x_m) * y_m)); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = abs(z);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(y_s, x_s, x_m, y_m, z_m)
tmp = 0.0;
if ((1.0 + (z_m * z_m)) <= 2.0)
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
else
tmp = 1.0 / (((z_m * z_m) * x_m) * y_m);
end
tmp_2 = y_s * (x_s * tmp);
end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[N[(1.0 + N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(1.0 - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(z$95$m * z$95$m), $MachinePrecision] * x$95$m), $MachinePrecision] * y$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;1 + z\_m \cdot z\_m \leq 2:\\
\;\;\;\;\frac{1 - z\_m \cdot z\_m}{y\_m \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(z\_m \cdot z\_m\right) \cdot x\_m\right) \cdot y\_m}\\
\end{array}\right)
\end{array}
if (+.f64 #s(literal 1 binary64) (*.f64 z z)) < 2Initial program 88.2%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
if 2 < (+.f64 #s(literal 1 binary64) (*.f64 z z)) Initial program 88.2%
lift-/.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
pow2N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.0%
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow2N/A
+-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
pow2N/A
associate-*r*N/A
*-lft-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6494.4
Applied rewrites94.4%
Taylor expanded in z around inf
associate-*l*N/A
pow2N/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
pow2N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
*-commutativeN/A
pow2N/A
lift-*.f64N/A
lift-*.f6452.4
Applied rewrites52.4%
z_m = (fabs.f64 z)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
(FPCore (y_s x_s x_m y_m z_m)
:precision binary64
(*
y_s
(*
x_s
(if (<= (+ 1.0 (* z_m z_m)) 2.0)
(/ (- 1.0 (* z_m z_m)) (* y_m x_m))
(/ 1.0 (* (* (* z_m z_m) y_m) x_m))))))z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
} else {
tmp = 1.0 / (((z_m * z_m) * y_m) * x_m);
}
return y_s * (x_s * tmp);
}
z_m = private
x\_m = private
x\_s = private
y\_m = private
y\_s = private
NOTE: x_m, y_m, and z_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(y_s, x_s, x_m, y_m, z_m)
use fmin_fmax_functions
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
real(8) :: tmp
if ((1.0d0 + (z_m * z_m)) <= 2.0d0) then
tmp = (1.0d0 - (z_m * z_m)) / (y_m * x_m)
else
tmp = 1.0d0 / (((z_m * z_m) * y_m) * x_m)
end if
code = y_s * (x_s * tmp)
end function
z_m = Math.abs(z);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
assert x_m < y_m && y_m < z_m;
public static double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
double tmp;
if ((1.0 + (z_m * z_m)) <= 2.0) {
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
} else {
tmp = 1.0 / (((z_m * z_m) * y_m) * x_m);
}
return y_s * (x_s * tmp);
}
z_m = math.fabs(z) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) [x_m, y_m, z_m] = sort([x_m, y_m, z_m]) def code(y_s, x_s, x_m, y_m, z_m): tmp = 0 if (1.0 + (z_m * z_m)) <= 2.0: tmp = (1.0 - (z_m * z_m)) / (y_m * x_m) else: tmp = 1.0 / (((z_m * z_m) * y_m) * x_m) return y_s * (x_s * tmp)
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) tmp = 0.0 if (Float64(1.0 + Float64(z_m * z_m)) <= 2.0) tmp = Float64(Float64(1.0 - Float64(z_m * z_m)) / Float64(y_m * x_m)); else tmp = Float64(1.0 / Float64(Float64(Float64(z_m * z_m) * y_m) * x_m)); end return Float64(y_s * Float64(x_s * tmp)) end
z_m = abs(z);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp_2 = code(y_s, x_s, x_m, y_m, z_m)
tmp = 0.0;
if ((1.0 + (z_m * z_m)) <= 2.0)
tmp = (1.0 - (z_m * z_m)) / (y_m * x_m);
else
tmp = 1.0 / (((z_m * z_m) * y_m) * x_m);
end
tmp_2 = y_s * (x_s * tmp);
end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * If[LessEqual[N[(1.0 + N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(1.0 - N[(z$95$m * z$95$m), $MachinePrecision]), $MachinePrecision] / N[(y$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(z$95$m * z$95$m), $MachinePrecision] * y$95$m), $MachinePrecision] * x$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \begin{array}{l}
\mathbf{if}\;1 + z\_m \cdot z\_m \leq 2:\\
\;\;\;\;\frac{1 - z\_m \cdot z\_m}{y\_m \cdot x\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(z\_m \cdot z\_m\right) \cdot y\_m\right) \cdot x\_m}\\
\end{array}\right)
\end{array}
if (+.f64 #s(literal 1 binary64) (*.f64 z z)) < 2Initial program 88.2%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
sub-flip-reverseN/A
sub-divN/A
lower-/.f64N/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
*-commutativeN/A
lower-*.f6452.2
Applied rewrites52.2%
if 2 < (+.f64 #s(literal 1 binary64) (*.f64 z z)) Initial program 88.2%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
pow2N/A
lift-*.f6448.5
Applied rewrites48.5%
z_m = (fabs.f64 z) x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) y\_m = (fabs.f64 y) y\_s = (copysign.f64 #s(literal 1 binary64) y) NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function. (FPCore (y_s x_s x_m y_m z_m) :precision binary64 (* y_s (* x_s (/ 1.0 (* y_m x_m)))))
z_m = fabs(z);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
y\_m = fabs(y);
y\_s = copysign(1.0, y);
assert(x_m < y_m && y_m < z_m);
double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
return y_s * (x_s * (1.0 / (y_m * x_m)));
}
z_m = private
x\_m = private
x\_s = private
y\_m = private
y\_s = private
NOTE: x_m, y_m, and z_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(y_s, x_s, x_m, y_m, z_m)
use fmin_fmax_functions
real(8), intent (in) :: y_s
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8), intent (in) :: z_m
code = y_s * (x_s * (1.0d0 / (y_m * x_m)))
end function
z_m = Math.abs(z);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
assert x_m < y_m && y_m < z_m;
public static double code(double y_s, double x_s, double x_m, double y_m, double z_m) {
return y_s * (x_s * (1.0 / (y_m * x_m)));
}
z_m = math.fabs(z) x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) y\_m = math.fabs(y) y\_s = math.copysign(1.0, y) [x_m, y_m, z_m] = sort([x_m, y_m, z_m]) def code(y_s, x_s, x_m, y_m, z_m): return y_s * (x_s * (1.0 / (y_m * x_m)))
z_m = abs(z) x\_m = abs(x) x\_s = copysign(1.0, x) y\_m = abs(y) y\_s = copysign(1.0, y) x_m, y_m, z_m = sort([x_m, y_m, z_m]) function code(y_s, x_s, x_m, y_m, z_m) return Float64(y_s * Float64(x_s * Float64(1.0 / Float64(y_m * x_m)))) end
z_m = abs(z);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x_m, y_m, z_m = num2cell(sort([x_m, y_m, z_m])){:}
function tmp = code(y_s, x_s, x_m, y_m, z_m)
tmp = y_s * (x_s * (1.0 / (y_m * x_m)));
end
z_m = N[Abs[z], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y_m, and z_m should be sorted in increasing order before calling this function.
code[y$95$s_, x$95$s_, x$95$m_, y$95$m_, z$95$m_] := N[(y$95$s * N[(x$95$s * N[(1.0 / N[(y$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
z_m = \left|z\right|
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
[x_m, y_m, z_m] = \mathsf{sort}([x_m, y_m, z_m])\\
\\
y\_s \cdot \left(x\_s \cdot \frac{1}{y\_m \cdot x\_m}\right)
\end{array}
Initial program 88.2%
Taylor expanded in z around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6457.7
Applied rewrites57.7%
herbie shell --seed 2025132
(FPCore (x y z)
:name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"
:precision binary64
(/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))