%-*-EMaxima-*-

Here we will discuss Maxima's ability to handle integration, 
differentiation, and other related concepts.

\section{Trigonometric Functions}

These operate more or less as you would expect.  The following functions
are defined by default:

~

{\center \begin{tabular}{|c|c|c|c|}
\hline 
sin&
Sine&
asin&
Arc Sine\\
\hline
cos&
Cosine&
acos&
Arc Cosine\\
\hline 
tan&
Tangent&
atan&
Arc Tangent\\
\hline 
csc&
Cosecant&
acsc&
Arc Cosecant\\
\hline 
sec&
Secant&
asec&
Arc Secant\\
\hline 
cot&
Cotangent&
acot&
Arc Cotangent\\
\hline 
sinh&
Hyperbolic Sine&
asinh&
Hyperbolic Arc Sine\\
\hline 
cosh&
Hyperbolic Cosine&
acosh&
Hyperbolic Arc Cosine\\
\hline 
tanh&
Hyperbolic Tangent&
atanh&
Hyperbolic Arc Tangent\\
\hline 
csch&
Hyperbolic Cosecant&
acsch&
Hyperbolic Arc Cosecant\\
\hline 
sech&
Hyperbolic Secant&
asech&
Hyperbolic Arc Secant\\
\hline 
coth&
Hyperbolic Cotangent&
acoth&
Hyperbolic Arc Cotangent\\
\hline
\end{tabular} \par}

~\\

~

There are a couple wrinkles worth noting - by default, Maxima will not
simplify expressions which numerically are nice fractions of $\pi$, so
there exists a package which may be loaded to allow this called
atrig1.  Here is an example:

\beginmaximasession
acos(1/sqrt(2));
load(atrig1)$
acos(1/sqrt(2));
\maximatexsession
\C1.  acos(1/sqrt(2)); \\
\D1.  \arccos \left(\frac{1}{\sqrt{2}}\right) \\
\C2.  load(atrig1)$ \\
\C3.  acos(1/sqrt(2)); \\
\D3.  \frac{\pi}{4} \\
\endmaximasession

Maxima is aware of the Half Angle relations, but by default will not use
them.  There is a variable which can be set called \texttt{halfangles}, and when
that is set to true the Half Angle definitions will be used.

\beginmaximasession
sin(a/2);
halfangles:true;
sin(a/2);
\maximatexsession
\C4.  sin(a/2); \\
\D4.  \sin \left(\frac{a}{2}\right) \\
\C5.  halfangles:true; \\
\D5.  \mathbf{true} \\
\C6.  sin(a/2); \\
\D6.  \frac{\sqrt{1-\cos a}}{\sqrt{2}} \\
\endmaximasession

You should be aware that when solving expressions 
involving trig functions, not all solutions will be presented.  This
is inevitable, since in many cases there are an infinite number - 
typically one will be displayed.  Usually you are warned when this
is happens.

\beginmaximasession
solve(sin(x)=%PI/2,x);
\maximatexsession
\C7.  solve(sin(x)=%PI/2,x); \\
\p
SOLVE is using arc-trig functions to get a solution.
Some solutions will be lost. \\
\D7.  \left[ x=\arcsin \left(\frac{\pi}{2}\right) \right] \\
\endmaximasession

There are a few global variables you can set which will change how
Maxima handles trig expressions:

\begin{itemize}
\item TRIGINVERSES \\
      This can be set to one of three values:  ALL, TRUE, or FALSE. The
      default is ALL
      \begin{itemize}
       \item ALL~~~When set to ALL, both arctfun(tfun(x)) and
            fun(arctfun(x)) are evaluated to x.
       \item TRUE~~~When set to TRUE, the arctfun(tfun(x)) simplification
             is turned off.
       \item FALSE~~~When set to FALSE, both simplifications are turned
             off.
      \end{itemize}
