TestDimensions - Maple Help

Units

 TestDimensions
 verify dimensional correctness of unit expression(s)

 Calling Sequence TestDimensions(expr) TestDimensions(expr, known, output)

Parameters

 expr - expression or list or set of expressions known - (optional) set or list of pairs to add restrictions to the possible dimensional mappings output - (optional) equation of the form output = o, where o indicates what type of output is requested

Description

 • The TestDimensions command verifies dimensional correctness of one or more expressions with units. By default, it returns true if there is a valid assignment of dimensions to all subexpressions of expr that is consistent with any of the mappings specified in the optional argument known, and false otherwise. Validity is tested for all subexpressions occurring in expr.
 • This command underlies the Simple Units environment, provided by the Units[Simple] subpackage. Every command in Units[Simple] that needs to determine whether an expression is valid or not, does so using the TestDimensions command.
 • The following rules apply:
 – All operands of sums, equations, inequations, and inequalities have to have the same dimension.
 – The outcome of a sum has the same dimension as all of its arguments.
 – The outcome of a product has the product of the dimensions of its arguments.
 – If an expression is raised to a rational power, the outcome has the dimension of the base raised to that same power.
 – If an expression is raised to a power that's not a rational constant, then the base and exponent need to be dimensionless and the outcome is also dimensionless.
 – The two operands of the two-argument $\mathrm{arctan}$ function have to have the same dimension.
 – All operands of other mathematical functions defined in Maple, such as $\mathrm{exp}$ or $\mathrm{ln}$ or $\mathrm{LambertW}$, have to be dimensionless.
 – The outcomes of other mathematical functions defined in Maple, such as $\mathrm{exp}$ or $\mathrm{ln}$ or $\mathrm{LambertW}$, have to be dimensionless.
 • Equality of dimensions is verified while discarding so-called unit annotations. For example, a quantity with the dimension of $\mathrm{plane_angle}$ has the same dimension as unitless constants.
 • The argument expr can be any Maple expression or collection of expressions, represented as a set, a list, an rtable, or generally any container for which the indets command examines the entries. It cannot be an expression sequence (except of length 1).
 • The argument known is a set or list of pairs subexpr :: Unit(some_unit), or equivalently, $\mathrm{subexpr}::⟦\mathrm{some_unit}⟧$. This can be used to enforce known dimensionalities of particular subexpressions.
 • By default, TestDimensions returns only true or false, to indicate whether it found a valid mapping of subexpressions to dimensions. You can select other types of output with the output option:
 – If you supply the optional argument output = boolean, you get the default output.
 – If you supply the optional argument output = units and a valid mapping of subexpressions to dimensions exists, the command will instead return a set of mappings of the form subexpr :: Unit(some_unit), where some_unit is a unit of a suitable dimension. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 – If you supply an optional argument of the form output = units(expr1, expr2, ..., exprk) and a valid mapping of subexpressions to dimensions exists, the command will instead return a set of mappings of the form norm_expr :: Unit(some_unit), where norm_expr is one of expr1, expr2, ..., exprk, normalized using a custom version of primpart, and where some_unit is a unit of a suitable dimension. Any expressions in expr1, expr2, ..., exprk that were not encountered are omitted from the result. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = dimensions and a valid mapping of subexpressions to dimensions exists, the command will instead return a set of mappings of the form subexpr :: some_dimension, where some_dimension is a valid product of base dimensions for subexpr, as the command convert/dimensions might return. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 In many cases, there are some degrees of freedom for the result. For example, in an expression such as $5⟦\mathrm{kg}⟧+xy$, the variable $x$ can have any arbitrary dimension, as long as the dimension of $y$ is such that $xy$ has the dimension mass. This is indicated by specifying, for example, the dimension of $x$ as a product of base dimensions raised to symbolic powers. In the previous example, for example, the dimension for $x$ may have a factor ${\mathrm{length}}^{{\mathrm{_t0}}_{1,1}}$ and the dimension for $y$ would then have a factor ${\mathrm{length}}^{-{\mathrm{_t0}}_{1,1}}$. Similarly, there might be a factor ${\mathrm{mass}}^{1-{\mathrm{_t0}}_{1,2}}$ in one and a factor ${\mathrm{mass}}^{{\mathrm{_t0}}_{1,2}}$ in the other. Any value assigned to these values ${\mathrm{_t0}}_{1,1}$ and ${\mathrm{_t0}}_{1,2}$ will lead to a valid dimension for $x$ and $y$.
 – If you supply an optional argument of the form output = dimensions(expr1, expr2, ..., exprk) and a valid mapping of subexpressions to dimensions exists, the command will instead return a set of mappings of the form norm_expr :: some_dimension, where norm_expr is one of expr1, expr2, ..., exprk, normalized using a custom version of primpart, and where some_dimension is a dimension, possibly including variable exponents as with output = dimensions. Any expressions in expr1, expr2, ..., exprk that were not encountered are omitted from the result. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = variables, and a valid mapping of subexpressions to dimensions exists, the command will instead return the set of variables occurring in the exponents that would be returned with the argument output = dimensions. This output is mostly useful for programs analyzing the dimensional consistency of expressions, not so much for users entering the command manually. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = variables(expr1, expr2, ..., exprk) and a valid mapping of subexpressions to dimensions exists, the command will instead return the set of variables occurring in the exponents that would be returned with the argument output = dimensions(expr1, expr2, ..., exprk). That is, this is like output = variables, but restricted to the subexpressions expr1, expr2, ..., exprk. If no valid mapping could be found, the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = ambiguous, and a valid mapping of subexpressions to dimensions was found, then the value $\mathrm{true}$ is returned if there are ambiguities in the dimensions returned for output = dimensions and $\mathrm{false}$ if there are no ambiguities. There are ambiguities exactly if the result for output = variables is a nonempty set. If no valid mapping of subexpressions to dimensions was found, then the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = ambiguous(expr1, expr2, ..., exprk) and a valid mapping of subexpressions to dimensions was found, then the value $\mathrm{true}$ is returned if there are ambiguities in the dimensions returned for output = dimensions(expr1, expr2, ..., exprk) and $\mathrm{false}$ if there are no ambiguities. There are ambiguities exactly if the result for output = variables(expr1, expr2, ..., exprk) is a nonempty set. If no valid mapping of subexpressions to dimensions was found, then the value $\mathrm{FAIL}$ is returned.
 – If you supply the optional argument output = contradictions, and a valid mapping of subexpressions to dimensions exists, the command will instead return the value $\mathrm{FAIL}$. If, on the other hand, there is no valid mapping, then the command returns a small subset of subexpressions of $\mathrm{expr}$ or entries of known so that those expressions cannot be given suitable dimensions simultaneously.
 – If you supply an option of the form output = o, where o is a list of (some of) the values described above, the command will return a sequence of the corresponding output values.

