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.unitsystems.dimensions.Dimension[source]

This class represent the dimension of a physical quantities.

The dimensions may have a name and a symbol. All other arguments are dimensional powers. They represent a characteristic of a quantity, giving an interpretation to it: 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.unitsystems.dimensions import Dimension
>>> length = Dimension(length=1)
>>> length
{'length': 1}
>>> time = Dimension(time=1)

Dimensions behave like a dictionary where the key is the name and the value corresponds to the exponent.

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.div(time)
>>> velocity  
{'length': 1, 'time': -1}
>>> length.add(length)
{'length': 1}
>>> length.pow(2)
{'length': 2}

Defining addition-like operations will help when doing dimensional analysis.

Note that two dimensions are equal if they have the same powers, even if their names and/or symbols differ.

>>> Dimension(length=1) == Dimension(length=1, name="length")
True
>>> Dimension(length=1) == Dimension(length=1, symbol="L")
True
>>> Dimension(length=1) == Dimension(length=1, name="length",
...                                  symbol="L")
True
add(other)[source]

Define the addition for Dimension.

Addition of dimension has a sense only if the second object is the same dimension (we don’t add length to time).

get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
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.

items() → list of D's (key, value) pairs, as 2-tuples[source]
keys() → list of D's keys[source]
values() → list of D's values[source]
class sympy.physics.unitsystems.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

Compute 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]

Vector 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.

Dimensions are displayed by decreasing power.

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.