\item TRIGSIGN \\
      Can be set to TRUE or FALSE.  The default is TRUE.  If TRUE,
      for example, sin(-x) simplifies to -sin(x).
\end{itemize}

\section{Differentiation}

To differentiate an expression, use the {\tt diff} command.  {\tt diff(expr,var)}  differentiates an expression with respect to the variable {\tt var}.

\beginmaximasession
sin(x)*cos(x);
diff(%,x);
\maximatexsession
\C8.  sin(x)*cos(x); \\
\D8.  \cos x\*\sin x \\
\C9.  diff(%,x); \\
\D9.  \cos ^{2 }x-\sin ^{2 }x \\
\endmaximasession

To take a second order derivative, use {\tt diff(expr,var,2)}.

\beginmaximasession
diff(sin(x)*cos(x),x,2);
\maximatexsession
\C10.  diff(sin(x)*cos(x),x,2); \\
\D10.  -4\*\cos x\*\sin x \\
\endmaximasession

Differentiation, unlike integration, can be handled in a fairly general
way by computer algebra.  As a result, you will be able to take derivatives
in most cases.  We will show some examples here:

Basic Algebraic Examples:

\beginmaximasession
diff(3*x^5+x^4+7*x^3-x^2+17,x);
diff((x^2+1)/(x^2-1),x);
diff((x^2+1)^5*(x^7-5*x-2)^19,x);
diff(x^(2/3)+x^(5/7),x);
\maximatexsession
\C11.  diff(3*x^5+x^4+7*x^3-x^2+17,x); \\
\D11.  15\*x^{4}+4\*x^{3}+21\*x^{2}-2\*x \\
\C12.  diff((x^2+1)/(x^2-1),x); \\
\D12.  \frac{2\*x}{x^{2}-1}-\frac{2\*x\*\left(x^{2}+1\right)}{\left(x^{2}-1\right)^{2}} \\
\C13.  diff((x^2+1)^5*(x^7-5*x-2)^19,x); \\
\D13.  10\*x\*\left(x^{2}+1\right)^{4}\*\left(x^{7}-5\*x-2\right)^{19}+19\*\left(x^{2}+1\right)^{5}\*\left(7\*x^{6}-5\right)\*\left(x^{7}-5\*x-2\right)^{18} \\
\C14.  diff(x^(2/3)+x^(5/7),x); \\
\D14.  \frac{5}{7\*\iexpt{x}{\frac{2}{7}}}+\frac{2}{3\*\iexpt{x}{\frac{1}{3}}} \\
\endmaximasession

Chain Rule Example:

In order to handle the problem of a function which depends
in an unknown way upon some variable, Maxima provides
the {\tt depends} command.  Using it, you can derive
general chain rule formulas.  It should be noted these
relations are understood only by the diff command - 
for operations such as integration you must give their 
dependencies explicitly in the command.

\beginmaximasession
DEPENDS([U],[r,theta],[r,theta],[x,y]);
diff(U,x)+diff(U,y);
\maximatexsession
\C15.  DEPENDS([U],[r,theta],[r,theta],[x,y]); \\
\D15.  \left[ U\left(r,\linebreak[0]\vartheta\right),\linebreak[0]r\left(x,\linebreak[0]y\right),\linebreak[0]\vartheta\left(x,\linebreak[0]y\right) \right] \\
\C16.  diff(U,x)+diff(U,y); \\
\D16.  \frac{d}{d\*y}\*\vartheta\*\left(\frac{d}{d\*\vartheta}\*U\right)+\frac{d}{d\*x}\*\vartheta\*\left(\frac{d}{d\*\vartheta}\*U\right)+\frac{d}{d\*y}\*r\*\left(\frac{d}{d\*r}\*U\right)+\frac{d}{d\*x}\*r\*\left(\frac{d}{d\*r}\*U\right) \\
\endmaximasession

If we wish to take derivatives with respect to multiple variables,
for example $d^2\over{dxdy}$, the syntax for derivatives is quite
general and we can perform the operation as follows:

