Table of Contents
Genius má vestavěnou základní funkcionalitu pro teorii množin. V současnosti je množina prostě jen vektor (nebo matice). S každým jednotlivým objektem je zacházeno jako s odlišným prvkem.
Podobně jako u vektorů, i v množinách mohou být objekty čísla, řetězce, null
, matice a vektory. Do budoucna je pro množiny plánován samostatný typ namísto vektorů. Upozorňujeme, že desetinná čísla (float) se odlišují od celých čísel (integer), i když vypadají stejně. Takže Genius bude s 0
a 0.0
zacházet jako s různými prvky. null
je považováno za prázdnou množinu.
To build a set out of a vector, use the
MakeSet
function.
Currently, it will just return a new vector where every element is unique.
genius>
MakeSet([1,2,2,3])
= [1, 2, 3]
Similarly there are functions
Union
,
Intersection
,
SetMinus
, which
are rather self explanatory. For example:
genius>
Union([1,2,3], [1,2,4])
= [1, 2, 4, 3]
Note that no order is guaranteed for the return values. If you wish to sort the vector you
should use the
SortVector
function.
For testing membership, there are functions
IsIn
and
IsSubset
,
which return a boolean value. For example:
genius>
IsIn (1, [0,1,2])
= true
The input IsIn(x,X)
is equivalent to
IsSubset([x],X)
. Note that since the empty set is a subset
of every set, IsSubset(null,X)
is always true.