Retrograde analysis

In chess problems, retrograde analysis is a technique employed  to determine which moves were played leading up to a given position.  While this technique is rarely needed for solving ordinary chess problems, there is a whole subgenre of chess problems in which it is an important part; such problems are known as retros.

Retros may ask, for example, for a mate in two, but the main puzzle is in explaining the history of the position. This may be important to determine, for example, if castling is disallowed or an en passant capture is possible. Other problems may ask specific questions relating to the history of the position, such as, "Is the bishop on c1 promoted?".  This is essentially a matter of logical reasoning, with high appeal for puzzle enthusiasts.

Sometimes it is necessary to determine if a particular position is legal, with "legal" meaning that it could be reached by a series of legal moves, no matter how illogical. Another important branch of retrograde analysis problems is proof game problems.

Example

An example of a retrograde analysis problem is shown on the left. The solver must deduce White's last move.  It is not immediately apparent how the white king could have moved, since every adjacent square puts White in a seemingly impossible double check; on further examination it becomes apparent that if the white king moved from f5, then Black could have delivered the double check by playing f4xg3, capturing a white pawn on g4 en passant. Therefore, on the previous move, white must have played pawn g2-g4. But what did Black move before that? The white king on f5 was under check by the bishop on h3 and there was a white pawn on g2.  The only possibility is that Black moved a knight from g4 to e5 with discovered check. Therefore, White's last move was king on f5 takes knight on e5. (The entire sequence of moves is 1...Ng4–e5+ (possibly capturing something on e5) 2.g2–g4 f4xg3+ e.p. 3.Kf5xe5.)

In this example, the fact that Black can deliver checkmate in several different ways is irrelevant; likewise, the fact that White could legally have captured the black queen by gxf3 on an earlier move is irrelevant. The solver is required only to deduce a legal sequence of moves which lead to the position, regardless of any considerations of chess strategy.

Castling and en passant capture conventions
In most chess problems, including retrograde analysis problems, castling is assumed to be legal unless it can be proved otherwise. An en passant capture, on the other hand, is permitted only if it can be proved that the last move was a double step of the pawn to be captured. These two conventions lead to features unique to retrograde analysis problems.

Partial retrograde analysis (PRA)

Some problems use a method called "partial retrograde analysis" (PRA). In these, the history of a position cannot be determined with certainty, but each of the alternative histories demands a different solution. In Article 16 of the Codex for Chess Composition, the PRA convention is formally defined as follows:"Where the rights to castle and/or to capture en-passant are mutually dependent, the solution consists of several mutually exclusive parts. All possible combinations of move rights, taking into account the castling convention and the en-passant convention, form these mutually exclusive parts." The problem to the left by W. Langstaff (from Chess Amateur 1922) is a relatively simple example; it is a mate in two. It is impossible to determine what move Black played last, but it is clear that he must have either moved the king or rook, or else played g7–g5 (g6–g5 is impossible, since the pawn would have been giving check). Therefore, either Black cannot castle, or White can capture on g6 en passant. It is impossible to determine exactly what Black's last move actually was, so the solution has two lines:

