
(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);
}
real(8) function code(x, y, z, t)
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 8 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);
}
real(8) function code(x, y, z, t)
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 (- x (/ (log1p (* (expm1 z) y)) t)))
double code(double x, double y, double z, double t) {
return x - (log1p((expm1(z) * y)) / t);
}
public static double code(double x, double y, double z, double t) {
return x - (Math.log1p((Math.expm1(z) * y)) / t);
}
def code(x, y, z, t): return x - (math.log1p((math.expm1(z) * y)) / t)
function code(x, y, z, t) return Float64(x - Float64(log1p(Float64(expm1(z) * y)) / t)) end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[1 + N[(N[(Exp[z] - 1), $MachinePrecision] * y), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\mathsf{log1p}\left(\mathsf{expm1}\left(z\right) \cdot y\right)}{t}
\end{array}
Initial program 54.5%
Taylor expanded in z around inf
associate--l+N/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6498.1
Applied rewrites98.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -8.8e+148) (not (<= y 1.36e+139))) (- x (/ (log (fma z y 1.0)) t)) (- x (* (/ (expm1 z) t) y))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -8.8e+148) || !(y <= 1.36e+139)) {
tmp = x - (log(fma(z, y, 1.0)) / t);
} else {
tmp = x - ((expm1(z) / t) * y);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((y <= -8.8e+148) || !(y <= 1.36e+139)) tmp = Float64(x - Float64(log(fma(z, y, 1.0)) / t)); else tmp = Float64(x - Float64(Float64(expm1(z) / t) * y)); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -8.8e+148], N[Not[LessEqual[y, 1.36e+139]], $MachinePrecision]], N[(x - N[(N[Log[N[(z * y + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+148} \lor \neg \left(y \leq 1.36 \cdot 10^{+139}\right):\\
\;\;\;\;x - \frac{\log \left(\mathsf{fma}\left(z, y, 1\right)\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y\\
\end{array}
\end{array}
if y < -8.7999999999999995e148 or 1.36000000000000004e139 < y Initial program 22.1%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6474.4
Applied rewrites74.4%
if -8.7999999999999995e148 < y < 1.36000000000000004e139Initial program 61.2%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
*-commutativeN/A
lower-*.f64N/A
div-subN/A
lower-/.f64N/A
lower-expm1.f6494.6
Applied rewrites94.6%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (if (<= z -3.8e+50) (- x (/ (log 1.0) t)) (fma (- y) (/ z t) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.8e+50) {
tmp = x - (log(1.0) / t);
} else {
tmp = fma(-y, (z / t), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.8e+50) tmp = Float64(x - Float64(log(1.0) / t)); else tmp = fma(Float64(-y), Float64(z / t), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.8e+50], N[(x - N[(N[Log[1.0], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[((-y) * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{+50}:\\
\;\;\;\;x - \frac{\log 1}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-y, \frac{z}{t}, x\right)\\
\end{array}
\end{array}
if z < -3.79999999999999987e50Initial program 72.4%
Taylor expanded in y around 0
Applied rewrites55.8%
if -3.79999999999999987e50 < z Initial program 49.0%
Taylor expanded in z around inf
associate--l+N/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6497.5
Applied rewrites97.5%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6488.5
Applied rewrites88.5%
(FPCore (x y z t) :precision binary64 (- x (* (/ (expm1 z) t) y)))
double code(double x, double y, double z, double t) {
return x - ((expm1(z) / t) * y);
}
public static double code(double x, double y, double z, double t) {
return x - ((Math.expm1(z) / t) * y);
}
def code(x, y, z, t): return x - ((math.expm1(z) / t) * y)
function code(x, y, z, t) return Float64(x - Float64(Float64(expm1(z) / t) * y)) end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(Exp[z] - 1), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\mathsf{expm1}\left(z\right)}{t} \cdot y
\end{array}
Initial program 54.5%
Taylor expanded in y around 0
associate-/l*N/A
div-subN/A
*-commutativeN/A
lower-*.f64N/A
div-subN/A
lower-/.f64N/A
lower-expm1.f6487.4
Applied rewrites87.4%
(FPCore (x y z t) :precision binary64 (fma (- y) (/ z t) x))
double code(double x, double y, double z, double t) {
return fma(-y, (z / t), x);
}
function code(x, y, z, t) return fma(Float64(-y), Float64(z / t), x) end
code[x_, y_, z_, t_] := N[((-y) * N[(z / t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-y, \frac{z}{t}, x\right)
\end{array}
Initial program 54.5%
Taylor expanded in z around inf
associate--l+N/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6498.1
Applied rewrites98.1%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6474.6
Applied rewrites74.6%
(FPCore (x y z t) :precision binary64 (fma (/ (- y) t) z x))
double code(double x, double y, double z, double t) {
return fma((-y / t), z, x);
}
function code(x, y, z, t) return fma(Float64(Float64(-y) / t), z, x) end
code[x_, y_, z_, t_] := N[(N[((-y) / t), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{-y}{t}, z, x\right)
\end{array}
Initial program 54.5%
Taylor expanded in z around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites62.9%
Taylor expanded in z around 0
Applied rewrites73.4%
(FPCore (x y z t) :precision binary64 (* (- y) (/ z t)))
double code(double x, double y, double z, double t) {
return -y * (z / t);
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = -y * (z / t)
end function
public static double code(double x, double y, double z, double t) {
return -y * (z / t);
}
def code(x, y, z, t): return -y * (z / t)
function code(x, y, z, t) return Float64(Float64(-y) * Float64(z / t)) end
function tmp = code(x, y, z, t) tmp = -y * (z / t); end
code[x_, y_, z_, t_] := N[((-y) * N[(z / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-y\right) \cdot \frac{z}{t}
\end{array}
Initial program 54.5%
Taylor expanded in z around inf
associate--l+N/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6498.1
Applied rewrites98.1%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6474.6
Applied rewrites74.6%
Taylor expanded in x around 0
Applied rewrites18.5%
(FPCore (x y z t) :precision binary64 (* (/ (- y) t) z))
double code(double x, double y, double z, double t) {
return (-y / t) * z;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (-y / t) * z
end function
public static double code(double x, double y, double z, double t) {
return (-y / t) * z;
}
def code(x, y, z, t): return (-y / t) * z
function code(x, y, z, t) return Float64(Float64(Float64(-y) / t) * z) end
function tmp = code(x, y, z, t) tmp = (-y / t) * z; end
code[x_, y_, z_, t_] := N[(N[((-y) / t), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{-y}{t} \cdot z
\end{array}
Initial program 54.5%
Taylor expanded in z around inf
associate--l+N/A
*-rgt-identityN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-expm1.f6498.1
Applied rewrites98.1%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
associate-/l*N/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f64N/A
lower-/.f6474.6
Applied rewrites74.6%
Taylor expanded in x around 0
Applied rewrites18.5%
Applied rewrites17.5%
Final simplification17.5%
(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;
}
real(8) function code(x, y, z, t)
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 2024326
(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)))