
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
double code(double x, double y, double z, double t) {
return x - (log(((1.0 - y) + (y * exp(z)))) / t);
}
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 - (log(((1.0d0 - y) + (y * exp(z)))) / t)
end function
public static double code(double x, double y, double z, double t) {
return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
def code(x, y, z, t): return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
function code(x, y, z, t) return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)) end
function tmp = code(x, y, z, t) tmp = x - (log(((1.0 - y) + (y * exp(z)))) / t); end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\end{array}
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
double code(double x, double y, double z, double t) {
return x - (log(((1.0 - y) + (y * exp(z)))) / t);
}
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 - (log(((1.0d0 - y) + (y * exp(z)))) / t)
end function
public static double code(double x, double y, double z, double t) {
return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
def code(x, y, z, t): return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
function code(x, y, z, t) return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)) end
function tmp = code(x, y, z, t) tmp = x - (log(((1.0 - y) + (y * exp(z)))) / t); end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log (fma (expm1 z) y 1.0)) t))))
(if (<= y -9.5e+43)
t_1
(if (<= y 3.35e+127)
(fma
(fma (/ (* (* (expm1 z) (expm1 z)) y) t) 0.5 (/ (expm1 z) (- t)))
y
x)
t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (log(fma(expm1(z), y, 1.0)) / t);
double tmp;
if (y <= -9.5e+43) {
tmp = t_1;
} else if (y <= 3.35e+127) {
tmp = fma(fma((((expm1(z) * expm1(z)) * y) / t), 0.5, (expm1(z) / -t)), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(log(fma(expm1(z), y, 1.0)) / t)) tmp = 0.0 if (y <= -9.5e+43) tmp = t_1; elseif (y <= 3.35e+127) tmp = fma(fma(Float64(Float64(Float64(expm1(z) * expm1(z)) * y) / t), 0.5, Float64(expm1(z) / Float64(-t))), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[Log[N[(N[(Exp[z] - 1), $MachinePrecision] * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -9.5e+43], t$95$1, If[LessEqual[y, 3.35e+127], N[(N[(N[(N[(N[(N[(Exp[z] - 1), $MachinePrecision] * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision] * 0.5 + N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\\
\mathbf{if}\;y \leq -9.5 \cdot 10^{+43}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\frac{\left(\mathsf{expm1}\left(z\right) \cdot \mathsf{expm1}\left(z\right)\right) \cdot y}{t}, 0.5, \frac{\mathsf{expm1}\left(z\right)}{-t}\right), y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -9.5000000000000004e43 or 3.3499999999999998e127 < y Initial program 36.2%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-expm1.f6486.6
Applied rewrites86.6%
if -9.5000000000000004e43 < y < 3.3499999999999998e127Initial program 72.5%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites97.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log (fma (expm1 z) y 1.0)) t))))
(if (<= y -95.0)
t_1
(if (<= y 3.35e+127) (- x (* (- y) (/ (expm1 z) (- t)))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (log(fma(expm1(z), y, 1.0)) / t);
double tmp;
if (y <= -95.0) {
tmp = t_1;
} else if (y <= 3.35e+127) {
tmp = x - (-y * (expm1(z) / -t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(log(fma(expm1(z), y, 1.0)) / t)) tmp = 0.0 if (y <= -95.0) tmp = t_1; elseif (y <= 3.35e+127) tmp = Float64(x - Float64(Float64(-y) * Float64(expm1(z) / Float64(-t)))); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[Log[N[(N[(Exp[z] - 1), $MachinePrecision] * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -95.0], t$95$1, If[LessEqual[y, 3.35e+127], N[(x - N[((-y) * N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\\
\mathbf{if}\;y \leq -95:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+127}:\\
\;\;\;\;x - \left(-y\right) \cdot \frac{\mathsf{expm1}\left(z\right)}{-t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -95 or 3.3499999999999998e127 < y Initial program 38.3%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-expm1.f6485.8
Applied rewrites85.8%
if -95 < y < 3.3499999999999998e127Initial program 73.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6498.2
Applied rewrites98.2%
lift-fma.f64N/A
lift-/.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
*-commutativeN/A
distribute-frac-neg2N/A
sub-divN/A
sub-negate-revN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sub-negate-revN/A
sub-divN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
lift-/.f6498.2
Applied rewrites98.2%
(FPCore (x y z t) :precision binary64 (if (<= (log (+ (- 1.0 y) (* y (exp z)))) 0.0) (- x (* (- y) (/ (expm1 z) (- t)))) (- x (/ (log (* (expm1 z) y)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (log(((1.0 - y) + (y * exp(z)))) <= 0.0) {
tmp = x - (-y * (expm1(z) / -t));
} else {
tmp = x - (log((expm1(z) * y)) / t);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (Math.log(((1.0 - y) + (y * Math.exp(z)))) <= 0.0) {
tmp = x - (-y * (Math.expm1(z) / -t));
} else {
tmp = x - (Math.log((Math.expm1(z) * y)) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if math.log(((1.0 - y) + (y * math.exp(z)))) <= 0.0: tmp = x - (-y * (math.expm1(z) / -t)) else: tmp = x - (math.log((math.expm1(z) * y)) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) <= 0.0) tmp = Float64(x - Float64(Float64(-y) * Float64(expm1(z) / Float64(-t)))); else tmp = Float64(x - Float64(log(Float64(expm1(z) * y)) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(x - N[((-y) * N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(\left(1 - y\right) + y \cdot e^{z}\right) \leq 0:\\
\;\;\;\;x - \left(-y\right) \cdot \frac{\mathsf{expm1}\left(z\right)}{-t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(\mathsf{expm1}\left(z\right) \cdot y\right)}{t}\\
\end{array}
\end{array}
if (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < 0.0Initial program 57.3%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6493.0
Applied rewrites93.0%
lift-fma.f64N/A
lift-/.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
*-commutativeN/A
distribute-frac-neg2N/A
sub-divN/A
sub-negate-revN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sub-negate-revN/A
sub-divN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
lift-/.f6493.0
Applied rewrites93.0%
if 0.0 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) Initial program 94.7%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6493.0
Applied rewrites93.0%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (log (fma z y 1.0))))
(if (<= y -7e+84)
(- x (* t_1 (/ 1.0 t)))
(if (<= y 3.35e+127)
(- x (* (- y) (/ (expm1 z) (- t))))
(- x (/ t_1 t))))))
double code(double x, double y, double z, double t) {
double t_1 = log(fma(z, y, 1.0));
double tmp;
if (y <= -7e+84) {
tmp = x - (t_1 * (1.0 / t));
} else if (y <= 3.35e+127) {
tmp = x - (-y * (expm1(z) / -t));
} else {
tmp = x - (t_1 / t);
}
return tmp;
}
function code(x, y, z, t) t_1 = log(fma(z, y, 1.0)) tmp = 0.0 if (y <= -7e+84) tmp = Float64(x - Float64(t_1 * Float64(1.0 / t))); elseif (y <= 3.35e+127) tmp = Float64(x - Float64(Float64(-y) * Float64(expm1(z) / Float64(-t)))); else tmp = Float64(x - Float64(t_1 / t)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Log[N[(z * y + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[y, -7e+84], N[(x - N[(t$95$1 * N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.35e+127], N[(x - N[((-y) * N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(t$95$1 / t), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log \left(\mathsf{fma}\left(z, y, 1\right)\right)\\
\mathbf{if}\;y \leq -7 \cdot 10^{+84}:\\
\;\;\;\;x - t\_1 \cdot \frac{1}{t}\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+127}:\\
\;\;\;\;x - \left(-y\right) \cdot \frac{\mathsf{expm1}\left(z\right)}{-t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{t\_1}{t}\\
\end{array}
\end{array}
if y < -6.9999999999999998e84Initial program 49.2%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6455.0
Applied rewrites55.0%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lower-/.f6455.0
Applied rewrites55.0%
if -6.9999999999999998e84 < y < 3.3499999999999998e127Initial program 70.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6496.2
Applied rewrites96.2%
lift-fma.f64N/A
lift-/.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
*-commutativeN/A
distribute-frac-neg2N/A
sub-divN/A
sub-negate-revN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sub-negate-revN/A
sub-divN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
lift-/.f6496.2
Applied rewrites96.2%
if 3.3499999999999998e127 < y Initial program 7.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6483.4
Applied rewrites83.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log (fma z y 1.0)) t))))
(if (<= y -7e+84)
t_1
(if (<= y 3.35e+127) (- x (* (- y) (/ (expm1 z) (- t)))) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (log(fma(z, y, 1.0)) / t);
double tmp;
if (y <= -7e+84) {
tmp = t_1;
} else if (y <= 3.35e+127) {
tmp = x - (-y * (expm1(z) / -t));
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(log(fma(z, y, 1.0)) / t)) tmp = 0.0 if (y <= -7e+84) tmp = t_1; elseif (y <= 3.35e+127) tmp = Float64(x - Float64(Float64(-y) * Float64(expm1(z) / Float64(-t)))); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[Log[N[(z * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e+84], t$95$1, If[LessEqual[y, 3.35e+127], N[(x - N[((-y) * N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{\log \left(\mathsf{fma}\left(z, y, 1\right)\right)}{t}\\
\mathbf{if}\;y \leq -7 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+127}:\\
\;\;\;\;x - \left(-y\right) \cdot \frac{\mathsf{expm1}\left(z\right)}{-t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.9999999999999998e84 or 3.3499999999999998e127 < y Initial program 35.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6464.1
Applied rewrites64.1%
if -6.9999999999999998e84 < y < 3.3499999999999998e127Initial program 70.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6496.2
Applied rewrites96.2%
lift-fma.f64N/A
lift-/.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
*-commutativeN/A
distribute-frac-neg2N/A
sub-divN/A
sub-negate-revN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sub-negate-revN/A
sub-divN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
lift-/.f6496.2
Applied rewrites96.2%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log (fma z y 1.0)) t))))
(if (<= y -7e+84)
t_1
(if (<= y 3.35e+127) (fma (/ (expm1 z) (- t)) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - (log(fma(z, y, 1.0)) / t);
double tmp;
if (y <= -7e+84) {
tmp = t_1;
} else if (y <= 3.35e+127) {
tmp = fma((expm1(z) / -t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(log(fma(z, y, 1.0)) / t)) tmp = 0.0 if (y <= -7e+84) tmp = t_1; elseif (y <= 3.35e+127) tmp = fma(Float64(expm1(z) / Float64(-t)), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(N[Log[N[(z * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7e+84], t$95$1, If[LessEqual[y, 3.35e+127], N[(N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{\log \left(\mathsf{fma}\left(z, y, 1\right)\right)}{t}\\
\mathbf{if}\;y \leq -7 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.35 \cdot 10^{+127}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{expm1}\left(z\right)}{-t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -6.9999999999999998e84 or 3.3499999999999998e127 < y Initial program 35.8%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6464.1
Applied rewrites64.1%
if -6.9999999999999998e84 < y < 3.3499999999999998e127Initial program 70.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6496.2
Applied rewrites96.2%
(FPCore (x y z t) :precision binary64 (if (<= y 8e+166) (fma (/ (expm1 z) (- t)) y x) (- x (/ (log (* z y)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8e+166) {
tmp = fma((expm1(z) / -t), y, x);
} else {
tmp = x - (log((z * y)) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 8e+166) tmp = fma(Float64(expm1(z) / Float64(-t)), y, x); else tmp = Float64(x - Float64(log(Float64(z * y)) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 8e+166], N[(N[(N[(Exp[z] - 1), $MachinePrecision] / (-t)), $MachinePrecision] * y + x), $MachinePrecision], N[(x - N[(N[Log[N[(z * y), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\mathsf{expm1}\left(z\right)}{-t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(z \cdot y\right)}{t}\\
\end{array}
\end{array}
if y < 7.99999999999999952e166Initial program 65.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6487.8
Applied rewrites87.8%
if 7.99999999999999952e166 < y Initial program 7.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.8
Applied rewrites85.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
(FPCore (x y z t) :precision binary64 (if (<= y 8e+166) (- x (/ (* (expm1 z) y) t)) (- x (/ (log (* z y)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8e+166) {
tmp = x - ((expm1(z) * y) / t);
} else {
tmp = x - (log((z * y)) / t);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8e+166) {
tmp = x - ((Math.expm1(z) * y) / t);
} else {
tmp = x - (Math.log((z * y)) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 8e+166: tmp = x - ((math.expm1(z) * y) / t) else: tmp = x - (math.log((z * y)) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 8e+166) tmp = Float64(x - Float64(Float64(expm1(z) * y) / t)); else tmp = Float64(x - Float64(log(Float64(z * y)) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 8e+166], N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(z * y), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8 \cdot 10^{+166}:\\
\;\;\;\;x - \frac{\mathsf{expm1}\left(z\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(z \cdot y\right)}{t}\\
\end{array}
\end{array}
if y < 7.99999999999999952e166Initial program 65.8%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6486.8
Applied rewrites86.8%
if 7.99999999999999952e166 < y Initial program 7.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6485.8
Applied rewrites85.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f6471.2
Applied rewrites71.2%
(FPCore (x y z t) :precision binary64 (if (<= z -0.000225) x (+ x (* y (/ z (- t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.000225) {
tmp = x;
} else {
tmp = x + (y * (z / -t));
}
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) :: tmp
if (z <= (-0.000225d0)) then
tmp = x
else
tmp = x + (y * (z / -t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.000225) {
tmp = x;
} else {
tmp = x + (y * (z / -t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -0.000225: tmp = x else: tmp = x + (y * (z / -t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -0.000225) tmp = x; else tmp = Float64(x + Float64(y * Float64(z / Float64(-t)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -0.000225) tmp = x; else tmp = x + (y * (z / -t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -0.000225], x, N[(x + N[(y * N[(z / (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000225:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z}{-t}\\
\end{array}
\end{array}
if z < -2.2499999999999999e-4Initial program 82.0%
Taylor expanded in x around inf
Applied rewrites63.1%
if -2.2499999999999999e-4 < z Initial program 53.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6489.7
Applied rewrites89.7%
lift-fma.f64N/A
lift-/.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
*-commutativeN/A
distribute-frac-neg2N/A
sub-divN/A
sub-negate-revN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
lower--.f64N/A
sub-negate-revN/A
sub-divN/A
distribute-frac-neg2N/A
lower-*.f64N/A
lower-neg.f64N/A
lift-expm1.f64N/A
lift-neg.f64N/A
lift-/.f6489.7
Applied rewrites89.7%
Taylor expanded in z around 0
Applied rewrites89.7%
lift--.f64N/A
lift-*.f64N/A
lift-neg.f64N/A
fp-cancel-sign-subN/A
lower-+.f64N/A
lower-*.f6489.7
Applied rewrites89.7%
(FPCore (x y z t) :precision binary64 (if (<= z -0.000225) x (fma (/ z (- t)) y x)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.000225) {
tmp = x;
} else {
tmp = fma((z / -t), y, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -0.000225) tmp = x; else tmp = fma(Float64(z / Float64(-t)), y, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -0.000225], x, N[(N[(z / (-t)), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000225:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{-t}, y, x\right)\\
\end{array}
\end{array}
if z < -2.2499999999999999e-4Initial program 82.0%
Taylor expanded in x around inf
Applied rewrites63.1%
if -2.2499999999999999e-4 < z Initial program 53.6%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-divN/A
frac-2negN/A
sub-negate-revN/A
lower-/.f64N/A
lower-expm1.f64N/A
lower-neg.f6489.7
Applied rewrites89.7%
Taylor expanded in z around 0
Applied rewrites89.7%
(FPCore (x y z t) :precision binary64 (if (<= z -0.000225) x (- x (/ (* z y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.000225) {
tmp = x;
} else {
tmp = x - ((z * y) / t);
}
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) :: tmp
if (z <= (-0.000225d0)) then
tmp = x
else
tmp = x - ((z * y) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.000225) {
tmp = x;
} else {
tmp = x - ((z * y) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -0.000225: tmp = x else: tmp = x - ((z * y) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -0.000225) tmp = x; else tmp = Float64(x - Float64(Float64(z * y) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -0.000225) tmp = x; else tmp = x - ((z * y) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -0.000225], x, N[(x - N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000225:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot y}{t}\\
\end{array}
\end{array}
if z < -2.2499999999999999e-4Initial program 82.0%
Taylor expanded in x around inf
Applied rewrites63.1%
if -2.2499999999999999e-4 < z Initial program 53.6%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f6488.4
Applied rewrites88.4%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 62.2%
Taylor expanded in x around inf
Applied rewrites71.1%
herbie shell --seed 2025128
(FPCore (x y z t)
:name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
:precision binary64
(- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))