| Alternative 1 | |
|---|---|
| Error | 9.0 |
| Cost | 13508 |
\[\begin{array}{l}
\mathbf{if}\;e^{z} \leq 0.99999998:\\
\;\;\;\;x - \frac{\left(e^{z} - 1\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot y\\
\end{array}
\]
(FPCore (x y z t) :precision binary64 (- x (/ (log (+ (- 1.0 y) (* y (exp z)))) t)))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ (log (+ (- 1.0 y) (* y (exp z)))) t))
(t_2 (* (- (exp z) 1.0) y))
(t_3 (- x (/ (log (+ 1.0 t_2)) t))))
(if (<= t_1 (- INFINITY))
(- x (/ (log (+ (* y z) 1.0)) t))
(if (<= t_1 -1e-186)
t_3
(if (<= t_1 0.0)
(- x (/ t_2 t))
(if (<= t_1 2e+210) t_3 (- x (* (/ z t) y))))))))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 t_1 = log(((1.0 - y) + (y * exp(z)))) / t;
double t_2 = (exp(z) - 1.0) * y;
double t_3 = x - (log((1.0 + t_2)) / t);
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = x - (log(((y * z) + 1.0)) / t);
} else if (t_1 <= -1e-186) {
tmp = t_3;
} else if (t_1 <= 0.0) {
tmp = x - (t_2 / t);
} else if (t_1 <= 2e+210) {
tmp = t_3;
} else {
tmp = x - ((z / t) * y);
}
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 t_1 = Math.log(((1.0 - y) + (y * Math.exp(z)))) / t;
double t_2 = (Math.exp(z) - 1.0) * y;
double t_3 = x - (Math.log((1.0 + t_2)) / t);
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = x - (Math.log(((y * z) + 1.0)) / t);
} else if (t_1 <= -1e-186) {
tmp = t_3;
} else if (t_1 <= 0.0) {
tmp = x - (t_2 / t);
} else if (t_1 <= 2e+210) {
tmp = t_3;
} else {
tmp = x - ((z / t) * y);
}
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): t_1 = math.log(((1.0 - y) + (y * math.exp(z)))) / t t_2 = (math.exp(z) - 1.0) * y t_3 = x - (math.log((1.0 + t_2)) / t) tmp = 0 if t_1 <= -math.inf: tmp = x - (math.log(((y * z) + 1.0)) / t) elif t_1 <= -1e-186: tmp = t_3 elif t_1 <= 0.0: tmp = x - (t_2 / t) elif t_1 <= 2e+210: tmp = t_3 else: tmp = x - ((z / t) * y) 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) t_1 = Float64(log(Float64(Float64(1.0 - y) + Float64(y * exp(z)))) / t) t_2 = Float64(Float64(exp(z) - 1.0) * y) t_3 = Float64(x - Float64(log(Float64(1.0 + t_2)) / t)) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(x - Float64(log(Float64(Float64(y * z) + 1.0)) / t)); elseif (t_1 <= -1e-186) tmp = t_3; elseif (t_1 <= 0.0) tmp = Float64(x - Float64(t_2 / t)); elseif (t_1 <= 2e+210) tmp = t_3; else tmp = Float64(x - Float64(Float64(z / t) * y)); end return tmp end
function tmp = code(x, y, z, t) tmp = x - (log(((1.0 - y) + (y * exp(z)))) / t); end
function tmp_2 = code(x, y, z, t) t_1 = log(((1.0 - y) + (y * exp(z)))) / t; t_2 = (exp(z) - 1.0) * y; t_3 = x - (log((1.0 + t_2)) / t); tmp = 0.0; if (t_1 <= -Inf) tmp = x - (log(((y * z) + 1.0)) / t); elseif (t_1 <= -1e-186) tmp = t_3; elseif (t_1 <= 0.0) tmp = x - (t_2 / t); elseif (t_1 <= 2e+210) tmp = t_3; else tmp = x - ((z / t) * y); end tmp_2 = 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_] := Block[{t$95$1 = N[(N[Log[N[(N[(1.0 - y), $MachinePrecision] + N[(y * N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Exp[z], $MachinePrecision] - 1.0), $MachinePrecision] * y), $MachinePrecision]}, Block[{t$95$3 = N[(x - N[(N[Log[N[(1.0 + t$95$2), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x - N[(N[Log[N[(N[(y * z), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -1e-186], t$95$3, If[LessEqual[t$95$1, 0.0], N[(x - N[(t$95$2 / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+210], t$95$3, N[(x - N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]]]]]]]]
x - \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}
\begin{array}{l}
t_1 := \frac{\log \left(\left(1 - y\right) + y \cdot e^{z}\right)}{t}\\
t_2 := \left(e^{z} - 1\right) \cdot y\\
t_3 := x - \frac{\log \left(1 + t_2\right)}{t}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x - \frac{\log \left(y \cdot z + 1\right)}{t}\\
\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-186}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;x - \frac{t_2}{t}\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+210}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;x - \frac{z}{t} \cdot y\\
\end{array}
Results
| Original | 24.3 |
|---|---|
| Target | 16.5 |
| Herbie | 8.5 |
if (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < -inf.0Initial program 64.0
Taylor expanded in z around 0 14.1
if -inf.0 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < -9.9999999999999991e-187 or 0.0 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < 1.99999999999999985e210Initial program 2.3
Taylor expanded in y around 0 2.0
if -9.9999999999999991e-187 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) < 0.0Initial program 12.0
Taylor expanded in y around 0 6.5
if 1.99999999999999985e210 < (/.f64 (log.f64 (+.f64 (-.f64 1 y) (*.f64 y (exp.f64 z)))) t) Initial program 59.6
Taylor expanded in y around 0 29.4
Taylor expanded in z around 0 17.5
Taylor expanded in y around inf 17.8
Taylor expanded in z around 0 17.8
Final simplification8.5
| Alternative 1 | |
|---|---|
| Error | 9.0 |
| Cost | 13508 |
| Alternative 2 | |
|---|---|
| Error | 9.0 |
| Cost | 13508 |
| Alternative 3 | |
|---|---|
| Error | 9.1 |
| Cost | 7428 |
| Alternative 4 | |
|---|---|
| Error | 9.1 |
| Cost | 7300 |
| Alternative 5 | |
|---|---|
| Error | 18.6 |
| Cost | 648 |
| Alternative 6 | |
|---|---|
| Error | 11.4 |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Error | 18.0 |
| Cost | 64 |
herbie shell --seed 2023090
(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)))