A strict computation model for µZ is described in the style of natural semantics [10]. The intention is to get a model which is abstract enough to provide an idea of computation in µZ, but also near enough to an implementation to serve as a starting point for its design.
The computation model is not primarily designed with the goal to get
``maximal'' computation power out of µZ. A complete model cannot be
realized anyway.
Efficient implementability and transparent traceability of execution
are as significant as computation power. The last point is in
particular important for the application to test-case evaluation,
where the reason of the failure of a test needs to be understandable
by humans. A major design decision derived from these considerations
is to use a strict evaluation order. Strictness in the context
of µZ means that members of the singleton set,
,
are
completely evaluated before the set is constructed. Similarly, in
constructed values,
,
the arguments are
fully evaluated prior to the constructor call. Moreover, we will not
provide ``parallel or'' (
): disjunctions are computed from left to right2. However, ``parallel and'' (
)
is provided in non-strict contexts,
i.e. the properties of schemas. Thus
is
if one of the properties
is false, independent of possible divergency of the other
property, whereas
will be
always undefined if
is undefined.
An expression inside a complement will not contribute to resolution in
its context. Thus it makes a difference whether distributivity laws for
pushing a complement into expressions have been applied. Moreover,
only certain forms of properties of schemas contribute to resolution.
Hence it is necessary to normalize expressions prior to constructing
their operational semantics. To this end, the disjunctive
normal form of expression is defined as follows:
The representation of schema properties,
,
determines the
contribution to resolution. The form
takes a set
and tests if it is the non-empty set, the form
is a shortcut
for
and tests if
its operand is the empty set. These properties are executed using
residuation, thus all variables in d need to be bounded before the
test can be completed. The form
denotes the
member test of a pattern
in the disjunction
,
where
is reduced by residuation. The form p1 = p2 demands the
unification of two patterns. The variables appearing in the patterns
p, p1, and p2 must be directly bounded by the enclosing
schema.
It can be shown that any flexible appearances of
variables in a property can be converted into a membership-property
together with a sequence of simple equations of flexible variables, x
= x'. By a flexible appearance we mean a variable x used as
in
,
where C is a positive conjunctive context build from intersections
and translations, and
a context of constructor applications.
As an example consider the schema
.
This results in the normalized schema
Values are a subset of normalized expressions, enriched by a tailored
representation of a schema-like construct, called an intension.
An intension consists of a pattern and a constraint.
A basic constraint,
,
is a value assignment
paired with a property expression. Constraints may be composed by
conjunction and by disjunction, though we expect only conjunctions
in intensions (disjunctions are needed later on):
A (partial) equality on values, written as
,
is assumed.
The equality takes commutativity and associativity of unions into
account. Since equality of intensions cannot be decided,
a second relation
is required, which decides inequality.
On base of value equality and inequality, a unification for ``extended
patterns'' build from constructor application, variables, and values,
written as
,
is assumed. This
unification uses
for comparing values found at the
bottom of constructor terms. The form
decides whether unification
fails (using
).
In principle, more powerful notions of unification can be embedded in our framework (e.g. set unification). This would require some technical modifications of the rules given in the next section to deal with sets of unifiers returned by unification instead of a single unifier.
Computation is defined by two relations, which are mutually dependent.
The first relation,
,
describes a
strict reduction step on expressions under the value assignment
.
It cannot be applied to unbound variables, which means in
the context of its usage that the according computation ``suspends''.
The second relation,
,
describes a resolution
step by mapping a constraint into a constraint.
is expected
to be in disjunctive normal form, and
will be so as well.
A few notational conventions for defining these relations are
introduced. We write
for a conjunction of
constraints, and
for a disjunction. For a sequence
of basic constraints,
is written. The
set of free variables used in a constraint can be retrieved by
.
The notation
``refines'' the
assignment
to the assignment
by the result of
unifying
with
.
With
the
propagation of an assignment into a constraint is described,
which distributes over conjunction and disjunction. For basic
constraints we have
,
where
is the
usual composition of mappings. The common assignment of a conjunction
of constraints is extracted with
:
for basic
constraints we have
,
and for
conjuncted ones
iff
and
(
).
The rules for
Rules
to
describe the elimination of
tautologies in set union of values, rules
to
similar for set intersection of values. With
a value sequence context is denoted, where the vi appear
in some order in the sequence. Rules
and
model the combination of intensional values by
intersection. If the patterns can be unified, then we simply
concatenate the constraints of the intensions, making
local existential variables disjunct; if they do not unify,
the intersection reduces to
.
Rule
describes
the distribution of intersection over union values. It should be noted
that in an implementation intersection can be realized more
efficiently as hinted by the rules: given a total order on values, and
set values in a normalized form
,
their intersection can be
realized by processing the extensional part,
,
in linear time,
and then the combinations with the intensional part.
Rule
handles the reduction of a translation to an
intension. It uses the possibility to use existential variables in an
intensions constraint:
may contain variables not bounded by
.
Rule
describes the translation of complement to an
intension.
Rules
to
handle the
-operator. Once the
argument of
has been reduced to a value v, the elements of
v are enumerated by resolving a constraint
.
The state
of this sub-resolution is stored in an intermediate expression
construct,
.
Once the sub-resolution
is in solved form,
,
a unique assignment for
is extracted, if it exists.
The rules for constraint resolution,
,
are
given in Fig. 2. Rule
describes the
left-to-right resolution of disjunctive constraints, rule
the elimination of unsolvable constraints. Rules
and
describe the elimination of unsolvable and solved
constraints in a conjunction, where
is a
sequence context. Rule
describes a resolution step of a
basic constraint in context of a conjunction. This rule models the
concurrent execution of constraints by ``interleaving'', since the
selection of a constraint in the context S is undetermined. The
selected constraint rewrites to a disjunction. The conjunction
context S is expanded for each member of this disjunction.
In an implementation, this expansion can be implemented by
backtracking (Sect. 4).
Rules
to
handle the reduction of
expressions to values in basic constraints by
.
Rule
decomposes the
membership test on a value union into disjuncted
constraints. Rule
and
describe a basic resolution step,
reducing a membership-test on a singleton set to an assignment or a
failure. Rule
and
describe the resolution
of a member-ship test on an intension. The constraint of the intension
is imported into the current resolution. Variables used in the
intension's pattern and constraint are renamed by
to fresh
ones. Finally, rules
and
model the resolution of a
pattern equality.
Rules
to
handle the resolution of tests of
emptiness and non-emptiness of sets. Similar to the treatment of
in expression reduction, a sub-resolution is started which
enumerates the elements of the set v by resolving the constraint
.
The state of this resolution is stored in an intermediate
property expression,
,
where s is
either
or
,
depending on the pole of the test.
The test succeeds (resp. fails, depending on s) if at least one
constraint can be solved, it fails (resp. succeeds) if no constraint
can be solved (which requires to enumerate the entire set).