Overview - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


type

type-checking function

 

Calling Sequence

Parameters

Description

Details

Defined Types

Examples

Calling Sequence

type(e, t)

Parameters

e

-

expression

t

-

valid type expression

Description

• 

In many contexts, it is not necessary to know the exact value of an expression; it suffices to know that an expression belongs to some broad class, or group, of expressions that share some common properties. These classes or groups are known as types. If T represents a type, then an expression is of type T if it belongs to the class that T represents. For example, an expression is said to be of type posint if it belongs to the class of expressions denoted by the type name posint, which is the set of positive integers.

• 

Many Maple procedures use types to direct the flow of control in algorithms or to decide whether an expression is a valid input. The behavior of the non-commutative multiplication operator `.` depends on the type of its arguments.

• 

Many of these types (classes) have names, such as integer, numeric, list, and radalgnum. Other types are described by forming more complicated type expressions, built up via a grammar (a set of rules for their valid combination) from more primitive type expressions. For more information, see type/structure. The class of expressions that represent valid types is itself described by a type called type. (That is, type(T, type) returns true only when T is a valid type expression. In particular, type(type, type) returns true.)

• 

Types can represent expressions that share a common underlying data structure, such as the types list and table, or can represent mathematical properties, such as type prime.

• 

The type(e, t) calling sequence allows you to test whether a Maple expression is of a given type. The call type(e, t) returns the value true if the expression e is of type t, and returns the value false otherwise.

  

Note: The type function does not check assumptions, it only considers the object itself. If you are using the assume facility, it is recommended that you use the is function.

• 

Two arguments must be passed to type. The first argument can be any Maple expression. The second argument must be a valid type expression. A type expression may be as simple as a name that is known to type, but it may also be an arbitrarily complicated structured type (see type/structure). It is assumed that the first argument is NULL in a flattened expression when only one argument is received by a call to type.

• 

An exception is raised only in the case that the second argument t is not a valid type.

• 

Expressions of the form e::t are also used to perform type tests in certain contexts. When evaluated in a Boolean context (such as the test expression in an if statement), the expression e::t evaluates to true if e is of type t, and evaluates to false otherwise. It is used, primarily, for automatically checking the types of arguments passed to procedures. For more information, see typematch.

Details

• 

Types (or type expressions) can be categorized according to the way in which they are defined in Maple.

  

The simplest types are the surface types. These are generally defined in the Maple kernel, and represent superficial or top-level properties of expressions. For example, type list is a surface type. Testing against a surface type is very fast; surface type tests can be completed in constant time, regardless of the size of the expression being tested. For more information, see type/surface.

  

Arbitrarily complicated structured types can be formed by combining simpler, more primitive types. They allow you to classify expressions based on their deep structure. For example, the type expression listposint represents the class of lists whose members are positive integers. Testing against this type requires not only that the top-level data type (list) of the expression be tested, but also that each list member be examined to determine whether it has the correct type (posint). Testing an expression against a structured type may require a full, recursive traversal of the expression, so the time required to perform a structured type test often increases with the size of the expression. For more information on structured type expressions, see type/structure.

  

Defined types are named types that may perform arbitrary computation. A type named T is defined by assigning to the global name `type/T` a structured type expression or a procedure. There is no rule of thumb for the performance characteristics of defined types, since they may be very simple or arbitrarily complex. For more information on defining types, see type/definition.

Defined Types

• 

The following type names, which include surface and structured types, are defined in Maple:

!

*

+

.

::

<

<=

<>

=

@

@@

^

_Inert

abstract_rootof

ac_var

algebraic

AlgebraicObject

algext

algfun

algnum

algnumext

And

and

anticommutative

anyfunc

anyindex

anything

appliable

applied

arctrig

arctrigh

arithop

array

Array

assignable

atomic

attributed

boolean

boolean_function

BooleanOpt

builtin

ByteArray

cache

callable

character

Clock

ClosedIdeal

CommAlgebra

commutative

complex

complexcons

composition

const

constant

copyrighted

cubefree

cubic

cx_infinity

cx_zero

DataFrame

DataSeries

Date

DeepLearning:-Tensor

dependent

dictionary

dimension

disjcyc

double

embedded_axis

embedded_imaginary

embedded_real

equation

equationlist

even

evenfunc

evenodd

expanded

extended_numeric

extended_rational

facint

factorial

filedesc

filename

finite

float

float[8]

float[]

foreign

form

fraction

freeof

function

global

hfarray

hfloat

identical

imaginary

implies

in

indexable

indexed

indexedfun

infinity

integer

intersect

last_name_eval

laurent

linear

list

listlist

literal

local

logical

maple

mathfunc

Matrix

matrix

MatrixPolynomialObject

minus

module

moduledefinition

monomial

MonomialOrder

mutable

MVIndex

name

