| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19968 |
\[\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \left(x + -1\right) \cdot \log y - t\right)
\]

(FPCore (x y z t) :precision binary64 (- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))
(FPCore (x y z t) :precision binary64 (fma (+ z -1.0) (log1p (- y)) (- (* (+ x -1.0) (log y)) t)))
double code(double x, double y, double z, double t) {
return (((x - 1.0) * log(y)) + ((z - 1.0) * log((1.0 - y)))) - t;
}
double code(double x, double y, double z, double t) {
return fma((z + -1.0), log1p(-y), (((x + -1.0) * log(y)) - t));
}
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x - 1.0) * log(y)) + Float64(Float64(z - 1.0) * log(Float64(1.0 - y)))) - t) end
function code(x, y, z, t) return fma(Float64(z + -1.0), log1p(Float64(-y)), Float64(Float64(Float64(x + -1.0) * log(y)) - t)) end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x - 1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(N[(z - 1.0), $MachinePrecision] * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(z + -1.0), $MachinePrecision] * N[Log[1 + (-y)], $MachinePrecision] + N[(N[(N[(x + -1.0), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]
\left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\mathsf{fma}\left(z + -1, \mathsf{log1p}\left(-y\right), \left(x + -1\right) \cdot \log y - t\right)
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 89.2%
Simplified99.8%
[Start]89.2% | \[ \left(\left(x - 1\right) \cdot \log y + \left(z - 1\right) \cdot \log \left(1 - y\right)\right) - t
\] |
|---|---|
+-commutative [=>]89.2% | \[ \color{blue}{\left(\left(z - 1\right) \cdot \log \left(1 - y\right) + \left(x - 1\right) \cdot \log y\right)} - t
\] |
associate--l+ [=>]89.2% | \[ \color{blue}{\left(z - 1\right) \cdot \log \left(1 - y\right) + \left(\left(x - 1\right) \cdot \log y - t\right)}
\] |
fma-def [=>]89.2% | \[ \color{blue}{\mathsf{fma}\left(z - 1, \log \left(1 - y\right), \left(x - 1\right) \cdot \log y - t\right)}
\] |
sub-neg [=>]89.2% | \[ \mathsf{fma}\left(z - 1, \log \color{blue}{\left(1 + \left(-y\right)\right)}, \left(x - 1\right) \cdot \log y - t\right)
\] |
log1p-def [=>]99.8% | \[ \mathsf{fma}\left(z - 1, \color{blue}{\mathsf{log1p}\left(-y\right)}, \left(x - 1\right) \cdot \log y - t\right)
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19968 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.6% |
| Cost | 13568 |
| Alternative 3 | |
|---|---|
| Accuracy | 95.3% |
| Cost | 7497 |
| Alternative 4 | |
|---|---|
| Accuracy | 96.0% |
| Cost | 7369 |
| Alternative 5 | |
|---|---|
| Accuracy | 88.1% |
| Cost | 7244 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 7232 |
| Alternative 7 | |
|---|---|
| Accuracy | 87.1% |
| Cost | 6985 |
| Alternative 8 | |
|---|---|
| Accuracy | 87.3% |
| Cost | 6985 |
| Alternative 9 | |
|---|---|
| Accuracy | 59.6% |
| Cost | 6920 |
| Alternative 10 | |
|---|---|
| Accuracy | 46.0% |
| Cost | 704 |
| Alternative 11 | |
|---|---|
| Accuracy | 42.7% |
| Cost | 584 |
| Alternative 12 | |
|---|---|
| Accuracy | 42.5% |
| Cost | 520 |
| Alternative 13 | |
|---|---|
| Accuracy | 45.7% |
| Cost | 384 |
| Alternative 14 | |
|---|---|
| Accuracy | 35.4% |
| Cost | 128 |
herbie shell --seed 2023171
(FPCore (x y z t)
:name "Statistics.Distribution.Beta:$cdensity from math-functions-0.1.5.2"
:precision binary64
(- (+ (* (- x 1.0) (log y)) (* (- z 1.0) (log (- 1.0 y)))) t))