
(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}
Sampling outcomes in binary64 precision:
Herbie found 9 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 (log (+ (- 1.0 y) (* y (exp z))))))
(if (<= t_1 (- INFINITY))
(* (- (/ (log1p (* z y)) (* (- t) x)) -1.0) x)
(if (<= t_1 0.0)
(- x (* (fma -0.5 (/ (* (pow (expm1 z) 2.0) y) t) (/ (expm1 z) t)) y))
(- x (/ (log (fma (expm1 z) y 1.0)) t))))))
double code(double x, double y, double z, double t) {
double t_1 = log(((1.0 - y) + (y * exp(z))));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = ((log1p((z * y)) / (-t * x)) - -1.0) * x;
} else if (t_1 <= 0.0) {
tmp = x - (fma(-0.5, ((pow(expm1(z), 2.0) * y) / t), (expm1(z) / t)) * y);
} else {
tmp = x - (log(fma(expm1(z), y, 1.0)) / t);
}
return tmp;
}
function code(x, y, z, t) t_1 = log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64(log1p(Float64(z * y)) / Float64(Float64(-t) * x)) - -1.0) * x); elseif (t_1 <= 0.0) tmp = Float64(x - Float64(fma(-0.5, Float64(Float64((expm1(z) ^ 2.0) * y) / t), Float64(expm1(z) / t)) * y)); else tmp = Float64(x - Float64(log(fma(expm1(z), y, 1.0)) / t)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(N[Log[1 + N[(z * y), $MachinePrecision]], $MachinePrecision] / N[((-t) * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(x - N[(N[(-0.5 * N[(N[(N[Power[N[(Exp[z] - 1), $MachinePrecision], 2.0], $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision] + N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(N[(Exp[z] - 1), $MachinePrecision] * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \log \left(\left(1 - y\right) + y \cdot e^{z}\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\left(\frac{\mathsf{log1p}\left(z \cdot y\right)}{\left(-t\right) \cdot x} - -1\right) \cdot x\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;x - \mathsf{fma}\left(-0.5, \frac{{\left(\mathsf{expm1}\left(z\right)\right)}^{2} \cdot y}{t}, \frac{\mathsf{expm1}\left(z\right)}{t}\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\\
\end{array}
\end{array}
if (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < -inf.0Initial program 2.6%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites52.8%
Taylor expanded in z around 0
*-commutativeN/A
lift-*.f6487.5
Applied rewrites87.5%
if -inf.0 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < 0.0Initial program 80.3%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
associate--l+N/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-expm1.f64N/A
sub-divN/A
lower-/.f64N/A
lower-expm1.f6499.9
Applied rewrites99.9%
if 0.0 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) Initial program 95.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-expm1.f6496.4
Applied rewrites96.4%
Final simplification96.4%
(FPCore (x y z t) :precision binary64 (if (<= (log (+ (- 1.0 y) (* y (exp z)))) 0.0) (- x (/ (* (expm1 z) y) t)) (- x (/ (log (fma (expm1 z) y 1.0)) 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 - ((expm1(z) * y) / t);
} else {
tmp = x - (log(fma(expm1(z), y, 1.0)) / 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(expm1(z) * y) / t)); else tmp = Float64(x - Float64(log(fma(expm1(z), y, 1.0)) / 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[(N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(N[(Exp[z] - 1), $MachinePrecision] * y + 1.0), $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 - \frac{\mathsf{expm1}\left(z\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(\mathsf{expm1}\left(z\right), y, 1\right)\right)}{t}\\
\end{array}
\end{array}
if (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < 0.0Initial program 58.4%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6493.3
Applied rewrites93.3%
if 0.0 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) Initial program 95.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-expm1.f6496.4
Applied rewrites96.4%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (expm1 z) y)))
(if (<= (log (+ (- 1.0 y) (* y (exp z)))) 0.02)
(- x (/ t_1 t))
(- x (/ (log t_1) t)))))
double code(double x, double y, double z, double t) {
double t_1 = expm1(z) * y;
double tmp;
if (log(((1.0 - y) + (y * exp(z)))) <= 0.02) {
tmp = x - (t_1 / t);
} else {
tmp = x - (log(t_1) / t);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = Math.expm1(z) * y;
double tmp;
if (Math.log(((1.0 - y) + (y * Math.exp(z)))) <= 0.02) {
tmp = x - (t_1 / t);
} else {
tmp = x - (Math.log(t_1) / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = math.expm1(z) * y tmp = 0 if math.log(((1.0 - y) + (y * math.exp(z)))) <= 0.02: tmp = x - (t_1 / t) else: tmp = x - (math.log(t_1) / t) return tmp
function code(x, y, z, t) t_1 = Float64(expm1(z) * y) tmp = 0.0 if (log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) <= 0.02) tmp = Float64(x - Float64(t_1 / t)); else tmp = Float64(x - Float64(log(t_1) / t)); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.02], N[(x - N[(t$95$1 / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[t$95$1], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{expm1}\left(z\right) \cdot y\\
\mathbf{if}\;\log \left(\left(1 - y\right) + y \cdot e^{z}\right) \leq 0.02:\\
\;\;\;\;x - \frac{t\_1}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log t\_1}{t}\\
\end{array}
\end{array}
if (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < 0.0200000000000000004Initial program 58.7%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6492.8
Applied rewrites92.8%
if 0.0200000000000000004 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) Initial program 95.8%
Taylor expanded in y around inf
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6496.5
Applied rewrites96.5%
(FPCore (x y z t) :precision binary64 (if (<= (log (+ (- 1.0 y) (* y (exp z)))) 150.0) (- x (/ (* (expm1 z) y) t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if (log(((1.0 - y) + (y * exp(z)))) <= 150.0) {
tmp = x - ((expm1(z) * y) / t);
} else {
tmp = x;
}
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)))) <= 150.0) {
tmp = x - ((Math.expm1(z) * y) / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if math.log(((1.0 - y) + (y * math.exp(z)))) <= 150.0: tmp = x - ((math.expm1(z) * y) / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) <= 150.0) tmp = Float64(x - Float64(Float64(expm1(z) * y) / t)); else tmp = x; 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], 150.0], N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(\left(1 - y\right) + y \cdot e^{z}\right) \leq 150:\\
\;\;\;\;x - \frac{\mathsf{expm1}\left(z\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) < 150Initial program 59.5%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6491.3
Applied rewrites91.3%
if 150 < (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) Initial program 95.2%
Taylor expanded in x around inf
Applied rewrites40.3%
(FPCore (x y z t) :precision binary64 (if (<= z -2.8e-181) (* (- (/ (log1p (* (expm1 z) y)) (* (- t) x)) -1.0) x) (- x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.8e-181) {
tmp = ((log1p((expm1(z) * y)) / (-t * x)) - -1.0) * x;
} else {
tmp = x - (y * (z / t));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -2.8e-181) {
tmp = ((Math.log1p((Math.expm1(z) * y)) / (-t * x)) - -1.0) * x;
} else {
tmp = x - (y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -2.8e-181: tmp = ((math.log1p((math.expm1(z) * y)) / (-t * x)) - -1.0) * x else: tmp = x - (y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -2.8e-181) tmp = Float64(Float64(Float64(log1p(Float64(expm1(z) * y)) / Float64(Float64(-t) * x)) - -1.0) * x); else tmp = Float64(x - Float64(y * Float64(z / t))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -2.8e-181], N[(N[(N[(N[Log[1 + N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] / N[((-t) * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision], N[(x - N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-181}:\\
\;\;\;\;\left(\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}{\left(-t\right) \cdot x} - -1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if z < -2.79999999999999986e-181Initial program 72.6%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.6%
Taylor expanded in y around 0
*-commutativeN/A
lift-expm1.f64N/A
lift-*.f6490.9
Applied rewrites90.9%
if -2.79999999999999986e-181 < z Initial program 55.1%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6492.8
Applied rewrites92.8%
Taylor expanded in z around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f6496.1
Applied rewrites96.1%
Final simplification93.7%
(FPCore (x y z t) :precision binary64 (if (or (<= y -2.5e+69) (not (<= y 5.1e+85))) (* (- (/ (log1p (* (/ 1.0 (/ (fma -0.5 z 1.0) z)) y)) (* (- t) x)) -1.0) x) (- x (/ (* (expm1 z) y) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -2.5e+69) || !(y <= 5.1e+85)) {
tmp = ((log1p(((1.0 / (fma(-0.5, z, 1.0) / z)) * y)) / (-t * x)) - -1.0) * x;
} else {
tmp = x - ((expm1(z) * y) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -2.5e+69) || !(y <= 5.1e+85)) tmp = Float64(Float64(Float64(log1p(Float64(Float64(1.0 / Float64(fma(-0.5, z, 1.0) / z)) * y)) / Float64(Float64(-t) * x)) - -1.0) * x); else tmp = Float64(x - Float64(Float64(expm1(z) * y) / t)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -2.5e+69], N[Not[LessEqual[y, 5.1e+85]], $MachinePrecision]], N[(N[(N[(N[Log[1 + N[(N[(1.0 / N[(N[(-0.5 * z + 1.0), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] / N[((-t) * x), $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] * x), $MachinePrecision], N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+69} \lor \neg \left(y \leq 5.1 \cdot 10^{+85}\right):\\
\;\;\;\;\left(\frac{\mathsf{log1p}\left(\frac{1}{\frac{\mathsf{fma}\left(-0.5, z, 1\right)}{z}} \cdot y\right)}{\left(-t\right) \cdot x} - -1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{expm1}\left(z\right) \cdot y}{t}\\
\end{array}
\end{array}
if y < -2.50000000000000018e69 or 5.0999999999999998e85 < y Initial program 36.9%
Taylor expanded in x around -inf
mul-1-negN/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites61.6%
Taylor expanded in y around 0
*-commutativeN/A
lift-expm1.f64N/A
lift-*.f6488.9
Applied rewrites88.9%
lift-expm1.f64N/A
unpow1N/A
metadata-evalN/A
pow-negN/A
lower-/.f64N/A
lower-pow.f64N/A
lift-expm1.f6488.9
Applied rewrites88.9%
Taylor expanded in z around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f6478.3
Applied rewrites78.3%
if -2.50000000000000018e69 < y < 5.0999999999999998e85Initial program 72.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6494.4
Applied rewrites94.4%
Final simplification90.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.8e-240) (not (<= x 2.4e-231))) x (- (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.8e-240) || !(x <= 2.4e-231)) {
tmp = x;
} else {
tmp = -(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 ((x <= (-2.8d-240)) .or. (.not. (x <= 2.4d-231))) then
tmp = x
else
tmp = -(y * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.8e-240) || !(x <= 2.4e-231)) {
tmp = x;
} else {
tmp = -(y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.8e-240) or not (x <= 2.4e-231): tmp = x else: tmp = -(y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -2.8e-240) || !(x <= 2.4e-231)) tmp = x; else tmp = Float64(-Float64(y * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -2.8e-240) || ~((x <= 2.4e-231))) tmp = x; else tmp = -(y * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -2.8e-240], N[Not[LessEqual[x, 2.4e-231]], $MachinePrecision]], x, (-N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.8 \cdot 10^{-240} \lor \neg \left(x \leq 2.4 \cdot 10^{-231}\right):\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if x < -2.7999999999999999e-240 or 2.39999999999999992e-231 < x Initial program 66.0%
Taylor expanded in x around inf
Applied rewrites72.6%
if -2.7999999999999999e-240 < x < 2.39999999999999992e-231Initial program 30.8%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-log1p.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift-exp.f6418.6
Applied rewrites18.6%
Taylor expanded in z around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f6468.2
Applied rewrites68.2%
Final simplification72.2%
(FPCore (x y z t) :precision binary64 (if (<= z -8200000.0) x (- x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -8200000.0) {
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 <= (-8200000.0d0)) 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 <= -8200000.0) {
tmp = x;
} else {
tmp = x - (y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -8200000.0: tmp = x else: tmp = x - (y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -8200000.0) tmp = x; else tmp = Float64(x - Float64(y * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -8200000.0) tmp = x; else tmp = x - (y * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -8200000.0], x, N[(x - N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8200000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if z < -8.2e6Initial program 86.7%
Taylor expanded in x around inf
Applied rewrites56.0%
if -8.2e6 < z Initial program 54.9%
Taylor expanded in y around 0
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6491.1
Applied rewrites91.1%
Taylor expanded in z around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f6494.0
Applied rewrites94.0%
Final simplification84.2%
(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 63.1%
Taylor expanded in x around inf
Applied rewrites68.1%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (- 0.5) (* y t))))
(if (< z -2.8874623088207947e+119)
(- (- x (/ t_1 (* z z))) (* t_1 (/ (/ 2.0 z) (* z z))))
(- x (/ (log (+ 1.0 (* z y))) t)))))
double code(double x, double y, double z, double t) {
double t_1 = -0.5 / (y * t);
double tmp;
if (z < -2.8874623088207947e+119) {
tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)));
} else {
tmp = x - (log((1.0 + (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) :: t_1
real(8) :: tmp
t_1 = -0.5d0 / (y * t)
if (z < (-2.8874623088207947d+119)) then
tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0d0 / z) / (z * z)))
else
tmp = x - (log((1.0d0 + (z * y))) / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = -0.5 / (y * t);
double tmp;
if (z < -2.8874623088207947e+119) {
tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z)));
} else {
tmp = x - (Math.log((1.0 + (z * y))) / t);
}
return tmp;
}
def code(x, y, z, t): t_1 = -0.5 / (y * t) tmp = 0 if z < -2.8874623088207947e+119: tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z))) else: tmp = x - (math.log((1.0 + (z * y))) / t) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(-0.5) / Float64(y * t)) tmp = 0.0 if (z < -2.8874623088207947e+119) tmp = Float64(Float64(x - Float64(t_1 / Float64(z * z))) - Float64(t_1 * Float64(Float64(2.0 / z) / Float64(z * z)))); else tmp = Float64(x - Float64(log(Float64(1.0 + Float64(z * y))) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = -0.5 / (y * t); tmp = 0.0; if (z < -2.8874623088207947e+119) tmp = (x - (t_1 / (z * z))) - (t_1 * ((2.0 / z) / (z * z))); else tmp = x - (log((1.0 + (z * y))) / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-0.5) / N[(y * t), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -2.8874623088207947e+119], N[(N[(x - N[(t$95$1 / N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t$95$1 * N[(N[(2.0 / z), $MachinePrecision] / N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[N[(1.0 + N[(z * y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{-0.5}{y \cdot t}\\
\mathbf{if}\;z < -2.8874623088207947 \cdot 10^{+119}:\\
\;\;\;\;\left(x - \frac{t\_1}{z \cdot z}\right) - t\_1 \cdot \frac{\frac{2}{z}}{z \cdot z}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\log \left(1 + z \cdot y\right)}{t}\\
\end{array}
\end{array}
herbie shell --seed 2025051
(FPCore (x y z t)
:name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
:precision binary64
:alt
(! :herbie-platform default (if (< z -288746230882079470000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (- x (/ (/ (- 1/2) (* y t)) (* z z))) (* (/ (- 1/2) (* y t)) (/ (/ 2 z) (* z z)))) (- x (/ (log (+ 1 (* z y))) t))))
(- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))