RPN (notation)
   HOME

TheInfoList



OR:

Reverse Polish notation (RPN), also known as reverse Łukasiewicz notation, 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, who invented Polish notation in 1924. The first computer to use postfix notation, though it long remained essentially unknown outside of Germany, was Konrad Zuse's Z3 in 1941 as well as his Z4 in 1945. The reverse Polish scheme was again proposed in 1954 by Arthur Burks, Don Warren, and Jesse Wright and was independently reinvented by Friedrich L. Bauer and
Edsger W. Dijkstra Edsger Wybe Dijkstra ( ; ; 11 May 1930 – 6 August 2002) was a Dutch computer scientist, programmer, software engineer, systems scientist, and science essayist. He received the 1972 Turing Award for fundamental contributions to developing progra ...
in the early 1960s to reduce computer memory access and use the
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
to evaluate expressions. The algorithms and notation for this scheme were extended by the Australian
philosopher A philosopher is a person who practices or investigates philosophy. The term ''philosopher'' comes from the grc, φιλόσοφος, , translit=philosophos, meaning 'lover of wisdom'. The coining of the term has been attributed to the Greek th ...
and
computer scientist A computer scientist is a person who is trained in the academic study of computer science. Computer scientists typically work on the theoretical side of computation, as opposed to the hardware side on which computer engineers mainly focus (al ...
Charles L. Hamblin in the mid-1950s. During the 1970s and 1980s,
Hewlett-Packard The Hewlett-Packard Company, commonly shortened to Hewlett-Packard ( ) or HP, was an American multinational information technology company headquartered in Palo Alto, California. HP developed and provided a wide variety of hardware components ...
used RPN in all of their desktop and hand-held calculators, and has continued to use it in some models into the 2020s. In computer science, reverse Polish notation is used in stack-oriented programming languages such as
Forth Forth or FORTH may refer to: Arts and entertainment * ''forth'' magazine, an Internet magazine * ''Forth'' (album), by The Verve, 2008 * ''Forth'', a 2011 album by Proto-Kaw * Radio Forth, a group of independent local radio stations in Scotla ...
, STOIC,
PostScript PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, Doug Br ...
, RPL and Joy.


Explanation

In reverse Polish notation, the operators follow their operands; for instance, to add 3 and 4 together, one would write rather than . If there are multiple operations, operators are given immediately after their final operands (often an operator takes two operands, in which case the operator is written after the second operand); so the expression written in conventional notation would be written in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it. The concept of a stack, a last-in/first-out construct, is integral to these actions. So in the above example, the 3 is loaded onto the bottom of the stack (the visible level) and a separate special keypress (the "" button on an HP calculator, for example) terminates that entry. Without this action, the 4 would append to the 3, giving 34, which is not desired. When the 4 is entered the 3 is promoted to the second stack level; the 3 is now above the 4, currently visible. The subtraction operator acts immediately on the first two levels of the stack contents, subtracting the lower value from the upper, yielding -1 at level one. This also terminates data entry, so the 5 can be immediately entered. This automatically raises the -1 to the second level. When the user then presses (add), the first two levels are added, and the result, 4, appears in the lower. This automatic promotion (and demotion) of data among levels in the stack as each operation is performed automatically sets up successive operators just as they are needed. In HP calculators, the stack is four levels high. So it is possible to type 3, , type 4, , type 5, , and type 6. The stack now holds all four values in its four levels. One can then hit the button three times, and the sum, 18, will appear in level one. Any new data entry promotes the 18 to level two. This activity is limited only by the "height" of the stack. Careful stack management allows complex parenthesis-filled expressions to be evaluated in a simple linear fashion. It is rarely required that intermediate results be stored and retrieved, as is required usually of algebraic notation systems. This advantage of reverse Polish notation is that it removes the need for parentheses that are required by
infix notation Infix notation is the notation commonly used in arithmetical and logical formulae and statements. It is characterized by the placement of operators between operands—" infixed operators"—such as the plus sign in . Usage Binary relations a ...
, since the stack holds all arguments in a last-in, first out progression. For example, to compute the expression , one would type 3, press , and type 4. Upon pressing (multiply), the intermediate product 12 appears visually at the bottom of the stack. Then one types 5, , and 6. The intermediate result 12 has been promoted to level three, with the 5 at level two and the 6 visible at level one. It is only required to press and then in succession. The intermediate product, 30, appears first in level one, and the final result, 42 appears at level one since the 12 at level two has now been added. Rare occasions of the need of storing intermediate results and how complex an expression can be solved without it can be read in Hans Klavers RPN Tutorial (see Further reading).


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


Converting from infix notation

Edsger W. Dijkstra Edsger Wybe Dijkstra ( ; ; 11 May 1930 – 6 August 2002) was a Dutch computer scientist, programmer, software engineer, systems scientist, and science essayist. He received the 1972 Turing Award for fundamental contributions to developing progra ...
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 computer implementing a form of reverse Polish notation (but without the name), was Konrad Zuse's Z3, which he started to construct in 1938 and demonstrated publicly on 12 May 1941. In dialog mode, it allowed operators to enter two operands followed by the desired operation. It was destroyed on 21 December 1943 in a bombing raid. With Zuse's help a first replica was built in 1961. The 1945 Z4 also added a
stack Stack may refer to: Places * Stack Island, an island game reserve in Bass Strait, south-eastern Australia, in Tasmania’s Hunter Island Group * Blue Stack Mountains, in Co. Donegal, Ireland People * Stack (surname) (including a list of people ...
. Other early 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 Burroughs B5000, announced in 1961 and also delivered in 1963: Presumably, the KDF9 designers drew ideas from Hamblin's GEORGE (General Order Generator), an autocode programming system written for a
DEUCE Deuce, Deuces, or The Deuce may refer to: Arts and entertainment Fictional characters * Deuce, in the ''Danger Girl'' comic book series * Deuce, a character in ''Shake It Up'' * Deuce, in the ''Wild Cards'' science fiction universe * Deuce Biga ...
computer installed at the University of Sydney, Australia, in 1957. 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 Irving Marmer Copi (; né Copilovich or Copilowish; July 28, 1917 – August 19, 2002) was an American philosopher, logician, and university textbook author. Biography Copi studied under Bertrand Russell while at the University of Chicago. I ...
, where he found a reference to Polish notation, which made him read the works of Jan Łukasiewicz as well, and before he was aware of Hamblin's work. Friden introduced reverse Polish notation to the desktop calculator market with the EC-130, designed by Robert "Bob" Appleby Ragen, supporting a four-level stack in June 1963. The successor EC-132 added a square root function in April 1965. Around 1966, the
Monroe Epic The Monroe EPIC was a programmable calculator that came on the market in the 1960s. It consisted of a large desktop unit which attached to a floor-standing logic tower and was capable of being programmed to perform many computer-like functions. Howe ...
calculator supported an unnamed input scheme resembling RPN as well.


Hewlett-Packard

Hewlett-Packard engineers designed the 9100A Desktop Calculator in 1968 with reverse Polish notation with only three stack levels with working registers ''X'' ("keyboard"), ''Y'' ("accumulate") and visible storage register ''Z'' ("temporary"), 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 An electronic calculator is typically a portable electronic device used to perform calculations, ranging from basic arithmetic to complex mathematics. The first solid-state electronic calculator was created in the early 1960s. Pocket-sized ...
, introduced the classical ''four-level RPN'' with its specific ruleset of the so-called ''operational (memory) stack'' (later also called ''automatic memory stack'') in 1972. In this scheme, the key duplicates values into Y under certain conditions, and the top register gets duplicated on drops in order to ease some calculations and to save keystrokes. 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 The Hewlett-Packard Voyager series of calculators were introduced by Hewlett-Packard in 1981. All members of this series are programmable, use Reverse Polish Notation, and feature continuous memory. Nearly identical in appearance, each mode ...
,
HP-11C The Hewlett-Packard Voyager series of calculators were introduced by Hewlett-Packard in 1981. All members of this series are programmable, use Reverse Polish Notation, and feature continuous memory. Nearly identical in appearance, each mode ...
, 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 again. Around 1987, HP introduced RPL, an object-oriented successor to reverse Polish notation. It deviates from classical reverse Polish notation by using a 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. 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 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 the ''automatic memory stack''. 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. 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 key behaves as in RPL. This latter variant is sometimes known as ''entry RPN''. 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 The HP 30b (NW238AA, variously codenamed "Big Euro", "Mid Euro" and "Fox") is a programmable financial calculator from HP which was released on 7 January 2010. The HP 30b is an advanced version of the HP's prior model HP 20b. F ...
and
WP 34S The HP 30b (NW238AA, variously codenamed "Big Euro", "Mid Euro" and "Fox") is a programmable financial calculator from HP which was released on 7 January 2010. The HP 30b is an advanced version of the HP's prior model HP 20b. F ...
, 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 and an eight-level stack was already suggested by John A. Ball in 1978.


Sinclair Radionics

In Britain,
Clive Sinclair Sir Clive Marles Sinclair (30 July 1940 – 16 September 2021) was an English entrepreneur and inventor, best known for being a pioneer in the computing industry, and also as the founder of several companies that developed consumer electronics ...
's
Sinclair Scientific The Sinclair Scientific calculator was a 12-function, pocket-sized scientific calculator introduced in 1974, dramatically undercutting in price other calculators available at the time. The Sinclair Scientific Programmable, released a year later, ...
and Scientific Programmable models used reverse Polish notation.


Commodore

In 1974, Commodore produced the Minuteman *6 (MM6) without key and the Minuteman *6X (MM6X) with 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) and an 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.


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 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 Elektronika B3-34 (Cyrillic: Электроника Б3-34) was a Soviet programmable calculator. It was released in 1980 and was sold for 85 rubles. B3-34 used reverse Polish notation and had 98 bytes of instruction memory, four stack user regist ...
and earlier B3-21 models) used reverse Polish notation for both automatic mode and programming. Modern Russian calculators MK-161 and MK-152, designed and manufactured in
Novosibirsk Novosibirsk (, also ; rus, Новосиби́рск, p=nəvəsʲɪˈbʲirsk, a=ru-Новосибирск.ogg) is the largest city and administrative centre of Novosibirsk Oblast and Siberian Federal District in Russia. As of the Russian Census ...
since 2007 and offered by Semico, are backwards compatible with them. Their extended architecture is also based on reverse Polish notation.


