Reverse polish and reverse Polish expressions

Source: Internet
Author: User

Reverse polish and reverse Polish expressions

Poland is a great country. The radioactive element Po in the periodic table was discovered by Mrs Curie and named after her motherland Poland. Polish Notation and Reverse Polish Notation, which are commonly used in computer science, are also named in Poland. China is also a great country, and I know the Chinese remainder theorem is named after China. Other things named after the Chinese title include the Chinese knot, the Chinese Dragon (Chinese Dragon), the Chinese dream, the Chinese model, and socialism with Chinese characteristics. Well, today we will not talk about China, but mainly Poland.

Jan Lukasiewicz, a Polish logistician, invented the polish expression in 1924 to simplify the propositional logic. Later, the Polish expression was also used to calculate (Arighmatic) and Algebra (Algebra ). A common expression is an infix expression. operator is in the middle of an operand. For example, the operator + of expression 1 + 2 is located in the middle of the operands 1 and 2. A Polish expression is also called a prefix expression. This type of expression operator is prior to the operand. The prefix expression corresponding to the infix expression 1 + 2 is + 1 2.

What prefix expression does not need to be used for infix expressions?

Operators have priority. For example, the infix expression 1 + 2 × 3 Calculate the multiplication and then the addition. If we need to calculate addition first and then calculate multiplication, we usually need to add parentheses to change the operation sequence. For example (1 + 2) × 3 . If a prefix expression is used, parentheses can be omitted if the number of parameters (arity) of the operator is known. For example, prefix expression × + 1 2 3 corresponds to the infix expression (1 + 2) × 3 . Prefix expressions are widely used in Lisp computer languages.

The inverse polish expression was independently invented by computer scientists F. L. Bauer and E. W. Dijkstra in 1960s. An Inverse polish expression is also called a suffix expression. This type of expression operator is behind the operand. The suffix expression corresponding to the infix expression 1 + 2 is 1 2 +. Not strictly speaking, the suffix expression is basically the reverse of the prefix expression. Suffix expressions have the advantage of prefix expressions, that is, they do not need parentheses to change the operation sequence. The other advantage is that it is easy to use a stack (Last In First Out) data structure to implement a scanning from left to right to calculate the expression value. (If the prefix expression is used, scan from the right to the left.) Suffix expressions are widely used in Forth, PostScript, and other computer languages.

The following is a step to use the stack computing suffix expression 3 2 + 4-(corresponding to the infix expression 3 + 2-4), the left is the bottom of the stack, and the right is the top of the stack.

3        3 23 2 + 5 5 4 5 4 - 1

At the same time, I think suffix expressions may be suitable for Chinese programming. Words in English sentences are separated by spaces. There are many symbols in English, including parentheses, square brackets, and curly brackets. Therefore, it is natural for English programming languages to use these symbols. These symbols are added later in Chinese, and they are not even funny in ancient Chinese. Therefore, I think the fewer Chinese programming languages, the better the symbols. In addition, there are many reverse expressions in Chinese, which are similar to reverse Polish expressions. For example, in Chinese, "who and who" means "who and who", "who you go" means "you go.

The following is a process in which 3 + 2-4 is calculated using a suffix expression in a micro-intimacy programming language in the experimental stage. And is used to separate numbers. The plus and minus operators are the plus and minus operators. The output result of each step is saved in the stack.

You are welcome to try the intimate Data Language! Pro> 3, 2, 3, and 2, plus 5, and 4, and minus 1.

Let's talk about F., inventor of the inverse polish expression. l. bauer is German, E. w. dijkstra is a Dutch expression, which is the opposite of a Polish expression. It is called a reverse polish expression, but not a German or Dutch expression. Yang wukasevich, inventor of the Polish expression, invented a pair of actual profits. My grandfather is willing to give his children a hand to read. His theory is that he is poor enough to read books (and he wants to read ugly now) and rich enough to raise pigs. He has another theory: providing a college student is equivalent to providing two students. Because a college student will marry another college student. This is, of course, based on the premise that the old man is optimistic about employment and target users.

References

[1] http://en.wikipedia.org/wiki/Polish_notation
[2] http://en.wikipedia.org/wiki/Reverse_Polish_notation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.