Reverse Polish notation

Reverse Polish notation (RPN), also known as Polish postfix notation or simply postfix notation, is a mathematical notation in which operators follow their operands, in contrast to Polish notation (PN), in which operators precede their operands. It does not need any parentheses as long as each operator has a fixed number of operands. The description "Polish" refers to the nationality of logician Jan Łukasiewicz,[1] who invented Polish notation in 1924.[2][3]

The reverse Polish scheme was proposed in 1954 by Arthur Burks, Don Warren, and Jesse Wright[4] and was independently reinvented by Friedrich L. Bauer and Edsger W. Dijkstra in the early 1960s to reduce computer memory access and utilize the stack to evaluate expressions. The algorithms and notation for this scheme were extended by Australian philosopher and computer scientist Charles L. Hamblin in the mid-1950s.[5][6]

During the 1970s and 1980s, Hewlett-Packard used RPN in all of their desktop and hand-held calculators, and continued to use it in some models into the 2010s.[7][8] In computer science, reverse Polish notation is used in stack-oriented programming languages such as Forth, STOIC, PostScript, RPL and Joy.

Explanation

In reverse Polish notation, the operators follow their operands; for instance, to add 3 and 4, one would write 3 4 + rather than 3 + 4. If there are multiple operations, operators are given immediately after their second operands; so the expression written 3 − 4 + 5 in conventional notation would be written 3 4 − 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it. An advantage of reverse Polish notation is that it removes the need for parentheses that are required by infix notation. While 3 − 4 × 5 can also be written 3 − (4 × 5), that means something quite different from (3 − 4) × 5. In reverse Polish notation, the former could be written 3 4 5 × −, which unambiguously means 3 (4 5 ×) − which reduces to 3 20 − (which can further be reduced to -17); the latter could be written 3 4 − 5 × (or 5 3 4 − ×, if keeping similar formatting), which unambiguously means (3 4 −) 5 ×.

Practical implications

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.[9][10] 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.[11] However, anecdotal evidence suggests that reverse Polish notation is more difficult for users to learn than algebraic notation.[10]

Converting from infix notation

Edsger W. Dijkstra invented the shunting-yard algorithm to convert infix expressions to postfix expressions (reverse Polish notation), so named because its operation resembles that of a railroad shunting yard.

There are other ways of producing postfix expressions from infix expressions. Most operator-precedence parsers can be modified to produce postfix expressions; in particular, once an abstract syntax tree has been constructed, the corresponding postfix expression is given by a simple post-order traversal of that tree.

Implementations

History

The first computers to implement architectures enabling reverse Polish notation were the English Electric Company's KDF9 machine, which was announced in 1960 and commercially available in 1963, and the American Burroughs B5000, announced in 1961 and also delivered in 1963. 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 by Irving Copi,[12][13][14] where he found a reference to Polish notation,[14] which made him read the works of Jan Łukasiewicz as well,[14] and before he was aware of Hamblin's work. Designed by Robert "Bob" Appleby Ragen,[15] Friden introduced reverse Polish notation to the desktop calculator market with the EC-130 supporting a four-level stack[3] in June 1963.[16] The successor EC-132 added a square root function in April 1965.[17] Around 1966, the Monroe Epic calculator supported an unnamed input scheme resembling RPN as well.[3]

Hewlett-Packard

A promotional Hewlett-Packard "No Equals" hat from the 1980s – both a boast and a reference to RPN

Hewlett-Packard engineers designed the 9100A Desktop Calculator in 1968 with reverse Polish notation[7] with only three stack levels,[18] a reverse Polish notation variant later referred to as three-level RPN. This calculator popularized reverse Polish notation among the scientific and engineering communities. The HP-35, the world's first handheld scientific calculator,[7] introduced the classical four-level RPN in 1972.[19] HP used reverse Polish notation on every handheld calculator it sold, whether scientific, financial, or programmable, until it introduced the HP-10 adding machine calculator in 1977. By this time, HP was the leading manufacturer of calculators for professionals, including engineers and accountants.

