This page uses content from Wikipedia and is licensed under CC BY-SA.

In algorithms, **precomputation** is the act of performing an initial computation before run time to generate a lookup table that can be used by an algorithm to avoid repeated computation each time it is executed. Precomputation is often used in algorithms that depend on the results of expensive computations that don't depend on the input of the algorithm. A trivial example of precomputation is the use of hardcoded mathematical constants, such as π and e, rather than computing their approximations to the necessary precision at run time.

In databases, the term **materialization** is used to refer to storing the results of a precomputation,^{[1]}^{[2]} e.g. in a materialized view.^{[3]}^{[4]}

Precomputing a set of intermediate results at the beginning of an algorithm's execution can often increase algorithmic efficiency substantially. This becomes advantageous when one or more inputs is constrained to a small enough range that the results can be stored in a reasonably sized block of memory. Because memory access is essentially constant in time complexity (except for caching delays), any algorithm with a component which has worse than constant efficiency over a small input range can be improved by precomputing values. In some cases efficient approximation algorithms can be obtained by computing a discrete subset of values and interpolating for intermediate input values, since interpolation is also a linear operation.

Before the advent of computers, printed lookup tables of values were used by people to speed up hand calculations of complex functions, such as in trigonometric tables, logarithm tables, and tables of statistical density functions^{[5]} School children are often taught to memorize "times tables" to avoid calculations of the most commonly used numbers (up to 9 x 9 or 12 x 12). Even as early as 493 A.D., Victorius of Aquitaine wrote a 98-column multiplication table which gave (in Roman numerals) the product of every number from 2 to 50 times and the rows were "a list of numbers starting with one thousand, descending by hundreds to one hundred, then descending by tens to ten, then by ones to one, and then the fractions down to 1/144" ^{[6]}

Even modern computer implementations of digital trigonometric functions often use precomputed lookup tables to either provide coefficients for interpolation algorithms or to initialise successive approximation algorithms.

Many attacks on cryptosystems involve precomputation.

Examples of large-scale precomputation as part of modern efficient algorithms include:

- Rainbow tables
- Perfect hashes
- The cube attack
- Precalculated BSP trees for visibility calculations in 3D graphics
- Radiosity precomputation for illumination in 3D graphics

Compilers use precomputation extensively as a means of increasing the run-time speed of the resulting code: this precomputation can be regarded as in effect a form of partial evaluation of the program code itself. Examples of this sort of precomputation include dataflow analysis and strength reduction steps.

**^**Jiawei Han; Micheline Kamber (9 June 2011).*Data Mining: Concepts and Techniques: Concepts and Techniques*. Elsevier. p. 159. ISBN 978-0-12-381480-7.**^**Sven Groppe (29 April 2011).*Data Management and Query Processing in Semantic Web Databases*. Springer Science & Business Media. p. 178. ISBN 978-3-642-19357-6.**^**Karen Morton; Kerry Osborne; Robyn Sands; Riyaj Shamsudeen; Jared Still (28 October 2013).*Pro Oracle SQL*. Apress. p. 48. ISBN 978-1-4302-6220-6.**^**Marie-Aude Aufaure; Esteban Zimányi (16 January 2012).*Business Intelligence: First European Summer School, EBISS 2011, Paris, France, July 3-8, 2011, Tutorial Lectures*. Springer Science & Business Media. p. 43. ISBN 978-3-642-27357-5.**^**Campbell-Kelly, Martin; Croarken, Mary; Flood, Raymond; et al., eds. (October 2, 2003) [2003].*The History of Mathematical Tables From Sumer to Spreadsheets*(1st ed.). New York, USA: Oxford University Press. ISBN 978-0-19-850841-0.**^**Maher, David. W. J. and John F. Makowski. "Literary Evidence for Roman Arithmetic With Fractions", 'Classical Philology' (2001) Vol. 96 No. 4 (2001) pp. 376-399. (See page p.383.)