Beginner's question for Maxima: how can I obtain trigonometric numbers in radical form?
For example, this expression evaluates nicely:
(%i) cos( 3 * %pi / 4);
1
(%o) - -------
sqrt(2)
But this one does not:
(%i) cos(3 * %pi / 5);
3 %pi
(%o) cos(-----)
5
I would expect it to show something like this:
(%i) cos( 3 * %pi / 5);
1 - sqrt(5)
(%o) -----------
4
See, for example, the output from Wolfram Alpha:
From the Maxima documentation for piargs
,
which is true
by default:
When
%piargs
istrue
, trigonometric functions are simplified to algebraic constants when the argument is an integer multiple of %pi, %pi/2, %pi/3, %pi/4, or %pi/6.
From the Maxima documentation for ntrig
:
The
ntrig
package contains a set of simplification rules that are used to simplify trigonometric function whose arguments are of the formf
(
n
%pi/10)
where f is any of the functionssin
,cos
,tan
,csc
,sec
andcot
.
This will work for 3π/5, but not for more complex values like π/96:
(%i) load(ntrig);
(%o) /usr/share/maxima/5.34.1/share/trigonometry/ntrig.mac
(%i) cos(3*%pi/5);
1 - sqrt(5)
(%o) -----------
4
(%i) sin(4*%pi/10);
sqrt(sqrt(5) + 5)
(%o) -----------------
3/2
2
(%i) sin(%pi/96);
%pi
(%o) sin(---)
96
To evaluate more complex results,
the trigeval
function from the trigtools
package will work:
(%i) load(trigtools);
(%o) /usr/share/maxima/5.34.1/share/contrib/trigtools/trigtools.mac
(%i) trigeval(sin(4*%pi/10));
sqrt(sqrt(5) + 5)
(%o) -----------------
3/2
2
(%i) trigeval(sin(%pi/96));
9/8 3/2 5/4
sqrt(2 - sqrt(sqrt(sqrt(3) + 2 + 1) + 2 ))
(%o) --------------------------------------------------
17/16
2
There is some documentation
for trigtools
, but because it is part of the 3rd-party contrib
packages,
it is not as well maintained.
The source code for trigtools
hasn't been updated since 2013.
Also, trigeval
only seems to work for angles corresponding to regular polygons,
and not for trigonometric numbers in general.
For example, cos (π / 23) = -(1/2)(-1)22/23(1+(-1)2/23),
but trigeval
is unhelpful in this case:
(%i) trigeval(cos(%pi/23));
%pi
(%o) cos(---)
23
Credit goes to Serge de Marre and Raymond Toy on the maxima-discuss mailing list, as well as David Billinghurst on the Maxima Area 51 Stackexchange.
Relevant links from other mailing lists: