Hello,
Chapter 7 of "Computer Algebra and Symbolic Computation: Elementary
Algorithms" by Joel Cohen deals with exponential and trigonometric
transformations. It's the final chapter of the book and builds on the
earlier defined procedures.
The 'expand-exp' procedure performs basic expansion of the expressions
containing 'exp'. Some examples from the tests:
(test-equal "EA: expression 7.1"
(expand-exp (alge " exp( 2 x + y ) "))
(alge " exp(x)^2 exp(y) "))
(test-equal "EA: Example 7.2"
(expand-exp (alge " exp( 2 w x + 3 y z "))
(alge " exp( w x )^2 exp( y z )^3 "))
(test-equal "EA: Example 7.3"
(expand-exp (alge " exp( 2 * (x + y) ) "))
(alge " exp(x)^2 exp(y)^2 "))
'contract-exp' is for going the other direction:
(test-equal "EA: Expression 7.27"
(contract-exp (alge " exp(u) * exp(v) "))
(alge " exp(u+v) "))
(test-equal "EA: Expression 7.28"
(contract-exp (alge " exp(u)^w "))
(alge " exp(w*u) "))
(test-equal "EA: Example 7.9 "
(contract-exp (alge " exp(x) * ( exp(x) + exp(y) ) "))
(alge " exp(2*x) + exp(x+y) "))
On to trigonometry.
sin and cos perform some basic transformations on their own.
(sin pi)
0
(sin -5)
(* -1 (sin 5))
(sin (- x))
(* -1 (sin x))
(sin (* -5 x))
(* -1 (sin (* 5 x)))
sin handles cases where it's argument is ( k/n * pi ) for n = 1 2 3 4 6
(test-equal (sin (* 3 pi)) 0)
(test-equal (sin (* 1/2 pi)) 1)
(test-equal (sin (* 3/2 pi)) -1)
(test-equal (sin (* 1/3 pi)) (alge " sqrt(3)/2 "))
(test-equal (sin (* 2/3 pi)) (alge " sqrt(3)/2 "))
(test-equal (sin (* 4/3 pi)) (alge " -sqrt(3)/2 "))
(test-equal (sin (* 5/3 pi)) (alge " -sqrt(3)/2 "))
(test-equal (sin (* 1/4 pi)) (alge " 1/sqrt(2) "))
(test-equal (sin (* 3/4 pi)) (alge " 1/sqrt(2) "))
(test-equal (sin (* 5/4 pi)) (alge " -1/sqrt(2) "))
(test-equal (sin (* 7/4 pi)) (alge " -1/sqrt(2) "))
(test-equal (sin (* 1/6 pi)) (alge " 1/2 "))
(test-equal (sin (* 5/6 pi)) (alge " 1/2 "))
(test-equal (sin (* 7/6 pi)) (alge " -1/2 "))
(test-equal (sin (* 11/6 pi)) (alge " -1/2 "))
If sin is given ( a/b * pi ) where a/b*pi is not in the first quadrant,
sin will try to shift it into the first quadrant:
(test-equal (sin (* 15/7 pi)) (sin (* 1/7 pi)))
(test-equal (sin (* 8/7 pi)) (- (sin (* 1/7 pi))))
(test-equal (sin (* 4/7 pi)) (sin (* 3/7 pi)))
Couple of more examples:
(sin (+ x (* -3 pi)))
(sin (+ pi x))
(sin (+ x (* -3/2 pi)))
(cos x)
Cos performs similar simplifications.
The advanced transformations are provided by 'expand-trig',
'contract-trig', and 'simplify-trig' which combines the two.
I'll show a few examples where 'simplify-trig' is able to reduce an
expression down to 0:
(simplify-trig
(alge
" ( cos(x) + sin(x) )^4 + ( cos(x) - sin(x) )^4 + cos(4*x) - 3 "))
0
(simplify-trig
(alge
" sin(x) + sin(y) - 2 * sin(x/2 + y/2) * cos(x/2 - y/2) "))
0
(simplify-trig
(alge " sin(x)^3 + cos(x+pi/6)^3 - sin(x+pi/3)^3 + 3*sin(3*x)/4 "))
0
(simplify-trig
(- (/ (alge " sin(x) + sin(3*x) + sin(5*x) + sin(7*x) ")
(alge " cos(x) + cos(3*x) + cos(5*x) + cos(7*x) "))
'(tan (* 4 x))))
0
Latest code is at:
http://github.com/dharmatech/mpl
There are currently 203 unit tests drawn mostly from examples and
exercises in Cohen's books:
http://github.com/dharmatech/mpl/raw/master/test.sls
Tests pass in Ikarus, Ypsilon, and Mosh.
Ed