nc_var

neg_infinity

negative

negint

negzero

nested

Non

noncommutative

nonemptylist

nonemptyset

nonemptystring

nonnegative

nonnegint

nonposint

nonpositive

nonreal

Not

not

nothing

numeric

object

odd

oddfunc

operator

Or

or

OreAlgebra

package

partition

patfunc

patindex

patlist

permlist

piecewise

Point

point

polynom

PolynomialIdeal

pos_infinity

posint

positive

posneg

poszero

prime

primepower

procedure

property

protected

python

quadratic

quartic

Queue

radalgfun

radalgnum

radext

radfun

radfunext

radical

radnum

radnumext

Range

range

rational

ratpoly

ratseq

real_infinity

realcons

record

relation

RootOf

rtable

satisfies

scalar

SDMPolynom

sequential

SERIES

series

set

sfloat

ShortMonomialOrder

ShortTermOrder

SkewAlgebra

SkewParamAlgebra

SkewPolynomial

specfunc

specified_rootof

specindex

sqrt

squarefree

Stack

stack(deprecated)

std

stdlib

string

structure

subset

suffixed

surface

symbol

SymbolicInfinity

symmfunc

syntactically_valid_compound_unit

syntactically_valid_unit_name

table

tabular

taylor

Temperature

TermOrder(deprecated)

TEXT

Time

trig

trigh

truefalse

truefalseFAIL

type

typefunc

typeindex

undefined

uneval

union

Vector

vector

VectorSpace

verification

verify

with_unit

xor

zppoly

||

 

Notes:

  

If a type name is an operator or keyword, it must be enclosed in left single quotes to prevent a syntax error.  See the examples below.

  

Some types become active only after a specific package is loaded. For example, the type/const is active after the difforms package is loaded.

• 

For extending the list above by embedding arbitrary predicates in the Maple type system, see type/satisfies. For more information on specific types, see type/datatype, where datatype is one of the names in the list above.

• 

Arguments passed to the type command are evaluated normally as for other Maple commands. While it is rarely necessary to do so in interactive use, Maple programs that seek to be robust should enclose names that appear in type expressions with unevaluation quotes (') to prevent evaluation. For example, if the name T is assigned the value 2 and is also used as a type name, then type(e, 'T') will work correctly, while type(e, T) will likely fail. (In this case, it would fail silently, because 2 is a valid type expression.) See the examples below.

• 

In Maple, type expressions are first class expressions. Types can be passed as arguments to, and returned from, procedures and can be stored in data structures. You can manipulate complicated type expressions just as you would any other Maple expression. Type expressions are, in fact, ordinary Maple expressions. It is only in certain contexts that these expressions are recognized as types. (Not all expressions are valid types, however.)

  

Note: There is no exprseq type in Maple. However, the whattype function returns exprseq for objects that are expression sequences. (There is no Maple object o for which type( o, exprseq ) returns true. In fact, it is not possible to construct a call to type with an expression sequence as its first argument, because expression sequences are flattened.)

• 

You can make a data type known to the type function in the following way. If you have defined the procedure `type/mytype`, then a call to type of the form: type(a, mytype(b, c, ...)) evaluates the function call `type/mytype`(a, b, c,...).

• 

A number of Maple commands other than type are designed to work with type expressions. See, for example, hastype, anames, and indets. Other commands, such as select, work well with the type command, though they are designed to work with more general predicates.

Examples

type6.777800&comma;float

true

(1)

type6.777800&comma;rational

false

(2)

whattypesolve3x+5=14&comma;x

integer

(3)

typesinx&comma;trig

true

(4)

typea+b&comma;polynom

true

(5)

type23&comma;axby&comma;rational&comma;polynom

true

(6)

For symbols and reserved names, use name quotes.

typea+b&comma;`+`

true

(7)

typeab&comma;`+`

false

(8)

typeaandb&comma;`and`

true

(9)

typemodule_exporteend module&comma;&apos;`module`&apos;

true

(10)

a,b,5

a,b,5

(11)

whattype

exprseq

(12)

whattypeNULL

exprseq

(13)

typeNULL&comma;exprseq

false

(14)

typeexprseq&comma;NULL

false

(15)

typea&comma;b&comma;c&comma;list

true

(16)

False negative test.

`type/T`list&colon;

T2&colon;

typea&comma;b&comma;c&comma;T

false

(17)

The next two commands are correct.

typea&comma;b&comma;c&comma;T

true

(18)

type2&comma;T

false

(19)

False positive test.

type2&comma;T

true

(20)

See Also

arithop

convert

define

equation

exprseq

ExtendingMaple

factorial

function

hastype

indexed

intersect

is

minus

name

procedure

quotes

satisfies

subtype

table

TEXT

type/definition

type/structure

type/surface

type/type

TypeTools

uneval

union

whattype