Units
TestDimensions
verify dimensional correctness of unit expression(s)
Calling Sequence
Parameters
Description
Examples
Compatibility
TestDimensions(expr)
TestDimensions(expr, known, output)
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
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 arctan function have to have the same dimension.
All operands of other mathematical functions defined in Maple, such as exp or ln or LambertW, have to be dimensionless.
The outcomes of other mathematical functions defined in Maple, such as exp or ln or LambertW, have to be dimensionless.
Equality of dimensions is verified while discarding so-called unit annotations. For example, a quantity with the dimension of 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, subexpr::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 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 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 FAIL is returned.
In many cases, there are some degrees of freedom for the result. For example, in an expression such as 5⁢kg+x⁢y, the variable x can have any arbitrary dimension, as long as the dimension of y is such that x⁢y 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 length_t01,1 and the dimension for y would then have a factor length−_t01,1. Similarly, there might be a factor mass1−_t01,2 in one and a factor mass_t01,2 in the other. Any value assigned to these values _t01,1 and _t01,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 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 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 FAIL is returned.
If you supply the optional argument output = ambiguous, and a valid mapping of subexpressions to dimensions was found, then the value true is returned if there are ambiguities in the dimensions returned for output = dimensions and 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 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 true is returned if there are ambiguities in the dimensions returned for output = dimensions(expr1, expr2, ..., exprk) and 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 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 FAIL. If, on the other hand, there is no valid mapping, then the command returns a small subset of subexpressions of 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.
Here is an example of an expression that is not valid.
UnitsTestDimensions⁡2⁢Unit⁡m+3⁢Unit⁡s
false
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.
with⁡Units
Automatically loading the Units[Simple] subpackage
AddBaseUnit,AddDimension,AddSystem,AddUnit,CommandsOnly,Converter,GetDimension,GetDimensions,GetSystem,GetSystems,GetUnit,GetUnits,HasDimension,HasSystem,HasUnit,Indets,Natural,RemoveDimension,RemoveSystem,Simple,Split,Standard,TestDimensions,Unit,UseContexts,UseMode,UseSystem,UseUnit,UsingContexts,UsingSystem
2⁢Unit⁡m+3⁢Unit⁡s
Error, (in Units:-Simple:-`+`) the following expressions imply incompatible dimensions: 2*Units:-Unit(m)+3*Units:-Unit(s)
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).
TestDimensions⁡2⁢Unit⁡m+v⋅3⁢Unit⁡s
true
TestDimensions⁡2⁢Unit⁡m+v⋅3⁢Unit⁡s,output=dimensions
v::lengthtime,v⁢s::length,2⁢m+3⁢v⁢s::length
TestDimensions⁡2⁢Unit⁡m+v⋅3⁢Unit⁡s,output=boolean,dimensions
true,v::lengthtime,v⁢s::length,2⁢m+3⁢v⁢s::length
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.
TestDimensions⁡2⁢Unit⁡m+v⋅3⁢Unit⁡s,v+x,v=f⁡y,v::Unit⁡kg,output=boolean,contradictions
false,v::kg,2⁢m+3⁢v⁢s
In some situations, there is some ambiguity in how units are assigned, for example in the expression x⁢y+5⁢kg if no extra information is given. In such a case, Maple will give the fully general value if you ask for output=dimensions. This output is sometimes hard to understand, but it is explained in the text above.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,output=dimensions
x::length−variable1,1⁢mass1−variable1,2⁢time−variable1,3⁢electric_current−variable1,4⁢thermodynamic_temperature−variable1,5⁢amount_of_substance−variable1,6⁢luminous_intensity−variable1,7⁢currency−variable1,8⁢amount_of_information−variable1,9⁢logarithmic_gain−variable1,10,y::lengthvariable1,1⁢massvariable1,2⁢timevariable1,3⁢electric_currentvariable1,4⁢thermodynamic_temperaturevariable1,5⁢amount_of_substancevariable1,6⁢luminous_intensityvariable1,7⁢currencyvariable1,8⁢amount_of_informationvariable1,9⁢logarithmic_gainvariable1,10,x⁢y::mass,x⁢y+5⁢kg::mass
We can also include the set of variables used in the exponents.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,output=dimensions,variables
x::length−variable1,1⁢mass1−variable1,2⁢time−variable1,3⁢electric_current−variable1,4⁢thermodynamic_temperature−variable1,5⁢amount_of_substance−variable1,6⁢luminous_intensity−variable1,7⁢currency−variable1,8⁢amount_of_information−variable1,9⁢logarithmic_gain−variable1,10,y::lengthvariable1,1⁢massvariable1,2⁢timevariable1,3⁢electric_currentvariable1,4⁢thermodynamic_temperaturevariable1,5⁢amount_of_substancevariable1,6⁢luminous_intensityvariable1,7⁢currencyvariable1,8⁢amount_of_informationvariable1,9⁢logarithmic_gainvariable1,10,x⁢y::mass,x⁢y+5⁢kg::mass,variable1,1,variable1,2,variable1,3,variable1,4,variable1,5,variable1,6,variable1,7,variable1,8,variable1,9,variable1,10
We can detect such an ambiguous case by asking for output=ambiguous.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,output=ambiguous
If we know that x has the dimension of mass per unit of time, then the result is unambiguous.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,x::Unit⁡kgs,output=ambiguous
For output=units, in the presence of ambiguity, Maple selects one of the possible assignments of units to subexpressions.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,output=units
x::kg,y::1,x⁢y::kg,x⁢y+5⁢kg::kg
We can also ask for the units for some specific subexpressions.
TestDimensions⁡x⁢y+5⁢Unit⁡kg,output=units⁡x,x⁢y
x::kg,x⁢y::kg
The Units[TestDimensions] command was introduced in Maple 2017.
For more information on Maple 2017 changes, see Updates in Maple 2017.
The Units[TestDimensions] command was updated in Maple 2018.
The output option was updated in Maple 2018.
See Also
Units,UseSystem
Units/Simple
Download Help Document