| Alternative 1 | |
|---|---|
| Error | 10.95% |
| Cost | 7232 |
\[x - \frac{1}{\frac{t}{y \cdot \mathsf{expm1}\left(z\right)} + t \cdot 0.5}
\]
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t) :precision binary64 (if (or (<= y -7.2e-8) (not (<= y 5e-77))) (- x (/ (log1p (* y (expm1 z))) t)) (- x (* (expm1 z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - (log(((1.0 - y) + (y * exp(z)))) / t);
}
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.2e-8) || !(y <= 5e-77)) {
tmp = x - (log1p((y * expm1(z))) / t);
} else {
tmp = x - (expm1(z) * (y / t));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return x - (Math.log(((1.0 - y) + (y * Math.exp(z)))) / t);
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -7.2e-8) || !(y <= 5e-77)) {
tmp = x - (Math.log1p((y * Math.expm1(z))) / t);
} else {
tmp = x - (Math.expm1(z) * (y / t));
}
return tmp;
}
def code(x, y, z, t): return x - (math.log(((1.0 - y) + (y * math.exp(z)))) / t)
def code(x, y, z, t): tmp = 0 if (y <= -7.2e-8) or not (y <= 5e-77): tmp = x - (math.log1p((y * math.expm1(z))) / t) else: tmp = x - (math.expm1(z) * (y / t)) return tmp
function code(x, y, z, t) return Float64(x - Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t)) end
function code(x, y, z, t) tmp = 0.0 if ((y <= -7.2e-8) || !(y <= 5e-77)) tmp = Float64(x - Float64(log1p(Float64(y * expm1(z))) / t)); else tmp = Float64(x - Float64(expm1(z) * Float64(y / t))); end return tmp 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]
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -7.2e-8], N[Not[LessEqual[y, 5e-77]], $MachinePrecision]], N[(x - N[(N[Log[1 + N[(y * N[(Exp[z] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x - N[(N[(Exp[z] - 1), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-8} \lor \neg \left(y \leq 5 \cdot 10^{-77}\right):\\
\;\;\;\;x - \frac{\mathsf{log1p}\left(y \cdot \mathsf{expm1}\left(z\right)\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \mathsf{expm1}\left(z\right) \cdot \frac{y}{t}\\
\end{array}
Results
| Original | 39.45% |
|---|---|
| Target | 25.39% |
| Herbie | 0.49% |
if y < -7.19999999999999962e-8 or 4.99999999999999963e-77 < y Initial program 62.68
Simplified0.72
[Start]62.68 | \[ x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\] |
|---|---|
*-lft-identity [<=]62.68 | \[ \color{blue}{1 \cdot \left(x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\right)}
\] |
distribute-lft-out-- [<=]62.68 | \[ \color{blue}{1 \cdot x - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}}
\] |
*-lft-identity [=>]62.68 | \[ \color{blue}{x} - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\] |
*-commutative [<=]62.68 | \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \cdot 1}
\] |
*-rgt-identity [=>]62.68 | \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}}
\] |
if -7.19999999999999962e-8 < y < 4.99999999999999963e-77Initial program 17.33
Simplified2.11
[Start]17.33 | \[ x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\] |
|---|---|
*-lft-identity [<=]17.33 | \[ \color{blue}{1 \cdot \left(x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\right)}
\] |
distribute-lft-out-- [<=]17.33 | \[ \color{blue}{1 \cdot x - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}}
\] |
*-lft-identity [=>]17.33 | \[ \color{blue}{x} - 1 \cdot \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\] |
*-commutative [<=]17.33 | \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t} \cdot 1}
\] |
*-rgt-identity [=>]17.33 | \[ x - \color{blue}{\frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}}
\] |
Taylor expanded in y around 0 7.86
Simplified0.31
[Start]7.86 | \[ x - \frac{\left(e^{z} - 1\right) \cdot y}{t}
\] |
|---|---|
associate-/l* [=>]7.9 | \[ x - \color{blue}{\frac{e^{z} - 1}{\frac{t}{y}}}
\] |
expm1-def [=>]0.31 | \[ x - \frac{\color{blue}{\mathsf{expm1}\left(z\right)}}{\frac{t}{y}}
\] |
Taylor expanded in z around inf 7.86
Simplified0.27
[Start]7.86 | \[ x - \frac{\left(e^{z} - 1\right) \cdot y}{t}
\] |
|---|---|
*-commutative [=>]7.86 | \[ x - \frac{\color{blue}{y \cdot \left(e^{z} - 1\right)}}{t}
\] |
expm1-def [=>]2.17 | \[ x - \frac{y \cdot \color{blue}{\mathsf{expm1}\left(z\right)}}{t}
\] |
associate-*l/ [<=]0.27 | \[ x - \color{blue}{\frac{y}{t} \cdot \mathsf{expm1}\left(z\right)}
\] |
Final simplification0.49
| Alternative 1 | |
|---|---|
| Error | 10.95% |
| Cost | 7232 |
| Alternative 2 | |
|---|---|
| Error | 13.73% |
| Cost | 6980 |
| Alternative 3 | |
|---|---|
| Error | 19.1% |
| Cost | 1088 |
| Alternative 4 | |
|---|---|
| Error | 19.12% |
| Cost | 960 |
| Alternative 5 | |
|---|---|
| Error | 19.22% |
| Cost | 832 |
| Alternative 6 | |
|---|---|
| Error | 22.18% |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 18.86% |
| Cost | 580 |
| Alternative 8 | |
|---|---|
| Error | 29.04% |
| Cost | 64 |
herbie shell --seed 2023121
(FPCore (x y z t)
:name "System.Random.MWC.Distributions:truncatedExp from mwc-random-0.13.3.2"
:precision binary64
:herbie-target
(if (< z -2.8874623088207947e+119) (- (- x (/ (/ (- 0.5) (* y t)) (* z z))) (* (/ (- 0.5) (* y t)) (/ (/ 2.0 z) (* z z)))) (- x (/ (log (+ 1.0 (* z y))) t)))
(- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))