structured types - Maple Help

Definition of a Structured Type in Maple

Description

 • A structured type is a Maple expression other than a symbol that can be interpreted as a type. A typical example would be set(name=algebraic). This specifies a set of equations whose left-hand sides are (variable) names, and whose right-hand sides are of type algebraic.
 • This file first gives a formal grammatical description of the valid structured types, then provides notes on some of the special types, and lastly gives examples.
 • In the formal definition below, read ::='' to mean is defined to be'', |'' to mean or'', and *'' to mean zero or more occurrences of''.

 Syntax Matches type ::= { type* } alternation; any of the types | [ type* ] a list of the given types | complex(numeric) match a complex numerical constant exactly | string match a string exactly | symbol a system, procedural, or assigned type | type = type an equation of the corresponding types | type <> type an inequality of the corresponding types | type < type a relation of the corresponding types | type <= type a relation of the corresponding types | type > type a relation of the corresponding types | type >= type a relation of the corresponding types | type .. type a range of the corresponding types | type and type an AND of the corresponding types | type or type an OR of the corresponding types | not type a NOT of the corresponding type | type &+ type ... a sum of the corresponding types | type &* type ... a product of the corresponding types | type ^ type a power of the corresponding types | type || type a concatenation of the corresponding types | 'type' an unevaluated expression of the given type | fcntype a function or a special type | name[type*] an indexed reference of the given types fcntype ::= set(type) a set of elements of the given type | list(type) a list of elements of the given type | Or(type*) any of the given types | And(type*) all of the given types | Not(type) not the given type | identical(expr) an expression identical to expr | specfunc(f) the function f with (possibly zero) arguments of any type | specfunc(type,f) the function f with (possibly zero) type arguments | anyfunc(type*) any function of the given types | specop(operator) an operator or function expression with operands of any type | specop(type,operator) an operator or function expression with type operands | anyop(type*) any operator or function of the given types | thistype(type) equivalent to the given type | typefunc(type0) a function of type type0 with arguments of any type | typefunc(type,type0) a function of type type0 with type arguments | patfunc(type*,type) a function matching the first type argument(s), with all remaining arguments matching the last type | patfunc[reverse](type,type*) a function matching the last type argument(s), with all preceding arguments matching the first type | specindex(x) the expression x with indices of any type | specindex(type,x) the expression x with all indices of the given type | typeindex(type0) an expression of type type0 with indices of any type | typeindex(type,type0) an expression of type type0 with all indices of the given type | anyindex(type*) any indexed expression with indices of the given types | patindex(type*,type) an indexed expression matching the first type argument(s), with all remaining arguments matching the last type | patindex[reverse](type,type*) an indexed expression matching the last type argument(s), with all preceding arguments matching the first type | function(type) any function with type arguments | name(type) any name with a value of the given type | patlist(type*,type) a list matching the first type argument(s), with all remaining arguments matching the last type | patlist[reverse](type,type*) a list matching the last type argument(s), with all preceding arguments matching the first type | p(anything*) type defined by a procedure type/p | f(type*) the function f of the given types | +(type) a sum of terms of the given type | *(type) a product of factors of the given type | &+(type*) a sum of terms in which the nth term is of the nth type specified in type* | &*(type*) a product of factors in which the nth factor is of the nth type specified in type* | type &under func an expression expr so that func(expr) is of type type | type &under (func, arg1, arg2) an expression expr so that func(expr, arg1, arg2) is of type type

 • Square brackets [] are used to check for a fixed argument sequence.  The type [name, set] matches a list with exactly two arguments: a name followed by a set.
 • Set brackets {} are used for alternation.  The type {set(name), list(integer)} matches either a set of names, or a list of integers.
 • The type anything matches any expression except a sequence.
 • The type identical(expr) matches the expression expr identically. If there is more than one expr (i.e. identical(expr1,expr2,...)), then this type matches any one of the exprN identically. The type identical() matches the empty expression sequence.
 • The type anyfunc(t1, ..., tn) matches any function with n arguments of type $\mathrm{t1},...,\mathrm{tn}$. Thus, type(f, anyfunc(t1,...,tn)) is equivalent to the logical conjunction type(f, function) and type([op(f)], [t1,...,tn]).
 • The type patfunc(t1,..., tn, t) matches any function with $n$ or more arguments where the first $n$ are of type $\mathrm{t1},...,\mathrm{tn}$, and the remaining arguments are of type t.
 • The type patfunc[reverse](t,t1,...,tn) matches any function with $n$ or more arguments where the last $n$ are of type $\mathrm{t1},...,\mathrm{tn}$, and the preceding arguments are of type $t$.
 • The type specfunc(t, n) matches the function $n$ with 0 or more arguments of type $t$.  Thus, type(f, specfunc(t, n)) is equivalent to the logical conjunction type(f, function) and op(0,f) = n and type([op(f)], list(t)). Instead of a single name n, a set of names may be passed as the second parameter to the specfunc type constructor.  In this case, an expression matches if it is a function call with any of the names in the set as the 0-th operand. Thus, type(f,specfunc(t,{n1,n2,...,nk})) is equivalent to type(f,specfunc(t,n1)) or type(f,specfunc(t, n2)) or ... or type(f,specfunc(t,nk)).
 • The type specop(t, n) matches an operator expression or function with zeroth operand $n$ and operands of type $t$. It is similar to the specfunc type constructor, but also matches expressions, for example, sums, products, and relations, as well as functions. As for the specfunc type constructor, the second parameter may be a set of names rather than just a single name.
 • The type typefunc(t, T) matches a function of type $T$ with 0 or more arguments of type $t$.  Thus, type(f, typefunc(t, T)) is equivalent to the logical conjunction type(f, function) and type([op(0,f)], [T]) and type([op(f)], list(t)).
 • Analogous to specfunc, anyfunc, typefunc, patfunc, and patfunc[reverse], the type constructors specindex, anyindex, typeindex, patindex, and patindex[reverse] can be used to test for expressions with indices of prescribed types and the type constructors patlist and patlist[reverse] can be used to test for lists with elements of prescribed types.
 • The type type &under func describes expressions expr for which func(expr) is of type type. The second form of this type takes an arbitrary number of extra arguments for func; in particular, type &under (func, arg1, arg2, ...) describes expressions expr for which func(expr, arg1, arg2, ...) is of type type.
 • The type specfunc(t) matches an expression of type $t$. It's primary use is to define types where $t$ is used more than once, such as {thistype,set}(t), which is equivalent to {t,set(t)}.

