Since sets are commonly used in esProc, the latter provides comprehensive set operations.

## 1. Binary Operation on Sets

The most basic set in esProc is sequence. Let’s look at some basic binary operations between two sequences A and B.

**A|B**

Concatenation: Concatenate the two sequences straightforwardly. The members of B are added behind the members of A. If A or B or both A and B are single-value instead of sequences, then they will be handled as single member sequences.

**A&B**

Union: Join the two sequences and remove the members of B that already exist in A. If one of A and B or both are single- value instead of sequences, then you can take them as single member sequences to process.

**A^B**

Intersection: Intersection set of A and B. Get a sequence composed of members that not only exist in A but also exist in B.

**A\B**

Complement: Members in A but not in B. If B is not a sequence, then treat it as the single member sequence.

**k*A**

A|A|…|A, which is to concatenate the *k* same sequences, that is, copy A k times. Positions of k and A are interchangeable in the expression.

A | B | |

1 | [a,b,1,2,3,4] | [d,b,10,12,4,3] |

2 | =A1|B1 | |

3 | =A1&B1 | |

4 | =A1^B1 | |

5 | =A1\B1 | |

6 | =2*A1 | |

7 | =[1]*8 |

A2, A3, A4 and A5 compute respectively the concatenation, union, intersection and complement of the sequence in A1 and the sequence in B1:

In A6 and A7, sequence A1 is multiplied by an integer. The result is as follows:

These basic operations – concatenation, complement, intersection and union – can also be used to deal with more complex set operations. Such as, to seek the “inverse intersection” of sets *A *and *B*, i.e., the set composed of all that is not the common members of *A* and *B*.

A | B | |

1 | [2,3,5,8,13,21,34] | [3,9,15,21,27] |

2 | =(A1&B1)\(A1^B1) |

The result of A2 is as follows:

The “inverse intersection” of two sets is the complement of their union and intersection. With this kind of transformation, more complex binary operations will be completed.

## 2. Alignment Arithmetic Operations on Sets

We can perform the alignment arithmetic operations on two sequences of the same length according to their members and return a new sequence.

**A++B**

[A(1)+B(1),A(2)+B(2),…]

**A–B**

[A(1)-B(1),A(2)-B(2),…]

**A**B**

[A(1)*B(1),A(2)*B(2),…]

**A//B**

[A(1)/B(1),A(2)/B(2),…]

**A%%B**

[A(1)%B(1),A(2)%B(2),…], the **%** here is the Mod computation.

**A\\B**

[A(1)\B(1),A(2)\B(2),…], the slash here means integer division.

A | B | |

1 | [1,2,3] | [4,1,2] |

2 | =A1++B1 | |

3 | =A1–B1 | |

4 | =A1//B1 | |

5 | =A1%%B1 |

The results of A2, A3, A4 and A5 are as follows:

## 3. A Comparison of Sets

In esProc, the function **cmp( A,B)** can be used to compare the sequence A and B.

**cmp(***A,B*)

Compare the values of members of the two sequences one by one in alignment. When the first pair of unequal members appear, return **1** if the member in *A* is greater than that in *B*; otherwise return **-1**. If A is identical to B, then return 0. Specifically, **cmp( A)** or

**cmp(**will compare A and the sequence with the same length and with its all members being 0, i.e.

*A*,0)**cmp(**.

*A*,[0,0,…,0])A | |

1 | =cmp([“a”,”b”,”c”],[“a”,”b”,”c”]) |

2 | =cmp([1,3,5,7],[1,3,7,5]) |

3 | =cmp([7,6,5,4],[7,6,4,10,11]) |

The results of A1, A2 and A3 are as follows:

The comparison of two sequences can be briefly expressed as *A==B, A>B.*

Note that a sequence in esProc is an ordered set, so order plays an important role in comparing if the two sequences *A* and *B *are equal. **A****.eq( B)** is used to see if the two sequences have common members.

A | |

1 | [Tom,Jerry,Tuffe,Tyke] |

2 | [Jerry,Tuffe,Tom,Tyke] |

3 | =A1==A2 |

4 | =A1.eq(A2) |

Because the member order in A1 and A2 is different, result in A3 is false, showing the two sequences are not equal:

While result in A4 is true, showing the two sequences have the same members: