# Dimensions and dimension systems¶

Definition of physical dimensions.

Unit systems will be constructed on top of these dimensions.

Most of the examples in the doc use MKS system and are presented from the computer point of view: from a human point, adding length to time is not legal in MKS but it is in natural system; for a computer in natural system there is no time dimension (but a velocity dimension instead) - in the basis - so the question of adding time to length has no meaning.

class sympy.physics.units.dimensions.Dimension[source]

This class represent the dimension of a physical quantities.

The Dimension constructor takes as parameters a name and an optional symbol.

For example, in classical mechanics we know that time is different from temperature and dimensions make this difference (but they do not provide any measure of these quantites.

>>> from sympy.physics.units import Dimension
>>> length = Dimension('length')
>>> length
Dimension(length)
>>> time = Dimension('time')
>>> time
Dimension(time)


Dimensions can be composed using multiplication, division and exponentiation (by a number) to give new dimensions. Addition and subtraction is defined only when the two objects are the same dimension.

>>> velocity = length / time
>>> velocity
Dimension(length/time)
>>> velocity.get_dimensional_dependencies()
{'length': 1, 'time': -1}
>>> length + length
Dimension(length)
>>> l2 = length**2
>>> l2
Dimension(length**2)
>>> l2.get_dimensional_dependencies()
{'length': 2}

has_integer_powers

Check if the dimension object has only integer powers.

All the dimension powers should be integers, but rational powers may appear in intermediate steps. This method may be used to check that the final result is well-defined.

is_dimensionless

Check if the dimension object really has a dimension.

A dimension should have at least one component with non-zero power.

class sympy.physics.units.dimensions.DimensionSystem(base, dims=(), name='', descr='')[source]

DimensionSystem represents a coherent set of dimensions.

In a system dimensions are of three types:

• base dimensions;
• derived dimensions: these are defined in terms of the base dimensions (for example velocity is defined from the division of length by time);
• canonical dimensions: these are used to define systems because one has to start somewhere: we can not build ex nihilo a system (see the discussion in the documentation for more details).

All intermediate computations will use the canonical basis, but at the end one can choose to print result in some other basis.

In a system dimensions can be represented as a vector, where the components represent the powers associated to each base dimension.

can_transf_matrix

Return the canonical transformation matrix from the canonical to the base dimension basis.

It is the inverse of the matrix computed with inv_can_transf_matrix().

dim

Give the dimension of the system.

That is return the number of dimensions forming the basis.

dim_can_vector(dim)[source]

Dimensional representation in terms of the canonical base dimensions.

dim_vector(dim)[source]

Vector representation in terms of the base dimensions.

extend(base, dims=(), name='', description='')[source]

Extend the current system into a new one.

Take the base and normal units of the current system to merge them to the base and normal units given in argument. If not provided, name and description are overriden by empty strings.

get_dim(dim)[source]

Find a specific dimension which is part of the system.

dim can be a string or a dimension object. If no dimension is found, then return None.

inv_can_transf_matrix

Compute the inverse transformation matrix from the base to the canonical dimension basis.

It corresponds to the matrix where columns are the vector of base dimensions in canonical basis.

This matrix will almost never be used because dimensions are always define with respect to the canonical basis, so no work has to be done to get them in this basis. Nonetheless if this matrix is not square (or not invertible) it means that we have chosen a bad basis.

is_consistent

Check if the system is well defined.

list_can_dims

List all canonical dimension names.

print_dim_base(dim)[source]

Give the string expression of a dimension in term of the basis symbols.

static sort_dims(dims)[source]

Sort dimensions given in argument using their str function.

This function will ensure that we get always the same tuple for a given set of dimensions.