\beginmaximasession
diff(U,x,1,y,1);
\maximatexsession
\C17.  diff(U,x,1,y,1); \\
\D17.  \frac{d}{d\*x}\*\vartheta\*\left(\frac{d}{d\*y}\*\vartheta\*\left(\frac{d^{2}}{d\*\vartheta^{2}}\*U\right)+\frac{d}{d\*y}\*r\*\left(\frac{d^{2}}{d\*r\*d\*\vartheta}\*U\right)\right)+\frac{d^{2}}{d\*x\*d\*y}\*\vartheta\*\left(\frac{d}{d\*\vartheta}\*U\right)+\frac{d}{d\*x}\*r\*\left(\frac{d}{d\*y}\*r\*\left(\frac{d^{2}}{d\*r^{2}}\*U\right)+\frac{d}{d\*y}\*\vartheta\*\left(\frac{d^{2}}{d\*r\*d\*\vartheta}\*U\right)\right)+\frac{d^{2}}{d\*x\*d\*y}\*r\*\left(\frac{d}{d\*r}\*U\right) \\
\endmaximasession

This is the same thing as doing

\beginmaximasession
diff(diff(U,x),y);
\maximatexsession
\C18.  diff(diff(U,x),y); \\
\D18.  \frac{d}{d\*x}\*\vartheta\*\left(\frac{d}{d\*y}\*\vartheta\*\left(\frac{d^{2}}{d\*\vartheta^{2}}\*U\right)+\frac{d}{d\*y}\*r\*\left(\frac{d^{2}}{d\*r\*d\*\vartheta}\*U\right)\right)+\frac{d^{2}}{d\*x\*d\*y}\*\vartheta\*\left(\frac{d}{d\*\vartheta}\*U\right)+\frac{d}{d\*x}\*r\*\left(\frac{d}{d\*y}\*r\*\left(\frac{d^{2}}{d\*r^{2}}\*U\right)+\frac{d}{d\*y}\*\vartheta\*\left(\frac{d^{2}}{d\*r\*d\*\vartheta}\*U\right)\right)+\frac{d^{2}}{d\*x\*d\*y}\*r\*\left(\frac{d}{d\*r}\*U\right) \\
\endmaximasession

Trigonometric Derivatives:

\beginmaximasession
diff(cos(x),x);
diff(acos(x),x);
diff(tan(x),x);
diff(atan(x),x);
diff(sinh(x),x);
diff(asinh(x),x);
\maximatexsession
\C25.  diff(cos(x),x); \\
\D25.  -\sin x \\
\C26.  diff(acos(x),x); \\
\D26.  -\frac{1}{\sqrt{1-x^{2}}} \\
\C27.  diff(tan(x),x); \\
\D27.  \sec ^{2 }x \\
\C28.  diff(atan(x),x); \\
\D28.  \frac{1}{x^{2}+1} \\
\C29.  diff(sinh(x),x); \\
\D29.  \cosh x \\
\C30.  diff(asinh(x),x); \\
\D30.  \frac{1}{\sqrt{x^{2}+1}} \\
\endmaximasession

\section{Integration}

Unlike differentiation, integration cannot be readily expressed in a general
way.  Maxima is quite capable when it comes to to such problems, although
like all computer algebra systems it has its limits.

In general, {\tt integrate} is the command most users will use to perform
various types of basic integrals.  It is therefore a logical place to begin
the introduction.

Beginning with a very basic example:

\beginmaximasession
integrate(a*x^n,x);
\maximatexsession
\C31.  integrate(a*x^n,x); \\
\p
Is  n+1  zero or nonzero?

nonzero; \\
\D31.  \frac{a\*\iexpt{x}{n+1}}{n+1} \\
\endmaximasession