Later calculators with LCD displays in the early 1980s, such as the HP-10C, HP-11C, HP-15C, HP-16C, and the financial HP-12C calculator also used reverse Polish notation. In 1988, Hewlett-Packard introduced a business calculator, the HP-19B, without reverse Polish notation, but its 1990 successor, the HP-19BII, gave users the option of using algebraic or reverse Polish notation.

Around 1987, HP introduced RPL, an object-oriented successor to reverse Polish notation. It deviates from classical reverse Polish notation by utilizing a stack only limited by the amount of available memory (instead of three or four fixed levels) and which can hold all kinds of data objects (including symbols, strings, lists, matrices, graphics, programs, etc.) instead of just numbers. 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 the ↵ Enter key so that it no longer duplicates values into Y under certain conditions, both part of the specific ruleset of the so-called automatic memory stack[20] or operational (memory) stack[21] in classical reverse Polish notation in order to ease some calculations and to save keystrokes, but which had shown to also sometimes cause confusion among users not familiar with these properties. From 1990 to 2003 HP manufactured the HP-48 series of graphing RPL calculators, and in 2006 introduced the HP 50g.

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.[22] While calculators emulating classical models continue to support classical reverse Polish notation, new reverse Polish notation models feature a variant of reverse Polish notation, where the ↵ Enter key behaves as in RPL. This latter variant is sometimes known as entry RPN.[23] In 2013, the HP Prime introduced a 128-level form of entry RPN called advanced RPN. By late 2017, only the 12C, 12C Platinum, 17bii+, 35s and Prime remain active HP models supporting reverse Polish notation.

WP 31S and WP 34S

The community-developed calculators WP 31S and WP 34S, which are based on the HP 20b/HP 30b hardware platform, support Hewlett-Packard-style classical reverse Polish notation with either a four- or an eight-level stack. A seven-level stack had been implemented in the MITS 7400C scientific desktop calculator in 1972[24][25][26] and an eight-level stack was already suggested by John A. Ball in 1978.[3]

Sinclair Radionics

In Britain, Clive Sinclair's Sinclair Scientific and Scientific Programmable models used reverse Polish notation.[27][28]

Commodore

In 1974 Commodore produced the Minuteman *6 (MM6) without ↵ Enter key and the Minuteman *6X (MM6X) with ↵ Enter key, both implementing a form of two-level RPN. The SR4921 RPN came with a variant of four-level RPN with stack levels named X, Y, Z, and W (rather than T). In contrast to Hewlett-Packard's reverse Polish notation implementation, W filled with 0 instead of its contents being duplicated on stack drops.[29]

Prinztronic

Prinz and Prinztronic were own-brand trade names of the British Dixons photographic and electronic goods stores retail chain, later rebranded as Currys 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[30] Programmable Scientific Calculator which featured reverse Polish notation.

Heathkit

The Aircraft Navigation Computer Heathkit OC-1401/OCW-1401 used five-level RPN in 1978.

Soviet Union

Soviet programmable calculators (MK-52, MK-61, B3-34 and earlier B3-21[31] models) used reverse Polish notation for both automatic mode and programming. Modern Russian calculators MK-161[32] and MK-152,[33] designed and manufactured in Novosibirsk since 2007 and offered by Semico,[34] are backwards compatible with them. Their extended architecture is also based on reverse Polish notation.

Other

Existing implementations using reverse Polish notation include:

See also

