[CSUSB] >>
[CompSci] >>
[Dick Botting]
>> [Papers & Essays]
>>
rjb95x.semantics
[Index]
|| [Contents]
Disclaimer. CSUSB and the CS Dept have no responsibility for it.
This is a Beta Version, read at your own risk.
Copyright. Richard J. Botting(Sun Jul 6 10:03:42 PDT 2003). This paper is being developed for
publication. Permission is granted to quote parts of it as
long as the source is acknowledged and the author informed.

Relational semantics is an extension of Denotational semantics where the denotation of a component of a language can be either a function (total, many to one) or a relation (any to any). Here I show that the result unifies the natural operational
semantics with the denotational method giving simple, structural, natural and compositional semantics can be if one uses mathematical relations.

This work benefits from Dana Scott's work on complete partial orders and fixed points. For more see
Nielsen and Nielsen 92

In my approach you present a set of equations that for each statement S define a relationship between s and s' in terms of the components of S. Thus we get a set of compositional equations for the natural semantics. To show this I define the
syntax and semantics the classic "While" Language used in all theoretical work and textbooks of programming language semantics:
[grammar_of_While]

This form of semantics benefits from the well developed theory and calculus of binary relations. I exploit the isomorphism between relations and sets of pairs, and the fact that functions (partial or total) are special kinds of relations. The key
concepts and notations are listed below:
[Calculus of Relations]

The set of relations on a set is a ready made domain or complete partial ordered set in the following sense. First, the set of binary relations on a set X is a partial order under inclusion(==>). The relations form a poset. Second, there is a unique
bottom and top element: the bottom(greatest lower bound) of the poset is the null relation and the top(least upper bound) the anything-to-anything relation. Finally, given any relation, R on X, the Kleene sequence:

(limit): do(R).
The above formulae use notations for the identity relation(Id), the union(|) and composition(;) of relations, and the reflexive and transitive closure(do) of relations: See
[Calculus of Relations]

I use a generalized version of BNF to define Syntax and Semantics called XBNF. The syntax is defined in a form close to traditional EBNF. The semantics is defined by a grammar of functions and relations. The details are below:
[XBNF]

I use the same symbol m to indicate denotations: m(C) indicates the "meaning of C". The symbol m indicates the function that maps C into m(C). For each syntactic category Syn, there is a set of meanings - a semantic domain Sem say, and
m maps each element of Syn into and element of Sem:

The semantic domain is determined by the Syntax of the argument to which m is applied: For example m("101") gives a number but m("while 1<x do x:=x-1") is a relationship between describing what can possibly happen. See
[CoProducts]
for the justification of this idea.

Two items C1, C2 in the same syntactic category are equivalent if and only if m(C1) = m(C2). Items in different syntactic categories can not be equivalent.

In the following I assume that we have the whole of abstract algebra available to us when we wish to define how a program behaves. The alternative is to spend time re-inventing wheels. The necessary algebras are listed in this section. They are used in
the following section:
[Semantic Equations]

In the While language without declarations, each identifier always identifies the same variable. I introduce a function that associates each symbol in Var with a corresponding name of a field in record structure (or labelled tuple). The set of all
possible records is called the State:

The semantic domain for Aexp is typically those of numbers - values in the target algebra. However because I start from assuming that we have an abstract algebra (not just an abstarct data type) we can associate each Aexp in While to an
expression in the algebra of number -- in the set expression(number). We can now use these expressions in predicates and get simpler rules defining the behavior of assignments.

A relation R:Change is
[determinstic]
when for each s there is no more thn one s' such that s R s'. A relation is
[total]
when for each s the is at least on s'. Functions are both total and deterministic. Partial functions a determinsic but not total.

Exercise: Show that all conditions are deterministic. Show that all Actions are deterministic.

Exercise: Is m on Num a total function or a partial function? Is it a one-to-one function or many-to-one function? If many to one derive a congruence so that modulus the congruence semantically equivalent.

m::Var->expression(number).
In fact I assume that for each item in Var (say "x") there is a corresponding component in a state record that is used to express numbers. See below:
[State Space]
for a more typical model of such a state space.

