"Reverse Polish" notation is embodied in the instruction languages of two recent machines, and "Forward Polish" notation is of use in mechanized algebra. This article illustrates, using a simple language without detail, some methods of translating between these notations and an "orthodox" one of the kind used in FORTRAN and ALGOL. The question of efficient translation between an "orthodox" mathematical notation of the kind ordinarily used in writing algebraic formulae (and copied as closely as is practicable in FORTRAN and ALGOL) and "Polish" notation has come to prominence as a result of the use of what is in effect Polish notation as the basic instruction language of two recent computers.* Polish notation is so-called because of its extensive use in Polish logical writings since its invention by-Lukasiewicz (1921, 1929).-Lukasiewicz demonstrated that if operators are written always in front of their operands, instead of (as in the case of the diadic operators of arithmetic, " + ", "-", " x " and so on) between them, there is never any need for brackets to indicate association of terms. Thus if in place of "a-f-b" we write " + a b", and so on, the brackets in an expression such as "(a + b) X c" may be dispensed with in translation, since " X + a b c" indicates unambiguously the result of operating with " x " on "-\-ab" and "c": for "a + (b X c)" we should instead write " + a X b c." The resulting notation, in the case of long formulae, is a little harder to read, since brackets aid the eye, but it has some other advantages. In particular Reverse Polish-the notation which results if operators are placed after operands, as in "a b +"-has the property that the operators appear in the order in which they are required in computation. Reverse Polish is hence in some sense a natural notation for an instruction language, each symbol being interpretable as an instruction. (Number variables are "fetch" instructions.) The absence of brackets further makes Polish notation (-either Forward or Reverse, but probably preferably Forward-) useful in mechanized algebra, since it eliminates a continual source of complication in algebraic manipulations. Machine translation from one notation to another is needed in writing compilers for the new machines, and it is possible to foresee a variety of future uses for it. This article illustrates, using a simple language without detail, some translation methods. In general, translation is extremely simple if done in the right way It is convenient to distinguish "pure" translation from translation which involves manipulation or rearrangement. A simple way of characterizing this distinction * The English Electric KDF9 and the Burroughs B5000. Each of these uses a "push-down" (or "nesting") type of store for arithmetic operands and results, following a scheme suggested by the present author (Hamblin, 1957, 1957, 1960; see also Hamblin, Humphreys, Karoly and Parker, 1960). is in terms of the order of the number-denoting symbols (numbers and number variables): in "pure" translation these symbols remain unaltered and in the same order in the translated formula as they were in the original. Thus we shall say that the transformation of "a +(b X c)" into Forward Polish " + a x J c " is a case of pure translation, whereas its transformation into " + X b c a" though this is an equivalent form, involves manipulation as well as translation, since the order "b c a" of the number variables is different. We confine ourselves to pure translation, so defined, in what follows. This restriction, however, does not yet entirely remove the possibility that a formula in a given notation should have alternative forms. This is because of the asso-ciativity of some arithmetical operators. Thus in orthodox notation "(a + b) + c" is equivalent to "a +{b + c)," and the brackets are usually omitted; but to these formulae correspond in Forward Polish the formulae "++abc" and "+a + bc" respectively. To resolve ambiguity we distinguish two special cases, the early-operator and late-operator forms respectively of Polish formulae. A Polish formula is in early-operator (late-operator) form if all operator symbols occur as early (late) in it as possible. Thus "a+b-\-c+d" becomes "+ + + a b c d" in early-operator Forward Polish, " + a + b + c d" in late-operator Forward Polish, "a b + c + d + " in early-operator Reverse Polish, and "a b c d + + + " in late-operator Reverse Polish. There are of course intermediate forms such as "++ab+cd" and "a b + c d + + " which, though valid Forward and Reverse Polish respectively, are neither early-operator nor late-operator. In the case of Reverse Polish for use as an instruction language it is usually the early-operator form that is desirable, since this uses the minimum number of locations in the push-down store. By Orthodox A I shall mean a language constructed with orthodox symbol-order out of the following symbols. (i) Number-variables a, b, c, d,. .. (The use of actual numerals raises no essential new issues; we need not consider it here.) (ii) Operators +,-, neg, x, f. Of these, "neg" (representing "negative") is monadic, i.e. operates on a single number, and is placed in front of its operand, as in "neg a": the others are diadic and stand between their operands, as in "a + b". Symbol " f " denotes 210
CITATION STYLE
Hamblin, C. L. (1962). Translation to and from Polish Notation. The Computer Journal, 5(3), 210–213. https://doi.org/10.1093/comjnl/5.3.210
Mendeley helps you to discover research relevant for your work.