## Thursday, 14 May 2015

### Operator Precedence

I see a number of people get the answer to the following equation wrong:
1 + 5 * 2
Depending who you talk to, it could either be 12 (6 * 2) or the appropriate and correct answer 11 (1 + 10).

Everybody knows the precedence of things, but to make matters clear, here's the list ordered in descending precedence:
1. parenthesis (also known as brackets)
2. exponents/roots
3. multiplication/division

# Mnemonics

Several mnemonics are in use to remember the correct precedence. Below are three examples.

“Please Excuse My Dear Aunt Sally”
• Parentheses
• Exponents
• Multiplication
• Division
• Subtraction

However, this mnemonic doesn't do justice to the fact that some operations actually have the same precedence, for example subtraction and addition.

“Hallo, Meneer van Dalen wacht op antwoord!”
• Haakjes (Parentheses)
• Machtsverheffen (Exponents)
• Vermenigvuldigen (Multiplication)
• Delen (Division)
• Worteltrekken (Root)
• Aftrekken (Subtraction)

This Dutch mnemonic is very very old (and very wrong nowadays). It indicates that roots are very low in priority. Also, if taken literally, it means there's a difference in precedence between, for example, addition and subtraction, similar to the English mnemonic.

“Hé, Mw. v/d Aorta!”

A different Dutch mnemonic (written above), also contains information regarding the equality of certain operations.
1. Haakjes (Parentheses)
2. Machtsverheffen (Exponents)/Worteltrekken (Root)
3. Vermenigvuldigen (Multiplication)/Delen (Division)
Unfortunately, it contains a number of abbreviations:
Mw.
mevrouw (misses)
v/d
van de (of)

# References

Wikipedia - Order of operations
http://en.wikipedia.org/wiki/Order_of_operations
Wikipedia - Bewerkingsvolgorde
http://nl.wikipedia.org/wiki/Bewerkingsvolgorde
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://randomthoughtsonjavaprogramming.blogspot.com/2015/05/operator-precedence.html", "fetch_time": 1532047414000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2018-30/segments/1531676591455.76/warc/CC-MAIN-20180720002543-20180720022543-00631.warc.gz", "warc_record_offset": 319104121, "warc_record_length": 24983, "token_count": 460, "char_count": 1811, "score": 3.65625, "int_score": 4, "crawl": "CC-MAIN-2018-30", "snapshot_type": "latest", "language": "en", "language_score": 0.8077490925788879, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00057-of-00064.parquet"}