Even in this basic case, there is a lot going on.  The general form of 
the integrate command for indefinite integrals is {\tt integrate(f(x),x)}.
When Maxima does not have sufficient information to evaluate an integral,
it will ask the user questions.  In the above example, for instance,
Whether or not n+1 was zero impacted how Maxima would approach the problem.
Above, it evaluated the integral after being told n+1 was not zero. If
the same integral is performed again, this time informing the system that
n+1 is zero, the results are different:

\beginmaximasession
integrate(a*x^n,x);
\maximatexsession
\C32.  integrate(a*x^n,x); \\
\p
Is  n+1  zero or nonzero?

zero; \\
\D32.  a\*\log x \\
\endmaximasession

\subsection{The {\tt assume} Command}

As one is working on a long problem session, having to answer the same
questions repeatedly quickly becomes inefficient.  Fortunately, Maxima
provides an {\tt assume} command which lets the system proceed without
having to repeatedly inquire at to the state of a variable.  This command
is actually useful throughout the Maxima system, not just in integration
problems, but since integration is likely where most users will first
encounter the need for it we will discuss it here.  Remember, this 
is the command you will use any time you wish to instruct Maxima to
assume some fact whatever you happen to be doing.  You will see this
command throughout this book.

We will use the previous integration example as the first illustration of
how this process works.

\beginmaximasession
assume(n+1>0);
integrate(a*x^n,x);
\maximatexsession
\C33.  assume(n+1>0); \\
\D33.  \left[ n>-1 \right] \\
\C34.  integrate(a*x^n,x); \\
\D34.  \frac{a\*\iexpt{x}{n+1}}{n+1} \\
\endmaximasession

Notice Maxima did not ask any questions, because it was able to find the
information it needed in its assume database.  Of couse, for one integral
it is simpler to just answer the question, but now if we wish to do another
integral that also depends on this knowledge:

\beginmaximasession
integrate((a+b)*x^(n+1),x);
\maximatexsession
\C35.  integrate((a+b)*x^(n+1),x); \\
\D35.  \frac{\left(b+a\right)\*\iexpt{x}{n+2}}{n+2} \\
\endmaximasession

Maxima already knew enough to handle the new integral.  Of course, we 
might not want this asssumption later on, so we need a way to get rid
of it.  This is done with the {\tt forget} command:

\beginmaximasession
forget(n+1>0);
integrate((a+b)*x^n,x);
\maximatexsession
\C36.  forget(n+1>0); \\
\D36.  \left[ n>-1 \right] \\
\C37.  integrate((a+b)*x^n,x); \\
\p
Is  n+1  zero or nonzero?

zero; \\
\D37.  \left(b+a\right)\*\log x \\
\endmaximasession

For multiple rule situations {\tt assume} and {\tt forget} will also 
take more than one assumption at a time, as in this example:

\beginmaximasession
assume(n+1>0, m+1>0);
integrate(a*x^n+b*x^m,x);
forget(n+1>0, m+1>0);
integrate(a*x^n+b*x^m,x);
\maximatexsession
\C38.  assume(n+1>0, m+1>0); \\
\D38.  \left[ n>-1,\linebreak[0]m>-1 \right] \\
\C39.  integrate(a*x^n+b*x^m,x); \\
\D39.  \frac{a\*\iexpt{x}{n+1}}{n+1}+\frac{b\*\iexpt{x}{m+1}}{m+1} \\
\C40.  forget(n+1>0, m+1>0); \\
\D40.  \left[ n>-1,\linebreak[0]m>-1 \right] \\
\C41.  integrate(a*x^n+b*x^m,x); \\
\p
Is  m+1  zero or nonzero?

zero;
Is  n+1  zero or nonzero?

zero; \\
\D41.  b\*\log x+a\*\log x \\
\endmaximasession

\subsection{Definite Integrals}

The same basic {\tt integration} command is used for definite integrals.
Let's take a basic example:

\beginmaximasession
integrate(a+x^3,x,0,5);
\maximatexsession
\C42.  integrate(a+x^3,x,0,5); \\
\D42.  \frac{20\*a+625}{4} \\
\endmaximasession