Examples

Here is an example of an expression that is not valid.

 > $\mathrm{Units}\left[\mathrm{TestDimensions}\right]\left(2\mathrm{Unit}\left(m\right)+3\mathrm{Unit}\left(s\right)\right)$
 ${\mathrm{false}}$ (1)

If you load the Units package (and therefore, the Units[Simple] subpackage), then this leads to an error. This also allows use of the short form of the TestDimensions command.

 > $\mathrm{with}\left(\mathrm{Units}\right)$
 $\left[{\mathrm{AddBaseUnit}}{,}{\mathrm{AddDimension}}{,}{\mathrm{AddSystem}}{,}{\mathrm{AddUnit}}{,}{\mathrm{CommandsOnly}}{,}{\mathrm{Converter}}{,}{\mathrm{GetDimension}}{,}{\mathrm{GetDimensions}}{,}{\mathrm{GetSystem}}{,}{\mathrm{GetSystems}}{,}{\mathrm{GetUnit}}{,}{\mathrm{GetUnits}}{,}{\mathrm{HasDimension}}{,}{\mathrm{HasSystem}}{,}{\mathrm{HasUnit}}{,}{\mathrm{Indets}}{,}{\mathrm{Natural}}{,}{\mathrm{RemoveDimension}}{,}{\mathrm{RemoveSystem}}{,}{\mathrm{Simple}}{,}{\mathrm{Split}}{,}{\mathrm{Standard}}{,}{\mathrm{TestDimensions}}{,}{\mathrm{Unit}}{,}{\mathrm{UseContexts}}{,}{\mathrm{UseMode}}{,}{\mathrm{UseSystem}}{,}{\mathrm{UseUnit}}{,}{\mathrm{UsingContexts}}{,}{\mathrm{UsingSystem}}\right]$ (2)
 > $2\mathrm{Unit}\left(m\right)+3\mathrm{Unit}\left(s\right)$

