Fix two issues on the diophantine module

##### TODO
- [x] merge #7448 

This PR fixes #7342 and fixes #7343.