Other

Existing implementations using reverse Polish notation include: *
Stack-oriented programming language Stack-oriented programming, is a programming paradigm which relies on a stack machine model for passing Parameter (computer programming), parameters. Stack-oriented languages operate on one or more Stack (data structure), stacks, each of which ...
s such as: **
Forth Forth or FORTH may refer to: Arts and entertainment * ''forth'' magazine, an Internet magazine * ''Forth'' (album), by The Verve, 2008 * ''Forth'', a 2011 album by Proto-Kaw * Radio Forth, a group of independent local radio stations in Scotla ...
** STOIC ** Factor **
PostScript PostScript (PS) is a page description language in the electronic publishing and desktop publishing realm. It is a dynamically typed, concatenative programming language. It was created at Adobe Systems by John Warnock, Charles Geschke, Doug Br ...
page description language ** BibTeX ** Befunge ** Joy **
IPTSCRAE Iptscrae is a stack-oriented scripting language used to give additional functionality to The Palace software and servers. Its name comes from the pronunciation of "script" in Pig Latin The language was created by Jim Bumgardner, who in turn was ...
** Lotus 1-2-3 and Lotus Symphony formulas ** RPL (aka Reverse Polish Language), a programming language for the Commodore PET around 1979/1981 ** RPL (aka Reverse Polish Lisp), a programming language for
Hewlett-Packard The Hewlett-Packard Company, commonly shortened to Hewlett-Packard ( ) or HP, was an American multinational information technology company headquartered in Palo Alto, California. HP developed and provided a wide variety of hardware components ...
calculators between 1984 and 2015 ** RPNL (Reverse Polish Notation Language) * Hardware calculators: ** Some Hewlett-Packard science/engineering and business/finance calculators ** Semico calculators ** SwissMicros calculators ** Some APF calculators as well can use RPN * Software calculators: ** Mac OS X Calculator ** Several Apple iPhone applications e.g. "reverse polish notation calculator" ** Several
Android Android may refer to: Science and technology * Android (robot), a humanoid robot or synthetic organism designed to imitate a human * Android (operating system), Google's mobile operating system ** Bugdroid, a Google mascot sometimes referred to ...
applications e.g. "RealCalc" ** Several Windows 10 Mobile applications e.g. "RPN9" **
Unix system Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
calculator program dc **
Emacs Emacs , originally named EMACS (an acronym for "Editor MACroS"), is a family of text editors that are characterized by their extensibility. The manual for the most widely used variant, GNU Emacs, describes it as "the extensible, customizable, s ...
lisp library package calc ** Xorg calculator ( xcalc) ** ARPCalc, a powerful scientific/engineering RPN calculator for Windows, Linux and Android that also has a web-browser based version. ** scientific/engineering calculator using the GIMP Toolkit (
GTK+ GTK (formerly GIMP ToolKit and GTK+) is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both free and proprie ...
) ** F-Correlatives in MultiValue dictionary items ** RRDtool, a widely used tabulating and graphing software ** , a program for algebraic operations on NetCDF grids, part of
Generic Mapping Tools Generic Mapping Tools (GMT) are an open-source collection of computer software tools for processing and displaying xy and xyz datasets, including rasterisation, filtering and other image processing operations, and various kinds of map projections ...
(GMT) suite ** , a GTK desktop calculator ** Mouseless Stack-Calculator scientific/engineering calculator including complex numbers. ** , a simple reverse polish notation calculator written in Python for Linux and MS Windows and published under the GNU GPLv2 license. ** orpie, RPN calculator for the terminal for real or complex numbers or matrices. * Class libraries ** TRURL, a class library for the construction of RPN calculators in Object Pascal.


