Maple study notes - data structure

immutable data structure

sequence

1. Definition: A set of expressions separated by commas
2. For example: the parameter item of the function is a sequence:

[< l := 2*x + 3 = 1, x;#Generate sequence
[< solve(l);#solve
                               -1

3. Extract sequence elements: use index(sequencename[index])
4. Encoding to generate a sequence: use the seq function

[< seq(2*i + 1, i = 1 .. 5, 2);#Generate sequence 2i+1,i=1,3,5
                            3, 7, 11

list

1. Definition: a sequence enclosed in square brackets: [ ]
2. Features: orderly, keep repeating elements

Related function operation

1. Determine the expression type: whattype(a)
2. Return a sequence of expressions in a list: op(a)
3. Test whether an expression is a member of a list: member( expression, list name) or has( list name, expression)
4. The number of elements in the list: numelems (list name)

a := seq(2*i + 1, i = 1 .. 5);#generate a sequence
                      a := 3, 5, 7, 9, 11
b:=[1,2,3,1]
whattype(a);whattype(b) #Determine the type of an expression
                            exprseq
                              list
member(1,b);hasr(b,4)
                             true
                              false
numelems(b);
                               4

gather

Definition: {sequence}
Features: No repeating elements, disordered.

Related operations

1. Extract the elements in the collection: op( )
2. Conversion of sets and lists: convert( collection name, 'list') or [op( collection name)]
3. Filter out the elements in the collection that meet certain conditions: select(x->conditional expression, collection name)
4. Remove elements that do not meet the conditions: remove(x->conditional expression, set name)
5. Filter + remove both: selectremove(issqr, d)
6. Apply a function to all elements in a list or set: map

a := {1, 2, 3};
b := {1, a};
                         a := {1, 2, 3}
                      b := {1, {1, 2, 3}}
op(a);#Extract elements from a collection
                            1, 2, 3
[op(b)];#Collection --> List
                         [1, {1, 2, 3}]
convert(a, 'list');List ->gather
                           [1, 2, 3]
select(x -> x^2 = 4, a);#Select the element x in the set a, which satisfies x^2=4
                              {2}
remove(x -> x^2 = 4, a);#Elements in the outgoing set a that satisfy x^2=4
                             {1, 3}
selectremove(x -> x^2 = 4, a);
                          {2}, {1, 3}
map(sin, a);#a as the domain of the sin function
                    {sin(1), sin(2), sin(3)}

mutable data structure

arrayArray

1. Create: a:=Array([a,b,c])
2. Get the number of elements in the array: numelems(a)
3. Get the upper and lower bounds of the index: lowerbound(a), upperbound(a);

4. Calculate the cumulative sum: s(k)=sum(xi,i=1,…k)
Here k=10;x(i)=i

matrix/vector

1. Create:
1.Matrix() , Vector()
2. Use index: M := Matrix(x, y, (i, j) -> f)
Where x,y are the number of rows and columns of the matrix, and f is the expression of the element Mij
3. Use <<>>:M := <<<1,2>|<3,4>>>
2. Type conversion:

Orderillustrate
convert( listname, Vector)list --> vector
convert(L[L1,[L2]], Matrix)List -> Matrix (L1, L2 are lists with the same number of elements)

surface

1. Create: A:=table(a1=b1,a2=b2;a3=b3,...)
Where a1,a2,... are the indices of the list; b1,b2,... are the corresponding values
Call: A[a1]
2. Add element: A[index]:= value
3. View the contents of the list: eval()
4. If the variable has no value, Maple will create an empty list
5. View the index sequence: indices( ) (the default output form is a list)
6. View the value: entries( ) (the default output form is a list)
7. Both get indices (array name, pairs); (the default output format is a list)
8. Parameter nolist: unpacking list indices(table, nolist), entries(table, nolist)

t := table([age = 18, name = lily]);
t[age];
t[name];
t[sex] := boy;
eval(t);
              t := table([age = 18, name = lily])
                               18
                              lily
                         t[sex] := boy
           table([age = 18, sex = boy, name = lily])
eval(T);
                               T
T[3] := 5;
                           T[3] := 5
eval(T);
                         table([3 = 5])
indices(t);entries(t);
indices(t, pairs);
indices(t, nolist);entries(t, nolist);
                      [age], [sex], [name]
                      [18], [boy], [lily]
                age = 18, sex = boy, name = lily
                         age, sex, name
                         18, boy, lily

Posted by BMorganVA on Thu, 13 Oct 2022 07:07:43 +1030