I think you can target only factorials with

```
e.rewrite(lambda x: isinstance(x, factorial), lambda x: x.rewrite(gamma))
```