In this section the definition of the µZ calculus is given: its syntax, semantics, and equational theory. As the meta language we loosely orient at the Z notation.
Let
be variable symbols, and let
be (term) constructor symbols. The µZ calculus knows the
syntactic categories of expressions, and a subset of them,
patterns:
The form
describes a constructor
application, where
is a sequence of expressions. (We
generally use the convention to denote sequences of terms t by
.) The set of patterns
are those
expressions which are solely build from constructor application to
patterns,
,
and variables,
.
The form
denotes a singleton set. The form
is the singleton set selection, which returns the element of a
singleton set, and is undefined for each other set. The usual forms
for set algebra are provided: the empty set is denoted by
,
set intersection by
,
set union by
,
and set complement by
.
The form
describes the
translation of the set
,
and is not so familiar (it
may found its roots in category theory). The result of translation
consists of all elements which match against
,
such that
there exists an element in
which matches against the pattern
under the same substitution. Thereby, both patterns may
contain unbound variables, which may be denoted by wildcards (_).
For example, the cartesian product of two sets,
,
can be expressed in µZ as
(with
the constructor
symbol for pairs used in mixfix notation). Vice versa, the range of a
binary relation
(a set of pairs) is denoted as
.
We call a translation with
an embedding and with
a hiding. Note
that there might exist translations which are neither embeddings or
hidings.
The form
describes a set-comprehension, or
a schema in Z speech. It denotes the set of values which match
the pattern
such that the boolean expression
is true
under the binding of variables resulting by the match. A boolean
expression is thereby just a set-expression over the element type of
units (a type containing just one element): let
be the
0-ary constructor for this element, then truth is the set
,
falsity the empty set, conjunction
intersection, disjunction union, and negation complement. For
example, the (sugared) schema
describes the set of triples where each member is larger then the
previous one. The boolean expression x < y thereby is syntactic
sugar for the form
(where
is a binary
relation, a set of pairs). The conclusive translation can be read as:
we are not interested in the actual result of the intersection, we
just want to know if it is empty or not.
The form
describes the smallest member of the set
(where the equality abbreviates
).
The order needed here is discussed in Sect. 2.3.
If a smallest member does not exists, the form is undefined.
The µZ calculus uses a shallow-polymorphic type system which, since
it is fairly standard, is not made explicit within this paper. To
this end, constructors
have associated a (generic) type,
and expressions are assumed to have a principal type.
A further condition for well-formedness is that patterns in
translations and schemas are used linear (no variable is allowed to
appear twice).
For commonly used forms of expressions, syntactic sugar is
used:
Before we take a closer look on the meaning of µZ expressions, the translation of Z into µZ is discussed. A brief comparison with the functional logic language Curry [7] is also given, anticipating some basics about the computation model of µZ.
The operations of the simple-typed
-calculus contained in Z
are mapped as follows:
We have already noted that predicate expressions are a special case
of set-expressions over the element type of units, and have defined
abbreviations for the basic predicates of membership-test and
equality. To make the picture complete, here is the mapping of
quantifiers:
In Z, a schema denotes a set of bindings, where bindings are
tuples (records) with named components. The set is constraint by the
declarations of a schema as well as by the property. For example, the
Z schema
denotes the set of bindings
,
where
,
,
and x <
y. Assuming appropriate µZ constructors for bindings, the above Z
schema is mapped to µZ by
(the constraint
vanishes
since
is a given type). The property x < y is further translated
as described in the previous section.
The connectivities of the schema calculus easily map as well. Schema
conjunction in Z,
,
is the set of bindings with the
joined signature of S1 and S2 where components with the same
name are identified. This is expressed in µZ as
,
where
is the pattern
for the joined signature, and the same pattern variables are chosen at
the identified positions. Existential schema quantification,
,
is mapped to
(where
denotes the removal of the components
from S in S'. Similarly, the remaining connectivities of the
schema calculus are mapped.
Languages such as Curry[7] can be mapped in principle to µZ. The exact operational semantics of such a mapping will not be the same, since for example in µZ a strict reduction order is preferred by design. An illustration of such a mapping is helpful anyway.
A function definition in Curry with constraints is mapped as follows
(where the fresh variables yi below must not appear in the patterns
):
The computation model of µZ as described later on executes
constraints concurrently, using both residuation as well as backtracking to deal with free variables. An access to a free
variable is generally suspended in a nested context. This is for
example the case for arguments of the
-operator, (and therefore
for function application e e' which is defined using
), or
for negative constraints. Backtracking may take place for constraints
which map to the membership test of a pattern in a set. For
illustration consider the definition of an ``append'' relation
on lists. Below a shortcut for introducing local variables is used:
is equivalent to
:
µZ is higher-order since sets can be stored in variables - and the relation app as defined above is nothing more than a set. Yet, as Curry, the µZ's computation model does not employs higher-order unification. This restriction is, however, not bounded to the notion of a type of a value (whether it is a set or not) but to the representation: sets which are extensionally represented are incorporated by a simple equality test in unification. An extensional representation is given by applying constructors, singleton sets, and set union to extensional values.
We will not give a detailed semantic mapping here, but only discuss
the principles. The model of µZ is based on a hierarchical typed
universe, where sets are represented as partial characteristic
(boolean) functions in a set-theoretical meaning, which can be
founded by Z itself or by ZF set theory [18]. This
representation of sets is a generalization of partial three-point
logics [13] to the case of set-algebra. There are three
observation to be made about a set represented as a partial
characteristic function: an element is member (it is in the domain and
is mapped to true), an element is not member (it is in the domain and
is mapped to false), or it is unknown to be member or not (it is not
in the domain). As a result, we are able to give expressions of the
kind
a meaning: for 0, membership
is unknown, for all other numbers it is known (1 is member and the
other numbers are not).
Indeed, for infinite sets the test whether an element is in the domain
of a characteristic function is not computable, but it is possible to
delay the need for this computation. For example,
the intersection of two sets represented by partial characteristic
functions is defined as
,
where the conjunction can be executed by ``parallel and''. Thus the
meaning behaves compositionally:
is a set with no unknowns. This is
a prerequisite for a clean equational theory of µZ.
The valid laws will be discussed in more detail in the next
section. In particular, we will see that De-Morgan's laws hold, such
that a disjunctive normal form can be constructed.
To give the fixed-point operator of µZ a meaning, an order on values
need to be defined. Since we have union and intersection as total
functions on sets, a µZ set constitutes a complete lattice,
with the empty set (the total characteristic function constantly
delivering false) the bottom element and the universal set of the
according type the top element. The order for fixed-point construction
is derived from this:
.
The order is pointwise lifted to values yielded from constructor
application. Since we are not in a constructive world a
priori,
might be not defined, since e may not be
monotonic.
µZ has a rich equational theory which can be used for partial evaluation and even for providing a narrowing semantics by plain expression transformation. Within this section, we will only discuss those laws which are necessary for establishing a disjunctive normal form as needed for the computation model.
The set operators of µZ follow the usual laws for boolean
algebras. Commutativity and distributivity of union and
intersection hold,
and De Morgan's laws are satisfied
such that we can build a conjunctive or disjunctive normal form.
However, because of partiality, the principle of excluded middle does
not hold (
does
not hold). Yet, we have
,
and excluded middle for the case of singleton sets:
.
A singleton set containing a constructor application with arity greater
zero can be decomposed into an intersection of embeddings as follows:
Several laws regarding set translation are of interest.
Consecutive translations are composable, if the intermediate patterns
can be unified. If they cannot be unified, consecutive translation
reduces to the empty set.
Any translation distributes over set union. A translation by an
embedding distributes over set intersection.
A translation which is neither hiding or embedding can be
split into an embeddings and a consecutive hiding. Any hiding
can be lifted out of an intersection, by widening the scope of the
hidden variables. The last two laws read as follows:
Unfortunately, set complement does not distribute over translation,
and translation cannot be lifted out of a complement in the general
case. It is notable in this context that the complement of a hiding is
related to a
-quantor:
maps to
.
The fact
that complement cannot be pushed to the leaves is a hint to the
necessary incompleteness of any computation model.
Schema construction distributes over union and intersection:
,
and similarly
for intersection. Set complement distributes over schema construction
as follows:
.
Those elements need to be added which are in the complemented schema's meaning
since they do not match the pattern
.