Concept of the abstract program

The aim of this paper is to alter the abstract definition of the program of the theoretical programming model which has been developed at Eotvos Lorand University for many years in order to investigate methods that support designing correct programs. The motivation of this modi?cation was that the dynamic properties of programs appear in the model. This new definition of the program gives a hand to extend the model with the concept of subprograms while the earlier results of the original programming model are preserved.


Introduction
It is a well-known aspiration to exclusively use methods which guarantee the correctness of the developed program with respect to the problem [1,5,6] posed, that is, what makes it essential to find abstract mathematical definition of programming notions. At Eötvös Loránd University, a relational model of programming which treats the most important, fundamental notions of programming-problem, program, state space, variable, data type, etc.-in a uniform and consistent way [2,3,7] has been built for thirty years.
The base of the abstract definitions of programming notions is the state space and their tool is the mathematical relation. The problem, for example, is a homogeneous binary relation over the state space that maps from the possible initial states to the appropriate goal states. The program is defined as all of its executions, so it can be described by the relation that maps from any state to the executions starting from one, where an execution is the sequence of the states concerned. The effect of a program is also a homogeneous binary relation where its domain contains the states from which the program surely terminates, i.e. the executions starting from these states are finite, and maps to states where these executions stop. The definition of the solution (when a program is said to solve a problem) establishes the main connection between the relations of the problem and the effect of the program. This theoretical approach makes it possible to investigate the concept and correctness of several kinds of program-designer methods such as program synthesis, analogous programming, etc.
The main characteristic of this relational model is the special static point of view in which the concept of the program is a mapping and not a working, nonetheless it is originally dynamic. The advantage of this static point of view is the simple definition of the solution. Although it is not self-evident if the number of the components of the state space of a problem and that of a program are different. To prove the correctness, in this case, the program and the problem must be transformed into a new common state space [4].
In the present model however, the state space is persistent, i.e. all variables of the program are global and static (the scope and life time of the variables involve the whole program), the so-called local variables cannot be created and destroyed during an execution. In absence of local variables, the concept of real subprograms cannot be introduced into our programming model. (Only macros can be defined.) Namely, the power of a subprogram is what permits creating new local auxiliary variables as well as parameter variables, and it is not supported by the present concept of the program. It is not a serious problem if simply the correctness is wanted to be proved but it is a great difficulty if our aim is to design a program. Unfortunately, the programming method, which is based on our programming model to synthetize correct programs, cannot produce subprograms with parameter variables, so their creation remains in the sphere of the implementation instead of the designing. It is an additional disadvantage that, without the concept of subprograms, recursive calling cannot be used in our programming model. The aim of this paper is to remedy this shortcoming of the definition of the program, and to preserve the earlier results of the programming model.

State space
All definitions of the programming model are based on the state space. The concept of the state space has already been interpreted in several ways. For many people, the state space is a model of a von Neumann type computer; others, e.g. Dijkstra [1], associate this notion with the problem to be solved, where a state is a compound of the values of the main data types. So, the program is "outside" of the state space operating on it. In our programming model, this second meaning is used. In [2], the notion of the state space is a Cartesian product of the value set of data types. The only mistake of this obvious definition is that it imposes an order on the components. In [3], where the state space is a direct product, this mistake is repaired.
Here it is the definition of the direct product and the notions related to it. Let I be a finite set named as index set. Let A i 's (i P I) be arbitrary sets. The set Ś iPI A i ::" tx : I Ñ Ť iPI A i |@i P I : xpiq P A i u is the direct product of the sets A i (i P I).
The If J Ď I and @j P J : B j " A j then B is the subspace of A, i.e. B ď A. The function pr B : A Ñ B is a projection if B ď A and @a P A : pr B paq " a| J . Not only one state but a set or sequence of states can also be projected if it is done one by one. If J " tju then the function pr B is named as j variable and j is the variable name.