Suppose Var={"x", "y" , "z" } then State = Net x,y,z::number End Net, and an typical state would by s=State(x=>1, y=>2, z=>3). The function m=("x"+>x | "y"+>y | "z"+> z) relates each symbolic string to its componet in the state space. Hence, m("x) =x
and s.m("x")=1 and s.m("y")=2 and s.m("z")=3.

Suppose Var={"x", "y" , "z" } then State = Net x,y,z::number End Net, and an typical state would by s=(x=>1, y=>2, z=>3). The function m=("x"+>x | "y"+>y | "z"+> z) relates each symbolic string to its componet in the state space. Hence, m("x) =x and
s.m("x")=1 and s.m("y")=2 and s.m("z")=3. So
:. m("x+y") = m("x") + m("y") = x+y.

However, m("x+y") is not 3 but x+y. In state s=(x=>1, y=>2, z=>3), though, x+y does have the value 3. By mapping strings in While into mathematical expressions (rather than values) this approach uses the algebra of the expressions to reason about
them.

Exercise: Is m on Aexp a total function or a partial function? Is it a one-to-one function or many-to-one function? If one to one prove that it, therwise find a equivalence relation so that semantically equivalent Aexp's are equivalent.

Exercise: How do you prove the following Aexp are equivalent?

"(x+y)+z" equivalent "x+(y+x)"
Write down half a dozen similar properties of the arithmetic expressions of While that must follow from this semantics.

The Boolean operations (and,or) on predicates define conditions that are related to the set theoretic operators of intersection and union: { s || P and Q} = {s||P} & {s||Q} and so to the
[Calculus of Relations]

I define m:(Aexp Op Aexp)->Condition in terms of two auxilary functions:

Suppose Var={"x", "y" , "z" } then State = Net x,y,z::number End Net, and a typical state would by s=State(x=>1, y=>2, z=>3). The function m=("x"+>x | "y"+>y | "z"+> z) relates each symbolic string to its componet in the state space. Hence, m("x) =x
and s.m("x")=1 and s.m("y")=2 and s.m("z")=3. So
:. m("x>y /\ z<2") = (m("x") >m("y")) and (m("z") < m("2") ) = ( x>y and z <2 ).

So "x>y /\ z<2" means the relation that does not change states and where (x>y and x<2) and does not permit any other state to proceed:
() rel[s,s']( s=s' and s.x>y.x and s.z<2) = Id & {(s,s')|| s.x>y.x} & {(s,s')|| s.z<2}.

Exercise: Is m on Bexp a total function or a partial function? Is it a one-to-one function or many-to-one function? If one to one prove that it, therwise find a equivalence realtion so that semantically equivalent Aexp's are equivalent.

Exercise: Show that for all b, m(b) is a Condition. Prove that it is there deterministic but not total. For which Bexp is m(b) a function? and which function is it?

The following relation semantics of While a natural semantics. The meaning of a statement is a relation that is defined to hold between s and s' precisely when the statement terminates in state s' when started in s'. It seems possible to develop
a set of relational equations that define the structural operational semantics of a statement - where the relation holds between successive states as the program executes. To find out more see
[Structural Operational Semantics]

below.

For S:Stm, m(S)::Change=Statement S terminates is state (2nd) if started in state (1st).

Note. These are a compositional definition: the meaning of each statement is expressed in terms of the meanings of its components in the syntax. In other words the definition is driven by the structure of the data.

Exercise: Is m on Stm a total function or a partial function? Is it a one-to-one function or many-to-one function? If many to one derive a congruence so that modulus the congruence semantically equivalent, , otherwise prove that the function is
one-one.

Exercise: Show that all assignents are Actions.

A statement S is deterministic if m(S) is deterministic in tha above syntax.

Exercise: Show that x:=a and skip are deterministic. Show that if the components of a sequence, selection, or itteration are deterministic then so are the compounds.

Exercise: From the previous exercise, can we deduce that all While programs are deterministic? Can you explain your answer? Can you present a formal proof of your answer?

Exercise(For Mathematicians) : In how many different senses is m a homomorphism between two systems? Is it a isomorphism, monomorphism, homeomorphism, etc.

Exercise(Advanced) : Suppose one started by defining m as function mapping some strings into a family of disjoint meanings, as above. Further suppose that every partial definition is compositional. Show that a context free grammar can be deconstructed
from the functions. Show that m is total on the language of your deconstructed grammar.

In the above collection of semantic equations m is nearly always distributed to all the parts of the construct being assigned a meaning. A few examples would show that every construct in While is mapped directly into a simple expression in the
calculus of relations.

I conclude that we could use the calculus of relations as our ultimate semantic metalanguage. I claim that, relations even forms an uniquely interesting and powerful programming language of their own. They are interesting because they are the only
piece of existing mathematics is already a programming language. They are powerful because they can express concurrency and non-determinism.

The formal model usually presented of a variable is a function s:Var->Val for some set of values. Thus if v:Var then s(v) \in Val. I assume that there is a labelled Cartesian Product or tuple where each v:Var has an associated label l and if
's:State' then s.l \in Val indicates the value of v in state s. I claim that this is effectively a simple change of notation.

When a predicate has no dynamic variables then it expresses a condition - a set of states that will not change, but can only be satsified by some states and not others (in general). For example x+y>0 is satisfied by the set of states `{ s || s.x+s.y
>0} and defines the relationship { s,s' || s=s' and s.x+s.y >0}`.

The formula
(sample) x'= e
is an example of a dynamic predicate that describes a change in variable x with other variables being held constant. The new value of x is the value of the expression e using the old value of x. Or to be more precise: e is evaluated using
values from the old state, and then the x component of the state is changed to the value of e.

Note: this is true for While, but is not true for soem extensions of While.

It might be wondered why it is worth have a more complex and less abstract way of stating the semantics of a programming language. One reason is that Natural semantics can not express the idea of a single step in a program and so can not define the idea
of interleaving the steps from two parallel programs.

An interesting question for further research is to find a set of compostional equations for the N relation to replace the derivation rules for ";", "if", and "while".