
(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 10 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 (* y (expm1 z))) t)))
double code(double x, double y, double z, double t) {
return x - (log1p((y * expm1(z))) / t);
}
public static double code(double x, double y, double z, double t) {
return x - (Math.log1p((y * Math.expm1(z))) / t);
}
def code(x, y, z, t): return x - (math.log1p((y * math.expm1(z))) / t)
function code(x, y, z, t) return Float64(x - Float64(log1p(Float64(y * expm1(z))) / t)) end
code[x_, y_, z_, t_] := N[(x - N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}
\end{array}
Initial program 65.1%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.8
Applied rewrites98.8%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- x (/ (log1p (* y z)) t)))
(t_2 (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(if (<= t_2 -5e+282)
t_1
(if (<= t_2 2e-77)
(+ x (/ -1.0 (/ (fma y (* t 0.5) (/ t (expm1 z))) y)))
(if (<= t_2 4e+274) (/ (log1p (* y (expm1 z))) (- t)) t_1)))))
double code(double x, double y, double z, double t) {
double t_1 = x - (log1p((y * z)) / t);
double t_2 = log(((1.0 - y) + (y * exp(z)))) / t;
double tmp;
if (t_2 <= -5e+282) {
tmp = t_1;
} else if (t_2 <= 2e-77) {
tmp = x + (-1.0 / (fma(y, (t * 0.5), (t / expm1(z))) / y));
} else if (t_2 <= 4e+274) {
tmp = log1p((y * expm1(z))) / -t;
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(log1p(Float64(y * z)) / t)) t_2 = Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t) tmp = 0.0 if (t_2 <= -5e+282) tmp = t_1; elseif (t_2 <= 2e-77) tmp = Float64(x + Float64(-1.0 / Float64(fma(y, Float64(t * 0.5), Float64(t / expm1(z))) / y))); elseif (t_2 <= 4e+274) tmp = Float64(log1p(Float64(y * 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[1 + N[(y * z), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+282], t$95$1, If[LessEqual[t$95$2, 2e-77], N[(x + N[(-1.0 / N[(N[(y * N[(t * 0.5), $MachinePrecision] + N[(t / N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 4e+274], N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / (-t)), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{\mathsf{log1p}\left(y \cdot z\right)}{t}\\
t_2 := \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+282}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-77}:\\
\;\;\;\;x + \frac{-1}{\frac{\mathsf{fma}\left(y, t \cdot 0.5, \frac{t}{\mathsf{expm1}\left(z\right)}\right)}{y}}\\
\mathbf{elif}\;t\_2 \leq 4 \cdot 10^{+274}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{-t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) t) < -4.99999999999999978e282 or 3.99999999999999969e274 < (/.f64 (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) t) Initial program 4.6%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.5
Applied rewrites98.5%
Taylor expanded in z around 0
Applied rewrites98.7%
if -4.99999999999999978e282 < (/.f64 (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) t) < 1.9999999999999999e-77Initial program 87.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6475.8
Applied rewrites75.8%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
lower-expm1.f6496.3
Applied rewrites96.3%
if 1.9999999999999999e-77 < (/.f64 (log.f64 (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z)))) t) < 3.99999999999999969e274Initial program 98.7%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f64N/A
lower-neg.f6482.5
Applied rewrites82.5%
Final simplification96.3%
(FPCore (x y z t) :precision binary64 (if (<= (+ (- 1.0 y) (* y (exp z))) 0.0) (- x (/ (log1p (* y z)) t)) (+ x (/ -1.0 (/ (fma y (* t 0.5) (/ t (expm1 z))) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((1.0 - y) + (y * exp(z))) <= 0.0) {
tmp = x - (log1p((y * z)) / t);
} else {
tmp = x + (-1.0 / (fma(y, (t * 0.5), (t / expm1(z))) / y));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(1.0 - y) + Float64(y * exp(z))) <= 0.0) tmp = Float64(x - Float64(log1p(Float64(y * z)) / t)); else tmp = Float64(x + Float64(-1.0 / Float64(fma(y, Float64(t * 0.5), Float64(t / expm1(z))) / y))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(x - N[(N[Log[1 + N[(y * z), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(-1.0 / N[(N[(y * N[(t * 0.5), $MachinePrecision] + N[(t / N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) + y \cdot e^{z} \leq 0:\\
\;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot z\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{-1}{\frac{\mathsf{fma}\left(y, t \cdot 0.5, \frac{t}{\mathsf{expm1}\left(z\right)}\right)}{y}}\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) < 0.0Initial program 1.9%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6499.9
Applied rewrites99.9%
Taylor expanded in z around 0
Applied rewrites99.9%
if 0.0 < (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) Initial program 88.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6473.1
Applied rewrites73.1%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6473.1
Applied rewrites73.1%
Taylor expanded in y around 0
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
metadata-evalN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
distribute-lft-neg-inN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
lower-*.f64N/A
lower-/.f64N/A
lower-expm1.f6490.7
Applied rewrites90.7%
Final simplification93.1%
(FPCore (x y z t) :precision binary64 (if (<= (+ (- 1.0 y) (* y (exp z))) 0.0) (- x (/ (* y z) t)) (- x (* (expm1 z) (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (((1.0 - y) + (y * exp(z))) <= 0.0) {
tmp = x - ((y * z) / t);
} else {
tmp = x - (expm1(z) * (y / t));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (((1.0 - y) + (y * Math.exp(z))) <= 0.0) {
tmp = x - ((y * z) / t);
} else {
tmp = x - (Math.expm1(z) * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((1.0 - y) + (y * math.exp(z))) <= 0.0: tmp = x - ((y * z) / t) else: tmp = x - (math.expm1(z) * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(1.0 - y) + Float64(y * exp(z))) <= 0.0) tmp = Float64(x - Float64(Float64(y * z) / t)); else tmp = Float64(x - Float64(expm1(z) * Float64(y / t))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(x - N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(Exp[z] - 1), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) + y \cdot e^{z} \leq 0:\\
\;\;\;\;x - \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) < 0.0Initial program 1.9%
Taylor expanded in z around 0
lower-*.f6480.2
Applied rewrites80.2%
if 0.0 < (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) Initial program 88.0%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-expm1.f64N/A
lower-/.f6487.7
Applied rewrites87.7%
(FPCore (x y z t) :precision binary64 (if (<= (+ (- 1.0 y) (* y (exp z))) 0.0) (- x (/ (* y z) t)) (fma z (/ y (- t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (((1.0 - y) + (y * exp(z))) <= 0.0) {
tmp = x - ((y * z) / t);
} else {
tmp = fma(z, (y / -t), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(1.0 - y) + Float64(y * exp(z))) <= 0.0) tmp = Float64(x - Float64(Float64(y * z) / t)); else tmp = fma(z, Float64(y / Float64(-t)), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0], N[(x - N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(z * N[(y / (-t)), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 - y\right) + y \cdot e^{z} \leq 0:\\
\;\;\;\;x - \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{-t}, x\right)\\
\end{array}
\end{array}
if (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) < 0.0Initial program 1.9%
Taylor expanded in z around 0
lower-*.f6480.2
Applied rewrites80.2%
if 0.0 < (+.f64 (-.f64 #s(literal 1 binary64) y) (*.f64 y (exp.f64 z))) Initial program 88.0%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.4
Applied rewrites98.4%
Taylor expanded in z around 0
Applied rewrites78.3%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-neg-outN/A
lower-fma.f64N/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6479.3
Applied rewrites79.3%
(FPCore (x y z t) :precision binary64 (if (<= z -5.8e+42) (- x (* (expm1 z) (/ y t))) (- x (/ (log1p (* y z)) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.8e+42) {
tmp = x - (expm1(z) * (y / t));
} else {
tmp = x - (log1p((y * z)) / t);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.8e+42) {
tmp = x - (Math.expm1(z) * (y / t));
} else {
tmp = x - (Math.log1p((y * z)) / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -5.8e+42: tmp = x - (math.expm1(z) * (y / t)) else: tmp = x - (math.log1p((y * z)) / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -5.8e+42) tmp = Float64(x - Float64(expm1(z) * Float64(y / t))); else tmp = Float64(x - Float64(log1p(Float64(y * z)) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.8e+42], N[(x - N[(N[(Exp[z] - 1), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Log[1 + N[(y * z), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{+42}:\\
\;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot z\right)}{t}\\
\end{array}
\end{array}
if z < -5.79999999999999961e42Initial program 84.9%
Taylor expanded in y around 0
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-expm1.f64N/A
lower-/.f6475.9
Applied rewrites75.9%
if -5.79999999999999961e42 < z Initial program 60.1%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.5
Applied rewrites98.5%
Taylor expanded in z around 0
Applied rewrites95.9%
(FPCore (x y z t)
:precision binary64
(if (<= z -0.036)
(- x (/ (log 1.0) t))
(-
x
(/
(*
z
(fma
z
(fma
z
(fma y 0.16666666666666666 (* y (* z 0.041666666666666664)))
(* y 0.5))
y))
t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -0.036) {
tmp = x - (log(1.0) / t);
} else {
tmp = x - ((z * fma(z, fma(z, fma(y, 0.16666666666666666, (y * (z * 0.041666666666666664))), (y * 0.5)), y)) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -0.036) tmp = Float64(x - Float64(log(1.0) / t)); else tmp = Float64(x - Float64(Float64(z * fma(z, fma(z, fma(y, 0.16666666666666666, Float64(y * Float64(z * 0.041666666666666664))), Float64(y * 0.5)), y)) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -0.036], N[(x - N[(N[Log[1.0], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(z * N[(z * N[(z * N[(y * 0.16666666666666666 + N[(y * N[(z * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * 0.5), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.036:\\
\;\;\;\;x - \frac{\log 1}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z \cdot \mathsf{fma}\left(z, \mathsf{fma}\left(z, \mathsf{fma}\left(y, 0.16666666666666666, y \cdot \left(z \cdot 0.041666666666666664\right)\right), y \cdot 0.5\right), y\right)}{t}\\
\end{array}
\end{array}
if z < -0.0359999999999999973Initial program 87.7%
Taylor expanded in y around 0
Applied rewrites60.2%
if -0.0359999999999999973 < z Initial program 57.6%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.4
Applied rewrites98.4%
Taylor expanded in y around 0
lower-*.f64N/A
lower-expm1.f6489.5
Applied rewrites89.5%
Taylor expanded in z around 0
Applied rewrites89.7%
(FPCore (x y z t)
:precision binary64
(if (<= z -4.1e+210)
(+
x
(/ -1.0 (/ (fma -0.5 (/ (* z (* t (- y (* y y)))) (* y y)) (/ t y)) z)))
(- x (/ (* y z) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4.1e+210) {
tmp = x + (-1.0 / (fma(-0.5, ((z * (t * (y - (y * y)))) / (y * y)), (t / y)) / z));
} else {
tmp = x - ((y * z) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -4.1e+210) tmp = Float64(x + Float64(-1.0 / Float64(fma(-0.5, Float64(Float64(z * Float64(t * Float64(y - Float64(y * y)))) / Float64(y * y)), Float64(t / y)) / z))); else tmp = Float64(x - Float64(Float64(y * z) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -4.1e+210], N[(x + N[(-1.0 / N[(N[(-0.5 * N[(N[(z * N[(t * N[(y - N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(t / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.1 \cdot 10^{+210}:\\
\;\;\;\;x + \frac{-1}{\frac{\mathsf{fma}\left(-0.5, \frac{z \cdot \left(t \cdot \left(y - y \cdot y\right)\right)}{y \cdot y}, \frac{t}{y}\right)}{z}}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y \cdot z}{t}\\
\end{array}
\end{array}
if z < -4.10000000000000001e210Initial program 93.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-fma.f6417.6
Applied rewrites17.6%
lift-/.f64N/A
clear-numN/A
lower-/.f64N/A
lower-/.f6417.6
Applied rewrites17.6%
Taylor expanded in z around 0
lower-/.f64N/A
Applied rewrites63.9%
if -4.10000000000000001e210 < z Initial program 63.4%
Taylor expanded in z around 0
lower-*.f6481.1
Applied rewrites81.1%
Final simplification80.1%
(FPCore (x y z t) :precision binary64 (fma z (/ y (- t)) x))
double code(double x, double y, double z, double t) {
return fma(z, (y / -t), x);
}
function code(x, y, z, t) return fma(z, Float64(y / Float64(-t)), x) end
code[x_, y_, z_, t_] := N[(z * N[(y / (-t)), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, \frac{y}{-t}, x\right)
\end{array}
Initial program 65.1%
Taylor expanded in z around inf
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f6498.8
Applied rewrites98.8%
Taylor expanded in z around 0
Applied rewrites84.0%
Taylor expanded in z around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
associate-*r/N/A
distribute-rgt-neg-outN/A
lower-fma.f64N/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6477.3
Applied rewrites77.3%
(FPCore (x y z t) :precision binary64 (* (/ z t) (- y)))
double code(double x, double y, double z, double t) {
return (z / t) * -y;
}
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 = (z / t) * -y
end function
public static double code(double x, double y, double z, double t) {
return (z / t) * -y;
}
def code(x, y, z, t): return (z / t) * -y
function code(x, y, z, t) return Float64(Float64(z / t) * Float64(-y)) end
function tmp = code(x, y, z, t) tmp = (z / t) * -y; end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * (-y)), $MachinePrecision]
\begin{array}{l}
\\
\frac{z}{t} \cdot \left(-y\right)
\end{array}
Initial program 65.1%
Taylor expanded in x around 0
mul-1-negN/A
distribute-neg-frac2N/A
lower-/.f64N/A
sub-negN/A
associate-+l+N/A
*-rgt-identityN/A
cancel-sign-sub-invN/A
distribute-lft-out--N/A
lower-log1p.f64N/A
lower-*.f64N/A
lower-expm1.f64N/A
lower-neg.f6427.7
Applied rewrites27.7%
Taylor expanded in y around 0
Applied rewrites17.5%
Taylor expanded in z around 0
Applied rewrites14.6%
Final simplification14.6%
(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 2024233
(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)))