% TeX code generated by batTeX. Don't edit this file; edit the  
% input file pdiff.tex instead.
\documentclass[12pt]{article}
\usepackage{mathptm}
\usepackage{battex}  
\usepackage{color}

\title{A positional derivative package for Maxima}
 \author{Barton Willis \\
   University of Nebraska at Kearney \\
   Kearney Nebraska}

\begin{document}

\maketitle

\subsection*{Introduction}

\noindent  Working with derivatives of unknown functions\footnote{By
{\em unknown  function\/}, we mean a function that isn't bound to a formula and
that has a derivative that isn't known to Maxima.} can be  cumbersome in Maxima.
If we want, for example, the first order  Taylor polynomial of 
$f(x + x^2)$ about $x = 1$, we get


\begin{mcline}{c1}
taylor(f(x + x^2),x,1,1);
\end{mcline}



\begin{mdline}{d1}
   f\left(2\right)+\left(\left.{{d}\over{d\,x}}\,f\left(x^2+x\right)
 \right|_{x=1}\right)\,\left(x-1\right)+\cdots 
\end{mdline}

\noindent To ``simplify'' the Taylor polynomial, we must assign a gradient to $f$ 

\begin{mcline}{c2}
gradef(f(x),df(x))$
\end{mcline}

\begin{mcline}{c3}
taylor(f(x+x^2),x,1,1);
\end{mcline}

\begin{mdline}{d3}
   f\left(2\right)+3\,df\left(2\right)\,\left(x-1\right)+\cdots 
\end{mdline}

This method works well for simple problems, but it 
is tedious for functions of several variables or high order
derivatives. The positional derivative package {\tt pdiff} gives 
an alternative to using {\tt gradef} when working with derivatives 
of unknown functions.

\subsection*{Installation}

To install the positional derivative package, download {\tt pdiff.lisp}
from  \\ \begin{verb} www.unk.edu/acad/math/people/willisb \end{verb}
and place it in a directory that Maxima can find.

\subsection*{Usage}

To use the positional derivative package, you must load it from
a Maxima prompt.  Assuming {\tt pdiff.lisp} is in a directory that 
Maxima can find, this is done with the command


\begin{mcline}{c1}
     load("pdiff.lisp")$
\end{mcline}


\noindent Use the full pathname if Maxima can't find the file. Loading 
{\tt pdiff.lisp} sets the option variable {\tt use\_pdiff} to true; 
when {\tt use\_diff} is true, Maxima will 
indicate derivatives of  unknown functions positionally. To illustrate, 
the first three  derivatives of $f$ are


\begin{mcline}{c2}
[diff(f(x),x),
  diff(f(x),x,2),
  diff(f(x),x,3)];
\end{mcline}



\begin{mdline}{d2}
   \left[ f_{\left(1\right)}(x),f_{\left(2\right)}(x),f_{\left(3
 \right)}(x) \right] 
\end{mdline}

The subscript indicates the order of the derivative;  since $f$ is a function of 
one variable, the subscript has only one index.  When a function has more 
than one variable, the subscript has an index for each variable


\begin{mcline}{c3}
     [diff(f(x,y),x,0,y,1), diff(f(y,x),x,0,y,1)];
\end{mcline}

\begin{mdline}{d3}
   \left[ f_{\left(0,1\right)}(x,y),f_{\left(1,0\right)}(y,x)
  \right] 
\end{mdline}

\noindent Setting {\tt use\_pdiff} to false  (either locally or globally) inhibits 
derivatives from begin computed positionally


\begin{mcline}{c4}
      diff(f(x,x^2),x), use_pdiff : false;
\end{mcline}



\begin{mdline}{d4}
   {{d}\over{d\,x}}\,f\left(x,x^2\right)
\end{mdline}

\begin{mcline}{c5}
   diff(f(x,x^2),x), use_pdiff : true;
\end{mcline}



\begin{mdline}{d5}
   f_{\left(1,0\right)}(x,x^2)+2\,x\,f_{\left(0,1\right)}(x,x^2)
\end{mdline}


Taylor polynomials of unknown functions can be found without using
{\tt gradef}. An example


\begin{mcline}{c6}
     taylor(f(x+x^2),x,1,2);
\end{mcline}



\begin{mdline}{d6}
   f\left(2\right)+3\,f_{\left(1\right)}(2)\,\left(x-1\right)+{{
 \left(2\,f_{\left(1\right)}(2)+9\,f_{\left(2\right)}(2)\right)\,
 \left(x-1\right)^2}\over{2}}+\cdots 
\end{mdline}

\noindent Additionally, we can verify that $ y = f(x-c \, t) + g(x+c \,t)$ is
a solution to a wave equation without using {\tt gradef}


\begin{mcline}{c7}
     y : f(x-c*t) + g(x+c*t)$
\end{mcline}

\begin{mcline}{c8}
   ratsimp(diff(y,t,2) - c^2 * diff(y,x,2));
\end{mcline}



\begin{mdline}{d8}
   0
\end{mdline}

\begin{mcline}{c9}
   remvalue(y)$
\end{mcline}

\noindent Expressions involving  positional derivatives can be differentiated

\begin{mcline}{c10}
     e : diff(f(x,y),x);
\end{mcline}


\begin{mdline}{d10}
   f_{\left(1,0\right)}(x,y)
\end{mdline}

\begin{mcline}{c11}
   diff(e,y);
\end{mcline}



\begin{mdline}{d11}
   f_{\left(1,1\right)}(x,y)
\end{mdline}


\noindent The chain rule is applied when needed


\begin{mcline}{c12}
     [diff(f(x^2),x), diff(f(g(x)),x)];
\end{mcline}



\begin{mdline}{d12}
   \left[ 2\,x\,f_{\left(1\right)}(x^2),g_{\left(1\right)}(x)\,f_{
 \left(1\right)}(g\left(x\right)) \right] 
\end{mdline}


The positional derivative package doesn't alter the way known functions
are differentiated


\begin{mcline}{c13}
     diff(exp(-x^2),x);
\end{mcline}



\begin{mdline}{d13}
   -2\,x\,e^ {- x^2 }
\end{mdline}


\noindent To convert positional derivatives to standard Maxima derivatives,
use {\tt convert\_to\_diff}


\begin{mcline}{c14}
     e : [diff(f(x),x), diff(f(x,y),x,1,y,1)];
\end{mcline}



\begin{mdline}{d14}
   \left[ f_{\left(1\right)}(x),f_{\left(1,1\right)}(x,y) \right] 
\end{mdline}

\begin{mcline}{c15}
   e : convert_to_diff(e);
\end{mcline}



\begin{mdline}{d15}
   \left[ {{d}\over{d\,x}}\,f\left(x\right),{{d^2}\over{d\,y\,d\,x}}
 \,f\left(x,y\right) \right] 
\end{mdline}

\noindent To convert back to a positional derivative, use {\tt ev} with {\tt diff} 
as an argument


\begin{mcline}{c16}
     ev(e,diff);
\end{mcline}



\begin{mdline}{d16}
   \left[ f_{\left(1\right)}(x),f_{\left(1,1\right)}(x,y) \right] 
\end{mdline}

\noindent Conversion to standard derivatives  sometimes requires the 
introduction of  a dummy variable. Here's an example


\begin{mcline}{c17}
     e : diff(f(x,y),x,1,y,1);
\end{mcline}



\begin{mdline}{d17}
   f_{\left(1,1\right)}(x,y)
\end{mdline}

\begin{mcline}{c18}
   e : subst(p(s),y,e);
\end{mcline}



\begin{mdline}{d18}
   f_{\left(1,1\right)}(x,p\left(s\right))
\end{mdline}

\begin{mcline}{c19}
   e : convert_to_diff(e);
\end{mcline}



\begin{mdline}{d19}
   \left.{{d^2}\over{d\,\%x_0\,d\,x}}\,f\left(x,\%x_0\right)\right|_{
 \left[ \%x_0=p\left(s\right) \right] }
\end{mdline}

Dummy variables have the form ci, where i=0,1,2\dots and c is the 
value of the option variable {\tt dummy\_char}. The default value
for {\tt dummy\_char} is {\tt \%x}. If a user variable conflicts with a 
dummy variable,  the conversion process can give an 
incorrect value. To convert the previous expression back to a positional derivative,
use {\tt ev} with {\tt diff} and {\tt at} as arguments


\begin{mcline}{c20}
      ev(e,diff,at);
\end{mcline}



\begin{mdline}{d20}
   f_{\left(1,1\right)}(x,p\left(s\right))
\end{mdline}


Maxima correctly evaluates expressions involving positional derivatives 
if a formula is  later given to the function.  (Thus converting an unknown 
function into a known one.)  Here is an example;  let


\begin{mcline}{c21}
     e : diff(f(x^2),x);
\end{mcline}



\begin{mdline}{d21}
   2\,x\,f_{\left(1\right)}(x^2)
\end{mdline}

\noindent Now, give $f$ a formula


\begin{mcline}{c22}
     f(x) := x^5;
\end{mcline}



\begin{mdline}{d22}
   f\left(x\right):=x^5
\end{mdline}

\noindent and evaluate {\tt e}


\begin{mcline}{c23}
     ev(e);
\end{mcline}



\begin{mdline}{d23}
   10\,x^9
\end{mdline}


\noindent This result is the same as  



\begin{mcline}{c24}
     diff(f(x^2),x);
\end{mcline}



\begin{mdline}{d24}
   10\,x^9
\end{mdline}

\noindent In this calculation, Maxima first evaluates $f(x)$ to $x^{10}$ and then
does the derivative.  Additionally, we can substitute a value for $x$ 
before evaluating



\begin{mcline}{c25}
     ev(subst(2,x,e));
\end{mcline}



\begin{mdline}{d25}
   5120
\end{mdline}


\noindent We can duplicate this with



\begin{mcline}{c26}
     subst(2,x,diff(f(x^2),x));
\end{mcline}



\begin{mdline}{d26}
   5120
\end{mdline}

\begin{mcline}{c27}
   remfunction(f);
\end{mcline}



\begin{mdline}{d27}
   \left[ f \right] 
\end{mdline}


\noindent We can also evaluate a positional derivative using a local 
function definition


\begin{mcline}{c28}
     e : diff(g(x),x);
\end{mcline}



\begin{mdline}{d28}
   g_{\left(1\right)}(x)
\end{mdline}

\begin{mcline}{c29}
   e, g(x) := sqrt(x);
\end{mcline}



\begin{mdline}{d29}
   {{1}\over{2\,\sqrt{x}}}
\end{mdline}

\begin{mcline}{c30}
   e, g = sqrt;
\end{mcline}



\begin{mdline}{d30}
   {{1}\over{2\,\sqrt{x}}}
\end{mdline}

\begin{mcline}{c31}
   e, g = h;
\end{mcline}



\begin{mdline}{d31}
   h_{\left(1\right)}(x)
\end{mdline}

\begin{mcline}{c32}
   e, g = lambda([t],t^2);
\end{mcline}



\begin{mdline}{d32}
   2\,x
\end{mdline}


\subsection*{The {\tt pderivop} function}

If $F$ is an atom and $i_1, i_2, \dots i_n$ are nonnegative
integers, then $ \mbox{pderivop}(F,i_1,i_2, \dots i_n)$, is the 
function that has the formula 
\[
   \frac{\partial^{i_1 + i_2 + \cdots + i_n}}{\partial x_1^{i_1} 
     \partial x_2^{i_2}  \cdots \partial x_n^{i_n}} F(x_1,x_2, \dots x_n). 
\]
If any of the derivative arguments are not nonnegative integers,
we'll get an error


\begin{mcline}{c33}
     pderivop(f,2,-1);
\end{mcline}

Each derivative order must be a nonnegative integer


\noindent The {\tt pderivop} function can be composed with itself

\begin{mcline}{c34}
     pderivop(pderivop(f,3,4),1,2);
\end{mcline}



\begin{mdline}{d34}
   f_{\left(4,6\right)}
\end{mdline}
\noindent If the number of derivative arguments between two calls 
to {\tt pderivop} isn't the same, Maxima gives an error

\begin{mcline}{c35}
     pderivop(pderivop(f,3,4),1);
\end{mcline}

The function f expected 2 derivative argument(s), but it received 1


When {\tt pderivop} is applied to a known function, the result is
a lambda form\footnote{If you repeat theses calculations, you 
may get a different prefix for the {\tt gensym} variables.}

\begin{mcline}{c37}
      f(x) := x^2;
\end{mcline}



\begin{mdline}{d37}
   f\left(x\right):=x^2
\end{mdline}

\begin{mcline}{c38}
   df : pderivop(f,1);
\end{mcline}



\begin{mdline}{d38}
   \lambda\left(\left[ Q_{1253} \right] ,2\,Q_{1253}\right)
\end{mdline}

\begin{mcline}{c39}
   apply(df,[z]);
\end{mcline}



\begin{mdline}{d39}
   2\,z
\end{mdline}

\begin{mcline}{c40}
   ddf : pderivop(f,2);
\end{mcline}



\begin{mdline}{d40}
   \lambda\left(\left[ Q_{1254} \right] ,2\right)
\end{mdline}

\begin{mcline}{c41}
   apply(ddf,[10]);
\end{mcline}



\begin{mdline}{d41}
   2
\end{mdline}

\begin{mcline}{c42}
   remfunction(f);
\end{mcline}



\begin{mdline}{d42}
   \left[ f \right] 
\end{mdline}


If the first argument to {\tt pderivop} is a lambda form, the
result is another lambda form



\begin{mcline}{c43}
     f : pderivop(lambda([x],x^2),1);
\end{mcline}



\begin{mdline}{d43}
   \lambda\left(\left[ Q_{1255} \right] ,2\,Q_{1255}\right)
\end{mdline}

\begin{mcline}{c44}
   apply(f,[a]);
\end{mcline}



\begin{mdline}{d44}
   2\,a
\end{mdline}

\begin{mcline}{c45}
   f : pderivop(lambda([x],x^2),2);
\end{mcline}



\begin{mdline}{d45}
   \lambda\left(\left[ Q_{1256} \right] ,2\right)
\end{mdline}

\begin{mcline}{c46}
   apply(f,[a]);
\end{mcline}



\begin{mdline}{d46}
   2
\end{mdline}

\begin{mcline}{c47}
   f : pderivop(lambda([x],x^2),3);
\end{mcline}



\begin{mdline}{d47}
   \lambda\left(\left[ Q_{1257} \right] ,0\right)
\end{mdline}

\begin{mcline}{c48}
   apply(f,[a]);
\end{mcline}



\begin{mdline}{d48}
   0
\end{mdline}

\begin{mcline}{c49}
   remvalue(f)$
\end{mcline}


If the first argument to {\tt pderivop} isn't an atom or
a lambda form, Maxima will signal an error 



\begin{mcline}{c50}
     pderivop(f+g,1);
\end{mcline}

Non-atom g+f used as a function


You may use {\tt tellsimpafter} together with {\tt pderivop} to 
give a value to a derivative of a function at a point; an
example


\begin{mcline}{c51}
tellsimpafter(pderivop(f,1)(1),1)$
\end{mcline}

\begin{mcline}{c52}
tellsimpafter(pderivop(f,2)(1),2)$
\end{mcline}

\begin{mcline}{c53}
diff(f(x),x,2) + diff(f(x),x)$
\end{mcline}

\begin{mcline}{c54}
subst(1,x,%);
\end{mcline}

\begin{mdline}{d54}
   3
\end{mdline}

This technique works for functions of several variables as well

\begin{mcline}{c55}
kill(rules)$
\end{mcline}


\begin{mcline}{c56}
tellsimpafter(pderivop(f,1,0)(0,0),a)$
\end{mcline}

\begin{mcline}{c57}
tellsimpafter(pderivop(f,0,1)(0,0),b)$
\end{mcline}

\begin{mcline}{c58}
sublis([x = 0, y = 0], diff(f(x,y),x) + diff(f(x,y),y));
\end{mcline}



\begin{mdline}{d58}
   b+a
\end{mdline}


\subsection*{\TeX{}-ing positional derivatives}

Several option variables control how positional derivatives
are converted to \TeX{}. When the option variable
{\tt tex\_uses\_prime\_for\_derivatives} is true (default false), 
makes functions of one variable \TeX{} as superscripted primes


\begin{mcline}{c59}
tex_uses_prime_for_derivatives : true$
\end{mcline}

\begin{mcline}{c60}
tex(makelist(diff(f(x),x,i),i,1,3))$
\end{mcline}

\begin{mdline}{d60}
\left[ f^{\prime}(x),f^{\prime\prime}(x),f^{\prime\prime\prime}(x)
  \right] 
\end{mdline}

\begin{mcline}{c61}
   tex(makelist(pderivop(f,i),i,1,3))$
\end{mcline}

\[
\left[ f^{\prime},f^{\prime\prime},f^{\prime\prime\prime} \right] 
\]

When the derivative order exceeds the value of the option
variable {\tt tex\_prime\_limit}, (default 3) 
derivatives are indicated with parenthesis delimited superscripts


\begin{mcline}{c62}
   tex(makelist(pderivop(f,i),i,1,5)), tex_prime_limit : 0$
\end{mcline}

\[
\left[ f^{(1)},f^{(2)},f^{(3)},f^{(4)},f^{(5)} \right] 
\]

\begin{mcline}{c63}
   tex(makelist(pderivop(f,i),i,1,5)), tex_prime_limit : 5$
\end{mcline}


\[
\left[ f^{\prime},f^{\prime\prime},f^{\prime\prime\prime},f^{\prime
 \prime\prime\prime},f^{\prime\prime\prime\prime\prime} \right] 
\]

The value of {\tt tex\_uses\_prime\_for\_derivatives} doesn't change the way 
functions of two or more variables are converted to \TeX{}.


\begin{mcline}{c64}
     tex(pderivop(f,2,1));
\end{mcline}

\[
f_{\left(2,1\right)}
\]



When the option variable {\tt tex\_uses\_named\_subscripts\_for\_derivatives}
(default false) is true, a derivative with respect to the i-th argument is 
indicated by a subscript that is the i-th element of the option variable
{\tt tex\_diff\_var\_names}.  An example is the clearest way to 
describe this.


\begin{mcline}{c65}
     tex_uses_named_subscripts_for_derivatives : true$
\end{mcline}

\begin{mcline}{c66}
   tex_diff_var_names;
\end{mcline}



\begin{mdline}{d66}
   \left[ x,y,z \right] 
\end{mdline}

\begin{mcline}{c67}
  
  tex([pderivop(f,1,0), pderivop(f,0,1), pderivop(f,1,1), pderivop(f,2,0)]);
\end{mcline}

$$\left[ f_{x},f_{y},f_{xy},f_{xx} \right] $$


\begin{mcline}{c68}
   tex_diff_var_names : [a,b];
\end{mcline}



\begin{mdline}{d68}
   \left[ a,b \right] 
\end{mdline}

\begin{mcline}{c69}
  
  tex([pderivop(f,1,0), pderivop(f,0,1), pderivop(f,1,1), pderivop(f,2,0)]);
\end{mcline}

$$\left[ f_{a},f_{b},f_{ab},f_{aa} \right] $$



\begin{mcline}{c70}
   tex_diff_var_names : [x,y,z];
\end{mcline}



\begin{mdline}{d70}
   \left[ x,y,z \right] 
\end{mdline}

\begin{mcline}{c71}
   tex([diff(f(x,y),x), diff(f(y,x),y)]);
\end{mcline}

$$\left[ f_{x}(x,y),f_{x}(y,x) \right] $$



When the derivative order exceeds {tt tex\_prime\_limit}, revert to the default
method for converting to \TeX{}


\begin{mcline}{c72}
     tex(diff(f(x,y,z),x,1,y,1,z,1)), tex_prime_limit : 4$
\end{mcline}

\[
f_{xyz}(x,y,z)
\]

\begin{mcline}{c73}
tex(diff(f(x,y,z),x,1,y,1,z,1)), tex_prime_limit : 1$
\end{mcline}

$$f_{\left(1,1,1\right)}(x,y,z)$$
\subsection*{A longer example}

We'll use the positional derivative package to change the independent
variable of the differential equation


\begin{mcline}{c74}
      de :  4*x^2*'DIFF(y,x,2) + 4*x*'DIFF(y,x,1) + (x-1)*y = 0;
\end{mcline}



\begin{mdline}{d74}
   4\,x^2\,\left({{d^2}\over{d\,x^2}}\,y\right)+4\,x\,\left({{d
 }\over{d\,x}}\,y\right)+\left(x-1\right)\,y=0
\end{mdline}

With malice aforethought, we'll assume a solution of the form
$ y = g(x^n)$, where $n$ is a number.  Substituting $y \rightarrow g(x^n)$
in the  differential equation  gives


\begin{mcline}{c75}
     de : subst(g(x^n),y,de);
\end{mcline}



\begin{mdline}{d75}
   4\,x^2\,\left({{d^2}\over{d\,x^2}}\,g\left(x^{n}\right)\right)+4\,
 x\,\left({{d}\over{d\,x}}\,g\left(x^{n}\right)\right)+\left(x-1
 \right)\,g\left(x^{n}\right)=0
\end{mdline}

\begin{mcline}{c76}
   de : ev(de, diff);
\end{mcline}



\begin{mdline}{d76}
   4\,x^2\,\left(n^2\,x^{2\,n-2}\,g^{\prime\prime}(x^{n})+\left(n-1
 \right)\,n\,x^{n-2}\,g^{\prime}(x^{n})\right)+4\,n\,x^{n}\,g^{\prime
 }(x^{n})+\left(x-1\right)\,g\left(x^{n}\right)=0
\end{mdline}

Now let $x \rightarrow t^{1/n}$


\begin{mcline}{c77}
     de : radcan(subst(x^(1/n),x, de));
\end{mcline}



\begin{mdline}{d77}
   4\,n^2\,x^2\,g^{\prime\prime}(x)+4\,n^2\,x\,g^{\prime}(x)+\left(x
 ^{{{1}\over{n}}}-1\right)\,g\left(x\right)=0
\end{mdline}

Setting $n \rightarrow 1/2$, we recognize that $g$ is the order 1 Bessel
equation


\begin{mcline}{c78}
     subst(1/2,n, de);
\end{mcline}



\begin{mdline}{d78}
   x^2\,g^{\prime\prime}(x)+x\,g^{\prime}(x)+\left(x^2-1\right)\,g
 \left(x\right)=0
\end{mdline}


\subsection*{Limitations}

\begin{itemize}
  \item Positional derivatives of subscripted functions are not allowed.

  \item Derivatives of unknown functions with symbolic orders are not 
   computed positionally.

  \item The positional derivative package has only been tested under 
  Maxima 5.6 compiled with GCL 2.4; it has not been tested with any
  other Maxima version.

  \item The {\tt pdiff.lisp} code alters the Maxima functions {\tt mqapply}
   and {\tt sdiffgrad} Although I'm unaware  of any problems associated 
   with these altered functions, there may be some.  Setting {\tt use\_pdiff} to
   false should restore {\tt mqapply} and {\tt sdiffgrad} to their
   original functioning.

\end{itemize}

\subsection*{Conclusion}

The {\tt pdiff} package provides a simple way of working with 
derivatives of unknown functions.  If you find a bug in the package,
or if you have a comment or a question, please send it to
{\tt willisb@unk.edu}. 

The {\tt pdiff} package could serve as a basis for a Maxima package
differential and integral operators.

\end{document}   

(D79)                                DONE
(C79) 