The basic syntax is apparent: {\tt integrate(f(x),x,lowerlimit,upperlimit)}

\subsection{{\tt changevar}}

Maxima provides a command {\tt changevar} which can make a change of
variable in an integral. It has the form {\tt changevar(exp,f(x,y),y,x)}
What this does is make the change of variable given by f(x,y) = 0 in all 
integrals occurring in exp with integration with respect to x; y is the 
new variable. For example:

\beginmaximasession
'integrate(exp(sqrt(5*x)),x,0,4)+'integrate(exp(sqrt(5*x+1)),x,0,5)+
'integrate(exp(sqrt(z*x)),z,0,4);
changevar(%,x-y^2/5,y,x);
\maximatexsession
\C43.  'integrate(exp(sqrt(5*x)),x,0,4)+'integrate(exp(sqrt(5*x+1)),x,0,5)+
'integrate(exp(sqrt(z*x)),z,0,4); \\
\D43.  \int_{0}^{4}{\iexpt{e}{\sqrt{x\*z}}\;dz}+\int_{0}^{5}{\iexpt{e}{\sqrt{5\*x+1}}\;dx}+\int_{0}^{4}{\iexpt{e}{\sqrt{5}\*\sqrt{x}}\;dx} \\
\C44.  changevar(%,x-y^2/5,y,x); \\
\D44.  \int_{0}^{4}{\iexpt{e}{\sqrt{x\*z}}\;dz}-\frac{2\*\int_{-2\*\sqrt{5}}^{0}{y\*\iexpt{e}{\left| y\right| }\;dy}}{5}-\frac{2\*\int_{-5}^{0}{y\*\iexpt{e}{\sqrt{y^{2}+1}}\;dy}}{5} \\
\endmaximasession

If you examine the above case, you see that the two integrals being
integrated with respect to x have undergone a variable, change, while
the z dependant integral has not.

\subsection{Behind the Black Box - Using Specific Approaches}

Once a user begins serious work with integration in Maxima, they may
find that they want to use other techniques.  Maxima has several
functions which allow more power and flexibility.  Definite integration
will be the first example:

(Need example of where DEFINT fails but ROMBERG succeeds.)  Discuss LDEFINT 
RISCH ILT INTSCE 

\subsection{Other Examples}
Since integration is such a major feature, we will include here a fairly
extensive collection of examples of integrals.

