Overview of

There are three kinds of filter: the binary form, the ternary form, and the n-ary form for n>3.

The ASCII form of is ->.

The binary form of the filter denotes an attack by a piece on a square:

      d4 // attacks d4

The ternary form deals with pins and simple interferences:

       // pinned by 
      h8 // is between  and h8

The n-ary form, of which the ternary form is a special case, is less commonly used:

      h8
means that there are two distinct white pawns preventing an attack of on h8.

Each of these forms are discussed in more detail below.

binary

If x and y are set filters, then
    xy
matches the current position if a piece on x attacks a piece on y.

A piece u is said to attack a square v if a king of different color than u would be in check from u if that king was on v.

For example, suppose that the current position is the chess start position. The following filters are all true:

    d1e2
    e2
    e2d3
    not d4
    g1f3

Note that the check filter can be written in terms of :

    check
    
     or 
    
    

Now suppose we remove all the pawns from the start position. Then the following filters are all true:

    d8
    
    g5

Value returned by

The value of
    XY
is the set of squares in Y that attack a square in Y.

This is equivalent to

    xX xY

For example, suppose the current position is the start position in chess. Then

    f3
    
    [g2,e2]
and
    f3
    
    [g2,e2,g1]

, binary case

The filter
    xy
is true exactly when
    yx
is true.

However, the value of

    yx
is the set of squares in y that are attacked by a piece in x.

For example, if the current position is the start position, then

    
    
    [e2,d2]

ternary

Suppose that x, y and z are set filters each representing a single square in the current position. We will identify the set filter with the set of squares it represents as usual.

One can think of

xyz
as being a sort of generalized pin. In fact, this matches a position exactly when
    pin from x through y to z
matches the position.

The ternary filter

xyz

matches a position if each of the following four conditions is true:

  1. There is a sliding piece on x which attacks y
  2. y is between x and z
  3. Any squares between x and y are empty
  4. Any squares between y and z are empty

The above discussion was limited to the case where x, y, and z denoted a single square.

In general there can be multiple squares denoted by each of these set filters. In the case, we say that

xyz
matches a position if there are squares X, Y, Z, in x, y, z respectively such that
XYZ

Examples of ternary

    
matches positions where a black piece is pinned by a white rook.
matches positions where there is a single white piece between a and the .

If the current position is the start position, then following are true:

    d1d2d7
    g5

The value of the ternary

The value of
xyz
is the set of squares X in x such that
Xyz
.

This can be written

    Xx Xyz
.

ternary versus nested binary

You can use parentheses to prevent ternary evaluation of . For example,
    
is true if a white rook is pinned by a black bishop. But
    ()
is true if a black bishop is attacking a white rook which is itself attacking the white king.

n-ary

Chains with more than two symbols are much rarer but are treated similarly (this section can be safely skipped unless necessary). More formally, consider a chain
    x1x2x3...xn
for some integer n4.

First, suppose each xi has only one square. The the chain matches a position in that case that, if empty squares were placed on each square

x2,x3,...,xn-1
then x1 would attack xn. But if any one of those squares were occupied, then x1 would not attack xn.

As before, in the general case where each xi could hold more than one square, we say that

x1x2x3...xn
if there are squares
    X1 in x1,
    X2 in x2,
     ... ,
    Xn in xn
such that
X1X2X3...Xn
For example, suppose the current position is the chess starting position. Then the following filters are all true:
    d2d7d8
    h1h2h4h7h8
    h1g1f1e1
However:
    not d2d7e7
    not h1h3h7h8

The value returned by chains

The value of a filter returned by a chain
x1x2x3...xn
is the set of squares X in x1 such that

X1x2x3...xn

For example, the set of white pieces pinning some black piece is:

    

chains

zyz
matches a position if and only if
xyz
matches the position.

The value returned by

zyz
is the set of squares Z in z such that
Zyx
matches the position.

Likewise,

x1x2x3...xn
matches a position if and only if
      xnxn-1...x1
matches the position.

As before, the value of

          xnxn-1...x1
is the set of X in xn such that
          Xxn-1...x1

Examples

There are many examples of simple denoting attacks in the examples, for example, in turton.cql.

There are also a number of examples of length-3 chains

xyz
.

One use is to detect moves crossing a particular square.

The filter

   ―― fromd4to
matches positions where the next move is a sliding move that crosses the square d4. That is because, from here is the departing square and to is the arriving square of the move matching ―― .

In many studies derived from problem themes, such as Bristol and Turton, a critical square must be crossed by a particular move. This usage occurs in turton.cql and bristol-universal.cql.

There are only two themes in our corpus where length-4 chains arise naturally: in indian.cql and likeinterference.cql. We have yet to see a true length-5 chain arise naturally however.