 with_unit - Maple Help

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 expr is of type with_unit if:
 – expr is the function Units[Unit] applied to some arguments;
 – expr is a rational power of such a function call;
 – expr is a product of such function calls, potentially raised to rational powers, potentially also with another Maple expression;
 – a call to the function Units[Unit] is present anywhere in expr (in the sense of the command has) and combine(expr, units) is of one of the three earlier forms described above.
 • The function call type(expr, with_unit) returns true if expr is of type with_unit. 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 expr is not of one of the first three forms above and calling combine(expr, units) is necessary to get it in that form, then the unit and multiplier of expr are those of combine(expr, units).
 • 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.
 – When you edit a unit, double brackets appear around it.
 > $\mathrm{with}\left(\mathrm{Units}\left[\mathrm{Standard}\right]\right):$
 > $3\mathrm{Unit}\left(m\right)$
 ${3}{}⟦{m}⟧$ (1)
 > $\mathrm{type}\left(3\mathrm{Unit}\left(m\right),\mathrm{with_unit}\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{type}\left(3\mathrm{Unit}\left(m\right),\mathrm{with_unit}\left(\mathrm{integer}\right)\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{type}\left(3{x}^{2}\mathrm{Unit}\left(m\right),\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{false}}$ (4)
 > $a,b$
 ${a}{,}{b}$ (5)
 > $\mathrm{type}\left(3{x}^{2}\mathrm{Unit}\left(m\right),\mathrm{with_unit}\left(\mathrm{anything},'a','b'\right)\right)$
 ${\mathrm{true}}$ (6)
 > $a,b$
 ${3}{}{{x}}^{{2}}{,}⟦{m}⟧$ (7)
 > $\mathrm{type}\left(2\mathrm{Unit}\left(m\right),\mathrm{with_unit}\left(\mathrm{integer},'a','b'\right)\right)$
 ${\mathrm{true}}$ (8)
 > $a,b$
 ${2}{,}⟦{m}⟧$ (9)
 > $\mathrm{with}\left(\mathrm{Units}\left[\mathrm{Natural}\right]\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)

In the following cases, expr is detected as being of type with_unit only after the call combine(expr, units).

 > $\mathrm{restart}$
 > $\mathrm{expr}≔x\mathrm{Unit}\left(m\right)+y\mathrm{Unit}\left(\mathrm{ft}\right)$
 ${\mathrm{expr}}{≔}{x}{}⟦{m}⟧{+}{y}{}⟦{\mathrm{ft}}⟧$ (19)
 > $\mathrm{type}\left(\mathrm{expr},\mathrm{with_unit}\left(\mathrm{anything},'a','b'\right)\right)$
 ${\mathrm{true}}$ (20)
 > $a,b$
 ${x}{+}\frac{{381}{}{y}}{{1250}}{,}⟦{m}⟧$ (21)

In this case, the call combine(expr, units) combines the units for expr by converting to the SI system of units. Because this is a necessary step in determining the unit and multiplier for this expression, the unit and multiplier found by with_unit are in the SI system.

 > $\mathrm{expr}≔5\mathrm{Unit}\left(\mathrm{ft}\right)+x\mathrm{Unit}\left(\mathrm{ft}\right)$
 ${\mathrm{expr}}{≔}{5}{}⟦{\mathrm{ft}}⟧{+}{x}{}⟦{\mathrm{ft}}⟧$ (22)
 > $\mathrm{combine}\left(\mathrm{expr},\mathrm{units}\right)$
 $\left(\frac{{381}}{{250}}{+}\frac{{381}{}{x}}{{1250}}\right){}⟦{m}⟧$ (23)
 > $\mathrm{type}\left(\mathrm{expr},\mathrm{with_unit}\left(\mathrm{anything},'a','b'\right)\right)$
 ${\mathrm{true}}$ (24)
 > $a,b$
 $\frac{{381}}{{250}}{+}\frac{{381}{}{x}}{{1250}}{,}⟦{m}⟧$ (25)