| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 12864 |
\[\mathsf{log1p}\left(\mathsf{expm1}\left(x\right)\right)
\]

(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
(FPCore (x) :precision binary64 (log1p (expm1 x)))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
double code(double x) {
return log1p(expm1(x));
}
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
public static double code(double x) {
return Math.log1p(Math.expm1(x));
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
def code(x): return math.log1p(math.expm1(x))
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function code(x) return log1p(expm1(x)) end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
code[x_] := N[Log[1 + N[(Exp[x] - 1), $MachinePrecision]], $MachinePrecision]
\frac{e^{x} - e^{-x}}{2}
\mathsf{log1p}\left(\mathsf{expm1}\left(x\right)\right)
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 51.4%
Taylor expanded in x around 0 83.1%
Simplified83.1%
[Start]83.1% | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot {x}^{3}}{2}
\] |
|---|---|
unpow3 [=>]83.1% | \[ \frac{2 \cdot x + 0.3333333333333333 \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot x\right)}}{2}
\] |
associate-*r* [=>]83.1% | \[ \frac{2 \cdot x + \color{blue}{\left(0.3333333333333333 \cdot \left(x \cdot x\right)\right) \cdot x}}{2}
\] |
distribute-rgt-out [=>]83.1% | \[ \frac{\color{blue}{x \cdot \left(2 + 0.3333333333333333 \cdot \left(x \cdot x\right)\right)}}{2}
\] |
*-commutative [<=]83.1% | \[ \frac{x \cdot \left(2 + \color{blue}{\left(x \cdot x\right) \cdot 0.3333333333333333}\right)}{2}
\] |
+-commutative [<=]83.1% | \[ \frac{x \cdot \color{blue}{\left(\left(x \cdot x\right) \cdot 0.3333333333333333 + 2\right)}}{2}
\] |
associate-*l* [=>]83.1% | \[ \frac{x \cdot \left(\color{blue}{x \cdot \left(x \cdot 0.3333333333333333\right)} + 2\right)}{2}
\] |
fma-def [=>]83.1% | \[ \frac{x \cdot \color{blue}{\mathsf{fma}\left(x, x \cdot 0.3333333333333333, 2\right)}}{2}
\] |
Taylor expanded in x around 0 55.6%
Applied egg-rr99.5%
[Start]55.6% | \[ \frac{x \cdot 2}{2}
\] |
|---|---|
associate-/l* [=>]55.3% | \[ \color{blue}{\frac{x}{\frac{2}{2}}}
\] |
metadata-eval [=>]55.3% | \[ \frac{x}{\color{blue}{1}}
\] |
/-rgt-identity [=>]55.3% | \[ \color{blue}{x}
\] |
log1p-expm1-u [=>]99.5% | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(x\right)\right)}
\] |
Final simplification99.5%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 12864 |
| Alternative 2 | |
|---|---|
| Accuracy | 92.8% |
| Cost | 1472 |
| Alternative 3 | |
|---|---|
| Accuracy | 84.3% |
| Cost | 841 |
| Alternative 4 | |
|---|---|
| Accuracy | 84.6% |
| Cost | 704 |
| Alternative 5 | |
|---|---|
| Accuracy | 52.0% |
| Cost | 320 |
| Alternative 6 | |
|---|---|
| Accuracy | 52.0% |
| Cost | 64 |
herbie shell --seed 2023271
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))