SymPy coeff() different behavior depending on how it is called

The issue here is x^(-1) is treated by the parser first; x^n dispatches to a generic implementation that errors. You can see the same behavior with x=2, it isn’t SymPy related.

Using a symbolic power, as in x^Sym(n), would stay within SymPy, and works as desired.

1 Like