Precomputation: Difference between revisions

Content deleted Content added
Ragzouken (talk | contribs)
No edit summary
SdkbBot (talk | contribs)
m History: Removed erroneous space and general fixes (task 1)
 
(36 intermediate revisions by 25 users not shown)
Line 1:
{{short description|Act of performing an initial computation before run time}}
[[Image:Abramowitz&Stegun.page97.agr.jpg|thumb|Part of a 20th -century table ofprecomputed [[commonmathematical logarithmtable]]s in the reference bookof [[Abramowitzcommon and Stegunlogarithm]]s.]]
 
In [[algorithms]], '''precomputation''' is the act of performing an initial [[computation]] before [[Run time (program lifecycle phase)|run time]] to generate resultsa [[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 [[Pi|π]] and [[E_E (mathematical_constantmathematical constant)|e]], rather than computing their approximations to the necessary precision at run time.
 
In [[database]]s, the term '''materialization''' is used to refer to storing the results of a precomputation,<ref name="HanKamber2011">{{cite book|author1=Jiawei Han|author2=Micheline Kamber|title=Data Mining: Concepts and Techniques: Concepts and Techniques|url=https://books.google.com/books?id=pQws07tdpjoC&pg=PA159|date=9 June 2011|publisher=Elsevier|isbn=978-0-12-381480-7|page=159}}</ref><ref name="Groppe2011">{{cite book|author=Sven Groppe|title=Data Management and Query Processing in Semantic Web Databases|url=https://books.google.com/books?id=HdVZ2MhzP_4C&pg=PA178|date=29 April 2011|publisher=Springer Science & Business Media|isbn=978-3-642-19357-6|page=178}}</ref> such as in a [[materialized view]].<ref name="MortonOsborne2013">{{cite book|author1=Karen Morton|author2=Kerry Osborne|author3=Robyn Sands |author4=Riyaj Shamsudeen |author5=Jared Still|title=Pro Oracle SQL|url=https://books.google.com/books?id=XUPXAQAAQBAJ&pg=PA48|date=28 October 2013|publisher=Apress|isbn=978-1-4302-6220-6|page=48}}</ref><ref name="AufaureZimányi2012">{{cite book|author1=Marie-Aude Aufaure|author2=Esteban Zimányi|title=Business Intelligence: First European Summer School, EBISS 2011, Paris, France, July 3-8, 2011, Tutorial Lectures|url=https://books.google.com/books?id=UWtes499ZaUC&pg=PA43|date=16 January 2012|publisher=Springer Science & Business Media|isbn=978-3-642-27357-5|page=43}}</ref>
 
== Overview ==
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 [[CPU cache|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 mathematics|discrete]] subset of values and [[interpolating]] for intermediate input values, since interpolation is also a linear operation.
 
== History ==
Before the advent of computers, printed [[lookup table]]s of values were used by people to speed up hand calculations of complex functions, such as in [[trigonometric table]]s, [[Common logarithm|logarithm tables]], and tables of [[statistical density function]]s.<ref>{{cite book
|editor1-last= Campbell-Kelly
|editor1-first= Martin|editor1-link=Martin Campbell-Kelly
|editor2-last= Croarken
|editor2-first= Mary|editor2-link=Mary Croarken
|editor3-last= Flood|editor3-link=Raymond Flood (mathematician)
|editor3-first= Raymond
|display-editors = 3 |editor4-last= Robson|editor4-link=Eleanor Robson
|editor3-last= Robson
|editor3editor4-first= Eleanor
|title= The History of Mathematical Tables From Sumer to Spreadsheets
|title-link= The History of Mathematical Tables
|url=
|origyearyear= 2003
|format=
|accessdate= May 5, 2010
|edition= 1st
|date= October 2, 2003
|origyear= 2003
|publisher= Oxford University Press
|___location= New York, USA
|language=
|isbn= 978-0-19-850841-0
|oclc=
|doi=
|bibcode=
|id=
}}
</ref>
School children are often taught to memorize "[[times table]]s" 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." <ref>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-399376–399. (See page p. 383.)</ref>
 
== Examples ==
Even modern computer implementations of digital [[trigonometric algorithmfunction]]s often use precomputed lookup tables to either provide coefficients for [[interpolation]] algorithms or to initialise successive [[successiveapproximation approximationalgorithm]] algorithmss.
 
Many attacks on [[cryptosystem]]s involve precomputation.
Line 44 ⟶ 37:
* [[Perfect hash]]es
* The [[cube attack]]
* Precalculated [[BSP tree]]s for visibility calculations in in 3D graphics
* [[Radiosity (3D computer graphics)|Radiosity]] precomputation for illumination in 3D graphics
 
[[Compiler]]s 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.
 
== References ==
{{reflist}}
 
== See also ==
* [[Mathematical table]]
* [[Algorithmic efficiency]]
* [[Partial evaluation]]
* [[Memoization]]
 
== References ==
[[Category:Software optimization]]
{{reflist}}
 
[[Category:Software optimization]]
 
{{compsci-stub}}