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
operand In mathematics, an operand is the object of a mathematical operation, i.e., it is the object or quantity that is operated on. Example The following arithmetic expression shows an example of operators and operands: :3 + 6 = 9 In the above exam ...
s, 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 Nationality is a legal identification of a person in international law, establishing the person as a subject, a ''national'', of a sovereign state. It affords the state jurisdiction over the person and affords the person the protection of t ...
of logician
Jan Łukasiewicz Jan Łukasiewicz (; 21 December 1878 – 13 February 1956) was a Polish logician and philosopher who is best known for Polish notation and Łukasiewicz logic His work centred on philosophical logic, mathematical logic and history of logic. ...
, 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 Konrad Ernst Otto Zuse (; 22 June 1910 – 18 December 1995) was a German civil engineer, pioneering computer scientist, inventor and businessman. His greatest achievement was the world's first programmable computer; the functional program- ...
'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 Friedrich Ludwig "Fritz" Bauer (10 June 1924 – 26 March 2015) was a German pioneer of computer science and professor at the Technical University of Munich. Life Bauer earned his Abitur in 1942 and served in the Wehrmacht during World Wa ...
and Edsger W. Dijkstra in the early 1960s to reduce
computer memory In computing, memory is a device or system that is used to store information for immediate use in a computer or related computer hardware and digital electronic devices. The term ''memory'' is often synonymous with the term '' primary storag ...
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 In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
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 (a ...
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 Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, 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, Do ...
, 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 are ...
, 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 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 Konrad Ernst Otto Zuse (; 22 June 1910 – 18 December 1995) was a German civil engineer, pioneering computer scientist, inventor and businessman. His greatest achievement was the world's first programmable computer; the functional program- ...
'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 computer installed at the
University of Sydney The University of Sydney (USYD), also known as Sydney University, or informally Sydney Uni, is a public research university located in Sydney, Australia. Founded in 1850, it is the oldest university in Australia and is one of the country's si ...
, 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. In 1 ...
, 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 An adding machine is a class of mechanical calculator, usually specialized for bookkeeping calculations. In the United States, the earliest adding machines were usually built to read in dollars and cents. Adding machines were ubiquitous off ...
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 model ...
,
HP-15C The HP-15C is a high-end scientific programmable calculator of Hewlett-Packard's Voyager series produced between 1982 and 1989. Models HP-15C The HP-15C is a high-end scientific pocket calculator with a root-solver and numerical integration. ...
, 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 The HP 48 is a series of graphing calculators designed and produced by Hewlett-Packard from 1990 until 2003. The series includes the HP 48S, HP 48SX, HP 48G, HP 48GX, and HP 48G+, the G models being expanded and im ...
of graphing RPL calculators, and in 2006 introduced the
HP 50g The HP 49/50 series are Hewlett-Packard (HP) manufactured graphing calculators. They are the successors of the popular HP 48 series. There are five calculators in the 49/50 series of HP graphing calculators. These calculators have both a ...
. 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 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 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 electronic ...
's Sinclair Scientific 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 Currys Digital was an electrical retailer in the United Kingdom owned by Dixons Carphone, with its origins in a photographic shop opened by Charles Kalms. The chain was known as ''Dixons'' until 2006, when parent company DSG International ann ...
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 The Soviet Union,. officially the Union of Soviet Socialist Republics. (USSR),. was a List of former transcontinental countries#Since 1700, transcontinental country that spanned much of Eurasia from 1922 to 1991. A flagship communist state, ...
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 regis ...
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 2021 Censu ...
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 parameters. Stack-oriented languages operate on one or more stacks, each of which may serve a different purpose. Programming constructs i ...
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, Do ...
page description language ** BibTeX **
Befunge Befunge is a two-dimensional stack-based, reflective, esoteric programming language. It differs from conventional languages in that programs are arranged on a two-dimensional grid. "Arrow" instructions direct the control flow to the left, ri ...
** Joy ** IPTSCRAE ** 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 applications e.g. "RealCalc" ** Several Windows 10 Mobile applications e.g. "RPN9" ** Unix system 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, ...
lisp library package calc **
Xorg X.Org Server is the free and open-source implementation of the X Window System display server stewarded by the X.Org Foundation. Implementations of the client-side X Window System protocol exist in the form of ''X11 libraries'', which serve a ...
calculator (
xcalc The X.Org Foundation is a non-profit corporation chartered to research, develop, support, organize, administrate, standardize, promote, and defend a free and open accelerated graphics stack. This includes, but is not limited to, the following p ...
) ** 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 prop ...
) ** 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 The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general us ...
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 There are various ways in which calculators interpret keystrokes. These can be categorized into two main types: * On a single-step or immediate-execution calculator, the user presses a key for each operation, calculating all the intermediate resul ...
*
FOCAL keystroke programming The HP-41C series are programmable, expandable, continuous memory handheld RPN calculators made by Hewlett-Packard from 1979 to 1990. The original model, HP-41C, was the first of its kind to offer alphanumeric display capabilities. Later cam ...
*
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 ...
*
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 ...
*
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)