Partial Evaluation
暂无分享,去创建一个
Partial evaluation is an automated program-transformation technique for specializing programs. Given a source program Phx; yi with the input parameters x and y, and a value s for x, a partial evaluator PE specializes P with respect to s, yielding the residual program P s hyi. To this end, PE precomputes all the parts of P that depend only upon the value of x, thus \partially evaluating" P, i.e., evaluating (executing) only the parts of P that do not depend on the value of y. The specialization process ensures the compatibility between source and residual programs: for any data item d in y's domain, running P s on the remaining input hdi computes the same output as running P on the complete input hs; di. The overall motivation for program specialization is that running P s on d is often more eecient than running P on both s and d, since PE has already precomputed the portions of P that depend only on s. This staging of P using PE pays oo if P is repeatedly used with the x parameter set to s. Since its value is xed, x is called a static parameter, while y, which may vary, is called a dynamic parameter. A simple example: Consider the following C function that squares the sum of its two arguments. int square_sum (int x, int y) { return (x*x + 2*x*y + y*y); } Specializing this function with x set to 3 yields the following residual function: int square_sum_3_u (int y) { return (9 + 6*y + y*y); } This specialized function is obtained by retaining the unknown parameter y, propagating the constant 3 in the body of square sum, and by evaluating the expressions x*x and 2*x that do not depend on y. Partial evaluators employ techniques found in optimizing compilers such as constant propagation and folding (evaluating expressions with constant parameters), loop unrolling (reducing the number of iterations by 1
[1] M. F.,et al. Bibliography , 1985, Experimental Gerontology.
[2] Peter Sestoft,et al. Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.