# expand trig function; expandtrig(a_+b_) := expandtrig(a)+expandtrig(b); expandtrig(a_*b_) := expandtrig(a)*expandtrig(b); expandtrig(sinh(a_)^n_):= If(n>0 and isodd(n), expand(sum(combination(n,k)*(-1)^(n+k+1)*sinh((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(combination(n,k)*cosh((n-2k)*a)+(-1)^(n/2+k)*combination(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expandtrig(cosh(a_)^n_):= If(n>0 and isodd(n), expand(sum(combination(n,k)*cosh((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(combination(n,k)*cosh((n-2k)*a)+combination(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expandtrig(sin(a_+b_)) := sin(a)*cos(b)+cos(a)*sin(b); expandtrig(sin(a_-b_)) := sin(a)*cos(b)-cos(a)*sin(b); expandtrig(cos(a_+b_)) := cos(a)*cos(b)- sin(a)*sin(b); expandtrig(cos(a_-b_)) := cos(a)*cos(b)+ sin(a)*sin(b); expandtrig(sin(a_)^n_):= If(n>0 and isodd(n), expand(sum(combination(n,k)*(-1)^(n+k)*sin((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum((-1)^(n/2+k)*combination(n,k)*cos((n-2k)*a)+combination(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1))))); expandtrig(cos(a_)^n_):= If(n>0 and isodd(n), expand(sum(combination(n,k)*cos((n-2k)*a), k,0,(n-1)/2,1)/(2^(n-1))), If(n>0 and iseven(n), expand(sum(combination(n,k)*cos((n-2k)*a)+combination(n,n/2)/2, k,0,n/2-1,1)/(2^(n-1)))));