\beginmaximasession
integrate(x,x);
assume(a>0)$
assume(n>0)$
integrate(a*x^n,x);
assume(b>0)$
integrate(a*exp(x*b),x);
assume(c>0)$
integrate(a*b^(x*c),x);
integrate(log(x),x);
integrate(a/(b^2+x^2),x);
assume(m>0)$
integrate(x^m*(a+b*x)^5,x);
integrate(x/(a+b*x)^n,x);
integrate(x^2/(a+b*x)^n,x);
integrate(1/(x^2-c^2)^5,x);
integrate(1/(a+b*x^2)^4,x);
integrate(sqrt(a+b*x)/(x^5),x);
\maximatexsession
\C45.  integrate(x,x); \\
\D45.  \frac{x^{2}}{2} \\
\C46.  assume(a>0)$ \\
\C47.  assume(n>0)$ \\
\C48.  integrate(a*x^n,x); \\
\D48.  \frac{a\*\iexpt{x}{n+1}}{n+1} \\
\C49.  assume(b>0)$ \\
\C50.  integrate(a*exp(x*b),x); \\
\D50.  \frac{a\*\iexpt{e}{b\*x}}{b} \\
\C51.  assume(c>0)$ \\
\C52.  integrate(a*b^(x*c),x); \\
\D52.  \frac{a\*\iexpt{b}{c\*x}}{\log b\*c} \\
\C53.  integrate(log(x),x); \\
\D53.  x\*\log x-x \\
\C54.  integrate(a/(b^2+x^2),x); \\
\D54.  \frac{a\*\arctan \left(\frac{x}{b}\right)}{b} \\
\C55.  assume(m>0)$ \\
\C56.  integrate(x^m*(a+b*x)^5,x); \\
\D56.  \frac{b^{5}\*\iexpt{x}{m+6}}{m+6}+\frac{5\*a\*b^{4}\*\iexpt{x}{m+5}}{m+5}+\frac{10\*a^{2}\*b^{3}\*\iexpt{x}{m+4}}{m+4}+\frac{10\*a^{3}\*b^{2}\*\iexpt{x}{m+3}}{m+3}+\frac{5\*a^{4}\*b\*\iexpt{x}{m+2}}{m+2}+\frac{a^{5}\*\iexpt{x}{m+1}}{m+1} \\
\C57.  integrate(x/(a+b*x)^n,x); \\
\D57.  -\frac{\left(b^{2}\*\left(n-1\right)\*x^{2}+a\*b\*n\*x+a^{2}\right)\*\iexpt{e}{- n\*\log \left(b\*x+a\right) }}{b^{2}\*\left(n^{2}-3\*n+2\right)} \\
\C58.  integrate(x^2/(a+b*x)^n,x); \\
\D58.  -\frac{\left(b^{3}\*\left(n^{2}-3\*n+2\right)\*x^{3}+a\*b^{2}\*\left(n^{2}-n\right)\*x^{2}+2\*a^{2}\*b\*n\*x+2\*a^{3}\right)\*\iexpt{e}{- n\*\log \left(b\*x+a\right) }}{b^{3}\*\left(n^{3}-6\*n^{2}+11\*n-6\right)} \\
\C59.  integrate(1/(x^2-c^2)^5,x); \\
\D59.  -\frac{35\*\log \left(x+c\right)}{256\*c^{9}}+\frac{35\*\log \left(x-c\right)}{256\*c^{9}}+\frac{105\*x^{7}-385\*c^{2}\*x^{5}+511\*c^{4}\*x^{3}-279\*c^{6}\*x}{384\*c^{8}\*x^{8}-1536\*c^{10}\*x^{6}+2304\*c^{12}\*x^{4}-1536\*c^{14}\*x^{2}+384\*c^{16}} \\
\C60.  integrate(1/(a+b*x^2)^4,x); \\
\D60.  \frac{5\*\arctan \left(\frac{\sqrt{b}\*x}{\sqrt{a}}\right)}{16\*\iexpt{a}{\frac{7}{2}}\*\sqrt{b}}+\frac{15\*b^{2}\*x^{5}+40\*a\*b\*x^{3}+33\*a^{2}\*x}{48\*a^{3}\*b^{3}\*x^{6}+144\*a^{4}\*b^{2}\*x^{4}+144\*a^{5}\*b\*x^{2}+48\*a^{6}} \\
\C61.  integrate(sqrt(a+b*x)/(x^5),x); \\
\D61.  -\frac{5\*b^{4}\*\log \left(\frac{2\*\sqrt{b\*x+a}-2\*\sqrt{a}}{2\*\sqrt{b\*x+a}+2\*\sqrt{a}}\right)}{128\*\iexpt{a}{\frac{7}{2}}}-\frac{15\*b^{4}\*\iexpt{\left(b\*x+a\right)}{\frac{7}{2}}-55\*a\*b^{4}\*\iexpt{\left(b\*x+a\right)}{\frac{5}{2}}+73\*a^{2}\*b^{4}\*\iexpt{\left(b\*x+a\right)}{\frac{3}{2}}+15\*a^{3}\*b^{4}\*\sqrt{b\*x+a}}{192\*a^{3}\*\left(b\*x+a\right)^{4}-768\*a^{4}\*\left(b\*x+a\right)^{3}+1152\*a^{5}\*\left(b\*x+a\right)^{2}-768\*a^{6}\*\left(b\*x+a\right)+192\*a^{7}} \\
\endmaximasession