In the following example, there is a valid assignment of dimensions to the variables - in this case the single variable, $v$. We ask Maple to tell us what dimension it assigns to $v$ (and some other subexpressions).

 > $\mathrm{TestDimensions}\left(2\mathrm{Unit}\left(m\right)+v\cdot 3\mathrm{Unit}\left(s\right)\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{TestDimensions}\left(2\mathrm{Unit}\left(m\right)+v\cdot 3\mathrm{Unit}\left(s\right),'\mathrm{output}'='\mathrm{dimensions}'\right)$
 $\left\{{v}{::}\left(\frac{{\mathrm{length}}}{{\mathrm{time}}}\right){,}\left({v}{}⟦{s}⟧\right){::}{\mathrm{length}}{,}\left({2}{}⟦{m}⟧{+}{3}{}{v}{}⟦{s}⟧\right){::}{\mathrm{length}}\right\}$ (4)
 > $\mathrm{TestDimensions}\left(2\mathrm{Unit}\left(m\right)+v\cdot 3\mathrm{Unit}\left(s\right),'\mathrm{output}'=\left['\mathrm{boolean}','\mathrm{dimensions}'\right]\right)$
 ${\mathrm{true}}{,}\left\{{v}{::}\left(\frac{{\mathrm{length}}}{{\mathrm{time}}}\right){,}\left({v}{}⟦{s}⟧\right){::}{\mathrm{length}}{,}\left({2}{}⟦{m}⟧{+}{3}{}{v}{}⟦{s}⟧\right){::}{\mathrm{length}}\right\}$ (5)

If we specify that $v$ has a dimension of mass, then the expression is not valid. If Maple detects this, it can find the offending subexpressions.

 > $\mathrm{TestDimensions}\left(\left[2\mathrm{Unit}\left(m\right)+v\cdot 3\mathrm{Unit}\left(s\right),v+x,v=f\left(y\right)\right],\left\{v::\mathrm{Unit}\left(\mathrm{kg}\right)\right\},'\mathrm{output}'=\left['\mathrm{boolean}','\mathrm{contradictions}'\right]\right)$
 ${\mathrm{false}}{,}\left\{{v}{::}⟦{\mathrm{kg}}⟧{,}{2}{}⟦{m}⟧{+}{3}{}{v}{}⟦{s}⟧\right\}$ (6)

In some situations, there is some ambiguity in how units are assigned, for example in the expression $xy+5⟦\mathrm{kg}⟧$ if no extra information is given. In such a case, Maple will give the fully general value if you ask for $\mathrm{output}=\mathrm{dimensions}$. This output is sometimes hard to understand, but it is explained in the text above.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{output}=\mathrm{dimensions}\right)$
 $\left\{{x}{::}\left({{\mathrm{length}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{1}}}{}{{\mathrm{mass}}}^{{1}{-}{{\mathrm{_t28}}}_{{2}{,}{2}}}{}{{\mathrm{time}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{3}}}{}{{\mathrm{electric_current}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{4}}}{}{{\mathrm{thermodynamic_temperature}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{5}}}{}{{\mathrm{amount_of_substance}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{6}}}{}{{\mathrm{luminous_intensity}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{7}}}{}{{\mathrm{currency}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{8}}}{}{{\mathrm{amount_of_information}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{9}}}{}{{\mathrm{logarithmic_gain}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{10}}}\right){,}{y}{::}\left({{\mathrm{length}}}^{{{\mathrm{_t28}}}_{{2}{,}{1}}}{}{{\mathrm{mass}}}^{{{\mathrm{_t28}}}_{{2}{,}{2}}}{}{{\mathrm{time}}}^{{{\mathrm{_t28}}}_{{2}{,}{3}}}{}{{\mathrm{electric_current}}}^{{{\mathrm{_t28}}}_{{2}{,}{4}}}{}{{\mathrm{thermodynamic_temperature}}}^{{{\mathrm{_t28}}}_{{2}{,}{5}}}{}{{\mathrm{amount_of_substance}}}^{{{\mathrm{_t28}}}_{{2}{,}{6}}}{}{{\mathrm{luminous_intensity}}}^{{{\mathrm{_t28}}}_{{2}{,}{7}}}{}{{\mathrm{currency}}}^{{{\mathrm{_t28}}}_{{2}{,}{8}}}{}{{\mathrm{amount_of_information}}}^{{{\mathrm{_t28}}}_{{2}{,}{9}}}{}{{\mathrm{logarithmic_gain}}}^{{{\mathrm{_t28}}}_{{2}{,}{10}}}\right){,}\left({x}{}{y}\right){::}{\mathrm{mass}}{,}\left({x}{}{y}{+}{5}{}⟦{\mathrm{kg}}⟧\right){::}{\mathrm{mass}}\right\}$ (7)

