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

(FPCore (x y z t) :precision binary64 (- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))
(FPCore (x y z t) :precision binary64 (fma x (log y) (fma z (log1p (- y)) (- t))))
double code(double x, double y, double z, double t) {
return ((x * log(y)) + (z * log((1.0 - y)))) - t;
}
double code(double x, double y, double z, double t) {
return fma(x, log(y), fma(z, log1p(-y), -t));
}
function code(x, y, z, t) return Float64(Float64(Float64(x * log(y)) + Float64(z * log(Float64(1.0 - y)))) - t) end
function code(x, y, z, t) return fma(x, log(y), fma(z, log1p(Float64(-y)), Float64(-t))) end
code[x_, y_, z_, t_] := N[(N[(N[(x * N[Log[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Log[N[(1.0 - y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision]
code[x_, y_, z_, t_] := N[(x * N[Log[y], $MachinePrecision] + N[(z * N[Log[1 + (-y)], $MachinePrecision] + (-t)), $MachinePrecision]), $MachinePrecision]
\left(x \cdot \log y + z \cdot \log \left(1 - y\right)\right) - t
\mathsf{fma}\left(x, \log y, \mathsf{fma}\left(z, \mathsf{log1p}\left(-y\right), -t\right)\right)
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 85.2% |
|---|---|
| Target | 99.6% |
| Herbie | 99.8% |
Initial program 82.9%
Simplified99.9%
[Start]82.9% | \[ \left(x \cdot \log y + z \cdot \log \left(1 - y\right)\right) - t
\] |
|---|---|
+-commutative [=>]82.9% | \[ \color{blue}{\left(z \cdot \log \left(1 - y\right) + x \cdot \log y\right)} - t
\] |
associate--l+ [=>]82.9% | \[ \color{blue}{z \cdot \log \left(1 - y\right) + \left(x \cdot \log y - t\right)}
\] |
+-commutative [=>]82.9% | \[ \color{blue}{\left(x \cdot \log y - t\right) + z \cdot \log \left(1 - y\right)}
\] |
associate-+l- [=>]82.9% | \[ \color{blue}{x \cdot \log y - \left(t - z \cdot \log \left(1 - y\right)\right)}
\] |
fma-neg [=>]82.9% | \[ \color{blue}{\mathsf{fma}\left(x, \log y, -\left(t - z \cdot \log \left(1 - y\right)\right)\right)}
\] |
sub0-neg [<=]82.9% | \[ \mathsf{fma}\left(x, \log y, \color{blue}{0 - \left(t - z \cdot \log \left(1 - y\right)\right)}\right)
\] |
associate-+l- [<=]82.9% | \[ \mathsf{fma}\left(x, \log y, \color{blue}{\left(0 - t\right) + z \cdot \log \left(1 - y\right)}\right)
\] |
neg-sub0 [<=]82.9% | \[ \mathsf{fma}\left(x, \log y, \color{blue}{\left(-t\right)} + z \cdot \log \left(1 - y\right)\right)
\] |
+-commutative [<=]82.9% | \[ \mathsf{fma}\left(x, \log y, \color{blue}{z \cdot \log \left(1 - y\right) + \left(-t\right)}\right)
\] |
fma-def [=>]82.9% | \[ \mathsf{fma}\left(x, \log y, \color{blue}{\mathsf{fma}\left(z, \log \left(1 - y\right), -t\right)}\right)
\] |
sub-neg [=>]82.9% | \[ \mathsf{fma}\left(x, \log y, \mathsf{fma}\left(z, \log \color{blue}{\left(1 + \left(-y\right)\right)}, -t\right)\right)
\] |
log1p-def [=>]99.9% | \[ \mathsf{fma}\left(x, \log y, \mathsf{fma}\left(z, \color{blue}{\mathsf{log1p}\left(-y\right)}, -t\right)\right)
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 26048 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19712 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 13312 |
| Alternative 4 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 7049 |
| Alternative 5 | |
|---|---|
| Accuracy | 89.5% |
| Cost | 6985 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 6976 |
| Alternative 7 | |
|---|---|
| Accuracy | 77.8% |
| Cost | 6857 |
| Alternative 8 | |
|---|---|
| Accuracy | 57.2% |
| Cost | 704 |
| Alternative 9 | |
|---|---|
| Accuracy | 47.0% |
| Cost | 520 |
| Alternative 10 | |
|---|---|
| Accuracy | 56.9% |
| Cost | 384 |
| Alternative 11 | |
|---|---|
| Accuracy | 42.4% |
| Cost | 128 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, B"
:precision binary64
:herbie-target
(- (* (- z) (+ (+ (* 0.5 (* y y)) y) (* (/ 0.3333333333333333 (* 1.0 (* 1.0 1.0))) (* y (* y y))))) (- t (* x (log y))))
(- (+ (* x (log y)) (* z (log (- 1.0 y)))) t))