81. unit

81.1 Introduction to Units

The unit package enables the user to convert between arbitrary
units and work with dimensions in equations. The functioning of this package
is radically different from the original Maxima units package - whereas the
original was a basic list of definitions, this package uses rulesets to allow
the user to chose, on a per dimension basis, what unit final answers should be
rendered in. It will separate units instead of intermixing them in the display,
allowing the user to readily identify the units associated with a particular
answer. It will allow a user to simplify an expression to its fundamental Base
Units, as well as providing fine control over simplifying to derived units.
Dimensional analysis is possible, and a variety of tools are available to
manage conversion and simplification options. In addition to customizable
automatic conversion, units also provides a traditional manual
conversion option.

Note - when unit conversions are inexact Maxima will make approximations resulting
in fractions. This is a consequence of the techniques used to simplify units.
The messages warning of this type of substitution are disabled by default in
the case of units (normally they are on) since this situation occurs frequently
and the warnings clutter the output. (The existing state of ratprint is restored
after unit conversions, so user changes to that setting will be preserved
otherwise.) If the user needs this information for units, they can set
unitverbose:on to reactivate the printing of warnings from the unit
conversion process.

unit is included in Maxima in the share/contrib/unit directory. It obeys
normal Maxima package loading conventions:

The WARNING messages are expected and not a cause for concern - they indicate
the unit package is redefining functions already defined in Maxima proper.
This is necessary in order to properly handle units. The user
should be aware that if other changes have been made to these functions by other
packages those changes will be overwritten by this loading process.

The unit.mac file also loads a lisp file unit-functions.lisp which
contains the lisp functions needed for the package.

Clifford Yapp is the primary author. He has received valuable assistance from
Barton Willis of the University of Nebraska at Kearney (UNK), Robert Dodier, and
other intrepid folk of the Maxima mailing list.

There are probably lots of bugs. Let me know. float and numer
don't do what is expected.

Notice that the unit package recognized the non MKS combination
of mass, length, and inverse time squared as a force, and converted it
to Newtons. This is how Maxima works in general. If, for example, we
prefer dyne to Newtons, we simply do the following:

By default, the unit package converts all units to the
seven fundamental dimensions using MKS units. This behavior can
be changed with the setunits command. After that, the
user can restore the default behavior for a particular dimension
by means of the uforget command:

When resetting the global environment is overkill, there is the convert
command, which allows one time conversions. It can accept either a single
argument or a list of units to use in conversion. When a convert operation is
done, the normal global evaluation system is bypassed, in order to avoid the
desired result being converted again. As a consequence, for inexact calculations
"rat" warnings will be visible if the global environment controlling this behavior
(ratprint) is true. This is also useful for spot-checking the
accuracy of a global conversion. Another feature is convert will allow a
user to do Base Dimension conversions even if the global environment is set to
simplify to a Derived Dimension.

If a user wishes to have a default unit behavior other than that described,
they can make use of maxima-init.mac and the usersetunits
variable. The unit package will check on startup to see if this variable
has been assigned a list. If it has, it will use setunits on that list and take
the units from that list to be defaults. uforget will revert to the behavior
defined by usersetunits over its own defaults. For example, if we have a
maxima-init.mac file containing:

Without usersetunits, the initial inputs would have been converted
to MKS, and uforget would have resulted in a return to MKS rules. Instead,
the user preferences are respected in both cases. Notice these can still
be overridden if desired. To completely eliminate this simplification - i.e.
to have the user defaults reset to factory defaults - the dontusedimension
command can be used. uforget can restore user settings again, but
only if usedimension frees it for use. Alternately,
kill(usersetunits) will completely remove all knowledge of the user defaults
from the session. Here are some examples of how these various options work.

Rebuilds global unit lists automatically creating all desired metric units.
x is a numerical argument which is used to specify how many metric
prefixes the user wishes defined. The arguments are as follows, with each
higher number defining all lower numbers' units:

Normally, Maxima will not define the full expansion since this results in a
very large number of units, but metricexpandall can be used to
rebuild the list in a more or less complete fashion. The relevant variable
in the unit.mac file is %unitexpand.