We can also include the set of variables used in the exponents.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{output}=\left[\mathrm{dimensions},\mathrm{variables}\right]\right)$
 $\left\{{x}{::}\left({{\mathrm{length}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{1}}}{}{{\mathrm{mass}}}^{{1}{-}{{\mathrm{_t28}}}_{{2}{,}{2}}}{}{{\mathrm{time}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{3}}}{}{{\mathrm{electric_current}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{4}}}{}{{\mathrm{thermodynamic_temperature}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{5}}}{}{{\mathrm{amount_of_substance}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{6}}}{}{{\mathrm{luminous_intensity}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{7}}}{}{{\mathrm{currency}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{8}}}{}{{\mathrm{amount_of_information}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{9}}}{}{{\mathrm{logarithmic_gain}}}^{{-}{{\mathrm{_t28}}}_{{2}{,}{10}}}\right){,}{y}{::}\left({{\mathrm{length}}}^{{{\mathrm{_t28}}}_{{2}{,}{1}}}{}{{\mathrm{mass}}}^{{{\mathrm{_t28}}}_{{2}{,}{2}}}{}{{\mathrm{time}}}^{{{\mathrm{_t28}}}_{{2}{,}{3}}}{}{{\mathrm{electric_current}}}^{{{\mathrm{_t28}}}_{{2}{,}{4}}}{}{{\mathrm{thermodynamic_temperature}}}^{{{\mathrm{_t28}}}_{{2}{,}{5}}}{}{{\mathrm{amount_of_substance}}}^{{{\mathrm{_t28}}}_{{2}{,}{6}}}{}{{\mathrm{luminous_intensity}}}^{{{\mathrm{_t28}}}_{{2}{,}{7}}}{}{{\mathrm{currency}}}^{{{\mathrm{_t28}}}_{{2}{,}{8}}}{}{{\mathrm{amount_of_information}}}^{{{\mathrm{_t28}}}_{{2}{,}{9}}}{}{{\mathrm{logarithmic_gain}}}^{{{\mathrm{_t28}}}_{{2}{,}{10}}}\right){,}\left({x}{}{y}\right){::}{\mathrm{mass}}{,}\left({x}{}{y}{+}{5}{}⟦{\mathrm{kg}}⟧\right){::}{\mathrm{mass}}\right\}{,}\left\{{{\mathrm{_t28}}}_{{2}{,}{1}}{,}{{\mathrm{_t28}}}_{{2}{,}{2}}{,}{{\mathrm{_t28}}}_{{2}{,}{3}}{,}{{\mathrm{_t28}}}_{{2}{,}{4}}{,}{{\mathrm{_t28}}}_{{2}{,}{5}}{,}{{\mathrm{_t28}}}_{{2}{,}{6}}{,}{{\mathrm{_t28}}}_{{2}{,}{7}}{,}{{\mathrm{_t28}}}_{{2}{,}{8}}{,}{{\mathrm{_t28}}}_{{2}{,}{9}}{,}{{\mathrm{_t28}}}_{{2}{,}{10}}\right\}$ (8)

We can detect such an ambiguous case by asking for $\mathrm{output}=\mathrm{ambiguous}$.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{output}=\mathrm{ambiguous}\right)$
 ${\mathrm{true}}$ (9)

If we know that $x$ has the dimension of mass per unit of time, then the result is unambiguous.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\left\{x::\left(\mathrm{Unit}\left(\frac{\mathrm{kg}}{s}\right)\right)\right\},\mathrm{output}=\mathrm{ambiguous}\right)$
 ${\mathrm{false}}$ (10)

For $\mathrm{output}=\mathrm{units}$, in the presence of ambiguity, Maple selects one of the possible assignments of units to subexpressions.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{output}=\mathrm{units}\right)$
 $\left\{{x}{::}⟦{\mathrm{kg}}⟧{,}{y}{::}{1}{,}\left({x}{}{y}\right){::}⟦{\mathrm{kg}}⟧{,}\left({x}{}{y}{+}{5}{}⟦{\mathrm{kg}}⟧\right){::}⟦{\mathrm{kg}}⟧\right\}$ (11)

We can also ask for the units for some specific subexpressions.

 > $\mathrm{TestDimensions}\left(xy+5\mathrm{Unit}\left(\mathrm{kg}\right),\mathrm{output}=\mathrm{units}\left(x,xy\right)\right)$
 $\left\{{x}{::}⟦{\mathrm{kg}}⟧{,}\left({x}{}{y}\right){::}⟦{\mathrm{kg}}⟧\right\}$ (12)

Compatibility

 • The Units[TestDimensions] command was introduced in Maple 2017.