Improvements to inequality solving

fixes #8206 (please feel free to any others that are related that also work with these changes)
fixes #8518
Which test? If you mean the one that triggers that line, I moved it to a new function (see last commit).