\documentstyle[12pt]{article}
%\renewcommand{\baselinestretch}{2}
%
% Expected paper size: 11 in x 8+1/2 in
%
\setlength{\oddsidemargin}{0in}
\setlength{\topmargin}{-0.5in}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.5in}
%
% *******************************************************************
%                             MACROS
% *******************************************************************
%
\def\l{\left}
\def\r{\right}
\def\pa{\partial}
\def\fr{\frac}
%
% *******************************************************************
% *******************************************************************
%
\begin{document}

\title{Maple Procedures for Partial and Functional Derivatives}

\author{E.S.Cheb-Terrab \thanks{
Computer Physics  Communications, 79,  E. S. Cheb-Terrab,  "Maple procedures
for partial and functional derivatives", 409-424 (1994), with kind permission
from Elsevier Science B.V., Amsterdam, The Netherlands} \\
\     \\
{\em Instituto de F\'\i sica}  \\
{\em Departamento de  F\'\i sica Te\'orica}  \\
{\em Universidade do Estado do Rio de Janeiro}  \\
{\em RJ 20550 - Brazil}}
\date{}
\maketitle
\thispagestyle{empty}

\begin{abstract}
% \hspace\parindent

A package with new {\bf Maple V} commands for the evaluation of
partial derivatives, functional derivatives and integrals containing the
Dirac delta function is presented. Some examples of the use of these
commands in physics are shown.

\end{abstract}

\newpage
\pagenumbering{arabic}

\section*{Introduction}
\hspace\parindent

As is well known, partial and functional derivatives play a major role in
calculations in physics.  On the other hand, even though the
advent of symbolic computing has made it possible to automate these
operations, functional derivatives are not yet implemented in general
purpose systems, and the evaluation of partial derivatives requires special
care\cite{MUC84,OPERATORS}, restricting the use of these programs in
research.

The subject of this paper is related to these topics, and consists of the
presentation of a set of new {\bf Maple V} differentiation
commands\footnote{The commands and routines here presented only work with
the {\bf Maple V} Release 5.2 environment and are not intended to work with
any other computer algebra system.} which both overcome some of the present
restrictions (with respect to the evaluation of partial derivatives) and
allow functional derivatives to be calculated.

The plan for the exposition is as follows.  In Sec.1, the whole package of new
commands is presented through a short {\it write-up}, followed by a long {\it
write-up} for the most relevant routines, mainly {\bf pdiff} for partial
derivatives and {\bf fdiff} for functional derivatives\footnote{Aside from
this, the package itself contains an {\it ON-LINE} help in standard {\bf
Maple} format which can be viewed as a User-manual for all the routines.}.
This long {\it write-up} also contains examples which can be viewed as simple
{\it input/output} tests for the routines of the package. Sec.2 was written as
an {\it input/output} test in the context of ``problems in physics", aiming at
giving a more concrete illustration of the new commands' abilities as well as
an idea of the type of problems which can be tackled with them.  Finally, the
conclusion contains a short comment about possible improvements, in order to
extend the use of general purpose symbolic algebra systems in theoretical
physics.

Aside from this, some additional information is given in two appendices.  The 
first one contains a brief discussion about the use of {\it mappings} in the 
calculation of partial derivatives, and the second one explains some new {\bf 
type/...} subroutines, as well as a slight change made to the {\bf 
D/procedure} standard routine, in order to make it compatible with the package 
here presented.

\section{The {\it partials} package}
\hspace\parindent

\subsection{Short {\it write-up}}

A brief review of the commands of the package is as follows:

\begin{itemize}
\item\ {\bf pdiff} performs the calculation of partial derivatives of
algebraic expressions with respect to parameters or functions.  It does not
require the previous definition of a mapping. It also allows the User to
freeze specified functions of the derivation variables, in order to arrive
at ``explicit" (fixed) partial derivatives, commonly used in physics.

\item\ {\bf usepdiff} takes full advantage of expressions involving the {\bf D}
standard operator for the evaluation of partial derivatives by
sending the task to {\bf pdiff}, allowing, in this way, the calculation to
be done without the previous building of a mapping.

\item\ {\bf fdiff} calculates functional derivatives of algebraic expressions
(containing or not multiple integrals).

\item\ {\bf evalDi} evaluates integrals containing the Dirac delta function
or its derivatives.

\item\ {\bf parameters} allows the parameters of a theory to be defined in
such a way that no functionality can be attached to them during the {\bf
Maple} session.  In this way, a parameter defined through this command will
behave not as a variable (standard behavior), but rather as if it were a
``number''  (fixed parameter).

\item\ {\bf odiff} returns the general differential order (or particular,
with respect to an indicated variable)  of an expression containing partial
derivatives.

\item\ {\bf seldiff} selects, from an algebraic expression, those terms which
contain derivatives of an indicated order with respect to an indicated
variable.

\item\ {\bf usediff} and {\bf useD} are syntax converters between the {\bf
diff} and the {\bf D} standard {\bf Maple} syntaxes for derivatives.
\end{itemize}
They are equivalent to the {\bf convert(...,diff)} and {\bf
convert(...,D)} standard {\bf Maple} routines. The main differences are: {\bf
usediff} does not return results through the {\bf \&where} function as does
{\bf convert(...,diff)}, and {\bf useD} realizes the conversions to the {\bf
D} syntax even inside composite functions, while {\bf convert(...,D)} does not.
\begin{itemize}
\item\ {\bf Intc}, {\bf Int2c}, {\bf Int3c}, and {\bf Int4c} are simple macros
that shorten the input of simple, double, triple and quadruple integrals
from $-\infty$ to $+\infty$.

\item\ A new {\bf Value} routine, with a definition slightly different from the
standard value routine, allows the User to define Value/... rules for functions
with indexed names (specially useful when working with Relativistic theories).

\end{itemize}

\subsection{Long {\it write-up}}
\hspace\parindent

The {\bf Maple} standard differentiation commands are {\bf diff}, {\bf
D} and {\bf Diff}. Because they already conform a powerful set, the goal
of the {\it partials} package was not to ``substitute" these commands
but to create new ones (mainly {\bf pdiff}, {\bf fdiff}), which work with the
standard ones in a complementary manner, extending the environment's ability
in that:
\begin{enumerate}
\item\ they permit the User to calculate partial derivatives, explicit (fixed)
or general ones, of algebraic expressions, with respect to parameters or
functions, without defining mappings;
\item\ they allow functional derivatives to be calculated.
\end{enumerate}
A detailed description of {\bf pdiff} and {\bf fdiff},
along with some examples which can be viewed as simple tests for the
{\it input/output} of the commands, is as follows:

\bigskip
\noindent
{\it Command name:} {\bf pdiff}

\noindent
{\it Feature:} Partial (general or explicit) differentiation command

\medskip
\noindent
{\it Calling sequence:}
\begin{verbatim}
> pdiff(a, x1, x2, ..., xn);
> pdiff(a, x1, x2, ...,xn, {f1(x,...),f2(x...),....});
\end{verbatim}

\medskip
\noindent
{\it Parameters:}

\medskip
\noindent
\begin{tabular}{lll}
\verb-a-               & - an algebraic expression (the ``derivand")
\\
\verb-x1, ...-         & - names or functions (the derivation variable(s))
 \\
\verb-{f1(x,...),...}- & - optional; indicates which  functions (and their
derivatives) of the \\
& \ \  derivation variables must be frozen
\end{tabular}

\medskip
\noindent
{\it Synopsis:}

\medskip
This function is part of the {\it partials} package, and so can be used
in the form \verb-pdiff(..)- only after performing the instruction

\noindent
\verb-> with(partials):-  (or)

\noindent
\verb-> with(partials,pdiff):-

\noindent
at the {\bf Maple} prompt ``\verb->-".

\medskip
{\bf pdiff} calculates the partial derivative, general or ``explicit", of
algebraic expressions with respect to parameters or functions (the {\bf
diff} command cannot differentiate with respect to functions), without
requiring the definition of a mapping for the ``derivand" (required when
using the {\bf D} operator).

In order to calculate ``explicit partial derivatives" (also not possible
with the {\bf diff} command), {\bf pdiff} requires the indication of which
functions of the derivation variables must be ``frozen" (fixed) during the
calculation.  This situation typically happens when using variational
principles which, in turn, introduce functions as parameters\footnote{This
is the case, for example, of the Lagrange formalism with the related
Lagrange equations in  mechanics.}.  If a function is indicated inside the
braces, all its derivatives will also be frozen.

It makes no difference whether to use the {\bf diff}, {\bf Diff}, or
{\bf D} command in the arguments passed to {\bf pdiff}, since it will
take into account the mathematical equivalence between them. For example,
instructions such as \verb-pdiff(L,diff(q(t),t))-, \verb-pdiff(L,Diff(q(t),t))-
and \verb-pdiff(L,D(q)(t))- will all give the same result.

As a rule, {\bf pdiff} will try not to change the User's choice of
syntax ({\bf diff}, {\bf Diff}, or {\bf D}).  Nevertheless, when the
arguments sent to {\bf pdiff} make use of more than one syntax to
represent the same mathematical object, the syntax selected by {\bf pdiff}
for the output will be that of the ``derivand".  If the derivand uses more
than one syntax representing the same mathematical object, the result will
be returned using the {\bf D} syntax for that object.

If the algebraic expression is given with the functional dependence
indicated but in implicit form (for example: $f(x,y,z)$, with unknown form for
$f$), the result will be returned using the {\bf D} operator. In this
case, the returned expression can be transformed into a concrete result
through the {\bf usepdiff} command, after defining the explicit form of the
functions involved by directly assigning values to them (mappings are not
mandatory).

Special rules for the evaluation of partial derivatives with respect
to User Defined functions using {\bf pdiff} can be stated by
indicating the rule (for the NAME of the U.D. function) to the {\bf
diff} command in {\bf Maple}'s usual way.

\medskip
\noindent
{\it Examples}\footnote{In
what follows, the {\it input} can be recognized by the {\bf Maple} prompt
\verb->-, and the output was obtained with {\bf Maple} release 5.2. {\it for
Windows}, in a DOS platform.  Further, special care was taken to keep
the {\it input}  and {\it output} shown along this paper with almost
exactly the same format and aspect as that which appears on the computer's
screen.\label{winmaple} }:
\begin{verbatim}
> with(partials,pdiff);
\end{verbatim}
\begin{displaymath}
[{\it pdiff}]
\end{displaymath}
\begin{verbatim}
> pdiff(cos(q(t)),q(t));
\end{verbatim}
\begin{equation}
-\sin(q(t))
\end{equation}
\begin{verbatim}
> Int(f(x)*exp(y(t)),x=0..y(t)^(1/2));
\end{verbatim}
\begin{displaymath}
\int _{0}^{\sqrt {y(t)}}\!f(x){e^{y(t)}}{dx}
\end{displaymath}
\begin{verbatim}
> pdiff(",y(t));
\end{verbatim}
\begin{equation}
{e^{y(t)}} \int _{0}^{\sqrt {y(t)}}\!f(x){dx}+{\frac {f(\sqrt {y(t)}){e
^{y(t)}}}{2\,\sqrt {y(t)}}}
\end{equation}
\begin{verbatim}

> alias(Q=(q(t),diff(q(t),t),t)):     # defines a "Q" functionality.
> pdiff(L(Q),t);                      # The total derivative:
\end{verbatim}
\begin{equation}
D_{[1]}(L)(\mbox {{\it Q}}){\frac {\pa }{\pa t}}q(t)+D_{{2}}(L)(\mbox {{
\it Q}}){\frac {\pa ^{2}}{\pa t^{2}}}q(t)+D_{[3]}(L)(\mbox {{\it Q}})
\end{equation}
\begin{verbatim}

> L(Q) := 1/2*diff(q(t),t)^2-1/2*k * q(t)^2 - cos(w*t); # Assigns a
                                                        # value to L(Q)
\end{verbatim}
\begin{equation}
L(Q):=\fr{1}{2} {\frac {\pa}{\pa t}}q(t)^{2}-\fr{1}{2} kq(t)^{2}-\cos(wt)
\end{equation}
\begin{verbatim}

> usepdiff("");           # The total derivative eq(3) without mappings:
\end{verbatim}
\begin{equation}
-kq(t){\frac {\pa }{\pa t}}q(t)
+\left ({\frac {\pa }{\pa t}}q(t)\right ){\frac {\pa ^{2}}{\pa t^{2}}}q(t)
+\sin(wt)w
\end{equation}
\begin{verbatim}

> pdiff(L(Q),q(t));       # Each partial derivative:
\end{verbatim}
\begin{equation}
-k q(t)
\end{equation}
\begin{verbatim}
> pdiff(L(Q),D(q)(t));
\end{verbatim}
\begin{equation}
{\frac {\pa}{\pa t}}q(t)
\end{equation}
\begin{verbatim}

> pdiff(L(Q),t,{q(t)});   # the "explicit" partial derivative:
\end{verbatim}
\begin{equation}
\sin(wt)w
\end{equation}

\noindent
\hrulefill

\bigskip
\noindent
{\it Command name:} {\bf fdiff}

\noindent
{\it Feature:} Evaluation of functional derivatives

\medskip
\noindent
{\it Calling sequence:}
\begin{verbatim}
> fdiff(a, f1);
> fdiff(a, f1, f2, ..., fn);
\end{verbatim}

\medskip
\noindent
{\it Parameters:}

\medskip
\noindent
\begin{tabular}{lll}
\verb-a-               & - an algebraic expression
\\
\verb-f1, ...-         & - functions (the functional differentiation
                            variables)
\\
\end{tabular}

\medskip
\noindent
{\it Synopsis:}

\medskip
This function is part of the {\it partials} package, and so can be used
in the form \verb-fdiff(..)- only after performing the instruction

\noindent
\verb-> with(partials):-  (or)

\noindent
\verb-> with(partials,fdiff):-

\noindent
at the {\bf Maple} prompt.

\medskip
{\bf fdiff} calculates functional derivatives of algebraic expressions.

If the expression being differentiated contains an integral (maybe a
multiple or nested one), {\bf fdiff} goes inside it and, after the functional
differentiation of the integrand, tries to evaluate the resulting
integral which now contains the Dirac delta function or its derivatives.  This
evaluation, in turn, will be carried out only if the integration limits are
from $-\infty$ to $+\infty$ and the argument of the Dirac delta function
involved is a linear function of the integration variable. Otherwise, the
{\it intermediate} integral without evaluation will be returned (after
replacing all occurrence of {\bf int} by its inert form {\bf Int}).  In
this way, it is possible to control the different steps of a calculation
through a simple change of the integration limits. The evaluation of these
integrals is performed by the {\bf evalDi} command.

Since {\bf fdiff} is implemented using {\bf pdiff}, which, in turn, makes
use of {\bf diff}, the differentiation knowledge of {\bf fdiff} with
respect to mathematical functions is exactly that of {\bf diff}, so any
special rule for the functional derivative of a User Defined function can
be stated by indicating the rule (for the NAME of the U.D.  function) to
{\bf diff} in {\bf Maple}'s usual way. In addition, since {\bf pdiff}
recognizes the derivatives built with the {\bf diff}, {\bf Diff}, or {\bf D}
syntaxes as mathematically equivalent, the same holds for {\bf fdiff}.

\medskip
\noindent
{\it Examples}\footnote{{\bf Maple}'s convention for the
derivative of the Dirac delta function is given by:
$$
\fr{\pa ^n}{\pa x^n}
\delta(x) = \delta(n,x)
$$}:
\begin{verbatim}
> alias(delta=Dirac):
> with(partials,fdiff);
\end{verbatim}
\begin{displaymath}
[{\it fdiff}]
\end{displaymath}
\begin{verbatim}
> fdiff(q(u1,u2,u3,u0),q(x1,x2,x3,x0));
\end{verbatim}
\begin{equation}
\delta(u1 - x1)\: \delta(u2 - x2)\: \delta(u3 - x3)\: \delta(u0 - x0)
\end{equation}
\begin{verbatim}
> diff(q(u,v),u,v$2);
\end{verbatim}
\begin{displaymath}
{\frac {\partial ^{3}}{\partial u\partial v^2}}q(u,v)
\end{displaymath}
\begin{verbatim}
> fdiff(",q(x,y));
\end{verbatim}
\begin{equation}
\delta (1,u-x)\: \delta (2,v-y)
\end{equation}
\begin{verbatim}
> Intc(1/2*diff(q(t),t)^2-1/2*k*q(t)^2,t);
\end{verbatim}
\begin{displaymath}
\int _{-\infty }^{\infty }\! \frac{1}{2} \frac {\pa}{\pa t} q(t)^{2}
- \frac{1}{2} kq(t)^{2}\, dt
\end{displaymath}
\begin{verbatim}
> fdiff(",q(u));
\end{verbatim}
\begin{equation}
-kq(u)-{\frac {\pa }{\pa u}}\mbox {D}(q)(u)
\end{equation}
\begin{verbatim}
> subsop(2=t,"");            # Changing the integration limits in eq("")
\end{verbatim}
\begin{displaymath}
\int  \frac{1}{2} \frac {\pa}{\pa t} q(t)^{2}
- \frac{1}{2} kq(t)^{2}\, dt
\end{displaymath}
\begin{verbatim}
> fdiff(",q(u));             # The intermediate integrals are returned
\end{verbatim}
\begin{equation}
-k \int \! \delta(t - u)\: q(t) dt
+ \int \! \mbox {D}(q)(t)\: \delta(1,t - u)\, dt
\end{equation}


\section{Test for the {\it input/output} of the package}
\hspace\parindent

What follows is an {\it input/output} test for the {\it partials} package,
in the context of ``problems in physics"\footnote{For a simple {\it
input/output} sequence of partial and functional derivatives without
context see the {\it write-up} in Sec.1.}. This context is in order to
illustrate the new commands' abilities, while giving the User some insight
on the kind of problems in which these commands can be used.

\subsection{Test 1: Poisson brackets in field theories }

As the first test, let's consider the building of the matrix of the
Poisson brackets of constraints in the canonical quantization of Maxwell's
theory in four dimensions.  The expected result is given in
reference\cite{das}. First, the main commands and some alias are
introduced:
\begin{verbatim}
> with(partials,fdiff,evalDi,Intc);
\end{verbatim}
\begin{displaymath}
[{\it Intc},{\it evalDi},{\it fdiff}]
\end{displaymath}
\begin{verbatim}
> with(linalg,matrix):
> alias(delta=Dirac):           # The string delta will represent Dirac.
> alias(x=(x1,x2,x3,x0)):
> alias(y=(y1,y2,y3,y0)):
> alias(z=(z1,z2,z3,z0)):
> alias(A=(A1,A2,A3,A0)):
> alias(P=(P1,P2,P3,P0)):
\end{verbatim}
\begin{equation}\end{equation}
These alias allow a short {\it input/output} for the space-time parameters
(here represented by $x$, $y$ or $z$), for the vector field $A^\mu$, and for
its canonical momentum $P^\mu$. Next, the Poisson brackets,
\begin{equation}
\{F(x),G(y)\}_{_{[x_0=y_0]}}=
\!\int _{-\infty }^{\infty }
\!\int _{-\infty }^{\infty }
\!\int _{-\infty }^{\infty }
\!\sum _{k=1}^{4}
\fr {\delta F}{\delta P_{[k]}(z)}\:
\fr {\delta G}{\delta A_{[k]}(z)}\:
-\fr {\delta G}{\delta P_{[k]}(z)}\:
\fr {\delta F}{\delta A_{[k]}(z)}\:
{d{\it z_1}}\,{d{\it z_2}}\,{d{\it z_3}}
\end{equation}
can be entered as:
\begin{verbatim}
> PB := (F,G) -> evalDi(Int3c(sum('fdiff'(F,P[k](z))*'fdiff'(G,A[k](z))
>                                -'fdiff'(G,P[k](z))*'fdiff'(F,A[k](z)),
>                                  k=1..4), z1, z2, z3):
\end{verbatim}
The {\bf evalDi} command is required for the evaluation of the integrals
containing the Dirac delta function, which will appear as a result of the
calculation of functional derivatives performed by {\bf fdiff}. The
evaluation of the Poisson brackets using this expression will test the {\it
output} of {\bf evalDi} and {\bf fdiff}, as well as that of {\bf pdiff},
{\bf odiff}, {\bf useD}, and {\bf usediff} (all these commands will be called
by {\bf fdiff}), at once.

Now, in order to evaluate these brackets at ``equal time", one may declare
that the corresponding Dirac delta functions are equal to one\footnote{This
would be incorrect in other contexts, but is justified here because it is a
very economical way of implementing the ``equal time" request of the
calculation of the Poisson brackets.}:
\begin{verbatim}
> delta(x0-z0) := 1: delta(y0-z0) := 1: delta(x0-y0) := 1:
\end{verbatim}
\begin{equation}\end{equation}
To arrive at the desired matrix, the constraints of the model are
entered as\cite{das}:
\begin{verbatim}
> c[1] := P0:
> c[2] := D[1](P1)+D[2](P2)+D[3](P3):
> c[3] := A0:
> c[4] := D[1](A1)+D[2](A2)+D[3](A3):
\end{verbatim}
\begin{equation}\end{equation}
where \verb-c[1]-, \verb-c[2]-,  \verb-c[3]-, and  \verb-c[4]- represent the
constraints $P_0 (\approx 0)$, $\nabla \vec{P} (\approx 0)$, $A_0 (\approx
0)$, and $\nabla \vec{A} (\approx 0)$, respectively. The space-time dependence
is not yet indicated, in order to allow different space-time parameters to be
used when calculating the functional derivatives inside the Poisson brackets.
Finally, the matrix can be built as:
\begin{verbatim}
> C := (i,j) -> PB(c[i](x),c[j](y)):
> matrix(4,4,C);
\end{verbatim}
\begin{equation}
\begin{array}{l}
[0,   0,    \delta(x1 - y1) \delta(x2 - y2) \delta(x3 - y3),    0]
\\*[0.15 in]
[0,    0,    0,   \delta(2, y1 - x1) \delta(x2 - y2) \delta(x3 -y3)
\\*[0.15 in]
+ \delta(x1 - y1) \delta(2, y2 - x2)\delta(x3 -y3)
+ \delta(x1 - y1) \delta(x2 - y2) \delta(2, y3 -x3)]
\\*[0.15 in]
[- \delta(x1 - y1) \delta(x2 - y2) \delta(x3 - y3),   0,   0,   0]
\\*[0.15 in]
[0,  -\delta(2, y1 - x1) \delta(x2 - y2) \delta(x3 -y3)
- \delta(x1 - y1) (\delta(2, y2 - x2))\delta(x3 -y3)
\\*[0.15 in]
- \delta(x1 - y1) \delta(x2 - y2) \delta(2, y3 -x3),  0,  0]
\end{array}
\end{equation}
This result includes the Laplacian of a tri-dimensional
Dirac delta function and checks {\it OK} with that of \cite{das}.

\subsection{Test 2: Lagrange equations in field theories}

The second test is related to the problem of the equivalence between
two Lagrange functions (a {\it standard} one and its {\it first order}
equivalent\footnote{A {\it first order} Lagrange function is linear in the
derivatives with respect to time.  This linearization is obtained by departing
from the {\it standard} Lagrange function and then extending the configuration
space through the introduction of auxiliary fields.}) in the context of a
field theory with {\it high order derivatives}.  This equivalence has already
been derived by hand for the specific case considered below\cite{eduardo}, and
its derivation will be done here using the new commands.

To start with, let's introduce the {\bf fdiff} command,  {\bf Value/...} rules
for the operatores ${\pa}_{\mu}$ and ${\pa}^{\mu}$ (here represented by
${d\_}_{[\mu]}$ and ${d}_{[\mu]}$ respectively), and for the Laplace
($\Delta$) and d'Alembert ($\Box$) differential operators, as
follows\footnote{The $\Box$ character in the {\it input} lines can be obtained
by pressing the combination of keys {\bf Ctrl}+{\bf Backspace} at the input
line of the {\bf Maple} {\it for Windows} worksheet. In platforms where this
character is not allowed one can work with any other valid string.}:
\begin{verbatim}
> with(partials,fdiff,Value);
\end{verbatim}
\begin{displaymath}
[ {\it fdiff},{\it Value}]
\end{displaymath}
\begin{verbatim}
> `Value/d_`:= proc(p) option `i n d e x e d`;
>              diff(op(p),cat(x,op(op(0,p))))
>              end:
>
>`Value/d`:= proc(p) option `i n d e x e d`;
>            if member(op(op(0,p)),{1,2,3}) then -1 else 1 fi:
>            "*diff(op(p),cat(x,op(op(0,p))))
>            end:
>
> `value/Delta` := u ->
>             diff(op(u),x1,x1) + diff(op(u),x2,x2) + diff(op(u),x3,x3);
\end{verbatim}
\begin{equation}
value/Delta :=
u\mapsto {\frac {\pa ^{2}}{\pa {\it x1}^{2}}}u
+{\frac {\pa ^{2}}{\pa {\it x2}^{2}}}u
+{\frac {\pa ^{2}}{\pa {\it x3}^{2}}}u
\end{equation}

\noindent
\verb-> `value/-$\Box$\verb^` := u -> diff(op(u),x0,x0) ^

\noindent
\verb^>
          - diff(op(u),x1,x1) - diff(op(u),x2,x2) - diff(op(u),x3,x3);^
\begin{equation}
value/\Box :=
u\mapsto -{\frac {\pa ^{2}}{\pa {\it x1}^{2}}}u
-{\frac {\pa ^{2}}{\pa {\it x2}^{2}}}u
-{\frac {\pa ^{2}}{\pa {\it x3}^{2}}}u
+{\frac {\pa ^{2}}{\pa {\it x0}^{2}}}u
\end{equation}
Since ${\pa}_{\mu}$ and ${\pa}^{\mu}$ are being defined as indexed
functions, both required the definition of their evaluation rules through the
new {\bf Value} command.

\noindent
Next, some aliases ($x$ and $u$) for the representation of the space-time
parameters, and $(\phi,  \pi_{[1]}, \pi_{[2]}, \pi_{[3]})$ for the main
($\phi$) and auxiliary fields ($\pi_{[...]}$)) as functions of $x$:
\begin{verbatim}
> alias(x=(x1,x2,x3,x0)):
> alias(u=(u1,u2,u3,u0)):
> alias(phi = phi(x1,x2,x3,x0)):
> alias(pi[1] = pi[1](x1,x2,x3,x0)):
> alias(pi[2] = pi[2](x1,x2,x3,x0)):
> alias(pi[3] = pi[3](x1,x2,x3,x0));
\end{verbatim}
\begin{equation}
[I,x,u,\phi,\pi_{[1]},\pi_{[2]},\pi_{[3]}]
\end{equation}
Now the standard ($L$) and first order ($L1$) Lagrange functions are
entered as:

\medskip
\noindent
\verb-
> L := 1/2 * Sum(d_[i](phi)*d[i](phi),i = 0..3)-

\noindent
\verb_
 >        - m/2*phi^2 + 1/kappa^2*`_$\Box$\verb_`(phi)^2 + lambda*phi^4/12;_
\begin{equation}
L :=
\frac{1}{2}
\sum^{3}_{i=0}\l( {d\_}_{[i]}(\phi)\ d_{[i]}(\phi) \r)
-{\frac {m\phi^{2}}{2}}
+{\frac {\lambda\,\phi^{4}}{12}}
+\frac {({\Box}(\phi))^{2}}{\kappa^{2}}
\end{equation}
(note the presence of high order derivatives in the $({\Box}(\phi))^{2}$ term)
\begin{verbatim}
> L1 := Sum(d_[i](phi)*d[i](phi),i = 1..3)/2-m*phi^2/2+lambda*phi^4/12
>       -pi[1]^2/2+2/kappa^2*pi[1]*pi[3]-pi[2]^2/kappa^2
>       -2/kappa^2*pi[1]*diff(pi[2],x0)-2/kappa^2*pi[3]*diff(phi,x0)
>       +pi[1]*diff(phi,x0)+4/kappa^2*Delta(pi[1])*diff(phi,x0)
>       -2/kappa^2*Delta(pi[1])*pi[1]+Delta(phi)^2/kappa^2;
\end{verbatim}
\begin{eqnarray}
\lefteqn{
L1 :=
\frac{1}{2}
\sum^{3}_{i=1}\l( {d\_}_{[i]}(\phi)\ d_{[i]}(\phi) \r)
-{\frac {m\phi^{2}}{2}}
+{\frac {\lambda\,\phi^{4}}{12}}
} % close lefteqn
\nonumber \\*[0.2in]
& &
-{\frac{1}{2}{\pi_{[1]}^{2}}}
+{\frac {2\,\pi_{[1]}\pi_{[3]}}{\kappa^{2}}}
-{\frac {\pi_{[2]}^{2}}{\kappa^{2}}}
{-{\frac {2\,\pi_{[1]}
{\displaystyle \frac {\pa }{\pa {\it x0}}}  \pi_{[2]}}{\kappa^{2}}}
-\frac {2\,\pi_{[3]}{\displaystyle
\frac {\pa }{\pa {\it x0}}}\phi}{\kappa^{2}}}
+\pi_{[1]}{\displaystyle \frac {\pa }{\pa {\it x0}}}\phi
\\*[0.2in] \nonumber
& &
+{\frac {4\,\Delta(\pi_{[1]})
 {\displaystyle \frac {\pa }{\pa {\it x0}}}\phi}{\kappa^{2}}}
-{\frac {2\,\Delta(\pi_{[1]})\pi_{[1]}}{\kappa^{2}}}
+{\frac {(\Delta(\phi))^{2}}{\kappa^{2}}}
\end{eqnarray}
where $m$ represents the mass of the particles associated to the $\phi$ field,
$\lambda$ is a parameter of the theory and {\it L1} contains only first order
derivatives with respect to $x0$.

$L$ and $L1$ are equivalent if they lead to the same equation for the $\phi$
field, after the elimination of all the auxiliary fields $\pi_{[...]}$,
through their own Lagrange equations. Therefore, to prove this equivalence,
the calculation of all the field equations is required. These equations will
be obtained by taking the functional derivative of the action $S$ with respect
to each field, using the new commands.

The procedure of calculation of the field equations (here named {\it
LE}) is now built as the functional derivative of a given action $S$ with
respect to a given field $Q$:
\begin{verbatim}
> LE := (S,Q) -> usediff(subs({u0=x0,u1=x1,u2=x2,u3=x3},fdiff(S,Q(u)))):
\end{verbatim}
\begin{equation}\end{equation}
the main part of the calculation being done by \verb-fdiff(S,Q(u))-, while
the other parts of the procedure aim at a readable output.
The action for $L$ and the movement equation for $\phi$ (here named $EQ$)
are given by:
\begin{verbatim}
> S := Int4c('Value(L)',x1,x2,x3,x0);
\end{verbatim}
\begin{equation}
S:=\int _{-\infty }^{\infty }\!\int _{-\infty }^{\infty }\!\int _{-
\infty }^{\infty }\!\int _{-\infty }^{\infty }\!Value(L){d{\it x1}}\,{d{\it
x2}}\,{d{\it x3}}\,{d{\it x0}}
\end{equation}
\begin{verbatim}
> EQ := LE(S,op(0,phi)):
\end{verbatim}
\begin{equation}\label{eq}\end{equation}
In the same way, the action for $L1$ and the Lagrange equations (here named
$EQ1_{[...]}$) for $\phi$ and for the auxiliary fields, obtained from this
action, are calculated through:
\begin{verbatim}
> S := Int4c('Value(L1)',x1,x2,x3,x0);
\end{verbatim}
\begin{equation}
S:=\int _{-\infty }^{\infty }\!\int _{-\infty }^{\infty }\!\int _{-
\infty }^{\infty }\!\int _{-\infty }^{\infty }\!{\it Value(L1)}{d{\it x1}}\,
{d{\it x2}}\,{d{\it x3}}\,{d{\it x0}}
\end{equation}
\begin{verbatim}
> for j in [phi,pi[1],pi[2],pi[3]] do EQ1[j] := LE(S,op(0,j)) od:
\end{verbatim}
\begin{equation}\label{auxeq}\end{equation}
The next step is connected with the elimination of the auxiliary fields using
the equations above. This elimination does not use the commands of the package
but is necessary to conclude the test.  To proceed, let's  first check the
number of terms and the functional dependence of each movement
equation\footnote{The {\it left hand sides} identify the fields to which the
movement equations are associated, while the {\it right hand sides} display
the required information. The {\bf type/Function} subroutine is also part of
the {\it partials} package (see Appendix B).}:
\begin{verbatim}
> map(nops,EQ1);
\end{verbatim}
\begin{equation}
\mbox {\tt table}([\phi=16,
\pi_{[1]}=10,
\pi_{[2]}=2,
\pi_{[3]}=2])
\end{equation}
\begin{verbatim}
> map(indets,EQ1,Function);
\end{verbatim}
\begin{equation}
\mbox {\tt table}([\phi = \left \{\phi, \pi_{[1]},\pi_{[3]}\right \},
 \pi_{[1]} = \left \{\phi,\pi_{[1]},\pi_{[2]},\pi_{[3]}\right \},
 \pi_{[2]} = \left \{\pi_{[1]},\pi_{[2]}\right \},
 \pi_{[3]} = \left \{\phi,\pi_{[1]}\right \}])
\end{equation}
Using the information above, one can eliminate the auxiliary fields from all
the field equations at once, taking into account each of the equations for the
auxiliary fields at a time, through\footnote{The {\bf Maple} mechanism used in
this step is known as {\it simplify with respect to side relations} (by doing
Grobner basis calculations).}:
\begin{verbatim}
> EQ1 :=  map(u -> simplify(u,{EQ1[pi[3]]},{pi[1]}),EQ1):
> EQ1 :=  map(u -> simplify(u,{EQ1[pi[2]]},{pi[2]}),EQ1):
> EQ1 :=  map(u -> simplify(u,{EQ1[pi[1]]},{pi[3]}),EQ1):
> map(indets,EQ1,Function);
\end{verbatim}
\begin{equation}
\mbox {\tt table}([
\phi= \left \{\phi\right \},
\pi_{[1]}= \left \{\right \},
\pi_{[2]}= \left \{\right \},
\pi_{[3]}= \left \{\right \}])
\end{equation}
The last instruction shows no functional dependence in the equations for
the auxiliary fields (they were eliminated), and only $\{\phi\}$
dependence for the $\phi$ equation. Finally, this $EQ1[\phi]$ equation is
tested against $EQ$ obtained from $L$:
\begin{verbatim}
> expand(EQ1[phi]-EQ);
                                  0
\end{verbatim}
arriving at the expected result, which states the equivalence between $L$
and $L1$.

\medskip

\section{Conclusions}

It is clear that computer support for theoretical research in physics is going
to grow in the following years. In this context, the introduction of handy and
flexible commands for the evaluation of partial and functional derivatives is
important since it extends the use of computer algebra systems in research.

The building of such commands was presented here, as the {\it partials}
package, of which the most relevant ones are {\bf pdiff} and {\bf fdiff}.  As
a consequence, problems requiring the calculation of partial and functional
derivatives can now be tackled using an almost trivial syntax (characteristic
of general purpose programs), as was shown in the examples treated in Sec.1
and 2.

Nevertheless, we are still far from the powerful required tool. The main
problem is that there still does not exist a handy manipulation of indices
associated with different representations for the space-time and for common
internal groups appearing in almost all interesting physical theories.
Specifically, it is not yet possible to evaluate functional derivatives with
respect to Grassman variables or to abstract indexed quantities in a direct
manner, as one is used to doing by hand. These subjects are now under study
and will be reported elsewhere.

\section*{Acknowledgements}

The author wishes to thank Prof. S.A.Dias\footnote{From {\bf C.B.P.F.},
Rio de Janeiro, Brazil.}
and Prof. J.F.Medeiros\footnote{From {\bf U.E.R.J.}, Rio de Janeiro,
Brazil.}, for fruitful comments and careful reading of this paper.

\appendix
\section*{Appendix A}
\hspace\parindent

This appendix contains a discussion about the use of {\it mappings} in the
calculation of partial derivatives. To start with, let's recall that
\begin{itemize}
\item\ the objects with which the {\bf Maple} program works are
classified into {\it types}.
\end{itemize}
These {\it types}, in turn, resemble the natural classification we are used to
giving to mathema\-ti\-cal objects. To know how {\bf Maple} classifies an
object, one can use either the {\bf whattype} or the {\bf type} command.
For example:
\begin{verbatim}
> whattype(t);
\end{verbatim}
$$
\mbox{\it string}
$$
\begin{verbatim}
> type(f(t),function);
\end{verbatim}
$$
\mbox{\it true}
$$
Objects which are identified as functions by the {\bf type} command are not
allowed as derivation variables for the {\bf diff} command. Therefore, typical
operations involving variational calculus are not possible using {\bf diff} in
a direct manner.  The standard alternative to this restriction requires the
use of mappings together with the {\bf D} operator while the alternative
propposed in this paper is a straight use of the {\bf pdiff} command. To
understand the standard alternative, let's first review some aspects of a {\bf
Maple} mapping.

Mappings may be used to represent explicit functions. For example, for
\begin{equation}
f(x,y,z)=x+y^2-z,
\label{f}
\end{equation}
one can introduce the mapping:
\begin{verbatim}
> f := (x,y,z) -> x + y^2 - z:
\end{verbatim}
\begin{equation}
f:= ({\it x},{\it y},{\it z}) \mapsto {\it x}+{\it y}^2-{\it z}
\label{map}\end{equation}
The main properties of a mapping are:
\begin{itemize}
\item\ It can be evaluated at a ``point".
\end{itemize}
For example,
\begin{verbatim}
> f(x,x,x);
\end{verbatim}
\begin{equation}
{\it x}^2
\end{equation}
\begin{itemize}
\item\ The $(x,y,...)$ variables used in the building of a mapping are
{\it local} to it.
\end{itemize}

Therefore, these {\it local} variables cannot have their {\it names}
associated with {\it global}  meanings, as is commonly done in physics. As
regards to this, the {\it mapping} defined in eq.(\ref{map}) does not
represents the function of eq.(\ref{f}) since (\ref{f}) has an explicit
$(x,y,z)$ dependence, probably with geometrical meanings associated to
(global) $(x,y,z)$, while (\ref{map}) does not depend on $(x,y,z)$ at all. As
an example of this difference, it does not make sense to differentiate the
mapping $f$ defined in eq.(\ref{map}) with respect to $x$, $y$ or $z$ but only
with respect to it ``first", ``second" or ``third" argument.

Now, as for the restriction mentioned at the beginning of this appendix, to
``differentiate with respect to functions", the User must build a {\it
mapping}, use the {\bf D} operator and indicate the {\it numeric position} of
the derivation variable, as well as the {\it point} at which the result must
be evaluated.  This {\it evaluation point}, in turn, may contain functions. In
this manner, one will receive what would be a representation for
``differentiation with respect to functions". As an example, the derivative of
$f$ with respect to the ``second variable", evaluated at the (function) point
$(y,z(t),x)$, returns:
\begin{verbatim}
D[2](f)(y,z(t),x);
\end{verbatim}
\begin{equation}
2{\it z(t)}
\end{equation}
and, if $x$, $y$ and $z(t)$ appear inside the evaluation point in the correct
order (not the case above), the result may be interpreted as differentiation
of eq.(\ref{f}) w.r.t the function $z(t)$. Finally,
\begin{itemize}
\item\ objects which are identified as functions by the {\bf type} command
are not allowed as the $(x,y,...)$ variables used in the building of a
mapping.
\end{itemize}
Hence, {\it composite functions} may not have a simple ``mapping
representation".

From the items above, the writer's opinion is that mappings are very powerful
objects, but their use for the calculation of partial derivatives implies on
undesired complications and restrictions. In the case of partial derivatives
of composite mappings, it is easy to make mistakes related to the wrong
numeric position of each variable inside each mapping, or related to the order
of the variables in each evaluation point.  Besides, the building of the
composite mappings may be not obvious and, in many situations, it may be
convenient to have global meanings associated to the variables.

The {\bf pdiff} command of the {\it partials} package presented in this paper
was proposed as an alternative to this restrictions by accomplishing the task
of partial derivatives of any type, in a simpler manner, as was shown in
sections 1 and 2.

\appendix
\section*{Appendix B}
\hspace\parindent

Making a slight change to the standard  {\bf D/procedure} routine of {\bf
Maple 5.2} and building some subroutines were necessary for the correct
working of the commands of the {\it partials} package. The change is related
to the following result and message:
\begin{verbatim}
> f(x,y,z) := x*y*z:      # Assigning a value to a function (not a mapping)
> D[2](f)(x,y,z);         # "D" returns an undesired result:

Error, (in D/procedure) index out of range: function takes only 0 arguments
\end{verbatim}
\begin{equation}\end{equation}
This message is related to the automatic creation of a procedure of ``$0$"
arguments, which happens when one assigns values to a function. When a command
of the {\it partials} package is loaded, the {\it Error} behavior mentioned
above is automatically changed by inserting a few lines in the standard {\bf
D/procedure} routine. With the {\it partials} routines one receives:
\begin{verbatim}
> D[2](f)(x,y,z);        # Returns unevaluated as in Maple 5.1
\end{verbatim}
\begin{equation}
D_{[2]}(f)(x,y,z)
\end{equation}
\begin{verbatim}
> D[4](f)(x,y,z);        # Checks the number of arguments of the
                         # automatically created procedures by looking
                         # at their remember tables
\end{verbatim}
\begin{verbatim}
Error, (in D/procedure) Function f takes no more than 3 arguments
\end{verbatim}

Aside from the difference mentioned above, the {\bf D/procedure} routine of 
the {\it partials} package works exactly as the standard one, and  the unique 
case which turn apparent the difference is that which happens when one {\em 
assigns} values to a function which was not previously defined as a mapping.

Some {\bf type} subroutines, built for the commands of the {\it
partials}  package, also useful by themselves are:
\begin{itemize}
\item\ {\bf type/diff}, {\bf type/Diff}, {\bf type/De},
{\bf type/Int}, {\bf type/int}, and {\bf type/Function}.
\end{itemize}
They allow a quick identification of derivatives, integrals, and functions
(which are not derivatives or integrals or sums or limits), respectively.

Finally, the {\bf Has} command analize the functional dependence of algebraic
expressions from a mathematical point of view, that is, discarding the
dependence through integration variables of definite integrals. It was
originally prepared as a subroutine for {\bf pdiff} and can be easely extended
in order to discard also summation indices, limit variables etc...

\begin{thebibliography}{10}

\bibitem{MUC84}
Michael Wester and Stanley Steinberg,
A Survey of Symbolic Differentiation Implementations,
{\em Proceedings of the 1984 MACSYMA Users' Conference},
Schenectady NY, (1984).

\bibitem{OPERATORS}
Gaston Gonnet,
An Implementation of Operators for Symbolic Algebra Systems,
{\em Proceedings of the 1986 Symposium on Symbolic and Algebraic Computations},
Symsac `86, ACM, (1986).

\bibitem{das}
J.Barcelos-Neto, Ashok Das and W.Scherer,
{\em Canonical quantization of constrained systems}, Acta Physica
Polonica, Vol. {\bf B}18 No. 4 (1987) 269.

\bibitem{eduardo}
J.Barcelos-Neto and E.Vasquez,
{\em Sympletic quantization with higher derivatives}, to appear in
Zeitschrift f\"{u}r Physik C (1994).

\end{thebibliography}
\end{document}
%



