Initial algebra semantics
Instructor's Guide
intro,
types,
algebra,
modules,
classes,
summary,
Q/A,
literature
In the previous section we have given a rather operational
characterization of the equivalence relation induced by
the equational theory and the process of term rewriting
that enables us to purge the generator universe of a type,
by eliminating redundant elements.
However, what we actually strive for is a mathematical
model that captures the meaning of an algebraic
specification.
Such a model is provided (or rather a class of such models)
by the mathematical structures known as
(not surprisingly) algebras.
A single sorted algebra
A\skipx is a structure
A\skipx
where A is a set of values, and
A\skipx specifies the signature
of the functions operating on A.
A multi-sorted algebra is a structure
A\skipx
where S is a set of sort names and
As the set of values belonging
to the sort s.
The set S may be ordered (in which case the ordering
indicates the subtyping relationships between the sorts).
We call the (multi-sorted) structure
As a
Σ-algebra.
Σ-algebra
slide: Interpretations and models
Having a notion of algebras, we need to have a way in which
to relate an algebraic specification to
such a structure.
To this end we define an interpretation
eval : TΣ → A\skipx
which maps closed terms formed by following the rules
given in the specification to elements of the structure
A\skipx .
We may extend the interpretation eval to include
variables as well (which we write
as
A\skipx ), but then we also need to assume
that an assignment
θ: X → TΣ(X) is given,
such that when applying
θ: X → TΣ(X) to a term t the result
is free of variables, otherwise no interpretation in
A\skipx exists.
See slide [8-algebra].
Interpretations
As an example, consider the interpretations
of the specification of Bool and
the specification of Nat, given in slide [8-B-N].
A\skipx
slide: Interpretations of Bool and Nat
The structure
B\skipx given above is simply a boolean algebra, with
the operators
B\skipx ,
B\skipx and
B\skipx .
The functions not, and and or naturally map to their semantic counterparts.
In addition, we assume that the constants true and false map
to the elements tt and ff.
As another example, look at the structure
B\skipx and the
interpretation
B\skipx , which maps
the functions S, mul and plus specified
in Nat in a natural way.
However, since we have also given equations for Nat
(specifying how to eliminate the functions mul and plus)
we must take precautions such that the requirement
N\skipx \models eval N\skipx (t1) = N\skipx eval N\skipx (t2) \desdak ENat \vdash t1 = t2
is satisfied if the structure
N\skipx \models eval N\skipx (t1) = N\skipx eval N\skipx (t2) \desdak ENat \vdash t1 = t2 is to count as an adequate
model of Nat.
The requirement above states
that whenever equality holds for two interpreted
terms (in
N\skipx ) then these terms must also be provably equal
(by using the equations given in the specification of Nat),
and vice versa.
As we will see illustrated later, many models may exist
for a single specification, all satisfying the requirement
of adequacy.
The question is, do we have a means to select one of these
models as (in a certain sense) the best model.
The answer is yes.
These are the models called initial models.
Initial models
A model (in a mathematical sense) represents the meaning
of a specification in a precise way.
A model may be regarded as stating a commitment with
respect to the interpretation of the specification.
An initial model is intuitively the least committing
model, least committing in the sense
that it imposes only identifications made necessary by
the equational theory of a specification.
Technically, an initial model is a model from which
every other model can be derived by an algebraic mapping
which is a homomorphism.
- ΣE-algebra - M\skipx = ( TΣ / ∼ , Σ/ ∼ )
- no junk - \A a : TΣ / ∼ \E t [e\dot]val M\skipx (t) = a
- no confusion - M\skipx \models t1 = t2 \desdak E \vdash t1 = t2
slide: Initial models
The starting point for the construction of an initial model
for a given specification with signature
- ΣE-algebra - M\skipx = ( TΣ / ∼ , Σ/ ∼ )
- no junk - \A a : TΣ / ∼ \E t [e\dot]val M\skipx (t) = a
- no confusion - M\skipx \models t1 = t2 \desdak E \vdash t1 = t2
is to
construct a term algebra
TΣ with
the terms that may be generated from the signature
Σ
as elements.
The next step is then to factor the universe of generated
terms into equivalence classes, such that
two terms belong to the same class if they can be proven equivalent
with respect to the equational theory of the specification.
We will denote the representative of the equivalence class to
which a term t belongs by
Σ.
Hence
t1 = t2 (in the model) iff
t1 = t2.
So assume that we have constructed a structure
M\skipx = (TΣ / ∼ , Σ) then; finally, we must define an interpretation,
say
M\skipx = (TΣ / ∼ , Σ) , that assigns closed
terms to appropriate terms in the term model
(namely the representatives of the equivalence class of that term).
Hence, the interpretation of a function f in the structure
M\skipx = (TΣ / ∼ , Σ)
is such that
M\skipx = (TΣ / ∼ , Σ)
where
M\skipx = (TΣ / ∼ , Σ) is the interpretation of f in
M\skipx = (TΣ / ∼ , Σ) .
In other words, the result of applying
f to terms
f
belongs to the same equivalence class as the result
of applying
f M\skipx to the representatives of the
equivalence classes of
t1,…,tn.
See slide [8-initial].
An initial algebra model has two important properties,
known respectively as the no junk and no confusion
properties.
The no junk property states that for each element of the
model there is some term for which the interpretation in
t1,…,tn
is equal to that element.
(For the
TΣ / ∼ model this is simply a representative of
the equivalence class corresponding with the element.)
The no confusion property states that if equality of two
terms can be proven in the equational theory of the specification,
then the equality also holds (semantically) in the model,
and vice versa.
The no confusion property means, in other words, that
sufficiently many identifications are made
(namely those that may be proven to hold),
but no more than that (that is, no other than those
for which a proof exists).
The latter property is why we may speak of an initial model
as the least committing model; it simply gives
no more meaning than is strictly needed.
The initial model constructed from the term algebra
of a signature
TΣ / ∼ is intuitively a very natural model
since it corresponds directly with (a subset of) the
generator universe of
Σ.
Given such a model, other models may be derived from it
simply by specifying an appropriate interpretation.
For example, when we construct a model for the natural
numbers (as specified by Nat) consisting of the
generator universe
Σ
and the operators
Σ
(which are defined as
Σ,
Σ
and
Σ)
we may simply derive from this model
the structure
({0,1,2,…}, {++, +, ∗})
for which the operations have their standard arithmetical
meaning.
Actually, this structure is also an initial model for
Nat, since we may also make the inverse transformation.
More generally, when defining an initial model only
the structural aspects
(characterizing the behavior of the operators) are
important, not the actual contents.
Technically, this means that initial models
are defined up to isomorphism, that is a mapping to
equivalent models with perhaps different contents
but an identical structure.
Not in all cases is a structure derived from an initial model itself
also an initial model, as shown in the example below.
Example
Consider the specification of Bool as given before.
For this specification we have given the structure
({0,1,2,…}, {++, +, ∗}) and the interpretation
eval B\skipx which defines
an initial model for Bool. (Check this!)
eval B\skipx
slide: Structure and interpretation
We may, however, also use the structure
B\skipx to
define an interpretation of Nat.
See slide [8-structure].
The interpretation
eval B\skipx : TNat → B\skipx is such
that
eval B\skipx : TNat → B\skipx ,
eval B\skipx (Sx) = ¬eval B\skipx (x),
eval B\skipx (Sx) = ¬eval B\skipx (x) and
eval B\skipx (plus(x,y)) = xor(eval B\skipx (x),eval B\skipx (y)),
where
xor(p,q) = (p ∨q) ∧(¬( p ∧q )).
The reader may wish to ponder on what this interpretation
effects.
The answer is that it interprets Nat as
specifying the naturals modulo 2, which discriminates
only between odd and even numbers.
Clearly, this interpretation defines not an initial model,
since it identifies all odd numbers with ff and all even numbers with tt.
Even if we replace ff by 0 and tt by 1, this is not what we
generally would like to commit ourselves to when we speak
about the natural numbers,
simply because it assigns too much meaning.