Set Functions

new to Analytica 4.3

Sets

In mathematics, a set is a collection of non-repeated elements. The functions described on this page operate on sets that are represented in Analytica as a reference to list or 1-D array. With this representation, a set is seen as an atomic element by Analytica's array abstraction, thus allowing all these functions to fully array abstract even when the collections comprising the sets are of different lengths or have different indexes.

The following demonstrates this representation:

Var A_list := ['a','b','c','d'];
Var A_set := \A_list;
...

The backslash in front of A_list turns the list into a set in the manner expected by functions here.

Suppose you have a 4-dimensional array, A, indexed by In1, In2, In3 and In4. The expression \[In4]A returns a 3-D array of sets, each set being one of the vectors indexed by In4. As seen, when using the reference operator, \ you can specify in brackets which index becomes the set dimension.

Literal Sets

To create a set from a literal list, you must either specify the Null dimension to the reference operator, or you must surround the brackets by parentheses. You cannot simply place a backslash in front of a literal list, since the backslash operator sees brackets and assumes that the brackets are specifying the indexes to swallow. Here are two examples of how to express a literal set:

\[ Null ][1,2,3]
\([1,2,3])

but

\[1,2,3]    { **** Does not work **** }

Converting a Set to a List

The dereference operator, # is used to convert a set back into a list. This operation does not array-abstract, so you can apply it to a single set, but not to an array of sets.

Function SetContains

Function SetContains( set, element )

Returns true if element is contained in the set.

SetContains( \Sequence(7,1000,7), [770,775,777] ) → [1,0,7]

SetsAreEqual

Function SetsAreEqual( sets, I, ignoreNulls )

Returns true when all the sets passed into the first parameter have exactly the same elements, without regard to duplicates or ordering, and ignoring Null values (unless «ignoreNulls» is explicitly specified to be false).

Var L1 := [1,1,1,2,3];
Var L2 := [3,2,2,1];
Var L3 := [2,3,1,Null];
SetsAreEqual( [\L1,\L2,\L3] ) → 1

In this example, all three sets are treated as the set {1,2,3}. But:

SetsAreEqual( [\L1,\L2,\L3], ignoreNulls:false ) → 0

With the optional parameter, the set \L3 is then understood to include the Null value.

The following tests whether every row of a table contains the same set of items (ignoring ordering), where T is indexed by Row and Col:

SetsAreEqual( \[Col]T, Row )

The first parameter specifies that each Col-vector (i.e., each row) is taken as a set. The index parameter, Row, specifie that the comparison takes place along the Row index of T.

SetIntersection

Function SetUnion( sets, I, resultIndex, keepNulls )

SetUnion

Function SetUnion( sets, I, resultIndex, keepNulls )

SetDifference

Function SetDifference( originalSet, remove, remove2, remove3, ..., resultIndex, keepNull)
Comments


You are not allowed to post comments.