The new concept of the program
The most important notion of the programming model is the program. In our explanation, the program is not a collection of some statements that can be executed on a computer. The statements could only describe a program but the program is the complex of its executions. An execution is a sequence of states. A program, by definition, can always begin, i.e. at least one execution has to start from each state. If several executions start from the same start state, it means that the program is non-deterministic: nobody knows which execution will happen.
In the original programming model, every state of the progam belongs to the same state space. Now we are going to permit that the state space can be permanently changed; the inner states of the executions may have got new components.
The other novelty of our new definition is the idea of the base state space of the program. The first state (start state) of all executions and the last, if the execution is finite, are in this base state space.
Before giving the formal definition of the program, some notions must be introduced. Let H˚˚denote the set of all finite and infinite sequences of the elements of set H. H 8 includes the infinite sequences; H˚contains the finite ones. So, H˚˚" H˚Y H 8 and H˚X H 8 " H. The length of the sequence α P H˚˚is |α|, the value of which is 8 if the sequence is infinite.

Definition 1 Let A be the so-called base state space andĀ be the set of all states which belong to the state spaces B whose subspace is
2. @α P R S XĀ˚: α |α| P A (the last state of the finite executions of the range of S), 3. @a P A and @α P Spaq : |α| ě 1 and α 1 " a.
The variables of the base state space are the base variables; the other variables are the auxiliary variables of the program.
The concept of the program allows to create and destroy new components (variables) during an execution, so the state space changes dynamically. All new components have to be destroyed at the termination, at the very latest, but the base variables should never be removed. The current state always contains the components of the base state space.
The following three definitions will outline that the base state space of any program is denoted arbitrarily. The base variables of a program can be extended, restricted or renamed without changing the essence of the program.
The base variables of any program can be renamed easily without the execution of the program is changed. However, if the new name of a base variable would be identical to an auxiliary variable's name then this auxiliary variable is given a new, unique name. of S onto C is the program (denoted by S 1 ) whose base state space is C and for all c P C : S 1 pcq " tγ P C˚˚| Dα P Sppr A pcqq : |α| " |γ|^@i P r2..|γ|s : if k R D α i then γ i | I " α i and γ i pkq " γ i´1 pkq if k P D α i then γ i " α i u.
It is easy to generalize this definition in case the state space A is a subspace of the state space C.
The following definition shows how a base variable can be degraded to an auxiliary variable: the first step creates it and the last step destroys it.

Definition 4 Let S be a program over the state space A "
Ś iPI A i and let C be the subspace of A. The restriction of S onto C is the program (denoted by S) whose base state space is C and for all c P C: The base state space of a program can be renamed, extended or restricted several times, thus the base state space can be totally transformed. But these transformations can change only the base state space and not the program. The essence of the executions of the program remains the same. The renamed, extended and restricted program hardly differs from its original version.
Definition 5 Two programs are identical if they can transform into the same program, using extensions, restrictions and renaming.

Conclusions
We have introduced a new concept of the program. Now let us observe what kinds of effects this modification has on the original programming model.

Concept of dynamic program
The new concept of the program smuggles the dynamic property of the program back to the static programming model [2,3] developed at Eötvös Loránd University. Certainly, the fact that a program can create and destroy auxiliary variables is not a brilliant discovery. The difficulty of our investigation was to find out how this dynamic property can be embedded into the programming model described in the static point of view.
The most important element of our concept is the base state space. It can be seen as the interface of the program. It determines the components through which the program can communicate, and can make contact with its environment. Only the base variables can get value from outside before the program starts, and their value can be asked after the termination.
The program becomes very flexible because its base state space can be changed easily. This property is reflected in the fact that the same program can possess different interfaces depending on the problem to be solved. The aim of a program can be changed by altering its base state space whereas its operation cannot be changed.

