Reverse Polish notation (RPN), also known asreverse Łukasiewicz notation,Polish postfix notation or simplypostfix notation, is a mathematical notation in whichoperatorsfollow theiroperands, in contrast toprefix orPolish notation (PN), in which operatorsprecede their operands. The notation does not need any parentheses as long as each operator has a fixednumber of operands.
The termpostfix notation describes the general scheme in mathematics and computer sciences, whereas the termreverse Polish notation typically refers specifically to the method used to enter calculations into hardware or software calculators, which often have additionalside effects and implications depending on the actual implementation involving astack. The description "Polish" refers to thenationality oflogicianJan Łukasiewicz,[1][2] who invented Polish notation in 1924.[3][4][5][6]
The first computer to use postfix notation, though it long remained essentially unknown outside of Germany, wasKonrad Zuse'sZ3 in 1941[7][8] as well as hisZ4 in 1945. The reverse Polish scheme was again proposed in 1954 byArthur Burks, Don Warren, and Jesse Wright[9] and was independently reinvented byFriedrich L. Bauer andEdsger W. Dijkstra in the early 1960s to reducecomputer memory access and use thestack to evaluateexpressions. Thealgorithms and notation for this scheme were extended by the philosopher and computer scientistCharles L. Hamblin in the mid-1950s.[10][11][12][13][14][15][excessive citations]
During the 1970s and 1980s,Hewlett-Packard used RPN in all of their desktop and hand-held calculators, and has continued to use it in some models into the 2020s.[16][17] Incomputer science, reverse Polish notation is used instack-oriented programming languages such asForth,dc,Factor,STOIC,PostScript,RPL, andJoy.
In reverse Polish notation, theoperators follow theiroperands. For example, to add 3 and 4 together, the expression is3 4 + rather than3 + 4. The conventional notation expression3 − 4 + 5 becomes3 (enter) 4 − 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it.
The concept of astack, a last-in/first-out construct, is integral to the left-to-right evaluation of RPN. In the example3 4 −, first the 3 is put onto the stack, then the 4; the 4 is now on top and the 3 below it. The subtraction operator removes the top two items from the stack, performs3 − 4, and puts the result of −1 onto the stack.
Common language in this context refers to items being pushed onto the stack when added and popped or removed from the stack when taken off.
The advantage of reverse Polish notation is that it removes the need for order of operations and parentheses that are required byinfix notation and can be evaluated linearly, left-to-right. For example, the infix expression(3 + 4) × (5 + 6) becomes3 4 + 5 6 + × in reverse Polish notation.
Reverse Polish notation has been compared to how one had to work through problems with aslide rule.[18]
In comparison, testing of reverse Polish notation with algebraic notation, reverse Polish has been found to lead to faster calculations, for two reasons. The first reason is that reverse Polish calculators do not need expressions to be parenthesized, so fewer operations need to be entered to perform typical calculations. Additionally, users of reverse Polish calculators made fewer mistakes than for other types of calculators.[19][20] Later research clarified that the increased speed from reverse Polish notation may be attributed to the smaller number of keystrokes needed to enter this notation, rather than to a smaller cognitive load on its users.[21] However, anecdotal evidence suggests that reverse Polish notation is more difficult for users who previously learned algebraic notation.[20]
Edsger W. Dijkstra invented theshunting-yard algorithm to convert infix expressions to postfix expressions (reverse Polish notation), so named because its operation resembles that of arailroad shunting yard.
There are other ways of producing postfix expressions from infix expressions. Mostoperator-precedence parsers can be modified to produce postfix expressions; in particular, once anabstract syntax tree has been constructed, the corresponding postfix expression is given by a simplepost-order traversal of that tree.
The first computer implementing a form of reverse Polish notation (but without the name and also without astack), wasKonrad Zuse'sZ3, which he started to construct in 1938 and demonstrated publicly on 12 May 1941.[22][23][24][25] In dialog mode, it allowed operators to enter two operands followed by the desired operation.[z3 1] It was destroyed on 21 December 1943 in a bombing raid.[23] With Zuse's help a first replica was built in 1961.[23] The 1945Z4 also added a 2-levelstack.[31][32]
Other early computers to implement architectures enabling reverse Polish notation were theEnglish Electric Company'sKDF9 machine, which was announced in 1960 and commercially available in 1963,[33] and theBurroughs B5000, announced in 1961 and also delivered in 1963:
The KDF9 designers drew ideas from Hamblin'sGEORGE (General Order Generator),[10][11][13][34][35][32] a high-level programming language written for aDEUCE computer installed atThe New South Wales University of Technology, Kensington, Australia, in 1957.[10][11][13][33]
One of the designers of the B5000,Robert S. Barton, later wrote that he developed reverse Polish notation independently of Hamblin sometime in 1958 after reading a 1954 textbook on symbolic logic byIrving Copi,[36][37][38] where he found a reference to Polish notation,[38] which made him read the works of Jan Łukasiewicz as well,[38] and before he was aware of Hamblin's work.
Friden introduced reverse Polish notation to the desktop calculator market with theEC-130, designed byRobert "Bob" Appleby Ragen,[39] supporting a four-level stack[5] in June 1963.[40] The successorEC-132 added a square root function in April 1965.[41] Around 1966, theMonroe Epic calculator supported an unnamed input scheme resembling RPN as well.[5]

