We propose a static size analysis procedure that combines term-rewriting and type checking to automatically obtain output-oninput size dependencies for first-order functions. Attention is restricted to functions for which the size of the result is strictly polynomial, not necessarily monotonous, in the sizes of the arguments. To infer a size dependency, the procedure generates hypotheses for increasing degrees of polynomials. For each degree, to define a hypothetical polynomial one needs to know its values on a finite collection of points (subject to some geometrical condition). To compute the value of a size polynomial in a certain point we use a term-rewriting system generated by a standard size-annotations inference procedure. We have proven that if a function with a given input terminates at runtime on a meaningful stack and heap then the static (’compile-time’) term rewriting system of the size inference also terminates, on the integers representing the sizes of the corresponding inputs. The term rewriting system may terminate at compile-time when the underlying function definition does not at run-time. This makes the theoretical applicability of the proposed approach larger than the previous state-of-the-art, where run-time testing was used to generate hypothetical polynomials. Also, the practical applicability is improved due to increased efficiency since the term rewriting system at compile time abstracts from many computations that are done at run-time.
[1]
Bart Jacobs,et al.
AHA: Amortized Heap Space Usage Analysis
,
2007,
Trends in Functional Programming.
[2]
Olha Shkaravska,et al.
Inferring static non-monotonically sized types through testing
,
2007
.
[3]
Olha Shkaravska,et al.
Type Checking and Weak Type Inference for Polynomial Size Analysis of First--Order Functions
,
2007
.
[4]
Marko C. J. D. van Eekelen,et al.
Polynomial Size Analysis of First-Order Functions
,
2007,
TLCA.
[5]
Peter Csaba Ölveczky,et al.
The Maude Formal Tool Environment
,
2007,
CALCO.
[6]
Jean-Yves Marion,et al.
Resource Analysis by Sup-interpretation
,
2006,
FLOPS.
[7]
Kevin Hammond,et al.
Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs
,
2003,
IFL.