type/with_unit - Maple Programming Help

Home : Support : Online Help : Programming : Data Types : Type Checking : Types : type/with_unit

type/with_unit

check for a Maple unit

 Calling Sequence type(expr, with_unit(typ, coeff, unit))

Parameters

 expr - expression typ - (optional) Maple type coeff, unit - (optional) names

Description

 • A Maple expression is with a unit if it is the function Units[Unit] applied to some arguments, a rational power of such an expression, or a product of such expressions, potentially also with another Maple expression.
 • The function call type(expr, with_unit) returns true if expr is of the form described above. Otherwise, false is returned.
 • In the remainder of this help page, we will refer to the product of the powers of the Units[Unit] function as the unit of the expression, and the product of the remaining factors (if any) as the multiplier. If there are no other factors, the multiplier is $1$.
 • If an optional type typ is given and expr is of the form described above, it additionally checks that the multiplier is of the type typ. The function returns true if this additional condition is satisfied. Otherwise, false is returned.
 • If optional arguments coeff and unit are given and type(expr, with_unit(typ)) returns true, then the unit of expr is assigned to unit and the multiplier is assigned to coeff.

Examples

Notes:

 – To enter a unit in 2-D Math input, select the unit from the appropriate Units palette. If the unit you want is not there, select $\mathrm{unit}$ and then enter the unit.
 – In Maple 2015 and later versions, the double brackets around a unit are not displayed unless you are editing the unit.
 > $\mathrm{with}\left(\mathrm{Units}[\mathrm{Standard}]\right):$
 > $3⟦m⟧$
 ${3}{}⟦{m}⟧$ (1)
 > $\mathrm{type}\left(3⟦m⟧,\mathrm{with_unit}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{type}\left(3⟦m⟧,\mathrm{with_unit}\left(\mathrm{integer}\right)\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{type}\left(3{x}^{2}⟦m⟧,\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{false}}$ (4)
 > $a,b$
 ${a}{,}{b}$ (5)
 > $\mathrm{type}\left(3{x}^{2}⟦m⟧,\mathrm{with_unit}\left(\mathrm{anything},'a','b'\right)\right)$
 ${\mathrm{true}}$ (6)
 > $a,b$
 ${3}{}{{x}}^{{2}}{,}⟦{m}⟧$ (7)
 > $\mathrm{type}\left(2⟦m⟧,\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{true}}$ (8)
 > $a,b$
 ${2}{,}⟦{m}⟧$ (9)
 > $\mathrm{with}\left(\mathrm{Units}[\mathrm{Natural}]\right):$
 > $3m$
 ${3}{}⟦{m}⟧$ (10)
 > $\mathrm{type}\left(3m,\mathrm{with_unit}\right)$
 ${\mathrm{true}}$ (11)
 > $\mathrm{type}\left(3m,\mathrm{with_unit}\left(\mathrm{integer}\right)\right)$
 ${\mathrm{true}}$ (12)
 > $\mathrm{type}\left(3{x}^{2}m,\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{false}}$ (13)
 > $a,b$
 ${2}{,}⟦{m}⟧$ (14)
 > $\mathrm{type}\left(3{x}^{2}m,\mathrm{with_unit}\left(\mathrm{anything},'a','b'\right)\right)$
 ${\mathrm{true}}$ (15)
 > $a,b$
 ${3}{}{{x}}^{{2}}{,}⟦{m}⟧$ (16)
 > $\mathrm{type}\left(2m,\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{true}}$ (17)
 > $a,b$
 ${2}{,}⟦{m}⟧$ (18)