Michael Yuxi Dong - 1 year ago 193

Python Question

If I use

`simplify()`

`log((exp(x)+1)/exp(x))`

`log(1+exp(-x))`

`ln((exp(x)+1)/exp(x))`

`log(1+exp(-x))`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You can more directly just use ** sympy.polys.polytools.cancel()**, which is available as a method on your expression with

`.cancel()`

. ```
>>> from sympy.abc import x
>>> from sympy import *
>>> my_expr = log((exp(x)+1)/exp(x))
>>> my_expr.cancel()
log(1 + exp(-x))
```

This is what is doing the work of simplifying your expression inside `simplify()`

.

A very naive benchmark:

```
>>> import timeit
>>> %timeit my_expr.simplify()
100 loops, best of 3: 7.78 ms per loop
>>> %timeit my_expr.cancel()
1000 loops, best of 3: 972 µs per loop
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**