Hewlett-Packard engineers designed the9100A Desktop Calculator in 1968 with reverse Polish notation[16] with only three stack levels with working registersX ("keyboard"),Y ("accumulate") and visible storage registerZ ("temporary"),[42][43] a reverse Polish notation variant later referred to asthree-level RPN.[44] This calculator popularized reverse Polish notation among the scientific and engineering communities.TheHP-35, the world's first handheld scientificcalculator,[16] introduced the classicalfour-level RPN with its specific ruleset of the so-calledoperational (memory) stack[45][nb 1] (later also calledautomatic memory stack[46][47][nb 1]) in 1972.[48] In this scheme, theEnter↑ key duplicates values into Y under certain conditions (automatic stack lift withtemporary stack lift disable), and the top registerT ("top") gets duplicated on drops (top copy on pop akatop stack level repetition) in order to ease some calculations and to save keystrokes.[47] HP used reverse Polish notation on every handheld calculator it sold, whether scientific, financial, or programmable, until it introduced theHP-10adding machine calculator in 1977. By this time, HP was the leading manufacturer of calculators for professionals, including engineers and accountants.
Later calculators with LCDs in the early 1980s, such as theHP-10C,HP-11C,HP-15C,HP-16C, and the financialHP-12C calculator also used reverse Polish notation. In 1988, Hewlett-Packard introduced a business calculator, theHP-19B, without reverse Polish notation, but its 1990 successor, theHP-19BII, gave users the option of using algebraic or reverse Polish notation again.
In 1986,[49][50] HP introducedRPL, an object-oriented successor to reverse Polish notation. It deviates from classical reverse Polish notation by using a dynamic stack only limited by the amount of available memory (instead of three or four fixed levels) and which could hold all kinds of data objects (including symbols, strings, lists, matrices, graphics, programs, etc.) instead of just numbers. The system would display an error message when running out of memory instead of just dropping values off the stack on overflow as with fixed-sized stacks.[51] It also changed the behaviour of the stack to no longer duplicate the top register on drops (since in an unlimited stack there is no longer a top register) and the behaviour of theEnter↑ key so that it no longer duplicated values into Y, which had shown to sometimes cause confusion among users not familiar with the specific properties of theautomatic memory stack. From 1990 to 2003, HP manufactured theHP-48 series of graphing RPL calculators, followed by theHP-49 series between 1999 and 2008. The last RPL calculator was namedHP 50g, introduced in 2006 and discontinued in 2015. However, there are several community efforts likenewRPL orDB48X to recreate RPL on modern calculators.
As of 2011, Hewlett-Packard was offering the calculator models 12C, 12C Platinum,17bII+,20b,30b,33s,35s,48gII (RPL) and 50g (RPL) which support reverse Polish notation.[52]
While calculators emulating classical models continued to support classical reverse Polish notation, new reverse Polish notation models feature a variant of reverse Polish notation, where theEnter↑ key behaves as in RPL. This latter variant is sometimes known asentry RPN.[53]
In 2013, theHP Prime introduced a128-level form of entry RPN calledadvanced RPN. In contrast to RPL with its dynamic stack, it just drops values off the stack on overflow like other fixed-sized stacks do.[51] However, like RPL, it does not emulate the behaviour of a classical operational RPN stack to duplicate the top register on drops.
In late 2017, the list of active models supporting reverse Polish notation included only the 12C, 12C Platinum, 17bii+, 35s, and Prime. By July 2023, only the 12C, 12C Platinum, theHP 15C Collector's Edition, and the Prime remain active models supporting RPN.
In Britain,Clive Sinclair'sSinclair Scientific (1974) andScientific Programmable (1975) models used reverse Polish notation.[54][55]
In 1974,Commodore produced theMinuteman *6 (MM6) without anEnter↑ key and theMinuteman *6X (MM6X) with anEnter↑ key, both implementing a form oftwo-level RPN. TheSR4921 RPN came with a variant offour-level RPN with stack levels named X, Y, Z, and W (rather than T) and anEnt key (for "entry"). In contrast to Hewlett-Packard's reverse Polish notation implementation, W filled with 0 instead of its contents being duplicated on stack drops.[56]
Prinz andPrinztronic were own-brand trade names of the BritishDixons photographic and electronic goods stores retail chain, later rebranded asCurrys Digital stores, and became part of DSG International. A variety of calculator models was sold in the 1970s under the Prinztronic brand, all made for them by other companies.
Among these was the PROGRAM[57] Programmable Scientific Calculator which featured reverse Polish notation.
TheAircraft Navigation ComputerHeathkit OC-1401/OCW-1401 usedfive-level RPN in 1978.
Soviet programmable calculators (MK-52,MK-61,B3-34 and earlierB3-21[58] models) used reverse Polish notation for both automatic mode and programming. Modern Russian calculatorsMK-161[59] andMK-152,[60] designed and manufactured inNovosibirsk since 2007 and offered bySemico,[61] are backwards compatible with them. Their extended architecture is also based on reverse Polish notation.
An eight-level stack was suggested by John A. Ball in 1978.[5]
The community-developed calculatorsWP 34S (2011),WP 31S (2014) andWP 34C (2015), which are based on theHP 20b/HP 30b hardware platform, support classical Hewlett-Packard-style reverse Polish notation supporting automatic stack lift behaviour of theEnter↑ key and top register copies on pops, but switchable between a four- and an eight-level operational stack.
In addition to the optional support for an eight-level stack, the newerSwissMicros DM42-basedWP 43S as well as theWP 43C (2019) /C43 (2022) /C47 (2023) derivatives support data types for stack objects (real numbers, infinite integers, finite integers, complex numbers, strings, matrices, dates and times). The latter three variants can also be switched betweenclassical andentry RPN behaviour of theEnter↑ key, a feature often requested by the community.[66] They also support a rarely seensignificant figures mode, which had already been available as a compile-time option for the WP 34S and WP 31S.[67][68]
Since 2021, theHP-42S simulatorFree42 version 3 can be enabled to support a dynamic RPN stack only limited by the amount of available memory instead of the classical 4-level stack. This feature was incorporated as a selectable function into the DM42 since firmware DMCP-3.21 / DM42-3.18.[69][70]
Software calculators:
Existing implementations using reverse Polish notation include:
[…] In their advertisements and also in a letter to me,Hewlett-Packard Company (HP), the best known manufacturer of RPN calculators, says that RPN is based on a suggestion byJan Łukasiewicz (1878–1956), and that RPN was invented and is patented by HP. Aside from the apparent contradiction in these two statements, I do not think that either of them is quite true. My first experience with RPN involved a nice oldFriden EC-130 desktop electronic calculator, circa 1964. The EC-130 has RPN with a push-down stack of four registers, all visible simultaneously on a cathode ray tube display. Furthermore, they are shown upside down, that is, the last-in-first-out register is at the bottom. […] Around 1966, theMonroe Epic calculator offered RPN with a stack of four, a printer, and either 14 or 42 step programmability. The instruction booklets with these two calculators make no mention of RPN orJan Łukasiewicz. […]
The interesting aspect of the programming of theZ-3 was that this code was very similar to that of, say, anHP-25. To perform an operation on two numbers, commands would first be given to recall the numbers from appropriate locations in the memory, followed by the command for the operation. Numbers were automatically positioned in registers in the Arithmetic Unit of the machine so that operations like division and subtraction would proceed in the right order. Results were left in a register in the AU so that long sequences of operations could be carried out. Thus, the Z-3 used a version of RPN that was nearly identical to that used by HP! I have obtained copies of early programs that Zuse had written for the evaluation of a 5 × 5 determinant, and it is possible to run these programs on anHP-41C with almost no modification whatsoever (once the numbers have been placed in the storage registers beforehand). The AU of the Z-3 contained 3 registers, although Zuse never referred to them as a stack, of course. These registers were labelled "f", "a", and "b". All entrance and exit to and from the AU was through the "f" register. This is sort of like the display register of the 41C, which is distinct from the stack. Arithmetic operations were performed on numbers in the a and b registers, so these may be thought of as corresponding to the x and y registers of HP's. Unlike modern computer practice, the actual numbers themselves were moved around the registers, not just a pointer.
[…]Hamblin soon became aware of the problems of (a) computing mathematical formulae containing brackets, and (b) the memory overhead in having dealing with memory stores each of which had its own name. One solution to the first problem wasJan Łukasiewicz's Polish notation, which enables a writer of mathematical notation to instruct a reader the order in which to execute the operations (e.g. addition, multiplication, etc) without using brackets. Polish notation achieves this by having an operator (+, ×, etc) precede the operands to which it applies, e.g., +ab, instead of the usual, a+b. Hamblin, with his training in formal logic, knew of Lukasiewicz's work. […]
[…] I changed the architecture to use RPN (Reverse Polish Notation), which is the ideal notation for programming environment in which coding efficiency is critical. In the beginning, that change was not well received... […]
In terms of practical choice between calculators, it would appear that RPN is faster and more accurate overall but particularly for more complex problems.(5 pages)
Die Z3 konnte in zwei Betriebsmodi betrieben werden, und zwar in dem Programm- und Dialogmodus. Das Rechnen im Dialog erfolgt wie mit einem Taschenrechner in der umgekehrten polnischen Notation.[1]
Zum Eingeben der Zahlen stand eine Tastatur bereit (Dezimalzahlen, Gleitkommadarstellung). Anweisungen gaben Nutzer in umgekehrter polnischer Notation: zuerst die Argumente, um Register zu befüllen, dann der auszuführende Operator.
Dazu stehen die beiden Register R1 und R2 als Kurzspeicher für die Operanden der arithmetischen Operationen zur Verfügung. Gerechnet wird in der umgekehrten polnischen Notation, wie z.B. beim TaschenrechnerHP 45 (1972) oderHP11 (1998).(5 pages)
The computer can be used as a simple hand-held calculator. In this mode besides entering the numeric values the user must enter the instructions and the addresses by pressing their keys. He has to enter the numbers and operators in the reverse Polish notation.
Er hat wohl auch als erster die vom polnischen MathematikerJan Lukasiewicz entwickelte ›polnische Notation‹ weiterentwickelt und daraus die ›umgekehrte polnische Notation‹ (UPN) ersonnen, da diese in seinen Rechnern verwendet wird: zunächst werden die Werte eingegeben, danach die gewünschte Rechenoperation ausgelöst. Klammern werden auf diese Weise vermieden.(4 pages)
Über die I/O-Einheit kann man dieZ3 als reine Rechenmaschine einsetzen, Operationen nimmt sie dann in der praktischen – wenn auch gewöhnungsbedürftigen – umgekehrten polnischen Notation entgegen. Werte im Speicher ablegen (oder von dort laden) kann man so allerdings nicht.
[…] TheKDF9 is remarkable because it is the believed to be the first zero-address instruction format computer to have been announced (in 1960). It was first delivered at about the same time (early 1963) as the other famous zero-address computer, theBurroughs B5000 in America. Like many modern pocket calculators, a zero-address machine allows the use of Reverse Polish arithmetic; this offers certain advantages to compiler writers. It is believed that the attention of the English Electric team was first drawn to the zero-address concept through contact withGeorge (General Order Generator), an autocode programming system written for aDeuce computer by theUniversity of Sydney, Australia, in the latter half of the 1950s. George used Reversed Polish, and the KDF9 team were attracted to this convention for the pragmatic reason of wishing to enhance performance by minimising accesses to main store. This may be contrasted with the more "theoretical" line taken independently byBurroughs. Besides a hardwarenesting store or stack - the basic mechanism of a zero-address computer - the KDF9 had other groups of central registers for improving performance which gave it an interesting internal structure. […][2] (NB. This is an edited version of a talk given to North West Group of the Society at the Museum of Science and Industry, Manchester, UK on 1996-10-01.)
[…] Bob holds over 80 patents awarded during his work as Director of RD forFriden, andSinger and as Senior Project Engineer atXerox. He retired from Xerox RD in 1990. He is responsible for the development of the first commercial electronic calculator, theFriden 130, which has been displayed at theSmithsonian. […]
[…] The operational stack and reverse Polish (Łukasiewicz) notation used in the HP-35 are the most efficient way known to computer science for evaluating mathematical expressions. […]
DATA STORAGE: 2 Auxiliary Storage Registers plus up to 7 push-up Stack Registers. […] 7400A 3 Registers Kit $299.95 Assembled $379.95 […] 7400B 5 Registers Kit $319.95 Assembled $399.95 […] 7400C 7 Registers Kit $339.95 Assembled $419.95