1.Ke6 and 2.Rd8# (if Black moved the king or rook)
1.hxg6 e.p. (threat: 2.Rd8#) 1...O-O 2.h7# (if Black played g7–g5)

The retro strategy convention (RS)

Sometimes it is possible to prove that only one of two castling moves is legal, but it is impossible to determine which one. In this case, whichever castling move is executed first is deemed to be legal. The Codex defines the retro strategy (RS) convention as follows:"If in the case of mutual dependency of castling rights a solution is not possible according to the PRA convention, then the Retro-Strategy (RS) convention should be applied: whichever castling is executed first is deemed to be permissible."

In the problem on the left, if the rook on f3 is a promoted piece, then it is possible to prove that Black cannot castle. White on the other hand can castle, since it cannot be proved that it is illegal. If the rook on f3 is not a promoted piece, then one of White's two rooks originally came from a1, in which case the white king has moved and White cannot castle; Black on the other hand can castle since it cannot be proved that it is illegal.

Put another way, either White can castle, or Black can castle, but not both. If Black can castle, then the problem has no solution, so White must castle in order to prove that Black cannot castle. The solution is therefore 1.O-O ("preventing" Black from castling by proving that the rook on f3 is promoted) followed by 2.Rf8#. Note that if White were to play 1.Rhf1, Black would be permitted to castle, and there would be no mate.

This problem is a witty case. Black is helpless against the threats on the d-file (2.dxc3 and 3.Rd8#), unless 1...O-O! is legal. Indeed, if 1...O-O is legal, the problem is insoluble, so White must prove that it is illegal.

If White has just castled, then the white king and queen's rook have never moved, so the king's rook can never have gotten out. So the rook on d3 is promoted. If it had promoted on d8, e8, or f8, then the black king must have moved; h8, and the black rook must have moved; a8, b8, or c8, and it must have come out via d8 and the black king must have moved. Thus g8 is the only possible square. But only the b- and e-pawns could have promoted there, and either would require at least seven captures to account for the positions of the White pawns, when only six Black units are missing. So, if White just castled, Black cannot castle.

Therefore, White retracts 1.O-O-O! By castling first, White proves that Black cannot castle. Now White must remake the battery on the d-file to give mate, which seems possible via either 1.O-O-O or 1.Rd1. But the latter fails to the enemy g-pawn: 1.Rd1 g3! and the threat of 2...gxf2+! costs White a move. Hence, White retracts 1.O-O-O and plays 1.O-O-O!

The a posteriori (AP) convention

This is perhaps the most controversial of the retrograde analysis conventions; if it is employed, the problem is usually marked as "AP".

Sometimes it is possible to prove that if castling is possible, then the previous move must have been a double step of a pawn, making an en passant capture legal. In this case, the en passant capture is made, then its legality is proved a posteriori; this is accomplished by castling. In some such problems, Black's defence consists of trying to prevent White from castling, rendering the initial en passant capture illegal. Nenad Petrović composed several problems in this vein; the example given on the left was discussed extensively in Tim Krabbé's book Chess Curiosities.

Black has made 6 captures; to account for his pawn formation, all 6 captures must have been made with pawns; the capturing pawns must have started on b7, c7, d7 and e7. White has made 4 captures; again all of these captures must have been made with pawns. 3 of these captures must have been made with the pawn on e6, which started on b2. Which of the pawns on f5 and f7 started on g2? Only one of these pawns made a capture; Black's original f-pawn has not made a capture and is still on the f-file, so the pawn on f7 cannot be the original f-pawn; it must have started on g2, and the pawn on f5 must have started on f2. The capture must have been made on f7, after Black played f7–f6 but before Black moved the g-pawn. The sequence was as follows: White's pawns advanced to f5 and g6; Black made a capture exf4; at some point Black played f7–f6; White made a capture gxf7; Black played g7–g5 (or g7–g6 and g6–g5).

In order to solve this problem, it must be considered what White's last move was. If the king or rook moved, then White cannot castle. It has been established that the f5 pawn started on f2, so the only way White could have moved a pawn is if the last move was gxf7, to which Black has immediately replied ...g7–g5. If this is in fact the case, then White can play 1.fxg6 (an en passant capture). It has thus been proved that if White can castle, then 1.fxg6 ep is legal.

The solution as originally given was 1.fxg6 ep (intending to prove its legality a posteriori by castling) 1...Bc5 (preventing castling and threatening ...Bf2+, which would force a king move and delegitimize the en passant capture) 2.e3 fxe3 3.O-O (sacrificing a rook in order to legitimize the en passant capture; if 3.d4 Bb4+ forces a king move and prevents castling) ...e2+ 4.Kg2 exf1=Q+ 5.Kxf1 and White has a won position.

This composition was highly controversial when first published, due in part to the "non-chess" motivations behind the moves 1...Bc5, 2.e3 and 3.O-O, and provoked heated debate in chess problemist circles. Amid the controversy, it was overlooked that the win is not clear in the final position, and in fact Black could have won with 3...exd2+! (instead of 3...e2+) 4.Kg2 e3.

See also 
 Backward induction
 Backward chaining

References

Further reading
Raymond M. Smullyan wrote two well-received retrograde analysis riddle books:
 The Chess Mysteries of Sherlock Holmes, 
 The Chess Mysteries of the Arabian Knights,

External links
The Retrograde Analysis Corner at Janko.at

Chess problems