Concept of solution
Despite the above modification, the definition of the solution can be preserved [2,3,7]. The only thing that must be done is to redefine the concept of the effect of the program because the definition of the solution relies on it.
Now we will repeat all definitions that are important to describe the concept of solution.
Let the problem generally be a relation F Ď AˆA where A is a state space. Let S be a program over A.
The program S is said to solve the problem F if The definition of the solution supposes that the state space of the problem is identical to the base state space of the program. As the base state space can be chosen arbitrarily, the program can be extended, restricted or renamed in order that its base state space is identical to the state space of the problem. Since programs of this kind are identical, if one of them can solve the problem, so can the others.
Moreover, if the effects of the programs S 1 and S 2 are identical over all common base state spaces (ppS 1 q " ppS 2 q) and if one of them can solve a problem, so can the others. In this case these programs are called equivalent. This relation is reflexive, symmetrical and transitive, thus it is an equivalence relation. Consequently, if one program belonging to an equivalence class can solve a problem, then every program derived from this class can also solve it.
In the original programming model, the definition of the solution must be generalized [4] when the state spaces of the problem and the program are different. Now, our new concept is used to avoid this. It is enough to fit the base state space of the program to the state space of the problem and transform the program onto this common state space.

Earlier results
The original programming model contains many important results that can be used in the verification of programs. It is apparent that these results are not based directly on the concept of the program; except for the effect of the program. The definition of the effect of the program has not been changed because the new definition of the program fixes that the start state and the end state of the finite execution are in the same state space (that is, the base state space). Accordingly, all earlier results, namely Dijkstra's weakest precondition [1], the theorem of the specification or the derivation rules [1,3] of the program constructions [3] are used in unalterable forms.
Certainly, in the definitions of program constructions, the components (programs and conditions) which are the parts of the construction have to be on the same base state space. Accordingly, before making one of the constructions, this common base state space has to be agreed on.

Subprograms
The concept of real subprograms, which have got parameter variables, could not be introduced into the original programming model because the program has got an unvarying state space, thus local variables cannot be created during the execution, so parameter variables, which are local variables, cannot be used. Now, the situation is changed. In our new programming model, the concept of the subprograms may be defined.
First and foremost the subprogram is a program. It can be executed independently; it has got own base state space. Its only speciality is that it can be built into another program. (This is the host program.) Each program, including subprograms, is equivalent to an assignment. This assignment is appropriate to identify the subprogram that is equivalent to it. Accordingly, in an arbitrary program description language, a subprogram can be denoted with this assignment. The variables of this assignment, which are the formal parameters, form the base state space of the subprogram. The variables at the left-hand side of the assignment are the output parameter variables; the ones at the right-hand side are the input parameter variables. (For simplicity's sake, we shall restrict our consideration to assignments where a parameter variable does not occur more than once.) This assignment can be also used as a calling statement in the description of the host program. Certainly, in the calling statement, the parameter variables can be substituted by actual parameters (arguments), which are the expressions (often, they are only variables) of the host program. An output variable cannot be changed by an expression more general than a variable. The number and the type of the formal and current parameters must be the same. At this calling statement, the execution of the host program is interrupted, the control switches over the subprogram, the values of current parameters are given to the formal parameter variables, and the subprogram is executed. After the termination of the subprogram, the values of the output parameter variables are recopied to the appropriate current parameter variables. (Here, two kinds of parameter passing have been defined: passing by value and passing by value-result but other passing methods may be introduced.) The base state space of the subprogram is the interface between the subprogram and the host program. At the beginning of the subprogram, the variables of this base state space will get their initial values from the current state of the host program. At the end of it these variables give their values to the variables of the host program. The parameter variables and other local variables of the subprogram are created when the subprogram is called and destroyed at the termination of the subprogram.
In addition, the usage of subprograms permits recursive callings because a subprogram can call itself. After each calling, the parameter and the local variables of the subprogram are created again and again without the error message "out of memory" because the memory of the abstract program is infinite.
During planning, it is convenient that all the current variables of the host program are treated as global with respect to the subprogram that is called by the host program. The applied programming style and the facilities of the selected programming language determine if these global variables can be used directly in the subprogram or not. Obviously, their use has to be forbidden if we want to guarantee the independency of the subprogram.
We can make difference between the calling statement and the calling expression. In the latter case, only the right-hand side of the subprogram's head appears inside an expression of the host program, which contains actual parameters instead of formal parameter variables. After the termination, the result value of the left-hand side of the head is given back to the place of the calling expression in the host program.
Certainly, the abstract program description language which is used for planning has to be extended with the notation of the subprogram and of its calling including the connection between the actual parameters and the parameter variables.
To sum up the introduction of the concept of the subprograms makes it possible to design subprograms during planning and not only during implementation.