Title:
|
Towards a verified determinacy analysis for Prolog including cut
|
The question of determinacy is constantly on the mind of a good Prolog programmer.
To write correct, efficient programs, it is extremely important to understand how many
different answers a goal will compute and whether it will compute the same answer more
than once. This thesis presents a backward determinacy analysis that derives conditions
on the parameters of a predicate which guarantee that a call will be deterministic. The
virtue of a backward analysis as compared to a forward checking of determinacy of a
whole predicate lies in its generality. It can determine that some classes of calls to a
predicate are deterministic, even though the predicate is not deterministic in general.
The backward analysis presented here advances the state-of-the-art in its treatment of
cut; it takes into account the fact that cut is used to make programs more deterministic,
by allowing determinacy conditions to be weakened by the occurrence of a cut.
This backward analysis is an instance of a style of program analysis based on semantic
reasoning and abstract interpretation, which can benefit from formal verification. Indeed
there has been much work in recent years on verifying such analyses of imperative and
functional programs. However, in the area of logic program analysis, the amount of
work on formal verification in semantic analysis has been modest. This thesis aims at
filling this gap by applying recent advances in verification to Prolog analysis. To this end
Chapter 2 presents Coq-formalisations of the mathematics underlying fixpoint semantics
in Prolog. Chapter 3 presents formalisations in Coq of different styles of semantics for
cut-free Prolog, and of relative correctness proofs between them. It thus demonstrates
the applicability of verification in general, and Coq in particular, to the task of proving.
semantic analyses of Prolog correct. These formalisations form the basis for the formal
definition and correctness argument of backward analysis.
To argue correctness of the backward determinacy analysis, Chapter 4 presents a denotational
semantics for Prolog with cut, again formally defined in Coq. It uses techniques
of normalisation and stratification to treat the cut in a uniform, contextual fashion. The
result is a semantics which is amenable to abstraction, and which allows reasoning about
cut to be disentangled from reasoning about divergence, which previous denotational semantics
do not facilitate. This semantics is intended to form the basis of a verified proof
?f semantic correctness of the determinacy analysis .
. Finally, Chapter 6 addresses the problem of computational efficiency, and specifically an
operator called 'mutual exclusion', which is at the heart of any determinacy inference
and, initially, constitutes a computational bottleneck. The insight in improving the efficiency
of computing mutual exclusion is that it is closely related to Craig-interpolation.
Interpolants, and in particular 'good' interpolants, are notoriously hard to compute.
In the context of determinacy analysis, 'good' means 'weak' or 'less constraining'; furthermore,
in this context it is reasonable to work with a size abstraction that produces
linear constraints, which disambiguate separate answers to a goal. Chapter 6 shows how
to apply a highly optimised linear solver, to efficiently compute very weak (though not
always weakest) interpolants between sets of linear constraints. It thus lays the foundation
for an efficient implementation of the analysis, by showing how mutual exclusion
can be formulated in terms of interpolants.
|