factoring reduction code for trig functions