The use of ALGOL 60 for the solution of logical problems

The use of ALGOL 60 for the solution of logical problems

THE USE OF ALGOL 60 FOR THE LOGICAL PROBLEMS* SOLUTION OF 0. M. KASTIN Moscow (Received 18 June 1969) 1. IN the solution of logical informatio...

361KB Sizes 0 Downloads 20 Views

THE

USE

OF

ALGOL 60 FOR THE LOGICAL PROBLEMS*

SOLUTION

OF

0. M. KASTIN Moscow (Received

18 June 1969)

1. IN the solution of logical information problems we have to deal with data which are organized in a complicated manner. With large volumes of processed data the question of the dense packing of the storage unit and the organization of a return to various elements of the data becomes important. [ll. There are a number of highly developed programming languages [2, 31, which enable us to describe and process data of a complicated structure. The use of languages assumes the presence of the corresponding translators, which is far from always the case. On the other hand, as remarked in 141, formal methods of describing data of a complicated nature leads to rather cumbersome apparatus. There are a number of simple languages [4,51 for processing data but they have not obtained wide acceptance in the sense of the creation of the corresponding translators. There are of course papers [61 in which supplements to ALGOL 60 are introduced and these enable us to solve problems of processing data of a complicated nature, but the realization of these supplements also requires the creation of new translators or the use of special devices [7l. The wide use of ALGOL 60, the existence of translators from this language for many computers and the need to solve problems of the processing of complicated data urge us to look into the possibility of using ALGOL 60 for the solution of the above problems. This paper proposes changes in the semantics of logical expressions and a standardization of the realization on a computer of the elements of the language connected with logical values, which will enable ALGOL 60 to be used without changes in its syntax for the solution of an extensive class of problems which are not considered to be ALGOL problems. 2. In Soviet and foreign translators from ALGOL 60 for logical values (true and false) or values of any logical variable the machine words are usually set

* Zh. v@hisl.

Mat. mat. Fiz.,

10, 2, 527-530,

351

1970.

0. M. Kastin

352

aside, while logical values are introduced into the various translators by different means: by one, several or all the bits of a word. The differences in the representation of logical values (if we leave out of consideration the taste of the authors of the translators) lead to differences in the methods of programming the logical expressions, testing words etc., which adds difficulty to the use of translators from ALGOL 60 for the solution of logical information progams. We shall find rules for realizing elements of a language using logical variables so as to obtain the greatest possibility for working with parts of a word and at the same time to avoid any contradictions when using logical values in the ordinary ALGOL 60 sense. 2.1. In the declaration of Boolean a any translator sets aside a machine word for the location of the value of the variable a. Since one bit is sufficient to represent the value of a logical variable we shall consider that the declaration of Boolean a introduces a Boolean vector a = (a [11, a [2],..., a [^A’]), where N is the number of bits in the word. Thus there are N logical variables, the bits of the Boolean vector a, connected with the identifier a. The variable a [il can assume the values 1 (true) and 0 (false). We shall distinguish between the ideas of “logical value” and “Algol logical value”. By logical value we mean any Boolean vector of length N and by “Algol logical value” we mean the value of the fixed bit of the logical value (vector) (e.g. for definiteness, a [ll), i.e. 1 and 0. We reserve separate words to represent true and false, i.e. true and false are particular cases of logical values. 2.2. We shall define logical operations, 1, A, V, 3 and 3 (to be more exact, the execution of these operations) in such a way that as a result of calculating a logical expression we obtain two values: the logical value and the Algol logical value, which is one of the components of the logical value. 19 The logical value true is represented by a vector for which a [il = 1 for 14 i .g N and the value false by a vector for which a [i I= 0 for 1 < i 6 N. 29 The designator of a logical function determines the logical value which is obtained as a result of the application of the rules defined by the procedure declaration to a fixed set of actual parameters - taking account of the requirements given below. 3”. Negation: 1 a = (7~ [II, la 49 Logical multiplication

[xl,..., 1~ [NI).

and logical addition:

The use of ALGOL

60

353

a A b = (ail] A b [iI, a 121A b M,..., = INI A b [NIL a V B = (a [1] V b (11, a [21 V b RI,..., a [Nl V b [NIL Constraint 1. In working with parta of a word we cannot obtain economy of calculation in the expression a A b A . . . A k, if none of the terms a, b, . . . , k entering into it is a direct logical value false. Constraint 2. In working with parts of a word we cannot economize in calculation in the expression a V b V . . . V k, if none of the elements a, b, . . . , k is the logical value true. 59 Implication is carried out by means of the identity (a 3 b) = (1~ V b), where the operations

1 and V are carried out as defined above.

69 If we define identity by the relation (a = b) = ((la V b) A (lb V ~11,

(‘)

it is obvious that with the use of logical variables in the usual Algol sense the interpretation suggested for the operations C ‘A ’ V ‘I_ and =_does not lead to any contradiction and that for the transformation of logical expressions we can use all the laws and relations of algebraic logic. For instance: (l(1 a)) G at (a V 1 a)= true, (a A 1 u) = false, ((a V b) A (1 a V c) A (b V c)) = ((a V V b) A (la V 4) etc. The definition of identity, however, by means of the relation (NJ does not make it possible to use this operation in working with parts of a word. We shall define identity as follows: the expression a = b assumes the value true or false depending on the value of the truth or falsehood of the quantifier of generality V i (a [i] s b Ii]),

lgi,
With such a definition of identity the relation (*) is no longer valid and is necessary to have the following constraint.

:**)

it

0. M. Kastin

354

Constraint. In using (**I we can carry out only the transformation of logical expressions in which the relation (*I or similar relations are not used. This constraint naturally affects only cases where logical expressions are used for work with parts of a word. For logical expressions in the ordinary Algol sense all the laws and relations of logical algebra remain in force with the use of the definition (**I. Also it is assumed that the definition (**) is valid. 2.3. Verification out as follows:

of the conditions

if

then is carried

(1) the logical value of the expression in the condition is calculated by the rules defined in ALGOL 60 with the requirements given in paragraph 2.2; (2) the truth or falsehood of the logical expression is determined by the truth or falsehood respectively flf the Algol logical value of the given expression (paragraph 2.1). The assignment statement, in whose right-hand side there is a logical expression, assigns a logical value to one or more variables or procedure identifiers, which is obtained as a result of the calculation of the expression. (3) To describe algorithms for the solution of logical information problems in ALGOL 60, in addition to the satisfaction of the requirements of paragraph 2, it is necessary to have some additional methods which can be realized as procedure functions with their body in the form of a code. 3.1. The initial assignment of the logical variables can be effected in two ways. The first consists of the use of an input operator for logical values which exists in the input language of any translator, and the second the use of a special procedure function which forms logical constants Boolean procedure boolcon (line); string line; . An actual parameter of the given procedure is a line of octuple ciphers of variable length. If the number of ciphers in the line is less than the maximum in the machine word, such a line in the body of the procedure is completed on the left by the necessary number of zeros. 3.2. In working with parts of a word it must be possible to move the word a

The use of ALGOL 60

number of bits.

355

For this purpose the following procedure function is used:

Boolean procedure shift (a, n); value a, n; Boolean a; integer n; , where sign (n) defines the direction of the movement and abs (n) is the number of bits which the word must be moved. The value 0 is assigned to the free bits. 3.3. To revert to separate elements of the data and use all the possibilities of ALGOL 60 two procedure functions are used to process them: (1) integer ptocedure boolint (a, i, nk Boolean a

value a, i, n; integer i, n;

, where i is the number of the bits (right-hand) with which the element of data in the word begins, and n the number of bits occupied by the element. This procedure changes the part of the word to the type integer; (2) Boolean procedure intbool (a, i); value a, i; integer a, i; .

This procedure changes the value of a from type integer into a two digit number and moves it from the i-th bit of the word. All the bits of the word not occupied by the value a are given the value 0. Note 1. The bodies of the procedure functions are assumed to be in the form of a code purely from considerations of the effectiveness of the program obtained. From the main point of view all the procedures can be completely described in ALGOL 60 if, instead of interpreting the logical variable as a Boolean vector of length N, we introduce ordinary logical blocks of length N and corresponding procedures for working with them. Note 2. For translators, in which identity is defined by the relation (*I of paragraph 2.2, we can introduce a procedure function which will realize the identity within the meaning of the definition (**) of paragraph 2.2. The application of the requirements of paragraph 2 to a translator from ALGOL and the presence in the translator of standard procedures is practically equivalent

356

0. M. Kastin

to the introduction into the language of variables of the type logicd suggested in 181 and enables us to use ALGOL 60 successfully to describe algorithms for the solution of logical information problems. The algorithms obtained are sufficiently general from the point of view of their independence of actual computers because their natural parameter is the number of bits N of a machine word. The author wishes to thank K. A. Semendyaeva for her advice and interest. Trmslated

by H. F. Cleaves

REVERENCES

1.

KITGV,

A. I.

Programming logical

informatsionno-logicheskikh

information problems

zadachf.

M.. ‘%ov. radio”,

2.

The universal programming language PL/If f M., *Mir” t 1968 *

3.

KOROLEV, M. A., KUZ’MIN, K. S., LAVROV, S. S., LETICHEVSKIK, A. A., STOLYAROV, G. K. and SHURA-BURA, M. R. Report on the algorithmic language ALGEK. Kibemetika, 2, 57-102, 1966.

4.

SGBEL’MAN, V. I. A programming language based on the library program method. In sb. =Tsi~roba~a v~eh~s~. Tekh. i p~g~~rn~~ou~ien. 3. M., “Sov. radio’, 18-28, 1967.

5.

POTTOSIN, I. V., RAR, A. F. and KATKOV, V. L. The epsilon system mating programming for problems of symbolic processing. Tr. I Vses. Programmirovaniyu. Kiev, IK Akad. Nauk USSR. 1968.

6.

GLAIXJN, V. P., L~TICHEVSKII, A. A., ~K~OVSKII, S. U., PO~KOLZ~A, K. M. and RABINOVICH, E. L. An extension of the logical potentialities ALGOL 60. Zh. u$hisl. Mat. mat. Fiz., 5, 2, 369-372, 1965.

7.

GLUSHKOV, language

8.

BARRON, 1963.

PL/I

Wniversal’nyi

(Programmirovnnie 1967. yazyk programmirovaniya

for autoKonf. po

of

V. M., LETICHEVSKII, A. A. and STOGNII, A. A. Computer input for engineering calculations. Klbemetiko, 1, 74-82, 1965.

U. W et al., The main features

of CPL.

Computer

J., 134-143,

July,