Factoring expressiions involving trigonometric functions