Polynomial: degree for constant expressions without generators

TODO

- [ ] modify code as shown
- [ ] add 4 tests as shown

fixes #7069