Contents Previous Next Index
8 Maple Expressions
This chapter provides basic information on using Maple expressions, including an overview of the basic data structures. Many of the commands described in this chapter are useful for programming. For information on additional Maple programming concepts, such as looping, conditional execution, and procedures, see Basic Programming.
8.1 In This Chapter
Section
Topics
Creating and Using Data Structures - How to define and use basic data structures
Expression Sequences
Sets
Lists
Tables
Arrays
Matrices and Vectors
Functional Operators
Strings
Working with Maple Expressions- Tools for manipulating and controlling the evaluation of expressions
Low-Level Operations
Manipulating Expressions
Evaluating Expressions
8.2 Creating and Using Data Structures
Constants, data structures, mathematical expressions, and other objects are Maple expressions. For more information on expressions, refer to the Maple Help System.
This section describes the key data structures:
Expression sequences
Functional operators
The fundamental Maple data structure is the expression sequence. It is a group of expressions separated by commas.
S⁢:=⁢2,⁢y,⁢sinx2,⁢I:
Accessing Elements
To access one of the expressions:
Enter the sequence name followed by the position of the expression enclosed in brackets([ ]).
For example:
S2
5
Using negative integers, you can select an expression from the end of a sequence.
S−2
sin⁡x2
You can select multiple expressions by specifying a range using the range operator (..).
S2..−2
5,sin⁡x2
Note: This syntax is valid for most data structures.
A set is an expression sequence enclosed in curly braces ({ }).
4, 12 i, sin23:
A Maple set has the basic properties of a mathematical set.
Each element is unique. Repeated elements are stored only once.
The order of elements is not stored.
c, a, a, a, b, c, a
a,b,c
Using Sets
To perform mathematical set operations, use the set data structure.
2,⁢6,⁢5,⁢1⁢⋃⁢2,⁢8,⁢6,⁢7
1,2,5,6,7,8
Note: The union operator is available in 1-D Math input as union.
For more information on sets, refer to the set help page.
A list is an expression sequence enclosed in brackets ([ ]).
L⁢:=⁢2,⁢3,⁢3,⁢1,⁢0
L≔2,3,3,1,0
Note: Lists preserve both the order and repetition of elements.
Accessing Entries
To refer to an element in a list:
Use square brackets.
L−2..−1
1,0
For more information, see Accessing Elements.
Using Lists
Some commands accept a list (or set) of expressions.
For example, you can solve a list (or set) of equations using the context panel or the solve command.
solvex⁢−⁢y2⁢=⁢−2,⁢x⁢+⁢y⁢=⁢0
For more information, see Solving Equations and Inequations.
For more information on sets and lists, refer to the set help page.
Conceptually, the Array data structure is a generalized list. Each element has an index that you can use to access it.
The two important differences are:
The indices can be any integers.
The dimension can be greater than one.
Creating and Using Arrays
To define an Array, use the Array constructor.
Standard Array constructor arguments are:
Expression sequences of ranges - Specify the indices for each dimension
Nested lists - Specify the contents
a⁢≔ Array1..3,⁢1..3, 1,⁢2,⁢3,⁢4,⁢5,⁢6,⁢7,⁢8,⁢9
123456789
b≔Array1..2,2..5,1.2,4.9,6.3,7.1,9.2,5.5,2.4,1.7
To access entries in an Array, use either square bracket or round bracket notation.
Square bracket notation respects the actual index of an Array, even when the index does not start at 1.
a1,⁢1
1
a2,⁢3
6
b2,3
5.5
b1,1
Error, Array index out of range
Round bracket indexing normalizes the dimensions to begin at 1. Since this method is relative, you can access the end of the array by entering −1.
a−1,2
8
1.2
Arrays can have more than one or two dimensions. For example, the following is a simple three-dimensional Array.
A ≔ Array1..2,1..2,1..2,fill=3
The Array constructor supports other syntaxes. It also supports many options. For more information on the Array constructor and the Array data structure, refer to the Array help page. For more information on indexing methods, refer to the rtable_indexing help page.
Large Arrays
Larger Arrays than can be practically displayed in the document display with a summary format. For example, the multidimensional Array in is displayed in summary format. The following 100-entry Array is as well. In both cases, double-clicking on the placeholder output opens a browser for the entire data structure.
Array0..100
To view large Arrays:
Double-click the placeholder output.
The Matrix Browser displays the Array.
In the case of a multidimensional array, you can change what slice you are viewing in the Options tab.
For more information, see Viewing Large Matrices and Vectors.
Tables are conceptually an extension of the Array data structure, but the table data structure is implemented using hash tables. Tables can be indexed by any values, not only integers.
Defining Tables and Accessing Entries
Greek ≔ tablea⁢=⁢α,⁢b⁢=⁢β,⁢c⁢=⁢γ:
Greekb
β
You can also assign anything, for example, a list, to each element.
Translation ≔ tableone = un,⁢uno,⁢two⁢=⁢deux,⁢dos,⁢three⁢=⁢trois,⁢tres:
Translationtwo
deux,dos
For more information on tables, refer to the table help page.
Matrices and Vectors are specialized data structures used in linear algebra and vector calculus computations.
M⁢:=⁢[12338312]:⁢v⁢:=⁢<2,⁢14>:
For information on defining Matrices and Vectors, see Creating Matrices and Vectors.
M.v
486334
v%T.M
1186234
M−1
−486511865832595−4865
For more information on these data structures, including how to access entries and perform linear algebra computations, see Linear Algebra.
A functional operator is a mapping f:⁢x⁢→⁢yx. The value of f⁡x is the result of evaluating yx.
Using functional operators, you can define mathematical functions.
Defining a Function
To define a function of one or two variables:
In the Expression palette, click one of the function definition items. See Figure 8.1. Maple inserts the function definition.