See also

* Calculator input methods * FOCAL keystroke programming *
Stack machine In computer science, computer engineering and programming language implementations, a stack machine is a computer processor or a virtual machine in which the primary interaction is moving short-lived temporary values to and from a push down st ...
*
Head-directionality parameter In linguistics, head directionality is a proposed parameter that classifies languages according to whether they are head-initial (the head of a phrase precedes its complements) or head-final (the head follows its complements). The head is th ...
*
Scrambling (linguistics) Scrambling is a syntactic phenomenon wherein sentences can be formulated using a variety of different word orders without any change in meaning. Scrambling often results in a discontinuity since the scrambled expression can end up at a distance ...


References


Further reading

* (NB. The book's cover title contains a typographical error reading "APS Mark 55" instead of the correct "APF Mark 55".) *

(16 pages) *

(13 of 702 pages) * (4 pages) * * * * * *


External links


Rosettacode.org
providing many implementations in several programming languages. * http://rpn.codeplex.com/ Implementation of RPN with custom functions support and flexible list of operators. * https://xrjunque.nom.es/ConvertAlg2RPN_RPL.aspx Free online Algebraic expression to RPN Converter {{DEFAULTSORT:Reverse Polish Notation Calculators Mathematical notation Science and technology in Poland Operators (programming)