Run-time algorithm specialisation

Run-time algorithm specialisation

In computer science, run-time algorithm specialisation is a methodology for creating efficient algorithms for costly computation tasks of certain kinds. The methodology originates in the field of automated theorem proving and, more specifically, in the Vampire theorem prover project.

The idea is inspired by the use of partial evaluation in optimising program translation. Many core operations in theorem provers exhibit the following pattern.Suppose that we need to execute some algorithm mathit{alg}(A,B) in a situation where a value of A "is fixed for potentially many different values of" B. In order to do this efficiently, we can try to find a specialisation of mathit{alg} for every fixed A, i.e., such an algorithm mathit{alg}_A, that executing mathit{alg}_A(B) is equivalent to executing mathit{alg}(A,B).

The specialised algorithm may be more efficient than the generic one, since it can "exploit some particular properties" of the fixed value A. Typically, mathit{alg}_A(B) can avoid some operations that mathit{alg}(A,B) would have to perform, if they are known to be redundant for this particular parameter A. In particular, we can often identify some tests that are true or false for A, unroll loops and recursion, etc.

The key difference between run-time specialisation and partial evaluation is that the values of A on which mathit{alg} is specialised are not known statically, so the "specialisation takes place at run-time".

There is also an important technical difference. Partial evaluation is applied to algorithms explicitly represented as codes in some programming language. At run-time, we do not need any concrete representation of mathit{alg}. We only have to "imagine" mathit{alg} "when we program" the specialisation procedure.All we need is a concrete representation of the specialised version mathit{alg}_A. This also means that we cannot use any universal methods for specialising algorithms, which is usually the case with partial evaluation. Instead, we have to program a specialisation procedure for every particular algorithm mathit{alg}. An important advantage of doing so is that we can use some powerful "ad hoc" tricks exploiting peculiarities of mathit{alg} and the representation of A and B, which are beyond the reach of any universal specialisation methods.

pecialisation with compilation

The specialised algorithm has to be represented in a form that can be interpreted.In many situations, usually when mathit{alg}_A(B) is to be computed on many values B in a row, we can write mathit{alg}_A as a code of a special abstract machine, and we often say that A is "compiled". Then the code itself can be additionally optimised by answer-preserving transformations that rely only on the semantics of instructions of the abstract machine.

Instructions of the abstract machine can usually be represented as records. One field of such a record stores an integer tag that identifies the instruction type, other fields may be used for storing additional Parameters of the instruction, for example a pointer to anotherinstruction representing a label, if the semantics of the instruction requires a jump. All instructions of a code can be stored in an array, or list, or tree.

Interpretation is done by fetching instructions in some order, identifying their typeand executing the actions associated with this type. In C or C++ we can use a switch statement to associate some actions with different instruction tags. Modern compilers usually compile a switch statement with integer labels from a narrow range rather efficiently by storing the address of the statement corresponding to a value i in the i-th cell of a special array. One can exploit thisby taking values for instruction tags from a small interval of integers.

Data-and-algorithm specialisation

There are situations when many instances of A are intended for long-term storage and the calls of mathit{alg}(A,B) occur with different B in an unpredicatable order.For example, we may have to check mathit{alg}(A_1,B_1) first, then mathit{alg}(A_2,B_2), then mathit{alg}(A_1,B_3), and so on.In such circumstances, full-scale specialisation with compilation may not be suitable due to excessive memory usage. However, we can sometimes find a compact specialised representation A^{prime}for every A, that can be stored with, or instead of, A. We also define a variant mathit{alg}^{prime} that works on this representation and any call to mathit{alg}(A,B) is replaced by mathit{alg}^{prime}(A^{prime},B), intended to do the same job faster.

See also

* Psyco, a specializing run-time compiler for Python
* multi-stage programming

Reading list

* A. Voronkov, "The Anatomy of Vampire: Implementing Bottom-Up Procedures with Code Trees", "Journal of Automated Reasoning", 15(2), 1995 ("original idea")

* A. Riazanov and A. Voronkov, "Efficient Checking of Term Ordering Constraints", "Proc. IJCAR" 2004, Lecture Notes in Artificial Intelligence 3097, 2004 ("compact but self-contained illustration of the method")
* A. Riazanov and A. Voronkov, "Efficient Instance Retrieval with Standard and Relational Path Indexing, Information and Computation", 199(1-2), 2005 ("contains another illustration of the method")

* A. Riazanov, "Implementing an Efficient Theorem Prover", PhD thesis, The University of Manchester, 2003 ("contains the most comprehensive description of the method and many examples")


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Partial evaluation — In computing, partial evaluation is a technique for program optimization by specialization.A computer program, prog , is seen as a mapping of input data into output data::prog : I {static} imes I {dynamic} o OI {static}, the static data , is the… …   Wikipedia

  • Vampire theorem prover — Vampire is an automatic theorem prover for first order classical logic developed in the Computer Science Department of the University of Manchester by Prof. Andrei Voronkov previously together with Dr. Alexandre Riazanov. It has won the world cup …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”