
(FPCore (x y z t) :precision binary64 (/ x (* (- y z) (- t z))))
double code(double x, double y, double z, double t) {
return x / ((y - z) * (t - 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x / ((y - z) * (t - z))
end function
public static double code(double x, double y, double z, double t) {
return x / ((y - z) * (t - z));
}
def code(x, y, z, t): return x / ((y - z) * (t - z))
function code(x, y, z, t) return Float64(x / Float64(Float64(y - z) * Float64(t - z))) end
function tmp = code(x, y, z, t) tmp = x / ((y - z) * (t - z)); end
code[x_, y_, z_, t_] := N[(x / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (/ x (* (- y z) (- t z))))
double code(double x, double y, double z, double t) {
return x / ((y - z) * (t - 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, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x / ((y - z) * (t - z))
end function
public static double code(double x, double y, double z, double t) {
return x / ((y - z) * (t - z));
}
def code(x, y, z, t): return x / ((y - z) * (t - z))
function code(x, y, z, t) return Float64(x / Float64(Float64(y - z) * Float64(t - z))) end
function tmp = code(x, y, z, t) tmp = x / ((y - z) * (t - z)); end
code[x_, y_, z_, t_] := N[(x / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\end{array}
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z t) :precision binary64 (let* ((t_1 (/ x_m (* (- y z) (- t z))))) (* x_s (if (<= t_1 -2e-294) t_1 (/ (/ x_m (- t z)) (- y z))))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double t_1 = x_m / ((y - z) * (t - z));
double tmp;
if (t_1 <= -2e-294) {
tmp = t_1;
} else {
tmp = (x_m / (t - z)) / (y - z);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = x_m / ((y - z) * (t - z))
if (t_1 <= (-2d-294)) then
tmp = t_1
else
tmp = (x_m / (t - z)) / (y - z)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double t_1 = x_m / ((y - z) * (t - z));
double tmp;
if (t_1 <= -2e-294) {
tmp = t_1;
} else {
tmp = (x_m / (t - z)) / (y - z);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): t_1 = x_m / ((y - z) * (t - z)) tmp = 0 if t_1 <= -2e-294: tmp = t_1 else: tmp = (x_m / (t - z)) / (y - z) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) t_1 = Float64(x_m / Float64(Float64(y - z) * Float64(t - z))) tmp = 0.0 if (t_1 <= -2e-294) tmp = t_1; else tmp = Float64(Float64(x_m / Float64(t - z)) / Float64(y - z)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
t_1 = x_m / ((y - z) * (t - z));
tmp = 0.0;
if (t_1 <= -2e-294)
tmp = t_1;
else
tmp = (x_m / (t - z)) / (y - z);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := Block[{t$95$1 = N[(x$95$m / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$1, -2e-294], t$95$1, N[(N[(x$95$m / N[(t - z), $MachinePrecision]), $MachinePrecision] / N[(y - z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
\begin{array}{l}
t_1 := \frac{x\_m}{\left(y - z\right) \cdot \left(t - z\right)}\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-294}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x\_m}{t - z}}{y - z}\\
\end{array}
\end{array}
\end{array}
if (/.f64 x (*.f64 (-.f64 y z) (-.f64 t z))) < -2.00000000000000003e-294Initial program 99.7%
if -2.00000000000000003e-294 < (/.f64 x (*.f64 (-.f64 y z) (-.f64 t z))) Initial program 85.0%
Applied rewrites97.3%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (<= z -1.7e+181)
(/ (/ x_m z) (+ (- t) z))
(if (<= z 1e+154)
(/ x_m (fma z (- z t) (* (- t z) y)))
(/ (/ x_m z) (+ (- y) z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (z <= -1.7e+181) {
tmp = (x_m / z) / (-t + z);
} else if (z <= 1e+154) {
tmp = x_m / fma(z, (z - t), ((t - z) * y));
} else {
tmp = (x_m / z) / (-y + z);
}
return x_s * tmp;
}
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if (z <= -1.7e+181) tmp = Float64(Float64(x_m / z) / Float64(Float64(-t) + z)); elseif (z <= 1e+154) tmp = Float64(x_m / fma(z, Float64(z - t), Float64(Float64(t - z) * y))); else tmp = Float64(Float64(x_m / z) / Float64(Float64(-y) + z)); end return Float64(x_s * tmp) end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[LessEqual[z, -1.7e+181], N[(N[(x$95$m / z), $MachinePrecision] / N[((-t) + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e+154], N[(x$95$m / N[(z * N[(z - t), $MachinePrecision] + N[(N[(t - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m / z), $MachinePrecision] / N[((-y) + z), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+181}:\\
\;\;\;\;\frac{\frac{x\_m}{z}}{\left(-t\right) + z}\\
\mathbf{elif}\;z \leq 10^{+154}:\\
\;\;\;\;\frac{x\_m}{\mathsf{fma}\left(z, z - t, \left(t - z\right) \cdot y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x\_m}{z}}{\left(-y\right) + z}\\
\end{array}
\end{array}
if z < -1.70000000000000015e181Initial program 73.3%
Taylor expanded in y around 0
mul-1-negN/A
distribute-neg-fracN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
if -1.70000000000000015e181 < z < 1.00000000000000004e154Initial program 92.6%
Applied rewrites92.6%
if 1.00000000000000004e154 < z Initial program 75.1%
Taylor expanded in t around 0
mul-1-negN/A
distribute-neg-fracN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification94.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (or (<= z -1.7e+181) (not (<= z 4.2e+151)))
(/ (/ x_m z) (+ (- t) z))
(/ x_m (* (- y z) (- t z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -1.7e+181) || !(z <= 4.2e+151)) {
tmp = (x_m / z) / (-t + z);
} else {
tmp = x_m / ((y - z) * (t - z));
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-1.7d+181)) .or. (.not. (z <= 4.2d+151))) then
tmp = (x_m / z) / (-t + z)
else
tmp = x_m / ((y - z) * (t - z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -1.7e+181) || !(z <= 4.2e+151)) {
tmp = (x_m / z) / (-t + z);
} else {
tmp = x_m / ((y - z) * (t - z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if (z <= -1.7e+181) or not (z <= 4.2e+151): tmp = (x_m / z) / (-t + z) else: tmp = x_m / ((y - z) * (t - z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if ((z <= -1.7e+181) || !(z <= 4.2e+151)) tmp = Float64(Float64(x_m / z) / Float64(Float64(-t) + z)); else tmp = Float64(x_m / Float64(Float64(y - z) * Float64(t - z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if ((z <= -1.7e+181) || ~((z <= 4.2e+151)))
tmp = (x_m / z) / (-t + z);
else
tmp = x_m / ((y - z) * (t - z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[Or[LessEqual[z, -1.7e+181], N[Not[LessEqual[z, 4.2e+151]], $MachinePrecision]], N[(N[(x$95$m / z), $MachinePrecision] / N[((-t) + z), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+181} \lor \neg \left(z \leq 4.2 \cdot 10^{+151}\right):\\
\;\;\;\;\frac{\frac{x\_m}{z}}{\left(-t\right) + z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{\left(y - z\right) \cdot \left(t - z\right)}\\
\end{array}
\end{array}
if z < -1.70000000000000015e181 or 4.2000000000000001e151 < z Initial program 74.4%
Taylor expanded in y around 0
mul-1-negN/A
distribute-neg-fracN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower--.f6497.5
Applied rewrites97.5%
if -1.70000000000000015e181 < z < 4.2000000000000001e151Initial program 92.6%
Final simplification93.6%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (<= z -1.7e+181)
(/ (/ x_m z) (+ (- t) z))
(if (<= z 1e+154) (/ x_m (* (- y z) (- t z))) (/ (/ x_m z) (+ (- y) z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (z <= -1.7e+181) {
tmp = (x_m / z) / (-t + z);
} else if (z <= 1e+154) {
tmp = x_m / ((y - z) * (t - z));
} else {
tmp = (x_m / z) / (-y + z);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= (-1.7d+181)) then
tmp = (x_m / z) / (-t + z)
else if (z <= 1d+154) then
tmp = x_m / ((y - z) * (t - z))
else
tmp = (x_m / z) / (-y + z)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (z <= -1.7e+181) {
tmp = (x_m / z) / (-t + z);
} else if (z <= 1e+154) {
tmp = x_m / ((y - z) * (t - z));
} else {
tmp = (x_m / z) / (-y + z);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if z <= -1.7e+181: tmp = (x_m / z) / (-t + z) elif z <= 1e+154: tmp = x_m / ((y - z) * (t - z)) else: tmp = (x_m / z) / (-y + z) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if (z <= -1.7e+181) tmp = Float64(Float64(x_m / z) / Float64(Float64(-t) + z)); elseif (z <= 1e+154) tmp = Float64(x_m / Float64(Float64(y - z) * Float64(t - z))); else tmp = Float64(Float64(x_m / z) / Float64(Float64(-y) + z)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if (z <= -1.7e+181)
tmp = (x_m / z) / (-t + z);
elseif (z <= 1e+154)
tmp = x_m / ((y - z) * (t - z));
else
tmp = (x_m / z) / (-y + z);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[LessEqual[z, -1.7e+181], N[(N[(x$95$m / z), $MachinePrecision] / N[((-t) + z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1e+154], N[(x$95$m / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m / z), $MachinePrecision] / N[((-y) + z), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+181}:\\
\;\;\;\;\frac{\frac{x\_m}{z}}{\left(-t\right) + z}\\
\mathbf{elif}\;z \leq 10^{+154}:\\
\;\;\;\;\frac{x\_m}{\left(y - z\right) \cdot \left(t - z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x\_m}{z}}{\left(-y\right) + z}\\
\end{array}
\end{array}
if z < -1.70000000000000015e181Initial program 73.3%
Taylor expanded in y around 0
mul-1-negN/A
distribute-neg-fracN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
if -1.70000000000000015e181 < z < 1.00000000000000004e154Initial program 92.6%
if 1.00000000000000004e154 < z Initial program 75.1%
Taylor expanded in t around 0
mul-1-negN/A
distribute-neg-fracN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-neg.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Final simplification94.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (or (<= z -1.7e+181) (not (<= z 1.35e+154)))
(/ (/ x_m z) z)
(/ x_m (* (- y z) (- t z))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -1.7e+181) || !(z <= 1.35e+154)) {
tmp = (x_m / z) / z;
} else {
tmp = x_m / ((y - z) * (t - z));
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-1.7d+181)) .or. (.not. (z <= 1.35d+154))) then
tmp = (x_m / z) / z
else
tmp = x_m / ((y - z) * (t - z))
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -1.7e+181) || !(z <= 1.35e+154)) {
tmp = (x_m / z) / z;
} else {
tmp = x_m / ((y - z) * (t - z));
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if (z <= -1.7e+181) or not (z <= 1.35e+154): tmp = (x_m / z) / z else: tmp = x_m / ((y - z) * (t - z)) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if ((z <= -1.7e+181) || !(z <= 1.35e+154)) tmp = Float64(Float64(x_m / z) / z); else tmp = Float64(x_m / Float64(Float64(y - z) * Float64(t - z))); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if ((z <= -1.7e+181) || ~((z <= 1.35e+154)))
tmp = (x_m / z) / z;
else
tmp = x_m / ((y - z) * (t - z));
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[Or[LessEqual[z, -1.7e+181], N[Not[LessEqual[z, 1.35e+154]], $MachinePrecision]], N[(N[(x$95$m / z), $MachinePrecision] / z), $MachinePrecision], N[(x$95$m / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{+181} \lor \neg \left(z \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\frac{\frac{x\_m}{z}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{\left(y - z\right) \cdot \left(t - z\right)}\\
\end{array}
\end{array}
if z < -1.70000000000000015e181 or 1.35000000000000003e154 < z Initial program 74.4%
Applied rewrites99.9%
Taylor expanded in z around inf
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6495.8
Applied rewrites95.8%
if -1.70000000000000015e181 < z < 1.35000000000000003e154Initial program 92.6%
Final simplification93.3%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (<= y -7.4e-67)
(/ x_m (* (- t z) y))
(if (<= y 3.5e-17) (/ x_m (* (- z) (- t z))) (/ (/ x_m y) t)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (y <= -7.4e-67) {
tmp = x_m / ((t - z) * y);
} else if (y <= 3.5e-17) {
tmp = x_m / (-z * (t - z));
} else {
tmp = (x_m / y) / t;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-7.4d-67)) then
tmp = x_m / ((t - z) * y)
else if (y <= 3.5d-17) then
tmp = x_m / (-z * (t - z))
else
tmp = (x_m / y) / t
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (y <= -7.4e-67) {
tmp = x_m / ((t - z) * y);
} else if (y <= 3.5e-17) {
tmp = x_m / (-z * (t - z));
} else {
tmp = (x_m / y) / t;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if y <= -7.4e-67: tmp = x_m / ((t - z) * y) elif y <= 3.5e-17: tmp = x_m / (-z * (t - z)) else: tmp = (x_m / y) / t return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if (y <= -7.4e-67) tmp = Float64(x_m / Float64(Float64(t - z) * y)); elseif (y <= 3.5e-17) tmp = Float64(x_m / Float64(Float64(-z) * Float64(t - z))); else tmp = Float64(Float64(x_m / y) / t); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if (y <= -7.4e-67)
tmp = x_m / ((t - z) * y);
elseif (y <= 3.5e-17)
tmp = x_m / (-z * (t - z));
else
tmp = (x_m / y) / t;
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[LessEqual[y, -7.4e-67], N[(x$95$m / N[(N[(t - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.5e-17], N[(x$95$m / N[((-z) * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m / y), $MachinePrecision] / t), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-67}:\\
\;\;\;\;\frac{x\_m}{\left(t - z\right) \cdot y}\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{-17}:\\
\;\;\;\;\frac{x\_m}{\left(-z\right) \cdot \left(t - z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x\_m}{y}}{t}\\
\end{array}
\end{array}
if y < -7.3999999999999999e-67Initial program 88.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.5
Applied rewrites77.5%
if -7.3999999999999999e-67 < y < 3.5000000000000002e-17Initial program 94.7%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6467.9
Applied rewrites67.9%
if 3.5000000000000002e-17 < y Initial program 81.5%
Applied rewrites96.0%
Taylor expanded in z around 0
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6460.8
Applied rewrites60.8%
Final simplification69.1%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (<= y -7.4e-67)
(/ x_m (* (- t z) y))
(if (<= y 2.6e-32) (/ x_m (* (- z) (- t z))) (/ (/ x_m t) y)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (y <= -7.4e-67) {
tmp = x_m / ((t - z) * y);
} else if (y <= 2.6e-32) {
tmp = x_m / (-z * (t - z));
} else {
tmp = (x_m / t) / y;
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= (-7.4d-67)) then
tmp = x_m / ((t - z) * y)
else if (y <= 2.6d-32) then
tmp = x_m / (-z * (t - z))
else
tmp = (x_m / t) / y
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (y <= -7.4e-67) {
tmp = x_m / ((t - z) * y);
} else if (y <= 2.6e-32) {
tmp = x_m / (-z * (t - z));
} else {
tmp = (x_m / t) / y;
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if y <= -7.4e-67: tmp = x_m / ((t - z) * y) elif y <= 2.6e-32: tmp = x_m / (-z * (t - z)) else: tmp = (x_m / t) / y return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if (y <= -7.4e-67) tmp = Float64(x_m / Float64(Float64(t - z) * y)); elseif (y <= 2.6e-32) tmp = Float64(x_m / Float64(Float64(-z) * Float64(t - z))); else tmp = Float64(Float64(x_m / t) / y); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if (y <= -7.4e-67)
tmp = x_m / ((t - z) * y);
elseif (y <= 2.6e-32)
tmp = x_m / (-z * (t - z));
else
tmp = (x_m / t) / y;
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[LessEqual[y, -7.4e-67], N[(x$95$m / N[(N[(t - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.6e-32], N[(x$95$m / N[((-z) * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m / t), $MachinePrecision] / y), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;y \leq -7.4 \cdot 10^{-67}:\\
\;\;\;\;\frac{x\_m}{\left(t - z\right) \cdot y}\\
\mathbf{elif}\;y \leq 2.6 \cdot 10^{-32}:\\
\;\;\;\;\frac{x\_m}{\left(-z\right) \cdot \left(t - z\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x\_m}{t}}{y}\\
\end{array}
\end{array}
if y < -7.3999999999999999e-67Initial program 88.6%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6477.5
Applied rewrites77.5%
if -7.3999999999999999e-67 < y < 2.5999999999999997e-32Initial program 94.4%
Taylor expanded in y around 0
mul-1-negN/A
lower-neg.f6471.3
Applied rewrites71.3%
if 2.5999999999999997e-32 < y Initial program 82.7%
Applied rewrites96.2%
Taylor expanded in t around inf
*-commutativeN/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower--.f6469.2
Applied rewrites69.2%
Taylor expanded in y around inf
Applied rewrites60.2%
Final simplification70.0%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (or (<= z -2.6e-45) (not (<= z 1.9e-27)))
(/ x_m (* z (- z y)))
(/ x_m (* (- t z) y)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -2.6e-45) || !(z <= 1.9e-27)) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / ((t - z) * y);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-2.6d-45)) .or. (.not. (z <= 1.9d-27))) then
tmp = x_m / (z * (z - y))
else
tmp = x_m / ((t - z) * y)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -2.6e-45) || !(z <= 1.9e-27)) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / ((t - z) * y);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if (z <= -2.6e-45) or not (z <= 1.9e-27): tmp = x_m / (z * (z - y)) else: tmp = x_m / ((t - z) * y) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if ((z <= -2.6e-45) || !(z <= 1.9e-27)) tmp = Float64(x_m / Float64(z * Float64(z - y))); else tmp = Float64(x_m / Float64(Float64(t - z) * y)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if ((z <= -2.6e-45) || ~((z <= 1.9e-27)))
tmp = x_m / (z * (z - y));
else
tmp = x_m / ((t - z) * y);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[Or[LessEqual[z, -2.6e-45], N[Not[LessEqual[z, 1.9e-27]], $MachinePrecision]], N[(x$95$m / N[(z * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[(N[(t - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-45} \lor \neg \left(z \leq 1.9 \cdot 10^{-27}\right):\\
\;\;\;\;\frac{x\_m}{z \cdot \left(z - y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{\left(t - z\right) \cdot y}\\
\end{array}
\end{array}
if z < -2.59999999999999987e-45 or 1.9e-27 < z Initial program 86.2%
Taylor expanded in t around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower--.f6472.3
Applied rewrites72.3%
Applied rewrites72.3%
if -2.59999999999999987e-45 < z < 1.9e-27Initial program 92.0%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.3
Applied rewrites82.3%
Final simplification76.7%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (or (<= z -5.7e-58) (not (<= z 8.2e-69)))
(/ x_m (* z (- z y)))
(/ x_m (* t y)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -5.7e-58) || !(z <= 8.2e-69)) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / (t * y);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-5.7d-58)) .or. (.not. (z <= 8.2d-69))) then
tmp = x_m / (z * (z - y))
else
tmp = x_m / (t * y)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -5.7e-58) || !(z <= 8.2e-69)) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / (t * y);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if (z <= -5.7e-58) or not (z <= 8.2e-69): tmp = x_m / (z * (z - y)) else: tmp = x_m / (t * y) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if ((z <= -5.7e-58) || !(z <= 8.2e-69)) tmp = Float64(x_m / Float64(z * Float64(z - y))); else tmp = Float64(x_m / Float64(t * y)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if ((z <= -5.7e-58) || ~((z <= 8.2e-69)))
tmp = x_m / (z * (z - y));
else
tmp = x_m / (t * y);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[Or[LessEqual[z, -5.7e-58], N[Not[LessEqual[z, 8.2e-69]], $MachinePrecision]], N[(x$95$m / N[(z * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[(t * y), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -5.7 \cdot 10^{-58} \lor \neg \left(z \leq 8.2 \cdot 10^{-69}\right):\\
\;\;\;\;\frac{x\_m}{z \cdot \left(z - y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{t \cdot y}\\
\end{array}
\end{array}
if z < -5.70000000000000032e-58 or 8.1999999999999998e-69 < z Initial program 87.0%
Taylor expanded in t around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower--.f6471.4
Applied rewrites71.4%
Applied rewrites71.4%
if -5.70000000000000032e-58 < z < 8.1999999999999998e-69Initial program 91.3%
Taylor expanded in z around 0
lower-*.f6476.5
Applied rewrites76.5%
Final simplification73.5%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (<= t -1.85e-140)
(/ x_m (* (- t z) y))
(if (<= t 2.3e-60) (/ x_m (* z (- z y))) (/ x_m (* (- y z) t))))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (t <= -1.85e-140) {
tmp = x_m / ((t - z) * y);
} else if (t <= 2.3e-60) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / ((y - z) * t);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (t <= (-1.85d-140)) then
tmp = x_m / ((t - z) * y)
else if (t <= 2.3d-60) then
tmp = x_m / (z * (z - y))
else
tmp = x_m / ((y - z) * t)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if (t <= -1.85e-140) {
tmp = x_m / ((t - z) * y);
} else if (t <= 2.3e-60) {
tmp = x_m / (z * (z - y));
} else {
tmp = x_m / ((y - z) * t);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if t <= -1.85e-140: tmp = x_m / ((t - z) * y) elif t <= 2.3e-60: tmp = x_m / (z * (z - y)) else: tmp = x_m / ((y - z) * t) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if (t <= -1.85e-140) tmp = Float64(x_m / Float64(Float64(t - z) * y)); elseif (t <= 2.3e-60) tmp = Float64(x_m / Float64(z * Float64(z - y))); else tmp = Float64(x_m / Float64(Float64(y - z) * t)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if (t <= -1.85e-140)
tmp = x_m / ((t - z) * y);
elseif (t <= 2.3e-60)
tmp = x_m / (z * (z - y));
else
tmp = x_m / ((y - z) * t);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[LessEqual[t, -1.85e-140], N[(x$95$m / N[(N[(t - z), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 2.3e-60], N[(x$95$m / N[(z * N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t \leq -1.85 \cdot 10^{-140}:\\
\;\;\;\;\frac{x\_m}{\left(t - z\right) \cdot y}\\
\mathbf{elif}\;t \leq 2.3 \cdot 10^{-60}:\\
\;\;\;\;\frac{x\_m}{z \cdot \left(z - y\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{\left(y - z\right) \cdot t}\\
\end{array}
\end{array}
if t < -1.84999999999999989e-140Initial program 90.4%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6466.0
Applied rewrites66.0%
if -1.84999999999999989e-140 < t < 2.3000000000000001e-60Initial program 89.8%
Taylor expanded in t around 0
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower--.f6475.6
Applied rewrites75.6%
Applied rewrites75.6%
if 2.3000000000000001e-60 < t Initial program 85.5%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.2
Applied rewrites76.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z t)
:precision binary64
(*
x_s
(if (or (<= z -2.8e-45) (not (<= z 4.6e+80)))
(/ x_m (* z z))
(/ x_m (* t y)))))x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -2.8e-45) || !(z <= 4.6e+80)) {
tmp = x_m / (z * z);
} else {
tmp = x_m / (t * y);
}
return x_s * tmp;
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z <= (-2.8d-45)) .or. (.not. (z <= 4.6d+80))) then
tmp = x_m / (z * z)
else
tmp = x_m / (t * y)
end if
code = x_s * tmp
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
double tmp;
if ((z <= -2.8e-45) || !(z <= 4.6e+80)) {
tmp = x_m / (z * z);
} else {
tmp = x_m / (t * y);
}
return x_s * tmp;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): tmp = 0 if (z <= -2.8e-45) or not (z <= 4.6e+80): tmp = x_m / (z * z) else: tmp = x_m / (t * y) return x_s * tmp
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) tmp = 0.0 if ((z <= -2.8e-45) || !(z <= 4.6e+80)) tmp = Float64(x_m / Float64(z * z)); else tmp = Float64(x_m / Float64(t * y)); end return Float64(x_s * tmp) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp_2 = code(x_s, x_m, y, z, t)
tmp = 0.0;
if ((z <= -2.8e-45) || ~((z <= 4.6e+80)))
tmp = x_m / (z * z);
else
tmp = x_m / (t * y);
end
tmp_2 = x_s * tmp;
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * If[Or[LessEqual[z, -2.8e-45], N[Not[LessEqual[z, 4.6e+80]], $MachinePrecision]], N[(x$95$m / N[(z * z), $MachinePrecision]), $MachinePrecision], N[(x$95$m / N[(t * y), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-45} \lor \neg \left(z \leq 4.6 \cdot 10^{+80}\right):\\
\;\;\;\;\frac{x\_m}{z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x\_m}{t \cdot y}\\
\end{array}
\end{array}
if z < -2.8000000000000001e-45 or 4.60000000000000008e80 < z Initial program 84.1%
Taylor expanded in z around inf
unpow2N/A
lower-*.f6463.0
Applied rewrites63.0%
if -2.8000000000000001e-45 < z < 4.60000000000000008e80Initial program 92.8%
Taylor expanded in z around 0
lower-*.f6466.4
Applied rewrites66.4%
Final simplification64.8%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function. (FPCore (x_s x_m y z t) :precision binary64 (* x_s (/ x_m (* t y))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z && z < t);
double code(double x_s, double x_m, double y, double z, double t) {
return x_s * (x_m / (t * y));
}
x\_m = private
x\_s = private
NOTE: x_m, y, z, and t 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(x_s, x_m, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x_s * (x_m / (t * y))
end function
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y && y < z && z < t;
public static double code(double x_s, double x_m, double y, double z, double t) {
return x_s * (x_m / (t * y));
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) [x_m, y, z, t] = sort([x_m, y, z, t]) def code(x_s, x_m, y, z, t): return x_s * (x_m / (t * y))
x\_m = abs(x) x\_s = copysign(1.0, x) x_m, y, z, t = sort([x_m, y, z, t]) function code(x_s, x_m, y, z, t) return Float64(x_s * Float64(x_m / Float64(t * y))) end
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y, z, t = num2cell(sort([x_m, y, z, t])){:}
function tmp = code(x_s, x_m, y, z, t)
tmp = x_s * (x_m / (t * y));
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, z, and t should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_, t_] := N[(x$95$s * N[(x$95$m / N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z, t] = \mathsf{sort}([x_m, y, z, t])\\
\\
x\_s \cdot \frac{x\_m}{t \cdot y}
\end{array}
Initial program 88.8%
Taylor expanded in z around 0
lower-*.f6446.2
Applied rewrites46.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- y z) (- t z)))) (if (< (/ x t_1) 0.0) (/ (/ x (- y z)) (- t z)) (* x (/ 1.0 t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = (y - z) * (t - z);
double tmp;
if ((x / t_1) < 0.0) {
tmp = (x / (y - z)) / (t - z);
} else {
tmp = x * (1.0 / t_1);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, y, z, t)
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) :: t_1
real(8) :: tmp
t_1 = (y - z) * (t - z)
if ((x / t_1) < 0.0d0) then
tmp = (x / (y - z)) / (t - z)
else
tmp = x * (1.0d0 / t_1)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (y - z) * (t - z);
double tmp;
if ((x / t_1) < 0.0) {
tmp = (x / (y - z)) / (t - z);
} else {
tmp = x * (1.0 / t_1);
}
return tmp;
}
def code(x, y, z, t): t_1 = (y - z) * (t - z) tmp = 0 if (x / t_1) < 0.0: tmp = (x / (y - z)) / (t - z) else: tmp = x * (1.0 / t_1) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(y - z) * Float64(t - z)) tmp = 0.0 if (Float64(x / t_1) < 0.0) tmp = Float64(Float64(x / Float64(y - z)) / Float64(t - z)); else tmp = Float64(x * Float64(1.0 / t_1)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (y - z) * (t - z); tmp = 0.0; if ((x / t_1) < 0.0) tmp = (x / (y - z)) / (t - z); else tmp = x * (1.0 / t_1); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]}, If[Less[N[(x / t$95$1), $MachinePrecision], 0.0], N[(N[(x / N[(y - z), $MachinePrecision]), $MachinePrecision] / N[(t - z), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y - z\right) \cdot \left(t - z\right)\\
\mathbf{if}\;\frac{x}{t\_1} < 0:\\
\;\;\;\;\frac{\frac{x}{y - z}}{t - z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{1}{t\_1}\\
\end{array}
\end{array}
herbie shell --seed 2025017
(FPCore (x y z t)
:name "Data.Random.Distribution.Triangular:triangularCDF from random-fu-0.2.6.2, B"
:precision binary64
:alt
(! :herbie-platform default (if (< (/ x (* (- y z) (- t z))) 0) (/ (/ x (- y z)) (- t z)) (* x (/ 1 (* (- y z) (- t z))))))
(/ x (* (- y z) (- t z))))