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

\title{A new Maxima package for dimensional analysis}
 \author{Barton Willis \\
  University of Nebraska at Kearney \\
  Kearney Nebraska}

\begin{document}

\maketitle


\subsubsection*{Introduction}

\noindent This document demonstrates some of the abilities
of a new Maxima package for dimensional analysis.  Maxima 
comes with an older package dimensional  analysis that is 
similar to the one that was in the commercial Macsyma system. 
The software described in this document differs greatly from 
the older one.

The new dimensional analysis package was written by Barton Willis of
the University of Nebraska at Kearney. It is released under the terms of 
the General Public License GPL. You may contact the author at
\begin{verb} willisb@unk.edu \end{verb}.


\subsubsection*{Installation}

To use this package, you must first download the file
{\tt dimension.mac}; it may be found at
\begin{verb} www.unk.edu/acad/math/people/willisb \end{verb}.
After downloading, copy it into a directory that Maxima
can find.


\subsubsection*{Usage}

To use the package, you must first load it. From a Maxima prompt, this
is done using the command

\vspace{0.1in}

\begin{mcline}{c1}
load("dimension.mac");
\end{mcline}

\begin{mdline}{d1}
dimen1.mac
\end{mdline}

\vspace{0.1in}

\noindent To begin, we need to assign  dimensions to the
variables  we want to use. Use the {\tt qput} function to do this;
for example,  to declare $x$ a length, $c$ a
speed, and $t$ a time, use the commands

\vspace{0.1in}

\begin{mcline}{c2}
qput(x, "length", dimension)$
\end{mcline}

\begin{mcline}{c3}
qput(c, "length" / "time", dimension)$
\end{mcline}

\begin{mcline}{c4}
qput(t, "time", dimension)$
\end{mcline}


\vspace{0.1in}

\noindent We've defined the dimensions length and time to be 
strings; doing so reduces the chance that they will conflict  
with other user variables. To declare a dimensionless  variable
$\sigma$, use $1$ for the dimension. Thus

\vspace{0.1in}

\begin{mcline}{c5}
qput(sigma,1,dimension)$
\end{mcline}

\vspace{0.1in}

\noindent To find the dimension of an expression, use the
{\tt dimension} function. For example

\vspace{0.1in}

\begin{mcline}{c6}
dimension(4 * sqrt(3) /t);
\end{mcline}

\begin{mdline}{d6}
{{1}\over{time}}
\end{mdline}

\begin{mcline}{c7}
dimension(x + c * t);
\end{mcline}

\begin{mdline}{d7}
length
\end{mdline}

\begin{mcline}{c8}
dimension(sin(c * t / x));
\end{mcline}

\begin{mdline}{d8}
1
\end{mdline}

\begin{mcline}{c9}
dimension(abs(x - c * t));
\end{mcline}

\begin{mdline}{d9}
length
\end{mdline}

\begin{mcline}{c10}
dimension(sigma * x / c);
\end{mcline}

\begin{mdline}{d10}
time
\end{mdline}

\begin{mcline}{c11}
dimension(x * sqrt(1 - c * t / x));
\end{mcline}

\begin{mdline}{d11}
length
\end{mdline}

\vspace{0.1in}

\noindent {\tt dimension} applies {\tt logcontract} to its 
argument; thus expressions involving a difference of logarithms
with dimensionally equal arguments are dimensionless; thus

\vspace{0.1in}

\begin{mcline}{c12}
dimension(log(x) - log(c*t));
\end{mcline}



\begin{mdline}{d12}
1
\end{mdline}


\vspace{0.1in}

\noindent {\tt dimension} is automatically maps over lists. Thus

\vspace{0.1in}



\begin{mcline}{c13}
dimension([42, min(x,c*t), max(x,c*t), x^^4, x . c]);
\end{mcline}



\begin{mdline}{d13}
\left[ 1,length,length,length^4,{{length^2}\over{time}} \right] 
\end{mdline}



\noindent When an expression is dimensionally inconsistent,
{\tt dimension} should signal an error



\begin{mcline}{c14}
dimension(x + c);
\end{mcline}

