Denotational semantics

from Wikipedia, the free encyclopedia

The denotational semantics (function semantics ; English: denotational semantics ) is one of several possibilities in theoretical computer science to define a formal semantics for a formal language . The formal language serves as a mathematical model for a real programming language . The mode of operation of a computer program can thus be formally described.

Specifically, given a given assignment for input variables, the end result for a set of output variables can be calculated using denotational semantics. More general proofs of correctness are also possible.

In denotational semantics, partial functions are used that map state spaces to one another. A state here is an assignment of variables with concrete values. Denotational semantics are inductively defined using the syntactic instruction constructs of the formal language. The partial functions are selected depending on the desired program semantics.

In addition to denotational semantics, there are also operational semantics and axiomatic semantics to describe the semantics of formal languages.

Definition of the semantic function f

Let be the set of all possible states. The effect that an instruction has a condition, spoken formally a picture

,

which assigns a subsequent state to a state .

denotes the semantic function and assigns a meaning to each instruction construct by causing a change in the state of the program.

The effect of the most important control structures of a programming language on a state is examined below.

  • The meaning of the empty statement :
.
The empty statement applied to a state does not change the state.
  • The semantics of an instruction sequence can be described as follows:
.
The meaning of this command sequence is the effect of applied on the state that results after the execution on .
  • The following applies to the effect of an assignment on a state:
The program does not terminate ( ) if the statement (or expression) applied to the state does not terminate. In all other cases the program goes into one state .
  • For the two-sided alternative, the following applies:
.
The subsequent state corresponds to applied to if . If so, the subsequent state is determined by applied to . In all other cases the program does not terminate.
  • The meaning of the repetition is defined recursively as:
.
If so, the While statement does not change the state.
If or , the entire program does not terminate.
In all other cases, the iteration statement is reapplied to the state that results after the execution of .
This recursive definition cannot be used to infer the effect of this statement. One is therefore interested in the fixed point of the function, which describes the semantics of the while loop.

Fixed point of the while semantics

The fixed point of the function, which describes the semantics of the While Loop, is explained below using a simple example.

As long as not equal , the value of the variable is increased by 1.

To determine the fixed point of this equation, one uses the Tarskian fixed point theorem . This theorem says that for an ordered set that has a smallest element and a strictly monotonic function that maps to itself, a smallest fixed point exists.

In order for the theorem to be applicable, an ordered set must first be defined for the example.

Let be the partial function of the while loop from the example. This maps one state, consisting of the assignment for the variables of the same name, to another state with the variable assignment . The variables and are whole numbers.

Now be the set of all partial functions .

The partial order for two partial functions , is defined as follows:

.

The partial mapping is less than or equal to if and only if the domain of is a subset of the domain of . It must also be the case that if a state change to causes and function of maps.

The smallest element of the set is the nowhere defined function .

In order to be able to use Tarski's theorem, a strictly monotonous function that maps to itself is still missing . A function is defined for this:

.

According to the example above, the following applies :

.

Furthermore let:

.

Now all requirements of the fixed point theorem are fulfilled, there is a fixed point.

The fixed point is calculated by forming the limit of the function .

In order to be able to infer the limit value, one begins with the calculation of individual function values.

  • as is the smallest element of the set .
  • is according to the definition of the function :
.
  • results in:
.
  • For can be formulated:
.

The limit value is now:

.

For the fixed point it must now apply that .

.

This can be transformed to:

.

Thus applies . The fixed point has been found. The meaning of the while loop in the example results from the fixed point. The loop terminates if , and returns the tuple . If so, the loop does not terminate.

literature