Richard Fateman wrote on August 23, 2008:
> try ratsubst(1,sin(x)^2+cos(x)^2,%);
>
> I got [1, -1, 1, -1, 1, -1, 1, -1]
>
> similarly, %,exponentialize,ratsimp;
>
> RJF
>
and Rafal Topolnicki wrote on August 23, 2008:
> I don't know what do you mean by 'simpler' but I found:
>
> (%i1)L:[-sin(x)^2/(cos(x)^2-1),sin(x)^2/(cos(x)^2-1),1,
> (cos(x)^2-1)/sin(x)^2,-cos(x)^2/(sin(x)^2-1),
> cos(x)^2/(sin(x)>^2-1),1,(sin(x)^2-1)/cos(x)^2]$
> (%i2) load(trigrat);
> (%o2) /usr/share/maxima/5.15.0/share/trigonometry/trigrat.lisp
> (%i3) trigrat(L);
> (%o3) [1, - 1, 1, - 1, 1, - 1, 1, - 1]
>
> Rafal Topolnicki
Thanks to Richard and Rafal for the suggestions.
I made the test a little harder with the result that
ratsubst(..) method works best so far, but I would
like a method which didn't require me to specify
the variable name "x".
Here is the record of my batch file run:
(%i1) display2d:false$
(%i2) batch(trig1)$
batching #pc:/work3/trig1.mac
(%i3) "define trs1(expr,var) using ratsubst"
(%i4) trs1(expr,var) := ratsubst(1, sin(var)^2+cos(var)^2, expr)
(%i5) "define e[j] trig expressions"
(%i6) (e[1]:cos(y)*sin(x)^3/(1-cos(x)^2),
e[2]:sin(x)^3/(cos(y)*(cos(x)^2-1)),
e[3]:cos(y)*(1-cos(x)^2)/sin(x)^3, e[4]:cos(y)*(cos(x)^2-1)/sin(x)^3,
e[5]:cos(x)^3/(cos(y)*(1-sin(x)^2)),
e[6]:cos(x)^3/(cos(y)*(sin(x)^2-1)),
e[7]:cos(y)*(1-sin(x)^2)/cos(x)^3,
e[8]:cos(y)*(sin(x)^2-1)/cos(x)^3)
(%i7) "define tlist - a list of trig expressions"
(%i8) tlist : makelist( e[i], i, 1, 8)
(%i9) "define trs1x assumes func of x"
(%i10) trs1x(expr) := trs1(expr, x)
(%i11) "try out trs1x on tlist of trig expressions"
(%i12) map( 'trs1x, tlist)
(%o12) [sin(x)*cos(y), -sin(x)/cos(y), cos(y)/sin(x), -cos(y)/sin(x),
cos(x)/cos(y), -cos(x)/cos(y), cos(y)/cos(x), -cos(y)/cos(x)]
(%i13) "define trs(..) using exponentialize, ratsimp, and demoivre"
(%i14) trs(expr) := (exponentialize(expr), ratsimp(%%), demoivre(%%))
(%i15) "try out trs on tlist of trig expressions"
(%i16) map( 'trs, tlist)
(%o16) [-((%i*(%i*sin(2*x)+cos(2*x))-%i)*(%i*sin(2*y)+cos(2*y))
+%i*(%i*sin(2*x)+cos(2*x))-%i)
*(cos(y+x)-%i*sin(y+x))
/4,
(%i*(%i*sin(2*x)+cos(2*x))-%i)*(%i*sin(y)+cos(y))
/* continues long complicated results */ ]
(%i17) "load trigrat package"
(%i18) load(trigrat)
(%i19) "try out trigrat on tlist"
(%i20) map('trigrat, tlist)
(%o20) [(sin(y+x)-sin(y-x))/2, -sin(x)/cos(y),
cos(y)/sin(x), -cos(y)/sin(x),
cos(x)/cos(y), -cos(x)/cos(y), cos(y)/cos(x), -cos(y)/cos(x)]
trigrat(..) succeeded on all but the first element of our list.
Ted Woollett