{\em Expression is dimensionally inconsistent.}


\begin{mcline}{c15}
dimension(sin(x));
\end{mcline}

{\em Expression is dimensionally inconsistent.}

\vspace{0.1in}

\noindent An {\em equation\/} is dimensionally correct
when either the dimensions of both sides match or
when one side of the equation vanishes.  For example

\begin{mcline}{c16}
dimension(x = c * t);
\end{mcline}

\begin{mdline}{d16}
length
\end{mdline}

\begin{mcline}{c17}
dimension(x * t = 0);
\end{mcline}

\begin{mdline}{d17}
length\,time
\end{mdline}


\vspace{0.1in}

\noindent When the two sides of an equation have
different dimensions and neither side vanishes,
{\tt dimension} signals an error

\vspace{0.1in}



\begin{mcline}{c18}
dimension(x = c);
\end{mcline}

{\em Expression is dimensionally inconsistent.}

\vspace{0.1in}

\noindent The function {\tt dimension} works with derivatives and
integrals

\vspace{0.1in}

\begin{mcline}{c19}
dimension('diff(x,t));
\end{mcline}



\begin{mdline}{d19}
{{length}\over{time}}
\end{mdline}

\begin{mcline}{c20}
dimension('diff(x,t,2));
\end{mcline}



\begin{mdline}{d20}
{{length}\over{time^2}}
\end{mdline}

\begin{mcline}{c21}
dimension('diff(x,c,2,t,1));
\end{mcline}



\begin{mdline}{d21}
{{time}\over{length}}
\end{mdline}

\begin{mcline}{c22}
dimension('integrate (x,t));
\end{mcline}

\begin{mdline}{d22}
length\,time
\end{mdline}

\vspace{0.1in}

Thus far, any string may be used as a dimension; the other
three functions in this package, 
\begin{verb} dimension_as_list  \end{verb}, 
\begin{verb} dimensionless \end{verb}, and
\begin{verb} natural_unit \end{verb} all require that each
dimension is a member of  the list 
\begin{verb} fundamental_dimensions \end{verb}. The default value  is of 
this list is

\vspace{0.1in}

\begin{mcline}{c23}
fundamental_dimensions;
\end{mcline}



\begin{mdline}{d23}
\left[ mass,length,time \right] 
\end{mdline}


\noindent A user may insert or delete elements from this list.
The function \begin{verb} dimension_as_list \end{verb} returns the dimension
of an expression as a list of the exponents of the
fundamental dimensions. Thus

\vspace{0.1in}



\begin{mcline}{c24}
dimension_as_list(x);
\end{mcline}



\begin{mdline}{d24}
\left[ 0,1,0 \right] 
\end{mdline}

\begin{mcline}{c25}
dimension_as_list(t);
\end{mcline}



\begin{mdline}{d25}
\left[ 0,0,1 \right] 
\end{mdline}

\begin{mcline}{c26}
dimension_as_list(c);
\end{mcline}



\begin{mdline}{d26}
\left[ 0,1,-1 \right] 
\end{mdline}

\begin{mcline}{c27}
dimension_as_list(x/t);
\end{mcline}



\begin{mdline}{d27}
\left[ 0,1,-1 \right] 
\end{mdline}

\begin{mcline}{c28}
dimension_as_list("temp");
\end{mcline}



\begin{mdline}{d28}
 \left[ 0,0,0 \right] 
\end{mdline}


\vspace{0.1in}

\noindent In the last example, "temp" isn't an element of
\begin{verb} fundamental_dimensions \end{verb}; thus,  
\begin{verb} dimension_as_list \end{verb} 
reports that "temp" is dimensionless. To correct this, append "temp" to the list 
\begin{verb} fundamental_dimensions \end{verb}

\vspace{0.1in}



\begin{mcline}{c29}
fundamental_dimensions : endcons("temp", fundamental_dimensions);
\end{mcline}



\begin{mdline}{d29}
\left[ mass,length,time,temp \right] 
\end{mdline}


\vspace{0.1in}

\noindent Now we have

\vspace{0.1in}



\begin{mcline}{c30}
dimension_as_list(x);
\end{mcline}



\begin{mdline}{d30}
\left[ 0,1,0,0 \right] 
\end{mdline}

\begin{mcline}{c31}
dimension_as_list(t);
\end{mcline}



\begin{mdline}{d31}
\left[ 0,0,1,0 \right] 
\end{mdline}

\begin{mcline}{c32}
dimension_as_list(c);
\end{mcline}



\begin{mdline}{d32}
\left[ 0,1,-1,0 \right] 
\end{mdline}

\begin{mcline}{c33}
dimension_as_list(x/t);
\end{mcline}



\begin{mdline}{d33}
\left[ 0,1,-1,0 \right] 
\end{mdline}

\begin{mcline}{c34}
dimension_as_list("temp");
\end{mcline}



\begin{mdline}{d34}
\left[ 0,0,0,1 \right] 
\end{mdline}


\vspace{0.1in}

\noindent To remove "temp" from  
\begin{verb} fundamental_dimensions \end{verb}, use the {\tt delete} command

\vspace{0.1in}



\begin{mcline}{c35}
fundamental_dimensions : delete("temp", fundamental_dimensions)$
\end{mcline}


\vspace{0.1in}


The function {\tt dimensionless} finds a {\em basis\/} for the
dimensionless quantities that can be formed from a list of
dimensioned  quantities.  For example

\vspace{0.1in}




\begin{mcline}{c36}
dimensionless([c,x,t]);
\end{mcline}


Dependent equations eliminated:  (1)


\begin{mdline}{d36}
\left[ {{c\,t}\over{x}},1 \right] 
\end{mdline}

\begin{mcline}{c37}
dimensionless([x,t]);
\end{mcline}


Dependent equations eliminated:  (1)


\begin{mdline}{d37}
\left[ 1 \right] 
\end{mdline}


\vspace{0.1in}

\noindent In the first example, every dimensionless quantity
that can be formed as a product of powers of $c,x$, and $t$ is
a power of $c t/x$; in the second example, the only
dimensionless quantity that can be formed from
$x$ and $t$ are the constants.

The function \begin{verb} natural_unit(e, [v1,v2,...,vn]) \end{verb}
 finds powers $p_1,p_2, \dots p_n$ such that
\[
  \mbox{dimension}(e) = \mbox{dimension} (v_1^{p_1} v_2^{p_2} \dots v_n^{p_n}).
\]
Simple examples are

\vspace{0.1in}



\begin{mcline}{c38}
natural_unit(x,[c,t]);
\end{mcline}


Dependent equations eliminated:  (1)


\begin{mdline}{d38}
   \left[ c\,t \right] 
\end{mdline}

\begin{mcline}{c39}
   natural_unit(x,[x,c,t]);
\end{mcline}


Dependent equations eliminated:  (1)


\begin{mdline}{d39}
   \left[ x \right] 
\end{mdline}


\vspace{0.1in}

Here is a more complex example; we'll study the Bohr model of
the hydrogen atom using dimensional analysis.  To make things
more interesting, we'll include the magnetic moments of the
proton and electron as well as the universal gravitational
constant in with our list of physical quantities. 
Let  $\hbar$ be Planck's constant, $e$ the electron charge, $\mu_e$ the
magnetic moment of the electron, $\mu_p$ the magnetic
moment of the proton, $m_e$ the mass of the electron, $m_p$
the mass of the proton, $G$ the universal gravitational constant,
 and $c$ the speed of light in a vacuum.  For this problem, we might 
like to display the square root as an exponent instead  of as a radical;
to do this, set {\tt sqrtdispflag} to false

\vspace{0.1in}



\begin{mcline}{c40}
     SQRTDISPFLAG : false$
\end{mcline}


\vspace{0.1in}

\noindent  Assuming a system of units where Coulomb's law is
\[
  \mbox{force} = \frac{\mbox{product of charges}}{\mbox{distance}^2},
\]
we have

\vspace{0.1in}



\begin{mcline}{c41}
qput(%hbar, "mass" * "length"^2 / "time",dimension)$
\end{mcline}

\begin{mcline}{c42}
qput(%%e, "mass"^(1/2) * "length"^(3/2) / "time",dimension)$
\end{mcline}

\begin{mcline}{c43}
qput(%mue, "mass"^(1/2) * "length"^(5/2) / "time",dimension)$
\end{mcline}

\begin{mcline}{c44}
qput(%mup, "mass"^(1/2) * "length"^(5/2) / "time",dimension)$
\end{mcline}

\begin{mcline}{c45}
qput(%me, "mass",dimension)$
\end{mcline}

\begin{mcline}{c46}
qput(%mp, "mass",dimension)$
\end{mcline}

\begin{mcline}{c47}
qput(%g, "length"^3 / ("time"^2 * "mass"), dimension)$
\end{mcline}

\begin{mcline}{c48}
qput(%c, "length" / "time", dimension)$
\end{mcline}

\vspace{0.1in}

\noindent  The numerical values of these quantities may 
defined using {\tt numerval}.  We have

\vspace{0.1in}

\begin{mcline}{c49}
numerval(%%e, 1.5189073558044265d-14*sqrt(kg)*meter^(3/2)/sec)$
\end{mcline}

\begin{mcline}{c50}
numerval(%hbar, 1.0545726691251061d-34*kg*meter^2/sec)$
\end{mcline}

\begin{mcline}{c51}
numerval(%c, 2.99792458d8*meter/sec)$
\end{mcline}

\begin{mcline}{c52}
numerval(%me, 9.1093897d-31*kg)$
\end{mcline}

\begin{mcline}{c53}
numerval(%mp, 1.6726231d-27*kg)$
\end{mcline}


\vspace{0.1in}

\noindent To begin, let's use only the variables $e, c, \hbar, m_e$, and
$m_p$ to find the dimensionless quantities.  We have

\begin{mcline}{c54}
dimensionless([%hbar, %me, %mp, %%e, %c]);
\end{mcline}

\begin{mdline}{d54}
\left[ {{m_e}\over{m_p}},{{c\,\hbar}\over{e^2}},1 \right] 
\end{mdline}


\vspace{0.1in}

\noindent The second element of this list is the reciprocal of the fine 
structure constant. To find numerical values, use {\tt float}

\vspace{0.1in}

\begin{mcline}{c55}
float(%);
\end{mcline}

\begin{mdline}{d55}
\left[ 5.4461699709874866 \times 10^{-4},137.035990744505,1.0
  \right] 
\end{mdline}


\vspace{0.1in}

The natural units of energy are given by

\begin{mcline}{c56}
      natural_unit("mass" * "length"^2 / "time"^2, [%hbar, %me, %mp, %%e, %c]);
\end{mcline}



\begin{mdline}{d56}
   \left[ c^2\,m_e,{{c^3\,\hbar\,m_p}\over{e^2}} \right] 
\end{mdline}


\noindent Let's see what happens when we include 
will include $\mu_e, \mu_p$, and  $G$.  We have

\vspace{0.1in}



\begin{mcline}{c57}
     dimensionless([%hbar, %%e, %mue, %mup, %me, %mp, %g, %c]);
\end{mcline}



\begin{mdline}{d57}
   \left[ {{\mu_p}\over{\mu_e}},{{c^2\,m_e\,\mu_e}\over{e^3}},{{c^2
 \,m_p\,\mu_e}\over{e^3}},{{e^4\,G}\over{c^4\,\mu_e^2}},{{c\,
 \hbar}\over{e^2}},1 \right] 
\end{mdline}


\vspace{0.1in}


To find the natural units of mass, length, time,
speed, force, and energy, use  the commands

\vspace{0.1in}



\begin{mcline}{c58}
    natural_unit("mass", [%hbar, %%e, %me, %mp, %mue, %mup, %g, %c]);
\end{mcline}



\begin{mdline}{d58}
   \left[ m_p,{{c^2\,m_e^2\,\mu_e}\over{e^3}},{{c^2\,m_e^2\,\mu_p
 }\over{e^3}},{{G\,m_e^3}\over{e^2}},{{c\,\hbar\,m_e}\over{e^
 2}} \right] 
\end{mdline}

\begin{mcline}{c59}
    natural_unit("length", [%hbar, %%e, %me, %mp, %mue, %mup, %g, %c]);
\end{mcline}



\begin{mdline}{d59}
   \left[ {{e^2\,m_p}\over{c^2\,m_e^2}},{{\mu_e}\over{e}},{{\mu_p
 }\over{e}},{{G\,m_e}\over{c^2}},{{\hbar}\over{c\,m_e}} \right] 
\end{mdline}

\begin{mcline}{c60}
   natural_unit("time", [%hbar, %%e, %me, %mp, %mue, %mup, %g, %c]);
\end{mcline}



\begin{mdline}{d60}
   \left[ {{e^2\,m_p}\over{c^3\,m_e^2}},{{\mu_e}\over{e\,c}},{{
 \mu_p}\over{e\,c}},{{G\,m_e}\over{c^3}},{{\hbar}\over{c^2\,m_e
 }} \right] 
\end{mdline}

\begin{mcline}{c61}
    natural_unit("mass" * "length" / "time"^2, [%hbar, %%e, %me, %mp, %mue, %mup, %g, %c]);
\end{mcline}



\begin{mdline}{d61}
   \left[ {{c^4\,m_e\,m_p}\over{e^2}},{{c^6\,m_e^3\,\mu_e}\over{
 e^5}},{{c^6\,m_e^3\,\mu_p}\over{e^5}},{{c^4\,G\,m_e^4}\over{
 e^4}},{{c^5\,\hbar\,m_e^2}\over{e^4}} \right] 
\end{mdline}

\begin{mcline}{c62}
    natural_unit("mass" * "length"^2 / "time"^2, [%hbar, %%e, %me, %mp, %mue, %mup, %g, %c]);
\end{mcline}



\begin{mdline}{d62}
   \left[ c^2\,m_p,{{c^4\,m_e^2\,\mu_e}\over{e^3}},{{c^4\,m_e^2\,
 \mu_p}\over{e^3}},{{c^2\,G\,m_e^3}\over{e^2}},{{c^3\,\hbar\,
 m_e}\over{e^2}} \right] 
\end{mdline}

\vspace{0.1in}

\noindent The first element of this list is the rest mass energy of the 
proton.


The dimension package can handle vector operators such as
dot and cross products, and the vector operators div, grad, and curl.
To use the vector operators, we'll first declare them


\begin{mcline}{c63}
prefix(div)$
\end{mcline}

\begin{mcline}{c64}
prefix(curl)$
\end{mcline}

\begin{mcline}{c65}
infix("~")$
\end{mcline}


\noindent Let's work with the electric and magnetic fields;
again assuming a system of units where Coulomb's law is
\[
  \mbox{force} = \frac{\mbox{product of charges}}{\mbox{distance}^2}
\]
the dimensions of the electric and magnetic field are


\begin{mcline}{c66}
qput(e, sqrt("mass") / (sqrt("length") * "time"), dimension)$
\end{mcline}

\begin{mcline}{c67}
qput(b, sqrt("mass") / (sqrt("length") * "time"),dimension)$
\end{mcline}

and the units of charge density $\rho$ and current density $j$ are


\begin{mcline}{c68}
qput(rho, sqrt("mass")/("time" * "length"^(3/2)), dimension)$
\end{mcline}

\begin{mcline}{c69}
qput(j, sqrt("mass") / ("time"^2 * sqrt("length")), dimension)$
\end{mcline}

Finally, declare the speed of light $c$ as


\begin{mcline}{c70}
qput(c, "length" / "time", dimension);
\end{mcline}



\begin{mdline}{d70}
{{length}\over{time}}
\end{mdline}

\noindent Let's find the dimensions of 
$\| \mathbf{E} \|^2, \mathbf{E} \cdot \mathbf{B},
\| \mathbf{B} \|^2$, and $\mathbf{E} \times \mathbf{B} / c$.  We have

\begin{mcline}{c71}
dimension(e.e);
\end{mcline}



\begin{mdline}{d71}
{{mass}\over{length\,time^2}}
\end{mdline}

\begin{mcline}{c72}
dimension(e.b);
\end{mcline}



\begin{mdline}{d72}
{{mass}\over{length\,time^2}}
\end{mdline}

\begin{mcline}{c73}
dimension(b.b);
\end{mcline}



\begin{mdline}{d73}
{{mass}\over{length\,time^2}}
\end{mdline}

\begin{mcline}{c74}
dimension((e ~ b) / c);
\end{mcline}



\begin{mdline}{d74}
{{mass}\over{length^2\,time}}
\end{mdline}


\vspace{0.1in}

\noindent The physical significance of these quantities becomes more apparent
if they are integrated over $\mathbf{R^3}$.  Defining

\vspace{0.1in}

\begin{mcline}{c75}
qput(v, "length"^3, dimension);
\end{mcline}



\begin{mdline}{d75}
length^3
\end{mdline}

\vspace{0.1in}

\noindent We now have


\begin{mcline}{c76}
dimension('integrate(e.e, v));
\end{mcline}



\begin{mdline}{d76}
{{length^2\,mass}\over{time^2}}
\end{mdline}

\begin{mcline}{c77}
dimension('integrate(e.b, v));
\end{mcline}

\begin{mdline}{d77}
{{length^2\,mass}\over{time^2}}
\end{mdline}

\begin{mcline}{c78}
dimension('integrate(b.b, v));
\end{mcline}

\begin{mdline}{d78}
{{length^2\,mass}\over{time^2}}
\end{mdline}

\begin{mcline}{c79}
 dimension('integrate((e ~ b) / c,v));
\end{mcline}


\begin{mdline}{d79}
{{length\,mass}\over{time}}
\end{mdline}

\noindent It's clear that $\| \mathbf{E} \|^2, \mathbf{E} \cdot \mathbf{B}$
and $\| \mathbf{B} \|^2$ are energy densities while
$\mathbf{E} \times \mathbf{B} / c$ is a momentum density.

Let's also check that the Maxwell equations are
dimensionally consistent.

\begin{mcline}{c80}
dimension(DIV(e)= 4*%pi*rho);
\end{mcline}

\begin{mdline}{d80}
{{mass^{{{1}\over{2}}}}\over{length^{{{3}\over{2}}}\,time}}
\end{mdline}

\begin{mcline}{c81}
dimension(CURL(b) - 'diff(e,t) / c = 4 * %pi * j / c);
\end{mcline}

\begin{mdline}{d81}
{{mass^{{{1}\over{2}}}}\over{length^{{{3}\over{2}}}\,time}}
\end{mdline}

\begin{mcline}{c82}
dimension(CURL(e) + 'diff(b,t) / c = 0);
\end{mcline}

\begin{mdline}{d82}
{{mass^{{{1}\over{2}}}}\over{length^{{{3}\over{2}}}\,time}}
\end{mdline}

\begin{mcline}{c83}
dimension(DIV(b) = 0);
\end{mcline}

\begin{mdline}{d83}
{{mass^{{{1}\over{2}}}}\over{length^{{{3}\over{2}}}\,time}}
\end{mdline}


\subsubsection*{Conclusion and Future directions}

Algorithmically, the dimensional analysis package is straightforward; 
nevertheless, there are many details, such as correctly setting
option variables for linsolve, that need to be tended to.  Let me know 
when you find a bug; I'll try to fix it.  There may be some operators that
aren't handled; again, let me know what is missing and I'll try
to fix it.

Eventually, I hope that this package will work smoothly with the new physical 
constants package. 

I could add predefined dimensions for derived units such as momentum, charge, 
density, etc.; however, given the plethora of schemes for
electromagnetic units, I'm hesitant to do this.

This documentation was processed by bat\TeX, a Maxima preprocessor
for \TeX. The bat\TeX software is also available from the author's
web page.

\end{document}

















(D84)                                DONE
(C84) 