The Decision Problem for Linear Tree Constraints

Transcription

The Decision Problem for Linear Tree Constraints
The Decision Problem for
Linear Tree Constraints
Sabine Bauer and Martin Hofmann, LMU Munich
Institut f¨
ur Informatik, Ludwig-Maximilians-Universit¨
at M¨
unchen, Germany
{hofmann,sabine.bauer}@ifi.lmu.de
We present new results on a constraint satisfaction problem arising from the inference of
resource types.
Linear constraints were introduced by Hofmann and Jost in the context of type-based amortized resource analysis by the potential method [5] where it was applied to functional programs.
The constraint systems appearing in this system and subsequent ones has finitely many variables and can be reduced to linear programming. Later, Hofmann and Rodriguez extended
type-based amortized resource analysis to object-oriented programs [8],[6] which led to constraints involving infinite lists or trees whose entries are numerical variables. Therefore, a
straightforward reduction to linear programming is no longer an option. However, the constraint systems exhibit enough regularity that a heuristic procedure developed by Hofmann
and Rodriguez allowed to find solutions in many cases.
In the case of infinite lists the constraint systems can be simply described as follows. One
has finitely many unknowns ranging over infinite lists (sequences) of nonnegative rational numbers including ∞. Terms and constraints are built from those by addition (+) and comparison
(≤) understood pointwise, and the tail function (tl) that removes the first element of a sequence. Furthermore, constraint systems may contain ordinary linear arithmetic constraints
over the nonnegative rationals including infinity where the head function (hd) maps sequences
to numbers. For example, the following constraint system is solvable and has the (not unique)
solution y a constant list and x an exponentially decreasing list and z a Fibonacci list with an
additional linear summand. We have the (arithmetic and list) constraints
hd(x)
hd(tl(x))
hd(y)
hd(z)
= 2,
= 5,
≥ 1,
≥ 2,
tl(y) ≥ y,
z + z ≤ tl(z),
tl(tl(x)) ≥ tl(x) + x + tl(y) + tl(y).
and the solutions
y = 1, 1, ...,
x = 2, 5, 9, 16, 27, 55, .., n − 1, n, n(n − 1) + 2, ...,
1
1 1 1
z = 2, 1, , , , ..., n , ...
2 4 8
2
In this paper we report progress on the general question of solvability and decidability
of these constraint systems. First, in the case of infinite lists of numerical variables we can in
many cases draw a connection to rational generating functions and in particular see that certain
resource behaviours cannot arise as solutions to type inference problems. A concrete example
is the harmonic series because it has a logarithmic generating function [4].
We also show that the general constraint satisfaction problem as formulated by Hofmann and
Rodriguez admits a reduction from the Skolem-Mahler-Lech problem [7, 2] whose decidability
status is as yet unknown but at least NP-hard. Recall that the Skolem-Mahler-Lech problem
27
The decision problem for linear tree constraints
Bauer and Hofmann
asks whether a sequence defined by a linear recurrence with integer coefficients (like Fibonacci)
contains zero.
However, we were able to better delineate the image of the translation from type inference
to the constraint satisfaction problem and thus identified a subproblem which—if solved—can
still be used for type-based resource inference but has better algorithmic properties.
More precisely, we can show that the characteristic polynomials of the linear recurrences
corresponding to the identified fragment always have a dominating zero (eigenvalue) which
allows for a decision procedure based on comparison of growth rates. There are still several fine
points to overcome which result from the fact that we are dealing with inequations rather than
equations.
We then also give a heuristic reduction from the case of general trees to infinite lists which
carries type-based amortized resource analysis considerably further than it was previously the
case. In particular, we are able to analyse programs with superpolynomial resource consumption
and also have a more intrinsic characterisation of the limitations of the analysis.
In currently ongoing work, we try to go beyond the question of mere satisfiability of constraint systems and to extract minimal solutions and also to treat trees in general not merely
by translating them to lists.
References
[1] J. Bell and S. Gerhold. The positivity set of a recurrence sequence. arXiv:0506.398, 2005.
[2] V. Blondel and N. Portier. The presence of a zero in an integer linear recurrent sequence is NP-hard
to decide. Lin. Alg. and Its Appl., 351–351:91–98, 2002.
[3] G. Everest, A. van der Poorten, I. Shparlinski, and T. Ward. Recurrence Sequences. Oxford Univ.
Press, 2003.
[4] R. Graham, D. Knuth, and O. Patashnik. Concrete Mathematics: A Foundation for Computer
Science. Addison-Wesley, 1994.
[5] M. Hofmann and S. Jost. Static prediction of heap space usage for first-order functional programs.
In Conf. Record of 30th ACM SIGPLAN-SIGACT Symp. on Principles of Programming Languages,
POPL ’03, pp. 185–197. ACM, 2003.
[6] M. Hofmann and D. Rodriguez. Linear constraints over infinite trees. In Proc. of 18th Int. Conf. on
Logic for Programming, Artificial Intelligence and Reasoning, LPAR 2012, v. 7180 of Lect. Notes
in Comput. Sci., pp. 343–358. Springer, 2012.
[7] J. Ouaknine and J. Worrell. Positivity problems for low-order linear recurrence sequences.
arXiv:1307.2779, 2013.
[8] D. Rodriguez. Amortized Analysis for object oriented programs. PhD thesis, LMU M¨
unchen, 2012.
28