# Semantics And Applications � Class Notes from Lecture 2

Document Sample

```					                 Semantics And Applications –
Class Notes from Lecture 2
Uri Israeli
Natalia Cherniavsky

Operational Semantics
• Natural Semantics – how the overall result of executions are
obtained (previous lecture).
• Structural Semantics – how the individual steps of the
computations take place (current lecture).

Properties of natural semantics

Semantic Equivalence
Two statements are semantically equivalent if the semantics cannot
distinguish between them.
Formally: Two statements S1 and S2 are semantically equivalent if for all
states σ and σ' : <S1, σ> → σ’ if and only if <S2, σ> → σ’.

Example: the statement "while b do S" is semantically equivalent to:
“if b then (S ; while b do S) else skip”.
Proof: See page 26 (chapter 2) in the Nielsen and Nielsen Textbook.

More examples:
• “skip; com” is semantically equivalent to “com”.
• “com; skip” is semantically equivalent to “com”. skip is neutral!
• “((com1 ; com2) ; com3)” is semantically equivalent to
“(com1 ;( com2 ; com3))”
Note: concatenation is associative but not commutative. For
example: “x:=3; x:=2” is not semantically equivalent to
“x:=2;x:=3”.
• “(X := 5; Y := X * 8)” is semantically equivalent to
“(X :=5; Y := 40)”.

Determinism
A natural semantic is deterministic if for all choices of a statement S and
states σ, σ', σ'':
<S, σ> → σ' and <S, σ> → σ'' implies σ’ = σ''.
Theorem: The natural semantics of IMP is deterministic
Proof: See page 29 (chapter 2) in the Nielsen and Nielsen Textbook.
The Semantic Function Sns
The Determinism property leads us to a definition of the semantic
function Sns . The meaning of commands can now be summarized as a
(partial) function from State to State. We define:
Sns: Com → (State y State)
This means that for every command S we have a partial function
Sns’S÷ ∈{State y State} which is given by:

Note that Sns is well defined if and only if the natural semantics is
deterministic.
The object in the ’ ÷ brackets is a syntactic object (program statement)
and the object in the ( ) brackets is a semantic object (state).
Examples:
• Sns’while true do skip÷ (σ) = undef
• Sns’skip÷ (σ) = σ
• Sns’X:=1÷ (σ) = σ [1/X]
Note that the result is undef when there is no state that can be reached by
executing the command.

Structural Operational Semantics
In Structural Operational Semantics the emphasis is on the individual
steps of the execution of the execution. The transition relation has the
form: <com, σ> ⇒ γ . The transition expresses the first step of the
execution of S from state σ.
γ can have two forms:
• <com', σ'>, in which case the execution of com from σ is not
completed and the remaining computation is expressed by the
intermediate configuration <com', σ'>.
• σ', in which case execution of com from σ is terminated and the
final state is σ'.
• We say that <com, σ> is stuck if there is no γ such that
<com, σ> ⇒ γ. This means that the computation is not completed
yet but there’s no where to move on. For example if there was a
runtime error, there won’t be any rules describing that.

SOS (IMP)

The following two rules are almost the same as in the Natural Semantics
since these two statements are fully executed in one step.
•   <skip, σ> ⇒ σ

•   <a, σ> → m         .
<X := a, σ> ⇒ σ[m/X]

The following two rules express that to execute com1; com2 in state σ, we
first execute com1 on step from σ:
• If the execution of com1 has been completed we can start the
execution of com2.         <com1, σ> ⇒ σ’                    .
<com1; com2, σ> ⇒ <com2, σ’>
• If the execution of com1 has not been completed then we have to
complete it before starting the execution of com2.
<com1, σ> ⇒ <com1’, σ’>           .
<com1; com2, σ> ⇒ <com1’; com2, σ’>
The following two rules express that to execute a conditional (if-then-
else) in state σ, we first perform the test and then select the appropriate
branch:
•         <b, σ> ⇒ true                             .
<if b then com1 else com2, σ> ⇒ <com1, σ>
•         <b, σ> ⇒ false                            .
<if b then com1 else com2, σ> ⇒ <com2, σ>
Finally, we have a rule for “while”. Here, in one step we convert the
statement to a semantically equivalent statement (however- more
complicated). We unfold one level of the “while”.
• <while b do com, σ> ⇒
<if b then (com; while b do com) else skip, σ>

Derivation Sequences:
♦ A finite derivation sequence of configurations starting at <S, σ> is
γ0, γ1, γ2… γk such that:
γ0 = <S, σ> (initial state), γi ⇒ γi+1, and γk is either a finite state or a
stuck configuration. A finite derivation sequence means a
computation that has terminated.

♦ An infinite derivation sequence of configurations starting at <S, σ>
is γ0, γ1, γ2… γk such that: γ0 = <S, σ> (initial state), γi ⇒ γi+1.
An infinite derivation sequence means a computation that does not
terminate.
i
♦ We write γ0 ⇒ γi to indicate that there are i steps in the execution
from γ0 to γi.
*
♦ We write γ0 ⇒ γi to indicate that there is a finite number of steps in
the execution from γ0 to γi.
* note that γ0 ⇒i γi and write γ0 ⇒* γi need not be derivation sequences. They will be
so iff γi is either a finite state or a stuck configuration.

♦ For each step there is a derivation tree.

Example 1:
Consider the statement: (z:=x; x:=y); y:=z and let σ0 be a state that maps:
σ0(x) = 5, σ0(y) = 7. (Assume that all other variables are mapped to 0).
We then have the derivation sequence:
<(z:=x; x:=y); y:=z, σ0> ⇒ <x:=y; y:=z, σ0[5/z]>
⇒ <y:=z, (σ0[5/z])[7/x]>
⇒ ((σ0[5/z])[7/x])[5/y]
Corresponding to each of these steps we have derivation trees explaining
why they take place. For the first step:
<(z:=x; x:=y); y:=z, σ0> ⇒ <x:=y; y:=z, σ0[5/z]> the derivation tree is:

<z:=x, σ0> ⇒ σ0[5/z]                 _
<z:=x; x:=y, σ0> ⇒ <x:=y, σ0[5/z]>        _
<(z:=x; x:=y); y:=z, σ0> ⇒ <x:=y; y:=z, σ0[5/z]>

Example 2:
Consider the statement: “y:=1; while ¬(x=1) do y:=y*x; x:=x-1” and let
σ be a state that maps: σ(x) = 3.
The first step of execution from the configuration
<y:=1; while ¬(x=1) do y:=y*x; x:=x-1, σ> will give the configuration
<while ¬(x=1) do y:=y*x; x:=x-1, σ[1/y]>. The next step of the
execution will rewrite the loop as a conditional so we get:
<if ¬(x=1) then ((y:=y*x; x:=x-1);
while ¬(x=1) do (y:=y*x; x:=x-1)) else skip, σ[1/y]>
The following step will perform the test and yield the configuration
<(y:=y*x; x:=x-1); while ¬(x=1) do (y:=y*x; x:=x-1)), σ[1/y]>
Next we obtain:
<x:=x-1; while ¬(x=1) do (y:=y*x; x:=x-1)), σ[3/y]>
The next configuration will be:
<while ¬(x=1) do (y:=y*x; x:=x-1)), σ[3/y][2/x]>.
Continuing in this way we eventually reach the final state σ[6/y][1/x].
Program Termination
Using the concept of derivation sequences we define program
termination. We say that the execution of a command "com" on a
statement σ :
• terminates iff there exists a finite derivation sequence starting with
<com, σ>
• loops iff there is an infinite derivation sequence starting with
<com, σ>
There are 2 ways in which a command can terminate:
• successfully, if <com, σ> ⇒* σ' for some state σ'.
• terminate in a stuck state.

Finally, we say that a command "com":
• always terminates if it terminates for all states.
• always loops if it loops for all states
Example: "while true do skip" always loops.

Note: in Natural semantics a command always terminates. (Non-
terminating computations are not explicitly represented).

Properties of structural semantics
Like in Natural Semantics, we define properties on Structural Semantics.

Semantic Equivalence
Two commands "com1" and "com2" are semantically equivalent if:
• for all states σ and σ' - <com1, σ> ⇒* σ' iff <com2, σ> ⇒* σ'
• there is an infinite derivation sequence starting at
<com1, σ> iff there is an infinite derivation sequence starting at
<com2, σ>
By this definition we ensure that com1 and com2 act identically on all
finite and infinite computations.

Example
We show that com;Skip and com are semantically equivalent:
Let σ be some state. There are 2 cases to be taken care of:
1. <S, σ> ⇒* γ where γ is a configuration that is either stuck or
terminal.
2. There is an infinite derivation sequence starting from <S, σ>

Assume that <S, σ> ⇒* γ (1st case). So:
If γ = σ' (meaning that σ' is a terminal state) then there is a finite
derivation sequence from <S, σ> that leads to σ': <S, σ> ⇒* σ’. So the
same derivation sequence will lead <S; skip, σ> to          <skip, σ'>
(according to the deterministic property which states that there is exactly
one derivation sequence starting at configuration <S, σ>, and also
according to the “concatenation” rule). Next, according the “skip” rule we
get <skip, σ'> ⇒ σ'. And over all we get:
<S; skip, σ> ⇒* <skip, σ'> ⇒ σ'.
If γ is a "stuck" configuration then <S; skip, σ> will also lead to a "stuck"
configuration because the execution of S in state σ will lead us to it.
Now assume that There is an infinite derivation sequence starting from
<S, σ> (2nd case). So there is also an infinite derivation sequence from
<S; skip, σ>. This is because the execution of S will occur first and lead
us to the same infinite derivation sequence. (Again, this is according to
the deterministic property).
The other direction:
Staring from <S; skip, σ> is analogue to what we've shown. This is
because skip is a "neutral" command, meaning it does not change the
state. So any result we get from <S; skip, σ> is a result only from the
execution of S.
For example if there is an infinite derivation sequence starting at <S; skip,
σ> then we conclude that the same derivation sequence starts at <S, σ>.
Because we know that there for any state s, <skip, s> leads to s
(terminal!).

Determinism
We say that a Structural Semantic is deterministic if:
<com, σ> ⇒* σ' and <com, σ> ⇒* σ'' implies σ'= σ''

Theorem: SOS(IMP) is deterministic.
Proof: by induction on length of derivations sequences.

Sequential Composition
We say that a Structural Semantic holds the property of Sequentinal
composition if for every 2 command "com1" and "com2" and for every
sate σ it holds that:

If <com1; com2, σ > ⇒k σ’’ then there exists a state σ’ and numbers k1
and k2 such that:
• <com1, σ > ⇒k1 σ’
• <com2, σ’> ⇒k2 σ’’
• k = k1 + k 2

Example:
<x:=2 ; while x>0 do x:=x-1, σ> ⇒ <while x>0 do x:=x-1, σ[2/x]> ⇒
<if (x>0) then (x:=x-1;while x>0 do x:=x-1) else skip, σ[2/x]> ⇒
<x:=x-1;while x>0 do x:=x-1, σ[2/x]> ⇒ <while x>0 do x:=x-1, σ[1/x]>
⇒ <if (x>0) then (x:=x-1;while x>0 do x:=x-1) else skip, σ[1/x]> ⇒
<x:=x-1;while x>0 do x:=x-1, σ[2/x]> ⇒ <while x>0 do x:=x-1, σ[0/x]>
⇒ <if (x>0) then (x:=x-1;while x>0 do x:=x-1) else skip, σ[0/x]> ⇒
<skip, σ[0/x]> ⇒ σ[0/x].

So we see that <x:=2 ; while x>0 do x:=x-1, σ> ⇒9 σ[0/x]. And there
exists a state σ’ = σ[2/x] and numbers k1 = 1, k2 = 8 such that:
• <x:=2, σ> ⇒k1=1 σ’ =σ[2/x]
• <while x>0 do x:=x-1, σ’> ⇒k2=8 σ[0/x]

Theorem: SOS(IMP) has the property of sequential composition.
Proof: by induction on length of derivations sequences.

The Semantic Function SSOS
As in Natural Semantics, we define a semantic function. The meaning of
a command com is defined as a partial function from State to State.
We define:
SSOS: Com → (State y State)
SSOS’com÷(σ) = σ’ if <com, σ> ⇒*σ’ and otherwise Ssos ’com÷(σ) is
undefined.

Theorem: SSOS’IMP÷ = SNS’IMP÷
The proof is done in two stages which are expressed by Lemma 1 and
Lemma 2 below:
Lemma 1: For every command com of IMP and states σ and σ' we have:
<com,σ>→ σ' implies <com,σ> ⇒*σ'.

The proof is given by induction on the shape of the derivation tree for
<com,σ>→ σ' .
Lemma2: For every command com of IMP, states σ and σ' and natural
number k we have:
<com,σ> ⇒k σ' implies <com,σ>→ σ' .
The proof is done by induction on k (By induction on the length of the
derivation sequence <com,σ> ⇒k σ').

The proof follows from Lemma 1 and Lemma 2.

This result expresses two properties:
• If the execution of com from some state terminates in one of the
semantics then it also terminates in the other, and the resulting
states are equal.
• If the execution of com from some states loops in one of the
semantics then it will also loop in the other.

Extension to IMP
In order to illustrate the power and weakness of the 2 approaches to
operational semantics (Natural and Structural) we shall consider various
extensions to the language IMP.

IMP + Abort
First we will consider the extension of IMP with the abort command.
Abort stops the execution of the program. Meaning, that no command
will be executed after an abort command. So a configuration of the form
<abort, σ> is stuck.

The new syntax of commands is given by:
com::= X := a | skip | com1 ; com2 | if b then com1 else com2 |
while b do com | abort
No new rules are needed in natural and structural operational semantics:
In natural semantics we don’t have intermediate configurations.
In SOS we will get exactly what we want by not adding any rules. If we
reach a point where we have an abort command, then since there are no
derivation rules we will enter a stuck configuration and the execution will
terminate.

Observation 1: From the SOS point of view abort and skip are not
semantically equivalent. The reason for this is that the only derivation
sequence for skip starting from σ is <skip, σ> ⇒ σ
And the only derivation sequence for abort staring from σ is <abort,σ>
(empty sequence).
Observation 2: From the SOS point of view abort and while true do skip
are not semantically equivalent. The reason for this is that
<while true do skip, σ> ⇒
<if true then (skip; while true do skip) else skip, σ> ⇒
<skip; while true do skip, σ> ⇒ <while true do skip, σ> ⇒ …
is a infinite derivation sequence for while true do skip. And abort has no
infinite derivation sequences.

Observation 3: From the Natural Semantics point of view abort and
while true do skip are semantically equivalent. The reason for this is that
in the Natural Semantics we are only concerned with executions that
terminate properly. S if we do not have a derivation for <com,σ> → σ'
then we cannot tell whether it's because we've entered a stuck
configuration or a looping execution.

Summary:

• In a natural semantics we cannot distinguish between looping and
abnormal termination.
• In structural semantics looping is reflected by infinite derivation
sequences and abnormal termination by finite derivation sequences
ending in a stuck state.

IMP + No determinism
We shall now consider a second extension to IMP which is given by:

com::= X := a | skip | com1 ; com2 | if b then com1 else com2 |
while b do com | com1 or com2

The idea of or is that in "com1 or com2" we can non-deterministically
choose to execute either com1 or com2.

Example: the execution of X := 1 or (X :=2 ; X := X+2) could result in a
state where x has the value 1, but it could as well result in a state where x
has the value 4.

We extend the Natural Semantics with the following 2 rules:

• <com1, σ> → σ'       .
<com1 or com2, σ> → σ'
• <com2, σ> → σ'       .
<com1 or com2, σ> → σ'

Example: corresponding to the configuration
<X := 1 or (X :=2 ; X := X+2), σ> we have derivation trees for:

<X := 1 or (X :=2 ; X := X+2), σ> → σ[X x1]
as well as
<X := 1 or (X :=2 ; X := X+2), σ> → σ[X x4]

Note: In the above example, if we replace "X := 1" with "while true do
skip" then we will only have one derivation tree:
<while true do skip or (X :=2 ; X := X+2), σ> → σ[X x4]
this is because we have no derivation for "while true do skip".

We extend the Structural Semantics with the following 2 axioms:
• <com1 or com2, σ> ⇒ <com1, σ>
• <com1 or com2, σ> ⇒ <com2, σ>

Example 1: corresponding to the above example, we have 2 derivation
sequences:
• <X := 1 or (X :=2 ; X := X+2), σ> ⇒* σ[X x1]
• <X := 1 or (X :=2 ; X := X+2), σ> ⇒* σ[X x4]

Note: In the above example, if we replace "X := 1" with "while true do
skip" then we will still have 2 derivation sequences:
• <while true do skip or (X :=2 ; X := X+2), σ> ⇒
<while true do skip, σ> ⇒ <while true do skip, σ> ⇒ …
• <X := 1 or (X :=2 ; X := X+2), σ> ⇒* σ[X x4]

Example 2: the configuration <X := 1 or X := 10; X := X+5 or X := X-5,
σ> has 4 different finite derivation sequences:
• <X := 1 or X := 10; X := X+5 or X := X-5,σ> ⇒
<X := 1; X := X+5 or X := X-5,σ> ⇒
<X := X+5 or X := X-5,σ[X x1]> ⇒
<X := X+5,σ[X x1]> ⇒
σ[X x6]
• <X := 1 or X := 10; X := X+5 or X := X-5,σ> ⇒
<X := 1; X := X+5 or X := X-5,σ> ⇒
<X := X+5 or X := X-5,σ[X x1]> ⇒
<X := X-5,σ[X x1]> ⇒
σ[X x-4]
• <X := 1 or X := 10; X := X+5 or X := X-5,σ> ⇒
<X := 10; X := X+5 or X := X-5,σ> ⇒
<X := X+5 or X := X-5,σ[X x10]> ⇒
<X := X+5,σ[X x10]> ⇒
σ[X x15]
• <X := 1 or X := 10; X := X+5 or X := X-5,σ> ⇒
<X := 10; X := X+5 or X := X-5,σ> ⇒
<X := X+5 or X := X-5,σ[X x10]> ⇒
<X := X-5,σ[X x10]> ⇒
σ[X x5]

Notes:
• In SNS non-determinism will suppress looping, if possible.
• In SOS non-determinism does not suppress looping.

IMP+ Parallelism:
Consider an extension with a parallel construct:
com::= X := a | skip | com1 ; com2 | if b then com1 else com2 |
while b do com| com1 par com2
com1 par com2 means that all the interleaving of com1 or com2 are
executed. This means that a statement like X := 1 par (X :=2 ; X := X+2)
can give three different results for x: if we first execute x:=1 then we get
x=4, if we first execute x:=2;x:= x+2 then we get x=1. finally, we have
the possibility of first executing x:=2, then x:=1 and lastly x:=x+2 and
then we get x=3.

We express this in SOS:
• <com1, σ> ⇒ <com1’, σ’>                    .
<com1 par com2, σ> ⇒ <com1’ par com2, σ’>
• <com1, σ> ⇒ σ’                  .
<com1 par com2, σ> ⇒ <com2, σ’>
• <com2, σ> ⇒ <com2’, σ’>                  .
<com1 par com2, σ> ⇒ <com1 par com2’, σ’>
• <com2, σ> ⇒ σ’                 .
<com1 par com2, σ> ⇒ <com1, σ’>

Example:
The configuration
<(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ>
has the following finite derivation sequences:
•  <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := 0; X := X+1) par (if X=4 then (while true do skip)),σ[X x3]> ⇒
<(X := X+1) par (if X=4 then (while true do skip)),σ[X x0]> ⇒
<if X=4 then (while true do skip),σ[X x1]> ⇒ σ[X x1]
• <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := 0; X := X+1) par (if X=4 then (while true do skip)),σ[X x3]> ⇒
<(X := X+1) par (if X=4 then (while true do skip)),σ[X x0]> ⇒
<(X := X+1),σ[X x0]> ⇒ σ[X x1]>
• <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := 0; X := X+1) par (if X=4 then (while true do skip)),σ[X x3]> ⇒
<X := 0; X := X+1,σ[X x3]> ⇒
<X := X+1,σ[X x0]> ⇒σ[X x1]
• <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := X+1) par (X := 3; if X=4 then (while true do skip)),σ[X x0]> ⇒
<(X := X+1) par (if X=4 then (while true do skip)),σ[X x3]> ⇒
<X := X+1,σ[X x3]> ⇒σ[X x4]
• <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := X+1) par (X := 3; if X=4 then (while true do skip)),σ[X x0]> ⇒
<(X := 3; if X=4 then (while true do skip),σ[X x1]> ⇒
<if X=4 then (while true do skip),σ[X x3]> ⇒ σ[X x3]
And the following infinite derivation sequence:
• <(X := 0; X := X+1) par (X := 3; if X=4 then (while true do skip)),σ> ⇒
<(X := X+1) par (X := 3; if X=4 then (while true do skip)),σ[X x0]> ⇒
<(X := X+1) par (if X=4 then (while true do skip)),σ[X x3]> ⇒
<if X=4 then (while true do skip),σ[X x4]> ⇒
<while true do skip,σ[X x4]> ⇒
<if true then (skip; while true do skip) else skip, σ[X x4]> ⇒
<skip; while true do skip, σ[X x4]> ⇒
<while true do skip, σ[X x4]> ⇒ …

We might express the extension in natural semantics (NS) in the
following way:
• <com1, σ> → σ’, <com2, σ’> → σ’’_
<com1 par com2, σ> →σ’’
• <com2, σ> → σ’, <com1, σ’> → σ’’          .
<com1 par com2, σ> →σ’’

However, it is easy to see that this will not do because the rules only
express that either com1 is executed before com2 or vice versa. This
means that we have lost the ability to interleave the execution of two
statements. Furthermore, it seems impossible to be able to express this
in NS because we consider the execution of a statement as an atomic
entity that cannot be split into smaller pieces.

Summary:
• In the natural semantics immediate constituent is an atomic entity
so we cannot express interleaving of computations
• In the structural operational semantics we concentrate on small
steps so interleaving of computations can be easily expressed.

IMP + Local variables:
We now extend the language with blocks containing declarations of local
variables: com::= X := a | skip | com1 ; com2 | if b then com1 else com2|
while b do com| begin Vars com end
Vars::= var X := a ; Vars | ε
The idea is that the variables declared inside a block begin Vars com end
are local to it.
We define the set DV(Vars) of variables declared in Vars:
DV(ε) = ∅
DV(var x:=a;Vars) = {x}∪DV(Vars)
We might express this in Natural Semantics (NS) in the following way:
• <Vars, σ> → σ’, <com, σ’> → σ’’_
<begin Vars com end , σ> →σ’’
This is incorrect, because for example, if we have a variable that is
redefined in a block then when coming out of the block we need to
restore its previous value.
The correct rule is:
• <Vars, σ> → σ’, <com, σ’> → σ’’                  _
<begin Vars com end , σ> →σ’’[σ/DV(Vars)]
Where:

• <x:=a, σ> → σ’, <Vars, σ’> → σ’’_
<var x:=a;Vars, σ> →σ’’
• <ε, σ> → σ

It is somewhat harder to specify the SOS for the extension. One approach
is to replace states with a structure that is similar to a runtime stacks used
in the implementation of block structured languages.

Example:
We’ll show how to execute the following statement in Natural Semantics:
Begin var x: =1
y: =2;
Begin var y: =1
x: = x+y
End;
y: = y +x +1
End

We denote Y: =2; Begin var y: =1 x: = x+y End; y: =y + x +1 by com1.

(1)       <x:=1, σ> → σ[1/x] , < com1, σ[1/x]> → γ?
<begin var x:=1 com1 end, σ>→γ? [σ/DV(Vars)]
Where DV(Vars) = {x} here.

Our purpose is to find γ?. In order to do that we need to execute com1:
Denote Y: =2 by com2, Begin var y: =1 x: = x+y End by com3 and
y: = y+ x +1 by com4.
Note that com1 = com2; com3; com4.

(2)           <y:=2, σ[1/x]> → σ[1/x][2/y] , < com3, σ[1/x][2/y]> → γ?1
<com2; com3, σ>→γ?1

(3)    <y:=1, σ[1/x][2/y]> → σ[1/x][1/y] , < x: = x+y, σ[1/x][1/y]> →σ[2/x][1/y]
<com3, σ>→(σ[2/x][1/y]) [σ[1/x][2/y] / DV(Vars)]
Where DV(Vars) = {y} here.

So we get that (3) is:
<y:=1, σ[1/x][2/y]> → σ[1/x][1/y] , < x: = x+y, σ[1/x][1/y]> →σ[2/x][1/y]
<com3, σ>→σ[2/x][2/y]

Also now we know that γ?1 = σ[2/x][2/y].
So (2) is now clearer:
<y:=2, σ[1/x]> → σ[1/x][2/y] , < com3, σ[1/x][2/y]> → σ[2/x][2/y]
<com2; com3, σ>→σ[2/x][2/y]

From (2) we get:
(4) <com2;com3, σ[1/x]> → σ[2/x][2/y] , <y: = y+ x +1, σ[2/x][2/y]> → σ[2/x][5/y]
<com2; com3; com4, σ[1/x]>→ σ[2/x][5/y]

So we can see that γ? = σ[2/x][5/y].
So (1) is:
<x:=1, σ> → σ[1/x] , < com1, σ[1/x]> → σ[2/x][5/y]
<begin var x:=1 com1 end, σ>→(σ[2/x][5/y]) [σ/DV(Vars)]

And since DV(Vars) = {x}, assume that x’s value in σ is x0.
Then we get:
(1)          <x:=1, σ> → σ[1/x] , < com1, σ[1/x]> → σ[2/x][5/y]
<begin var x:=1 com1 end, σ>→σ[x0/x][5/y]

A different construction:
This construction was suggested by Tal Lev-Ami.
This construction refers to block per variable.
com::= X := a | skip | com1 ; com2 | if b then com1 else com2|
while b do com| begin var x:=a com end
According to this extension, defining a variable “opens” a new block
which refers to it. This construction doesn’t need the definition of DV,
since we deal with one variable at a time.

<Var x: = a, σ> → σ’, <com, σ’> → σ’’ _
<begin Var x:=a com end , σ> →σ’’[σ/x].

Summary
• Structural operational semantics allows us to simulate low level
computations without getting bugged into too many details
• Natural semantics allows to abstract more
– Local memory
– Non termination

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 17 posted: 11/1/2008 language: English pages: 15
How are you planning on using Docstoc?