Lists
Use the square brackets for lists: [1,2,3]
As a sequence (the second element determines step size, defaults to 1 or -1):
[1...10] = [1,2,3,4,5,6,7,8,9,10]
[3...-3] = [3,2,1,0,-1,-2,-3]
[1,3...11] = [1,3,5,7,9,11]
Evaluation (Broadcasting)
Evaluation of an expression with lists starts with the first element of every list in expression, followed by second elements, third elements etc. (this is called "broadcasting")
[a,b,c]+d=[a+d,b+d,c+d]
[a,b,c]+[d,e,f]=[a+d,b+e,c+f]
Evaluation ends after one of the lists runs out of elements.
Can be assigned to a variable: L=[-5,-3,-2,4,5,5]
List Filter
Accessing the elements of a list:
| Expression | Returns | Definition |
|---|---|---|
| L[1] | -5 | the first element of L |
| L[1,3,5] | [-5,-2,5] | the 1st, 3rd and 5th elements of L |
| L[...4] | [-5,-3,-2,4] | first 4 elements of L |
| L[3...] | [-2,4,5,5] | L without the first 2 elements |
| L[2...5] | [-3,-2,4,5] | 2nd, 3rd, 4th and 5th elements of L |
| L[L>0] | [4,5,5] | positive elements of L |
| L[L=5] | [5,5] | Extracts all 5's from L |
| L[M] | [-3,4,5] | a list of elements from L at the indices specified by M (M=[2,4,5]) |
Also, L[L=L] strips out NaNs and L[-∞<L<∞] also strips out infinities.
List Comprehension
You can create new lists based on existing lists using a list comprehension. A list comprehension consists of a "body" expression and one or more "input list" variables. The resulting list is created by evaluating the body expression for each combination of values from the input lists. In the example below, 2k is the body and k=[1,2,3] is the input.
2k for k=[1,2,3] = [4,5,6]
Use square brackets if there is something else.
[2k for k=[1,2,3]]+2 = [6,7,8]
List of Points
A list of points: [(-4,1),(-3,1),(-2,1)]
A grid of points: (x,y) for x=-[2,2.5...4],y=[2,2.5...4]
The polygon() function can also accept a list of points or two lists of numbers:
polygon([-1,0,1],[4,5,4])
A list of polygons: polygon([2,3,4],[2,3,2]+k) for k=[0,1.5,3]
Labeling points with the elements of a list of numbers: First point is named after the first element, second point is named after the second element, etc.
Input:

Rendered as:
