Square filter

A square filter consists of the keyword square, then an optional keyword all, then a variable, then the keyword in, then a set filter, then an arbitrary filter:
  square variable in in_filter body
  square all variable in in_filter body

Here, variable is a set variable; in_filter is a set filter; and body is any filter.

For example,

  square x in 
      x

square z in a1-8 az

square all z in A power z<2

In the first example above, variable is x; in_filter is ; and body is x.

The operation of the square filter when the the optional all parameter is absent is as follows:

  1. The set in represented by in_filter in the current position is computed
  2. For each square s in in,
    • the variable x is set to s.
    • (*) body is evaluated in the current position
  3. The square filter represents the set of s in in for which body was true in step (*)

The operation of the square filter when the all parameter is present is similar:

  1. The set in represented by in_filter in the current position is computed
  2. For each square s in in,
    • the variable x is set to s.
    • (*) body is evaluated in the current position
  3. The square filter matches the position if body is never false in step (*): for each s in in, the body is true

Thus, a square filter is a set filter only if the all parameter is absent.

Example of a square filter

Suppose the current position is set to the following position:

Now let's compute what happens when the following square filter is evaluted on that position:

square x in h1-8
   x
   x

To determine the set of squares represented by this square filter in the diagram, the variable x will be successively set to each square in the set represented by the following the word in, namely h1-8.

The square filter will match an assignment of x to a particular square only if a white rook attacks that square and if that square attacks the white King. In the current position, note that:

h3 attacks the white king's square and is attacked by a white rook - match!
h6 attacks the white king's square but is NOT attacked by the white rook - no match
h4 attacks the white king's square but is NOT attacked by the white rook - no match
h7 attacks the white king's square and is attacked by a7 - match!

all other squares on the h-file fail both clauses The result is that filter matches when x is either h3 or h7.

Therefore, the square filter represents the set of squares consisting of h3 and h7. In particular, the square filter will match the current position.