References

  1. Łukasiewicz, Jan (1957). Aristotle's Syllogistic from the Standpoint of Modern Formal Logic. Oxford University Press. (Reprinted by Garland Publishing in 1987. ISBN 0-8240-6924-2)
  2. Hamblin, Charles Leonard (1962). "Translation to and from Polish notation" (PDF). Computer Journal. 5 (3): 210–213. doi:10.1093/comjnl/5.3.210.
  3. Ball, John A. (1978). Algorithms for RPN calculators (1 ed.). Cambridge, Massachusetts, USA: Wiley-Interscience, John Wiley & Sons, Inc. ISBN 0-471-03070-8. […] 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 by Jan Ł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 old Friden 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, the Monroe 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 or Jan Łukasiewicz. […]
  4. Burks, Arthur Walter; Warren, Don W.; Wright, Jesse B. (1954). "An Analysis of a Logical Machine Using Parenthesis-Free Notation". Mathematical Tables and Other Aids to Computation. 8 (46): 53–57. doi:10.2307/2001990. JSTOR 2001990.
  5. "Charles L. Hamblin and his work" Archived 2008-12-06 at the Wayback Machine by Peter McBurney
  6. McBurney, Peter (2008-07-27). "Charles L. Hamblin: Computer Pioneer". Archived from the original on 2008-12-07. […] 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 was Jan Ł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. […]
  7. Osborne, Thomas E. (2010) [1994]. "Tom Osborne's Story in His Own Words". Steve Leibson. Retrieved 2016-01-01. […] 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... […]
  8. Peterson, Kristina (2011-05-04). "Wall Street's Cult Calculator Turns 30". Wall Street Journal. Archived from the original on 2015-03-16. Retrieved 2015-12-06.
  9. Kasprzyk, D. M.; Drury, Colin G.; Bialas, W. F. (1979), "Human behaviour and performance in calculator use with Algebraic and Reverse Polish Notation", Ergonomics, 22 (9): 1011–1019, doi:10.1080/00140137908924675
  10. Agate, Seb J.; Drury, Colin G. (March 1980), "Electronic calculators: which notation is the better?", Applied Ergonomics, Department of Industrial Engineering, University at Buffalo, State University of New York, USA: IPC Business Press, 11 (1): 2–6, doi:10.1016/0003-6870(80)90114-3, PMID 15676368, 0003-6870/80/01 0002-05, archived from the original on 2018-09-22, retrieved 2018-09-22
  11. Hoffman, Errol; Ma, Patrick; See, Jason; Yong, Chee Kee; Brand, Jason; Poulton, Matthew (1994), "Calculator logic: when and why is RPN superior to algebraic?", Applied Ergonomics, 25 (5): 327–333, doi:10.1016/0003-6870(94)90048-5
  12. "Archived copy" (PDF). Archived from the original (PDF) on 2012-04-22. Retrieved 2013-02-27.CS1 maint: archived copy as title (link) A New Approach to the Design of a Digital Computer (1961)
  13. The Burroughs B5000 Conference (1985) p. 49
  14. "Oral History: Burroughs B5000 Conference", OH 98. Oral history on 6 September 1985, conducted by Bernard A. Galler and Robert F. Rosin, sponsored by AFIPS and Burroughs Corporation, at Marina del Rey, California, archived by the Charles Babbage Institute, University of Minnesota, Minneapolis.
  15. "1928–2012 Obituary Condolences Robert (Bob) Ragen". 2012-07-23. Archived from the original on 2017-12-18. Retrieved 2016-01-01. […] Bob holds over 80 patents awarded during his work as Director of RD for Friden, and Singer and as Senior Project Engineer at Xerox. He retired from Xerox RD in 1990. He is responsible for the development of the first commercial electronic calculator, the Friden 130, which has been displayed at the Smithsonian. […]
  16. "Friden EC-130 Electronic Calculator". www.oldcalculatormuseum.com. Retrieved 2018-03-21.
  17. "Friden EC-132 Electronic Calculator". www.oldcalculatormuseum.com. Retrieved 2018-03-21.
  18. Monnier, Richard E. (September 1968). "A New Electronic Calculator with Computerlike Capabilities" (PDF). Hewlett-Packard Journal. Palo Alto, California, USA: Hewlett-Packard. 20 (1): 3–9. Retrieved 2016-01-03.
  19. Laporte, Jacques (2014-05-22). "The slide rule killer: a milestone in computer history". Archived from the original on 2015-02-11. Retrieved 2016-01-01.
  20. HP-42S RPN Scientific Calculator – Owner's Manual (PDF) (1 ed.). Corvallis, OR, USA: Hewlett-Packard Co. June 1988. p. 3. 00042-90001. Archived (PDF) from the original on 2017-09-17. Retrieved 2017-09-17.
  21. HP35 User's Manual. Hewlett-Packard. p. i. […] 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. […]
  22. HP Calculators
  23. http://h20331.www2.hp.com/hpsub/downloads/S07%20HP%20RPN%20Evolves%20V5b.pdf
  24. Radio-Electronics magazine, 1972
  25. Berger, Ivan (May 1973). "New calculator kits: From pocket minis to versatile desk models". Popular Mechanics: 152. Retrieved 2017-04-29.
  26. "MITS 7400 Scientific/Engineering Calculator". Archived from the original on 2017-04-30. Retrieved 2017-04-30. (NB. Shows a photo of the MITS 7400, but the text erroneously refers to the later algebraic 7440 model instead of the 7400A/B/C models.)
  27. Shirriff, Ken. "Reversing Sinclair's amazing 1974 calculator hack – half the ROM of the HP-35". Retrieved 2013-12-09.
  28. Sharwood, Simon (2013-09-02). "Google chap reverse engineers Sinclair Scientific Calculator". The Register. Retrieved 2013-12-09.
  29. http://www.wass.net/manuals/Commodore%20SR4921R.pdf
  30. "Prinztronic Program". www.vintagecalculators.com. Retrieved 2018-03-21.
  31. Elektronika B3-21 page on RSkey.org
  32. Elektronika MK-161 page on RSkey.org
  33. "Elektronika MK-61/52 and 152/161: small tech review (En) - Кон-Тики". arbinada.com. Retrieved 2018-03-21.
  34. "НПП СЕМИКО - вычислительная техника и устройства автоматизации". mk.semico.ru. Retrieved 2018-03-21.
  35. Geschke, Charles (1986) [1985]. Preface. PostScript Language Tutorial and Cookbook. By Adobe Systems Incorporated (27th printing, August 1998, 1st ed.). Addison Wesley Publishing Company. ISBN 0-201-10179-3. 9-780201-101799. (NB. This book is informally called "blue book" due to its blue cover.)
  36. Adobe Systems Incorporated (February 1999) [1985]. PostScript Language Reference Manual (PDF) (1st printing, 3rd ed.). Addison-Wesley Publishing Company. ISBN 0-201-37922-8. Archived (PDF) from the original on 2017-02-18. Retrieved 2017-02-18. (NB. This book is informally called "red book" due to its red cover.)
  37. Born, Günter (December 2000). "Kapitel 1. LOTUS 1-2-3-Format (WKS/WK1)" [Chapter 1. Lotus 1-2-3 WKS/WK1 format]. Dateiformate – Eine Referenz – Tabellenkalkulation, Text, Grafik, Multimedia, Sound und Internet [File formats – a reference – spreadsheets, text, graphics, multimedia, sound and internet] (PDF) (in German). Bonn, Germany: Galileo Computing. ISBN 3-934358-83-7. Archived (PDF) from the original on 2016-11-29. Retrieved 2016-11-28.
  38. Born, Günter (December 2000). "Kapitel 2. LOTUS 1-2-3-Format (WK3)" [Chapter 2. Lotus 1-2-3 WK3 format]. Dateiformate – Eine Referenz – Tabellenkalkulation, Text, Grafik, Multimedia, Sound und Internet [File formats – a reference – spreadsheets, text, graphics, multimedia, sound and internet] (PDF) (in German). Bonn, Germany: Galileo Computing. ISBN 3-934358-83-7. Archived (PDF) from the original on 2016-11-29. Retrieved 2016-11-28.
  39. Feichtinger, Herwig (1987). Arbeitsbuch Mikrocomputer (in German) (2 ed.). Munich, Germany: Franzis-Verlag GmbH. pp. 427–428. ISBN 3-7723-8022-0. (NB. According to this book, a 4 KB compiler was available from Lifeboat Software for CP/M.)
  40. Wostrack, Gustav (January 1989). RPNL. Eine FORTH ähnliche Sprache mit strukturunterstützenden Sprachkonstrukten (in German). Wolf-Detlef Luther, Gens. ISBN 978-3-88707022-9.
  41. "Katharina & Paul Wilkins' Home Page". lashwhip.com. Retrieved 2018-03-21.
  42. "galculator - a GTK 2 / GTK 3 algebraic and RPN calculator". galculator.sourceforge.net. Retrieved 2018-03-21.
  43. Schrijver, Frans. "Home - mouseless Stack-Calculator". www.stack-calculator.com. Retrieved 2018-03-21.

Further reading

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.