| Alternative 1 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 13252 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 700:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 0.5 + \log 2\right) - x \cdot y\\
\end{array}
\]

(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
(FPCore (x y) :precision binary64 (if (<= x 700.0) (- (log1p (exp x)) (* x y)) (- (+ (* x 0.5) (log 2.0)) (* x y))))
double code(double x, double y) {
return log((1.0 + exp(x))) - (x * y);
}
double code(double x, double y) {
double tmp;
if (x <= 700.0) {
tmp = log1p(exp(x)) - (x * y);
} else {
tmp = ((x * 0.5) + log(2.0)) - (x * y);
}
return tmp;
}
public static double code(double x, double y) {
return Math.log((1.0 + Math.exp(x))) - (x * y);
}
public static double code(double x, double y) {
double tmp;
if (x <= 700.0) {
tmp = Math.log1p(Math.exp(x)) - (x * y);
} else {
tmp = ((x * 0.5) + Math.log(2.0)) - (x * y);
}
return tmp;
}
def code(x, y): return math.log((1.0 + math.exp(x))) - (x * y)
def code(x, y): tmp = 0 if x <= 700.0: tmp = math.log1p(math.exp(x)) - (x * y) else: tmp = ((x * 0.5) + math.log(2.0)) - (x * y) return tmp
function code(x, y) return Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)) end
function code(x, y) tmp = 0.0 if (x <= 700.0) tmp = Float64(log1p(exp(x)) - Float64(x * y)); else tmp = Float64(Float64(Float64(x * 0.5) + log(2.0)) - Float64(x * y)); end return tmp end
code[x_, y_] := N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, 700.0], N[(N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
\mathbf{if}\;x \leq 700:\\
\;\;\;\;\mathsf{log1p}\left(e^{x}\right) - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 0.5 + \log 2\right) - x \cdot y\\
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 79.4% |
|---|---|
| Target | 99.9% |
| Herbie | 89.7% |
if x < 700Initial program 100.0%
Simplified100.0%
[Start]100.0% | \[ \log \left(1 + e^{x}\right) - x \cdot y
\] |
|---|---|
log1p-def [=>]100.0% | \[ \color{blue}{\mathsf{log1p}\left(e^{x}\right)} - x \cdot y
\] |
if 700 < x Initial program 13.7%
Simplified13.7%
[Start]13.7% | \[ \log \left(1 + e^{x}\right) - x \cdot y
\] |
|---|---|
log1p-def [=>]13.7% | \[ \color{blue}{\mathsf{log1p}\left(e^{x}\right)} - x \cdot y
\] |
Taylor expanded in x around 0 57.3%
Final simplification88.6%
| Alternative 1 | |
|---|---|
| Accuracy | 89.7% |
| Cost | 13252 |
| Alternative 2 | |
|---|---|
| Accuracy | 89.2% |
| Cost | 7108 |
| Alternative 3 | |
|---|---|
| Accuracy | 88.9% |
| Cost | 6984 |
| Alternative 4 | |
|---|---|
| Accuracy | 89.2% |
| Cost | 6980 |
| Alternative 5 | |
|---|---|
| Accuracy | 77.6% |
| Cost | 6728 |
| Alternative 6 | |
|---|---|
| Accuracy | 52.1% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 49.9% |
| Cost | 256 |
herbie shell --seed 2023277
(FPCore (x y)
:name "Logistic regression 2"
:precision binary64
:herbie-target
(if (<= x 0.0) (- (log (+ 1.0 (exp x))) (* x y)) (- (log (+ 1.0 (exp (- x)))) (* (- x) (- 1.0 y))))
(- (log (+ 1.0 (exp x))) (* x y)))