Examples

 > $\mathrm{type}\left(\mathrm{string},\mathrm{string}\right)$
 ${\mathrm{false}}$ (1)
 > $\mathrm{type}\left(\mathrm{string},\mathrm{identical}\left(\mathrm{string}\right)\right)$
 ${\mathrm{true}}$ (2)
 > $\mathrm{type}\left({x}^{-2},{\mathrm{name}}^{\mathrm{integer}}\right)$
 ${\mathrm{true}}$ (3)
 > $\mathrm{type}\left({x}^{-2},{\mathrm{name}}^{\mathrm{posint}}\right)$
 ${\mathrm{false}}$ (4)
 > $\mathrm{type}\left({x}^{-2},{\mathrm{algebraic}}^{\mathrm{integer}}\right)$
 ${\mathrm{true}}$ (5)
 > $\mathrm{type}\left(x+{y}^{\frac{1}{2}}+1,\mathrm{&+}\left(\mathrm{name},\mathrm{radical},\mathrm{integer}\right)\right)$
 ${\mathrm{true}}$ (6)
 > $\mathrm{type}\left(abc,\mathrm{&*}\left(\mathrm{algebraic},\mathrm{algebraic},\mathrm{algebraic}\right)\right)$
 ${\mathrm{true}}$ (7)
 > $\mathrm{type}\left({ⅇ}^{x},{ⅇ}^{\mathrm{name}}\right)$
 ${\mathrm{true}}$ (8)
 > $T≔\mathrm{TEXT}\left("line 1","line 2"\right):$
 > $\mathrm{type}\left(T,\mathrm{TEXT}\left(\mathrm{string}\right)\right)$
 ${\mathrm{false}}$ (9)
 > $\mathrm{type}\left(T,\mathrm{TEXT}\left(\mathrm{string},\mathrm{string}\right)\right)$
 ${\mathrm{true}}$ (10)
 > $\mathrm{type}\left(T,\mathrm{specfunc}\left(\mathrm{string},\mathrm{TEXT}\right)\right)$
 ${\mathrm{true}}$ (11)
 > $\mathrm{type}\left(T,\mathrm{anyfunc}\left(\mathrm{string}\right)\right)$
 ${\mathrm{false}}$ (12)
 > $\mathrm{type}\left(T,\mathrm{anyfunc}\left(\mathrm{string},\mathrm{string}\right)\right)$
 ${\mathrm{true}}$ (13)
 > $\mathrm{type}\left(T,\mathrm{typefunc}\left(\mathrm{string},\mathrm{symbol}\right)\right)$
 ${\mathrm{true}}$ (14)
 > $\mathrm{type}\left(T,\mathrm{function}\left(\mathrm{string}\right)\right)$
 ${\mathrm{true}}$ (15)
 > $\mathrm{type}\left(F\left(a,b\right),\mathrm{specop}\left(\mathrm{anything},F\right)\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{type}\left(a+b,\mathrm{specfunc}\left(\mathrm{anything},\mathrm{+}\right)\right)$
 ${\mathrm{false}}$ (17)
 > $\mathrm{type}\left(a+b,\mathrm{specop}\left(\mathrm{anything},\mathrm{+}\right)\right)$
 ${\mathrm{true}}$ (18)
 > $\mathrm{type}\left(a+b,\mathrm{specop}\left(\mathrm{anything},\left\{\mathrm{+},\mathrm{*}\right\}\right)\right)$
 ${\mathrm{true}}$ (19)
 > $\mathrm{type}\left(\left[x,1\right],\left[\mathrm{name},\mathrm{integer}\right]\right)$
 ${\mathrm{true}}$ (20)
 > $\mathrm{type}\left(\left[x,1\right],\mathrm{list}\left(\mathrm{integer}\right)\right)$
 ${\mathrm{false}}$ (21)
 > $\mathrm{type}\left(\left[x,1\right],\mathrm{list}\left(\mathrm{name}\right)\right)$
 ${\mathrm{false}}$ (22)
 > $\mathrm{type}\left(\left[x,1\right],\mathrm{list}\left(\left\{\mathrm{name},\mathrm{integer}\right\}\right)\right)$
 ${\mathrm{true}}$ (23)
 > $\mathrm{type}\left(T,\mathrm{name}\left(\mathrm{TEXT}\left(\mathrm{string},\mathrm{string}\right)\right)\right)$
 ${\mathrm{false}}$ (24)
 > $\mathrm{type}\left('T',\mathrm{name}\left(\mathrm{TEXT}\left(\mathrm{string},\mathrm{string}\right)\right)\right)$
 ${\mathrm{true}}$ (25)
 > $\mathrm{type}\left({a}_{b},'\mathrm{specindex}\left(\mathrm{anything},a\right)'\right)$
 ${\mathrm{true}}$ (26)
 > $\mathrm{type}\left({a}_{b},'\mathrm{specindex}\left(\mathrm{integer},a\right)'\right)$
 ${\mathrm{false}}$ (27)
 > $\mathrm{type}\left({a}_{2},'\mathrm{specindex}\left(\mathrm{integer},a\right)'\right)$
 ${\mathrm{true}}$ (28)
 > $\mathrm{type}\left({a}_{2,"a string"},'\mathrm{anyindex}\left(\mathrm{integer},\mathrm{string}\right)'\right)$
 ${\mathrm{true}}$ (29)
 > $\mathrm{type}\left({a}_{2,"a string"},'\mathrm{anyindex}\left(\mathrm{string},\mathrm{integer}\right)'\right)$
 ${\mathrm{false}}$ (30)
 > $\mathrm{type}\left({a}_{2},'\mathrm{typeindex}\left(\mathrm{integer},\mathrm{symbol}\right)'\right)$
 ${\mathrm{true}}$ (31)

Test for angles that have a rational cosine.

 > $\mathrm{type}\left(\frac{\mathrm{Pi}}{3},'\mathrm{rational}&under\mathrm{cos}'\right)$
 ${\mathrm{true}}$ (32)
 > $\mathrm{type}\left(\frac{\mathrm{Pi}}{4},'\mathrm{rational}&under\mathrm{cos}'\right)$
 ${\mathrm{false}}$ (33)

Test for an arbitrary data structure containing positive integers.

 > $\mathrm{type}\left(⟨2,3,4⟩,'\left(\mathrm{list}\left(\mathrm{posint}\right)\right)&under\left(\mathrm{convert},\mathrm{list}\right)'\right)$
 ${\mathrm{true}}$ (34)
 > $\mathrm{type}\left(⟨⟨1,2⟩|⟨3,\frac{5}{2}⟩⟩,'\left(\mathrm{list}\left(\mathrm{posint}\right)\right)&under\left(\mathrm{convert},\mathrm{list}\right)'\right)$
 ${\mathrm{false}}$ (35)