| Alternative 1 | |
|---|---|
| Error | 0.14% |
| Cost | 13376 |
\[x + \mathsf{fma}\left(\log y, -0.5 - y, y - z\right)
\]
(FPCore (x y z) :precision binary64 (- (+ (- x (* (+ y 0.5) (log y))) y) z))
(FPCore (x y z) :precision binary64 (- (+ x (+ (+ (exp (log1p y)) -1.0) (* (log y) (- -0.5 y)))) z))
double code(double x, double y, double z) {
return ((x - ((y + 0.5) * log(y))) + y) - z;
}
double code(double x, double y, double z) {
return (x + ((exp(log1p(y)) + -1.0) + (log(y) * (-0.5 - y)))) - z;
}
public static double code(double x, double y, double z) {
return ((x - ((y + 0.5) * Math.log(y))) + y) - z;
}
public static double code(double x, double y, double z) {
return (x + ((Math.exp(Math.log1p(y)) + -1.0) + (Math.log(y) * (-0.5 - y)))) - z;
}
def code(x, y, z): return ((x - ((y + 0.5) * math.log(y))) + y) - z
def code(x, y, z): return (x + ((math.exp(math.log1p(y)) + -1.0) + (math.log(y) * (-0.5 - y)))) - z
function code(x, y, z) return Float64(Float64(Float64(x - Float64(Float64(y + 0.5) * log(y))) + y) - z) end
function code(x, y, z) return Float64(Float64(x + Float64(Float64(exp(log1p(y)) + -1.0) + Float64(log(y) * Float64(-0.5 - y)))) - z) end
code[x_, y_, z_] := N[(N[(N[(x - N[(N[(y + 0.5), $MachinePrecision] * N[Log[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision] - z), $MachinePrecision]
code[x_, y_, z_] := N[(N[(x + N[(N[(N[Exp[N[Log[1 + y], $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[Log[y], $MachinePrecision] * N[(-0.5 - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\left(x + \left(\left(e^{\mathsf{log1p}\left(y\right)} + -1\right) + \log y \cdot \left(-0.5 - y\right)\right)\right) - z
Results
| Original | 0.18% |
|---|---|
| Target | 0.18% |
| Herbie | 0.13% |
Initial program 0.18
Simplified0.17
[Start]0.18 | \[ \left(\left(x - \left(y + 0.5\right) \cdot \log y\right) + y\right) - z
\] |
|---|---|
associate-+l- [=>]0.17 | \[ \color{blue}{\left(x - \left(\left(y + 0.5\right) \cdot \log y - y\right)\right)} - z
\] |
Applied egg-rr0.13
Simplified0.13
[Start]0.13 | \[ \left(x - \left(\left(\left(y + 0.5\right) \cdot \log y - e^{\mathsf{log1p}\left(y\right)}\right) + 1\right)\right) - z
\] |
|---|---|
associate-+l- [=>]0.13 | \[ \left(x - \color{blue}{\left(\left(y + 0.5\right) \cdot \log y - \left(e^{\mathsf{log1p}\left(y\right)} - 1\right)\right)}\right) - z
\] |
*-commutative [=>]0.13 | \[ \left(x - \left(\color{blue}{\log y \cdot \left(y + 0.5\right)} - \left(e^{\mathsf{log1p}\left(y\right)} - 1\right)\right)\right) - z
\] |
+-commutative [<=]0.13 | \[ \left(x - \left(\log y \cdot \color{blue}{\left(0.5 + y\right)} - \left(e^{\mathsf{log1p}\left(y\right)} - 1\right)\right)\right) - z
\] |
Final simplification0.13
| Alternative 1 | |
|---|---|
| Error | 0.14% |
| Cost | 13376 |
| Alternative 2 | |
|---|---|
| Error | 23.62% |
| Cost | 7509 |
| Alternative 3 | |
|---|---|
| Error | 22.72% |
| Cost | 7508 |
| Alternative 4 | |
|---|---|
| Error | 28.72% |
| Cost | 7381 |
| Alternative 5 | |
|---|---|
| Error | 10.88% |
| Cost | 7245 |
| Alternative 6 | |
|---|---|
| Error | 10.48% |
| Cost | 7244 |
| Alternative 7 | |
|---|---|
| Error | 28.45% |
| Cost | 7117 |
| Alternative 8 | |
|---|---|
| Error | 0.18% |
| Cost | 7104 |
| Alternative 9 | |
|---|---|
| Error | 51.62% |
| Cost | 392 |
| Alternative 10 | |
|---|---|
| Error | 41.82% |
| Cost | 192 |
| Alternative 11 | |
|---|---|
| Error | 69.43% |
| Cost | 64 |
herbie shell --seed 2023121
(FPCore (x y z)
:name "Numeric.SpecFunctions:stirlingError from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(- (- (+ y x) z) (* (+ y 0.5) (log y)))
(- (+ (- x (* (+ y 0.5) (log y))) y) z))