defines and constructs a set
setA = define_set(e1,e2,...)
character strings or vectors of character strings
set
The function define_set
defines and constructs a set.
e1
, e2
,... are character strings or vectors of character strings.
The set then contains all the character strings e1
,
e2
,... A set is not ordered and does not contain duplicate elements.
For example {a,b,c} and {b,a,c,a} represent the same set. When a set is created, duplicate elements are
suppress, and for convenience, its elements are arranged in alphabetical order.
Note that define_set()
creates an empty set.
It is possible to assign values to the elements of a set. This enables one, for example, to have sets of coins, tickets or playing cards with values. For this, the value is given by placing them in parentheses at the end of the name of an element. For example to create a set of 3 coins called "a", "b" and "c", with values 1 euro, 1 euro and 2 euros, one writes :
set1=define_set("a(1)","b(1)","c(2)").
The function value
returns the vector of values for the elements of a set,
allowing numerical calculations to be done with them (see value).
To change or remove an item from a set, use parentheses as with a vector. We put the rank of the element in parentheses, knowing that the elements were stored automatically in alphabetical order.
To obtain the size of a set use the function
size
.
To compare two sets use the usual comparison operator
==
.