Changes

Jump to: navigation, search

Iteration

14,461 bytes added, 16:04, 4 June 2018
Created page with "'''Home * Programming * Algorithms * Iteration''' FILE:iteration.png|border|right|thumb|link=http://www.natur-struktur.ch/populationen/iterationen.htm..."
'''[[Main Page|Home]] * [[Programming]] * [[Algorithms]] * Iteration'''

[[FILE:iteration.png|border|right|thumb|link=http://www.natur-struktur.ch/populationen/iterationen.html| Iteration <ref>[http://www.natur-struktur.ch/populationen/iterationen.html Iterationen] from [http://www.natur-struktur.ch/ Strukturen in der Biologie] (German)</ref> ]]

In computer science, '''Iteration''' is the act of repeating instructions inside an algorithm, implemented either by the control structure of a [https://en.wikipedia.org/wiki/Loop_%28computing%29#Loops loop] or by direct or indirect [[Recursion|recursive]] calls. Despite all kinds of low level loops supported by various [[Languages|programming languages]], so called [https://en.wikipedia.org/wiki/Iterator Iterators] allow for traversing [https://en.wikipedia.org/wiki/Container_%28data_structure%29 data container] hiding the concrete implementation, i.e. [[Linked List|linked list]] or [[Array|array]]. While recursion can be considered as a special case of iteration, iteration describes the style of [https://en.wikipedia.org/wiki/Imperative_programming imperative programming] in contrast to the more [https://en.wikipedia.org/wiki/Declarative_programming declarative] nature of recursion. In a stricter sense, to distinguish iteration from recursion, iteration implies performing a loop inside the [https://en.wikipedia.org/wiki/Scope_%28computer_science%29 scope] of a [https://en.wikipedia.org/wiki/Subroutine subroutine] restricted to one [https://en.wikipedia.org/wiki/Call_stack 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|learning]] and [[Automated Tuning|automated tuning]] purpose, to iterate over moves while [[Chess Game|playing a game]], [[Iterative Deepening]], the move loop and current variation inside a [[Minimax|minimax]] [[Depth-First|depth-first search]], processing exchange sequences in [[Static Exchange Evaluation|SEE]], looking for [[Repetitions|repetitions]], [[Move Generation|generating moves]] of one piece and for all [[Pieces|pieces]], [[Bitboard Serialization|serializing]] [[Bitboards|bitboards]], and whatever else.

==Learning==
[[Learning]] and [[Automated Tuning|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. [[Genetic Programming#EvolutionaryComputation|Evolutionary computation]], [[Genetic Programming|genetic programming]] and [[Simulated Annealing|simulated annealing]] apply iterative processes where one iteration deals with one generation of the chess or game playing program.

==Game Loop==
Playing a [[Chess Game|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|pondering]], or the user [[Entering Moves|entered a move]]. The [[Chess Game#GameLoop|Game Loop]] terminates when the game is finished or aborted.

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

==Move Loop==
The typical [https://en.wikipedia.org/wiki/Control_flow control structure] inside a [[Minimax|minimax]] [[Depth-First|depth-first search]] of a chess program is the Move Loop, a [https://en.wikipedia.org/wiki/Generator_%28computer_programming%29 generator] or [https://en.wikipedia.org/wiki/Iterator_pattern iterator pattern] traversing the moves of one [[Node|node]] or [[Chess Position|position]]. The whole implementation details of [[Move Generation|move generation]], [[Move Ordering|move ordering]], [[Pruning|pruning]], bookkeeping and accessing a [[Move List|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|search tree]], that is actually [[Make Move|making the move]] and recursively calling the [[Negamax|negamaxed]] [[Search|search]] routine for the child node, appear in the current depth-first variation started at the [[Root|root]]. It can be considered as nested iterations of the move loops processed in all upper nodes. Keeping an explicit [[Stack|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==
[https://en.wikipedia.org/wiki/Tail_call Tail recursion] is trivially convertible to iteration <ref>[https://en.wikipedia.org/wiki/Recursion_%28computer_science%29#Tail-recursive_functions Recursion - Tail-recursive functions from Wikipedia,]</ref> <ref>[http://www.refactoring.com/catalog/replaceRecursionWithIteration.html Replace Recursion with Iteration]</ref>, and performed by various optimizing compilers. Since a call as used in recursion is nothing else than a [https://en.wikipedia.org/wiki/Jump_%28computer_science%29 jump] to an address, remembering the next instruction on the stack for the [https://en.wikipedia.org/wiki/Return_statement return], recursion can always replaced by iteration using an array as explicit stack, an index (stack pointer) for the current nesting level, and [https://en.wikipedia.org/wiki/Goto goto] instructions, as demonstrated in [[Iterative Search]]. [[Donald Knuth|Knuth]] and Moore already introduced an [[Knuth-iterative|iterative solution]] of [[Alpha-Beta]] in 1975 <ref>[[Donald Knuth]], [http://dblp.uni-trier.de/pers/hd/m/Moore:Ronald_W= Ronald W. Moore] ('''1975'''). ''[http://www.scribd.com/doc/28194932/An-Analysis-of-Alpha-Beta-Pruning An analysis of alpha-beta pruning].'' Artificial Intelligence, 6:293–326</ref> . Iterative solutions of otherwise recursive algorithms are harder to understand and to [[Debugging|debug]] and tend to become [https://en.wikipedia.org/wiki/Spagetti_code Spaghetti code] <ref>[https://en.wikipedia.org/wiki/Considered_harmful Considered harmful from Wikipedia]</ref>, but are required for certain [[Parallel Search|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 [https://en.wikipedia.org/wiki/Computational_mathematics computational mathematics], an [https://en.wikipedia.org/wiki/Iterative_method iterative algorithm] or method is a procedure that generates [https://en.wikipedia.org/wiki/Integer_sequence integer], [https://en.wikipedia.org/wiki/Fixed-point_arithmetic fixed point], or [[Float|floating point]] sequences and calculates [https://en.wikipedia.org/wiki/Series_%28mathematics%29 Series]. Iterative algorithms are used to approximate [https://en.wikipedia.org/wiki/Nonlinear_system nonlinear equations] <ref>[http://www5.wittenberg.edu/academics/computerscience/facultystaff/shelburne.html Brian J. Shelburne] ('''1999'''). ''Zuse's Z3 Square Root Algorithm''. [http://www4.wittenberg.edu/academics/mathcomp/bjsdir/ZuseZ3Talk.pdf pdf] » [[Konrad Zuse]]</ref> and to solve certain optimization problems. An iterative method is called convergent if the corresponding sequence converges for given initial approximations.
<span id="PRNG"></span>
==PRNG==
In computer chess, iterative algorithms are used for instance directly or indirectly in initializing [[Zobrist Hashing|Zobrist keys]] with [[Pseudorandom Number Generator|Pseudorandom number generators]] (PRNG), for instance the [https://en.wikipedia.org/wiki/Linear_congruential_generator linear congruential generator], the [https://en.wikipedia.org/wiki/Mersenne_twister Mersenne twister], the [https://en.wikipedia.org/wiki/Xorshift Xorshift] by [[Mathematician#GMarsaglia|George Marsaglia]] or the [[Bob Jenkins#RKISS|KISS]] approach by [[Bob Jenkins]] similar as used in [[Stockfish]] <ref>[http://www.talkchess.com/forum/viewtopic.php?t=38313 RKISS copyright?] by Giorgio Medeot, [[CCC]], March 07, 2011</ref>.

==Fill Algorithms==
[[Fill Algorithms|Flood-filling]] in [[Bitboards|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#8QinBitboards|Backtracking - Eight Queens puzzle with Bitboards]]
* [[Bitboard Serialization]]
* [[King Pattern#FloodFillAlgorithms|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 ''[http://la-science.lanl.gov/lascience15.shtml Stanislaw Ulam 1909-1984]''. [http://la-science.lanl.gov/ Los Alamos Science], No. 15, [https://www.fas.org/sgp/othergov/doe/lanl/pubs/00285739.pdf pdf] » [[Stanislaw Ulam]]

=Forum Posts=
* [http://www.talkchess.com/forum/viewtopic.php?t=42588 how to print tree non-recursively] by [[Daniel Shawul]], [[CCC]], February 24, 2012 » [[Search Tree]], [[Recursion]]

=External Links=
==General==
* [https://en.wikipedia.org/wiki/Iteration Iteration from Wikipedia]
* [https://en.wikipedia.org/wiki/Iterative_and_incremental_development Iterative and incremental development from Wikipedia]
* [https://en.wikipedia.org/wiki/Recursion_%28computer_science%29 Recursion from Wikipedia]

==[https://en.wikipedia.org/wiki/Control_flow Control flow]==
* [https://en.wikipedia.org/wiki/Control_flow#Loops Control flow: Loops from Wikipedia]
* [https://en.wikipedia.org/wiki/Inner_loop Inner loop from Wikipedia]
* [https://en.wikipedia.org/wiki/Idle_%28CPU%29 Idle loop from Wikipedia]
* [https://en.wikipedia.org/wiki/Spinlock Spinlock loop from Wikipedia]

==[https://en.wikipedia.org/wiki/Iterator Iterator]==
* [https://en.wikipedia.org/wiki/Iterator_pattern Iterator pattern from Wikipedia]
: [https://en.wikipedia.org/wiki/Generator_%28computer_programming%29 Generator (computer programming) from Wikipedia]
* [https://en.wikipedia.org/wiki/Iterated_function Iterated function from Wikipedia]

==[[Languages|Programming languages]]==
* [http://www.cplusplus.com/reference/std/iterator/ iterator - C++ Reference] » [[Cpp|C++]]
* [http://download.oracle.com/javase/1,5.0/docs/api/java/util/Iterator.html Iterator (Java 2 Platform SE 5.0)] » [[Java]]
* [http://docs.python.org/release/2.5.2/lib/typeiter.html 3.5 Iterator Types - Python Library Reference] » [[Python]]

==[https://en.wikipedia.org/wiki/Iterative_method Iterative methods]==
* [https://en.wikipedia.org/wiki/Arnoldi_iteration Arnoldi iteration from Wikipedia]
* [https://en.wikipedia.org/wiki/Bregman_method Bregman method from Wikipedia]
* [https://en.wikipedia.org/wiki/Euclidean_algorithm Euclidean algorithm from Wikipedia]
* [https://en.wikipedia.org/wiki/Fixed_point_iteration Fixed point iteration from Wikipedia]
* [https://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm Gauss–Newton algorithm from Wikipedia]
* [https://en.wikipedia.org/wiki/Gauss%E2%80%93Seidel_method Gauss–Seidel method from Wikipedia]
* [https://en.wikipedia.org/wiki/Gradient_descent Gradient descent from Wikipedia]
* [https://en.wikipedia.org/wiki/Hill_climbing Hill climbing from Wikipedia]
* [https://en.wikipedia.org/wiki/Householder%27s_method Householder's method from Wikipedia]
* [https://en.wikipedia.org/wiki/Iterated_local_search Iterated local search from Wikipedia]
* [https://en.wikipedia.org/wiki/Jacobi_eigenvalue_algorithm Jacobi eigenvalue algorithm from Wikipedia]
* [http://math.fullerton.edu/mathews/n2003/JacobiMethodMod.html Jacobi Iteration for Eigenvectors]
* [https://en.wikipedia.org/wiki/Jacobi_method Jacobi method]
* [https://en.wikipedia.org/wiki/Local_search_%28optimization%29 Local search (optimization) from Wikipedia]
* [https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization Newton's method from Wikipedia]
* [https://en.wikipedia.org/wiki/Newton%27s_method_in_optimization Newton's method in optimization]
* [http://math.fullerton.edu/mathews/n2003/picarditerationmod.html Picard Iteration Revisited]
* [https://en.wikipedia.org/wiki/Power_iteration Power iteration from Wikipedia]
* [https://en.wikipedia.org/wiki/Rate_of_convergence Rate of convergence from Wikipedia]
* [https://en.wikipedia.org/wiki/Root-finding_algorithm Root-finding algorithm from Wikipedia]
* [https://en.wikipedia.org/wiki/Simulated_annealing Simulated annealing from Wikipedia]
* [https://en.wikipedia.org/wiki/Subgradient_method Subgradient method from Wikipedia]

==[https://en.wikipedia.org/wiki/Sequence Sequence]==
* [https://en.wikipedia.org/wiki/Collatz_conjecture Collatz conjecture from Wikipedia]
* [https://en.wikipedia.org/wiki/Fibonacci_number Fibonacci number from Wikipedia]
* [https://en.wikipedia.org/wiki/Integer_sequence Integer sequence from Wikipedia]
* [https://en.wikipedia.org/wiki/Linear_congruential_generator Linear congruential generator from Wikipedia]
* [https://en.wikipedia.org/wiki/Recurrence_relation Recurrence relation from Wikipedia]

==[https://en.wikipedia.org/wiki/Series_%28mathematics%29 Series]==
* [https://en.wikipedia.org/wiki/Arithmetic_progression Arithmetic progression from Wikipedia]
* [https://en.wikipedia.org/wiki/Convergent_series Convergent series from Wikipedia]
* [https://en.wikipedia.org/wiki/Geometric_series Geometric series from Wikipedia]
* [https://en.wikipedia.org/wiki/Fourier_series Fourier series from Wikipedia]
* [https://en.wikipedia.org/wiki/Harmonic_series_%28mathematics%29 Harmonic series from Wikipedia]
* [https://en.wikipedia.org/wiki/Taylor_series Taylor series from Wikipedia]

=References=
<references />

'''[[Algorithms|Up one Level]]'''

Navigation menu