| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 19392 |
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{expm1}\left(a \cdot x\right)\right)\right)
\]

(FPCore (a x) :precision binary64 (- (exp (* a x)) 1.0))
(FPCore (a x) :precision binary64 (log1p (expm1 (expm1 (* a x)))))
double code(double a, double x) {
return exp((a * x)) - 1.0;
}
double code(double a, double x) {
return log1p(expm1(expm1((a * x))));
}
public static double code(double a, double x) {
return Math.exp((a * x)) - 1.0;
}
public static double code(double a, double x) {
return Math.log1p(Math.expm1(Math.expm1((a * x))));
}
def code(a, x): return math.exp((a * x)) - 1.0
def code(a, x): return math.log1p(math.expm1(math.expm1((a * x))))
function code(a, x) return Float64(exp(Float64(a * x)) - 1.0) end
function code(a, x) return log1p(expm1(expm1(Float64(a * x)))) end
code[a_, x_] := N[(N[Exp[N[(a * x), $MachinePrecision]], $MachinePrecision] - 1.0), $MachinePrecision]
code[a_, x_] := N[Log[1 + N[(Exp[N[(Exp[N[(a * x), $MachinePrecision]] - 1), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]
e^{a \cdot x} - 1
\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{expm1}\left(a \cdot x\right)\right)\right)
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 53.8% |
|---|---|
| Target | 99.7% |
| Herbie | 99.7% |
Initial program 48.1%
Simplified100.0%
[Start]48.1% | \[ e^{a \cdot x} - 1
\] |
|---|---|
expm1-def [=>]100.0% | \[ \color{blue}{\mathsf{expm1}\left(a \cdot x\right)}
\] |
Applied egg-rr100.0%
[Start]100.0% | \[ \mathsf{expm1}\left(a \cdot x\right)
\] |
|---|---|
log1p-expm1-u [=>]100.0% | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\mathsf{expm1}\left(a \cdot x\right)\right)\right)}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 19392 |
| Alternative 2 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6592 |
| Alternative 3 | |
|---|---|
| Accuracy | 88.5% |
| Cost | 964 |
| Alternative 4 | |
|---|---|
| Accuracy | 89.1% |
| Cost | 964 |
| Alternative 5 | |
|---|---|
| Accuracy | 84.9% |
| Cost | 836 |
| Alternative 6 | |
|---|---|
| Accuracy | 88.7% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 87.6% |
| Cost | 836 |
| Alternative 8 | |
|---|---|
| Accuracy | 75.5% |
| Cost | 192 |
herbie shell --seed 2023277
(FPCore (a x)
:name "expax (section 3.5)"
:precision binary64
:herbie-target
(if (< (fabs (* a x)) 0.1) (* (* a x) (+ 1.0 (+ (/ (* a x) 2.0) (/ (pow (* a x) 2.0) 6.0)))) (- (exp (* a x)) 1.0))
(- (exp (* a x)) 1.0))