create a table
(optional) indexing function
(optional) list or set of initial table entries
(optional) table or array
A table is created either explicitly by a call to the table function or implicitly by assigning to an indexed name. Unlike arrays, where indices must be integers, the indices (or keys) of a table can be any value.
The table function creates a table with initial values specified by L. If L is a list or set of equations then the left-hand side is taken to be the table index (key), and the right-hand side the entry (value). Otherwise, L is taken to be a list of entries with indices 1, 2, ... . The use of a set of initial values in the latter case is ambiguous because there is no ordering of set elements, and hence the ordering of the entries in the result may not correspond to the ordering in which the entries are given. If L is not specified, then an empty table is created.
Tables created with a list initializer, for example, table([a=A, b=B, c=C]), are created such that the assignment of the table entries proceeds from left to right. That is, the first element of the list is inserted into the table first, the second is inserted second, and so on.
New entries can be added to a table using the subscript notation. Thus, T := table() is equivalent to:
T := table() and T := 4,
T := 4 if T was unassigned (implicit creation).
Entries can be removed from a table by assigning a table entry to its own name using evaln. Thus, T := evaln(T) removes the entry 4 from T.
The indexing function F can be a procedure or a name specifying how indexing is to be performed; if null then ordinary indexing is implied. The built-in indexing functions are: symmetric, antisymmetric, sparse, diagonal, identity, exception, readonly and case_insensitive. For more information on indexing functions, see indexfcn.
Tables have special evaluation rules (like procedures) so that if the name T has been assigned a table then T evaluates to T. The call op(T) yields the actual table structure; and op(op(T)) yields the components of the table, which are the indexing function (if there is one) and a list of equations for the tables values.
The indices function can be used to obtain a sequence of a table's indices and likewise, the entries function returns a sequence of the table's entries.
When the table constructor is called with a single argument, t, whose value is an existing table, a copy of t is returned. If t is an array, the resulting copy will be a table object. Since tables are mutable objects, and assignment in Maple is by-reference, making a copy of a table to work with is useful when you do not want to modify the original table.
For information about weak tables and the table[weak] calling sequence, see weaktable.
The table command is thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
Create an empty table:
Create a table with two entries 1=22 and 2=42:
Create a table with two entries at specified indices:
S ≔ table⁡2=45,4=61
Fetch a value from a table using square-bracket notation:
When an index doesn't map to a value, the query will return unevaluated:
Use the assigned function to check if an entry exists
The sparse indexing function can be used to set a default for lookups rather than returning unevaluated
T ≔ table⁡sparse,2=22,3=33:
The default for sparse tables is to return 0 when an index is not found. This can be changed to a constant value that you choose:
T ≔ table⁡sparse=not found,2=22,3=33:
T ≔ table⁡sparse=∞,2=22,3=33:
Other indexing functions control the lookup based on indices and/or entries in the table:
T ≔ table⁡symmetric,c,b=x
A table can contain callable procedures:
DiffTab ≔ table⁡sin=cos,cos=−sin:
Download Help Document
What kind of issue would you like to report? (Optional)