Difference between revisions of "Lists"

From GeoGebra Manual
Jump to: navigation, search
m (Text replace - "<div class="box info"> 48px|left This page is part of the official manual for print and pdf. For structural reasons normal users can't edit this page. If you found any errors on this page please contact )
m
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>{{Manual Page|version=4.2}}</noinclude>
+
<noinclude>{{Manual Page|version=5.0}}</noinclude>{{objects|general}}
{{objects|general}}
+
Using curly braces you can create a ''list'' of several objects (e.g. points, segments, circles).
Using curly braces you can create a list of several objects (e. g. points, segments, circles).
 
  
 
{{Example|1=<br>
 
{{Example|1=<br>
* <code>L = {A, B, C}</code> gives you a list consisting of three prior defined points A, B, and C.
+
* <code>L = {A, B, C}</code> gives you a list consisting of three prior defined points ''A'', ''B'', and ''C''.
* <code>L = {(0, 0), (1, 1), (2, 2)}</code> produces a list that consists of the entered points, as well as these nameless points. }}
+
* <code>L = {(0, 0), (1, 1), (2, 2)}</code> produces a list that consists of the entered points and also creates these nameless points.
{{Note|By default, the elements of this list are not shown in the [[Graphics View]].}}
+
* The short syntax <code>..</code> creates a list of successive integers: e.g. <code>-5..5</code> creates the list {''-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5''}. }}
 +
{{Notes|1=<div>
 +
*By default, the elements of this list are not shown in the [[File:Menu view graphics.svg|link=|16px]] [[Graphics View]].
 +
*Lists can also be used as arguments in list operations (mentioned further in this article) or [[List Commands]].</div>}}
  
To access particular elements of the list you can use [[Element Command]]. Lists can be used as arguments in list operations (mentioned further in this article) or [[List Commands]].
+
==Accessing Elements of Lists==
 +
To access particular elements of a list you can use the [[Element Command]] or the simplified syntax shown in the example below:
 +
{{Example|1=Let <code>list = {1, 2, 3, 4, 5}</code>, then:<div>
 +
*<code>list(1)</code> returns the first element of the list: ''1''
 +
*<code>list(2)</code> returns the second element of the list: ''2''
 +
*.../...
 +
*<code>list(-1)</code> returns the last element of the list: ''5''
 +
*<code>list(-5)</code> returns the first element of the list: ''1''
 +
*<code>list(0)</code> returns ''undefined'', as well as <code>list(k)</code> for k > 5 or k < -5</div>}}
  
==Compare Lists of Objects==
+
==Comparing Lists of Objects==
  
 
You can compare two lists of objects by using the following syntaxes and commands:
 
You can compare two lists of objects by using the following syntaxes and commands:
* <code>List1 == List2</code>: Checks if the two lists are equal as ordered [[w:Tuple|tuples]], and gives you true or false as a result.
+
* <code>List1 == List2</code>: checks if the two lists are equal as ordered [[w:Tuple|tuples]], and yields ''true'' or ''false''.
* <code>List1 != List2</code>: Checks if the two lists are not equal as ordered tuples, and gives you true or false as a result.
+
* <code>List1 != List2</code>: checks if the two lists are not equal as ordered tuples, and yields ''true'' or ''false''.
* <code>Unique[list1] == Unique[list2]</code> or <code>{list1} \ {list2} == {}</code> : Checks if the two lists are equal as sets (i.e. all repeated elements are ignored, as well as the elements order)
+
* <code>Unique[list1] == Unique[list2]</code> or <code>list1 \ list2 == {}</code> : checks if the two lists are equal as sets (i.e. all repeated elements are ignored, as well as the elements order) and yields ''true'' or ''false''.
* <code>Sort[list1] == Sort[list2]</code>: Checks  if the two lists are equal as [[w:Multiset|multisets]] (i.e. the elements order is ignored)
+
* <code>Sort[list1] == Sort[list2]</code>: checks if the two lists are equal as [[w:Multiset|multisets]] (i.e. the elements order is ignored) and yields ''true'' or ''false''.
  
 
See also [[Unique Command|Unique]] and [[Sort Command|Sort]] commands.
 
See also [[Unique Command|Unique]] and [[Sort Command|Sort]] commands.
  
==List Operations==
+
==List Operators==
  
<Object> ∈ <List> is an element of
+
<code><Object> ∈ <List></code>: returns ''true'' if ''Object'' is an element of ''List''
  
<List> ⊆ <List> is subset of
+
<code><List1> ⊆ <List2></code>: returns ''true'' if ''List1'' is subset of ''List2''
  
<List> ⊂ <List> is subset of (strict)
+
<code><List1> ⊂ <List2></code>: returns ''true'' if ''List1'' is a strict subset of ''List2''
  
<List> \ <List> set difference
+
<code><List1> \ <List2></code>: creates the set difference of ''List1'' and ''List2''
  
 
==Apply Predefined Operations and Functions to Lists==
 
==Apply Predefined Operations and Functions to Lists==
 
 
If you apply [[Predefined Functions and Operators]] to lists, you will always get a new list as a result.
 
If you apply [[Predefined Functions and Operators]] to lists, you will always get a new list as a result.
  
 
===Addition and subtraction===
 
===Addition and subtraction===
* List1 + List2: Adds corresponding elements of two lists. {{Note|The two lists need to be of the same length.}}
+
* <code>List1 + List2</code>: adds the corresponding elements of two lists. {{Note|The two lists need to be of the same length.}}
* List + Number: Adds the number to every element of the list.
+
* <code>List + Number</code>: adds ''Number'' to every element of ''List''.
* List1 – List2: Subtracts the elements of the second list from corresponding elements of the first list. {{Note|The lists need to be of the same length.}}
+
* <code>List1 – List2</code>: subtracts the elements of ''List2'' from corresponding elements of ''List1''. {{Note|The lists need to be of the same length.}}
* List – Number: Subtracts the number from every element of the list.
+
* <code>List – Number</code>: subtracts ''Number'' from every element of ''List''.
  
 
===Multiplication and division===
 
===Multiplication and division===
* List1 * List2: Multiplies corresponding elements of two lists. {{Note|The lists need to be of the same length. If the two lists are compatible matrices, matrix multiplication is used.}}
+
* <code>List1 * List2</code>: multiplies the corresponding elements of two lists. {{Note|The lists need to be of the same length. If the two lists are compatible matrices, matrix multiplication is used.}}
* List * Number: Multiplies every list element with the number.
+
* <code>List * Number</code>: multiplies every ''List'' element by the given ''Number''.
* List1 / List2: Divides elements of the first list by corresponding elements of the second list. {{Note|The two lists need to be of the same length.}}
+
* <code>List1 / List2</code>: divides the elements of ''List1'' by the corresponding elements of ''List2''. {{Note|The two lists need to be of the same length.}}
* List / Number: Divides every list element by the number.
+
* <code>List / Number</code>: divides every ''List'' element by ''Number''.
* Number / List: Divides the number by every element of the list.
+
* <code>Number / List</code>: divides ''Number'' by every element of ''List''.
 
{{Note|See also [[Points and Vectors#Vector Product|Vector product]].}}
 
{{Note|See also [[Points and Vectors#Vector Product|Vector product]].}}
 
===Other examples===
 
===Other examples===
* List^2: Squares every element of the list.
+
* <code>List ^ 2</code>: squares every element of ''List''.
* 2^List: Creates list of powers of two with exponents from the list.
+
* <code>2 ^ List</code>: creates a list of powers of two, using the ''List'' elements as exponents.
* List1^List2: Creates list of ''a^b'', where ''a'' and ''b'' are corresponding elements of List1 and List2.
+
* <code>List1 ^ List2</code>: creates a list containing ''a^b'', where ''a'' and ''b'' are corresponding elements of ''List1'' and ''List2''.
* sin(List): Applies the sine function to every element of the list. User defined [[Functions|functions]] can be applied the same way as well.
+
* <code>sin(List)</code>: applies the sine function to every element of ''List''. <br>
 +
User defined [[Functions|functions]] can be applied the same way as well.

Latest revision as of 15:17, 30 October 2015


Using curly braces you can create a list of several objects (e.g. points, segments, circles).

Example:
  • L = {A, B, C} gives you a list consisting of three prior defined points A, B, and C.
  • L = {(0, 0), (1, 1), (2, 2)} produces a list that consists of the entered points and also creates these nameless points.
  • The short syntax .. creates a list of successive integers: e.g. -5..5 creates the list {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}.
Notes:
  • By default, the elements of this list are not shown in the Menu view graphics.svg Graphics View.
  • Lists can also be used as arguments in list operations (mentioned further in this article) or List Commands.

Accessing Elements of Lists

To access particular elements of a list you can use the Element Command or the simplified syntax shown in the example below:

Example: Let list = {1, 2, 3, 4, 5}, then:
  • list(1) returns the first element of the list: 1
  • list(2) returns the second element of the list: 2
  • .../...
  • list(-1) returns the last element of the list: 5
  • list(-5) returns the first element of the list: 1
  • list(0) returns undefined, as well as list(k) for k > 5 or k < -5


Comparing Lists of Objects

You can compare two lists of objects by using the following syntaxes and commands:

  • List1 == List2: checks if the two lists are equal as ordered tuples, and yields true or false.
  • List1 != List2: checks if the two lists are not equal as ordered tuples, and yields true or false.
  • Unique[list1] == Unique[list2] or list1 \ list2 == {} : checks if the two lists are equal as sets (i.e. all repeated elements are ignored, as well as the elements order) and yields true or false.
  • Sort[list1] == Sort[list2]: checks if the two lists are equal as multisets (i.e. the elements order is ignored) and yields true or false.

See also Unique and Sort commands.

List Operators

<Object> ∈ <List>: returns true if Object is an element of List

<List1> ⊆ <List2>: returns true if List1 is subset of List2

<List1> ⊂ <List2>: returns true if List1 is a strict subset of List2

<List1> \ <List2>: creates the set difference of List1 and List2

Apply Predefined Operations and Functions to Lists

If you apply Predefined Functions and Operators to lists, you will always get a new list as a result.

Addition and subtraction

  • List1 + List2: adds the corresponding elements of two lists.
    Note: The two lists need to be of the same length.
  • List + Number: adds Number to every element of List.
  • List1 – List2: subtracts the elements of List2 from corresponding elements of List1.
    Note: The lists need to be of the same length.
  • List – Number: subtracts Number from every element of List.

Multiplication and division

  • List1 * List2: multiplies the corresponding elements of two lists.
    Note: The lists need to be of the same length. If the two lists are compatible matrices, matrix multiplication is used.
  • List * Number: multiplies every List element by the given Number.
  • List1 / List2: divides the elements of List1 by the corresponding elements of List2.
    Note: The two lists need to be of the same length.
  • List / Number: divides every List element by Number.
  • Number / List: divides Number by every element of List.
Note: See also Vector product.

Other examples

  • List ^ 2: squares every element of List.
  • 2 ^ List: creates a list of powers of two, using the List elements as exponents.
  • List1 ^ List2: creates a list containing a^b, where a and b are corresponding elements of List1 and List2.
  • sin(List): applies the sine function to every element of List.

User defined functions can be applied the same way as well.

© 2024 International GeoGebra Institute