Iteration

Home * Programming * Algorithms * Iteration



In computer science, Iteration is the act of repeating instructions inside an algorithm, implemented either by the control structure of a loop or by direct or indirect recursive calls. Despite all kinds of low level loops supported by various programming languages, so called Iterators allow for traversing data container hiding the concrete implementation, i.e. linked list or array. While recursion can be considered as a special case of iteration, iteration describes the style of imperative programming in contrast to the more declarative nature of recursion. In a stricter sense, to distinguish iteration from recursion, iteration implies performing a loop inside the scope of a subroutine restricted to one stack frame in a call hierarchy, or equivalently processed by the same local iterator object.

=Iterations= There are various macro- and micro-iterations going on within a chess program and/or its creator, game controller and/or learning framework, i.e. the process to develop and tune a chess program, to repeat a series of games against various opponents for learning and automated tuning purpose, to iterate over moves while playing a game, Iterative Deepening, the move loop and current variation inside a minimax depth-first search, processing exchange sequences in SEE, looking for repetitions, generating moves of one piece and for all pieces, serializing bitboards, and whatever else.

Learning
Learning and automated tuning in computer chess programming deals with algorithms that allow the program to change its behavior based on data acquired during game play against variations of itself or a variety of opponents considering the final outcome and/or the game record. Evolutionary computation, genetic programming and simulated annealing apply iterative processes where one iteration deals with one generation of the chess or game playing program.

Game Loop
Playing a game of chess versus a chess program, is a sequential, iterative process. The next iteration either starts after the program played its move and starts pondering, or the user entered a move. The Game Loop terminates when the game is finished or aborted.

Iterative Deepening
In the context of Iterative Deepening in search algorithms, an iteration refers the current call of the search routine with a certain search depth inside the loop body of the ID framework. The resulting sequence is a sequence of exact scores for subsequent incremented search depths.

Move Loop
The typical control structure inside a minimax depth-first search of a chess program is the Move Loop, a generator or iterator pattern traversing the moves of one node or position. The whole implementation details of move generation, move ordering, pruning, bookkeeping and accessing a move list, might be hidden behind an iterator object and its interface.

Search
While the "horizontal" iteration of the move loop appears in one node, the "vertical" edges of the search tree, that is actually making the move and recursively calling the negamaxed search routine for the child node, appear in the current depth-first variation started at the root. It can be considered as nested iterations of the move loops processed in all upper nodes. Keeping an explicit stack of move iterators per node further allows to reformulate the recursive search routine as iterative solution, with makes it simpler to unwind the search.

Recursion to Iteration
Tail recursion is trivially convertible to iteration, and performed by various optimizing compilers. Since a call as used in recursion is nothing else than a jump to an address, remembering the next instruction on the stack for the return, recursion can always replaced by iteration using an array as explicit stack, an index (stack pointer) for the current nesting level, and goto instructions, as demonstrated in Iterative Search. Knuth and Moore already introduced an iterative solution of Alpha-Beta in 1975. Iterative solutions of otherwise recursive algorithms are harder to understand and to debug and tend to become Spaghetti code, but are required for certain parallel search algorithms like Dynamic Tree Splitting. There are jumps from inside the move loop body outside (call), and vice versa (return).

=Iterative Algorithms= In computational mathematics, an iterative algorithm or method is a procedure that generates integer, fixed point, or floating point sequences and calculates Series. Iterative algorithms are used to approximate nonlinear equations and to solve certain optimization problems. An iterative method is called convergent if the corresponding sequence converges for given initial approximations.

PRNG
In computer chess, iterative algorithms are used for instance directly or indirectly in initializing Zobrist keys with Pseudorandom number generators (PRNG), for instance the linear congruential generator, the Mersenne twister, the Xorshift by George Marsaglia or the KISS approach by Bob Jenkins similar as used in Stockfish.

Fill Algorithms
Flood-filling in bitboards is an iterative method as well, consecutively feeding back the propagated output as input. The loop terminates if either the flood stops or has reached a target set.

=See also=
 * Automated Tuning
 * Backtracking - Eight Queens puzzle with Bitboards
 * Bitboard Serialization
 * Flood Fill Algorithms
 * Internal Iterative Deepening
 * Iterative Deepening
 * Iterative Search
 * Mate-in-two
 * Pseudorandom Number Generator
 * Recursion
 * Retrograde Analysis
 * SEE - The Swap Algorithm
 * Traversing Subsets of a Set

=Selected Publications=
 * Paul Stein (1987). Iteration of Maps, Strange Attractors, and Number Theory - An Ulamian Potpourri. in Stanislaw Ulam 1909-1984. Los Alamos Science, No. 15, pdf » Stanislaw Ulam

=Forum Posts=
 * how to print tree non-recursively by Daniel Shawul, CCC, February 24, 2012 » Search Tree, Recursion

=External Links=

General

 * Iteration from Wikipedia
 * Iterative and incremental development from Wikipedia
 * Recursion from Wikipedia

Control flow

 * Control flow: Loops from Wikipedia
 * Inner loop from Wikipedia
 * Idle loop from Wikipedia
 * Spinlock loop from Wikipedia

Iterator

 * Iterator pattern from Wikipedia
 * Generator (computer programming) from Wikipedia


 * Iterated function from Wikipedia

Programming languages

 * iterator - C++ Reference » C++
 * Iterator (Java 2 Platform SE 5.0) » Java
 * 3.5 Iterator Types - Python Library Reference » Python

Iterative methods

 * Arnoldi iteration from Wikipedia
 * Bregman method from Wikipedia
 * Euclidean algorithm from Wikipedia
 * Fixed point iteration from Wikipedia
 * Gauss–Newton algorithm from Wikipedia
 * Gauss–Seidel method from Wikipedia
 * Gradient descent from Wikipedia
 * Hill climbing from Wikipedia
 * Householder's method from Wikipedia
 * Iterated local search from Wikipedia
 * Jacobi eigenvalue algorithm from Wikipedia
 * Jacobi Iteration for Eigenvectors
 * Jacobi method
 * Local search (optimization) from Wikipedia
 * Newton's method from Wikipedia
 * Newton's method in optimization
 * Picard Iteration Revisited
 * Power iteration from Wikipedia
 * Rate of convergence from Wikipedia
 * Root-finding algorithm from Wikipedia
 * Simulated annealing from Wikipedia
 * Subgradient method from Wikipedia

Sequence

 * Collatz conjecture from Wikipedia
 * Fibonacci number from Wikipedia
 * Integer sequence from Wikipedia
 * Linear congruential generator from Wikipedia
 * Recurrence relation from Wikipedia

Series

 * Arithmetic progression from Wikipedia
 * Convergent series from Wikipedia
 * Geometric series from Wikipedia
 * Fourier series from Wikipedia
 * Harmonic series from Wikipedia
 * Taylor series from Wikipedia

=References=

Up one Level