make trig rewriting more robust in solve