# `∩` operator

The `∩` filter has the syntax:
`  left ∩ right`

where `left` and `right` are each filters. The `left` and `right` arguments must each be set filters or each be positionfilters.

## ASCII equivalent

The symbol may be replaced by the ASCII `&` .

## `∩` operator as set intersection

If the `left` and `right` arguments to the `∩` filter are each set filters, then the `∩` filter is itself a set filter whose value is the intersection of the sets of squares represented by its arguments.

For example,

`  pin ∩ {♖→♚}`

Is the set of squares on which a pinned white rook attacks the black king. The `left` argument to the `∩` filter is pin whose value is the set of squares on which there is a pinned piece. The `right` argumnet to the `∩` filter is `{♖→ ♚}` , whose value is the set of squares on which there is a white rook which attacks the black king. The value of the `∩` filter is the intersection of these two sets.

## positional intersection: `∩` used to compare two positions

If the `left` and `right` arguments to the `∩` filter are each position filters, then the value of the `∩` filter is the positional intersection of the positions represented by these arguments. In this case we call the `∩` filter a `positional intersection`

The positional intersection of two positions is the set of squares on which the two positions have the same type and color of piece.

For example, consider the PGN file representing moves beginning from the start position of the game of chess:

```  1. e4 e5
2. Nf3 Nc6```

Now, after reading this game, let

```  x= position 0
y= position 2```

Thus, `x` is the initial position and `y` is the position after `1. e4 e5`.

Then `x ∩ y` is the set of squares on which `x` and `y` have the same contents. This is the 60 squares represented by:

`  ~[e2,e4,e7,e5]`

That is because on each of these 4 squares, `x` and `y` differ. The contents of `x` on the square `e2` for example is a white pawn; but the contents of `y` on that square is empty, so they differ.

More generally, suppose `X` and `Y` are any variables that hold positions. Then then

```  X ∩ Y
≡
square z in .
X:colortype z == Y:colortype z```

That is because `colortype z` is a number expressing the type and color of the contents of the square `z` in the current position. Thus, `X:colortype z` is a number expressing the type and color of the contents of the square `z` in the position `X` (and likewise for `Y:colortype z`).

The square filter therefore gives the set of squares in which `X` and `Y` have the same contents, that is, `X ∩ Y`

# Examples

The `∩` operator as set intersection is used throughout the CQL examples.

The positional `∩` operator is most often used with the echo filter to compare positions. For example, in missingwhitepiece.cql , the filter

`  mismatches= ~(source∩target)`

is used to get the set of squares at which the positions `source` and `target` differ.

The line

`mismatches > 0`
verifies that there is at least one mismatch.

`  mismatches== △∩source:□`

checks that the only such mismatches are those where the target has a white piece, `△` and the source has an empty square, `□`.