Urutan operasi

Revisi sejak 18 Desember 2014 00.48 oleh JohnThorne (bicara | kontrib) (←Membuat halaman berisi ''''Urutan operasi''' dalam matematika dan pemrograman komputer adalah suatu kaidah yang digunakan untuk menjelaskan prosedur mana yang harus dilakukan paling d...')
(beda) ← Revisi sebelumnya | Revisi terkini (beda) | Revisi selanjutnya → (beda)

Urutan operasi dalam matematika dan pemrograman komputer adalah suatu kaidah yang digunakan untuk menjelaskan prosedur mana yang harus dilakukan paling dahulu dalam suatu ekspresi matematika. Juga disebut sebagai "preseden operator" (operator precedence).

Urutan operasi standar

Urutan operasi yang digunakan dalam matematika, sains, teknologi dan banyak bahasa pemrogramam komputer didaftarkan di sini :[1]

eksponen dan akar
perkalian dan pembagian
penjumlahan dan pengurangan

Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. PEMDAS is often expanded to "Please Excuse My Dear Aunt Sally", with the first letter of each word creating the acronym PEMDAS. Canada uses BEDMAS, standing for Brackets, Exponents, Division, Multiplication, Addition, Subtraction. Most common in the UK and Australia[2] are BODMAS and BIDMAS. In some English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponents may be called either Indices, Powers or Orders, which have the same precedence as Roots or Radicals. Since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BOMDAS. The original order of operations in most countries was BODMAS which stood for Brackets, Orders, Division, Multiplication, Addition, Subtraction. This mnemonic was used until exponentials were added into the mnemonic.

These mnemonics may be misleading when written this way, especially if the user is not aware that multiplication and division are of equal precedence, as are addition and subtraction. Using any of the above rules in the order "addition first, subtraction afterward" would also give the wrong answer to the problem

 .

The correct answer is 9 (and not 5, which we get when we do the addition first and then the subtraction). The best way to understand a combination of addition and subtraction is to think of the subtraction as addition of a negative number. In this case, we see the problem as the sum of positive ten, negative three, and positive two.

 

To emphasize that addition and subtraction have the same precedence (and multiplication and division have the same precedence) the mnemonic is sometimes written P E MD AS; or, simply as PEMA.

All of these acronyms conflate two different ideas, operations on the one hand and symbols of grouping on the other, which can lead to confusion.

Special cases

If exponentiation is indicated by stacked symbols, the usual rule is to work from the top down, thus

 ,

which typically is not equal to  . However, some computer systems may resolve the ambiguous expression differently. For example, Microsoft Office Excel evaluates a^b^c as (a^b)^c which is opposite of normally accepted convention of top-down order of execution for exponentiation. If a=4, p=3, and q=2,   is evaluated to be 4096 in Microsoft Excel 2013, the same as  . The expression  , on the other hand, results in 262144 using the same program.

Calculators

Different calculators follow different orders of operations. Most non-scientific calculators without a stack work left to right without any priority given to different operators, for example giving

 

while more sophisticated calculators will use a more standard priority, for example giving

 

The Microsoft Calculator program uses the former in its standard view and the latter in its scientific and programmer views.

The non-scientific calculator expects two operands and an operator. When the next operator is pressed, the expression is immediately evaluated and the answer becomes the left hand of the next operator. Advanced calculators allow entry of the whole expression, grouped as necessary, and evaluates only when the user uses the equals sign.

Calculators may associate exponents to the left or to the right depending on the model. For example, the expression a ^ b ^ c on the TI-92, the TI-30XII and the TI-30XS MultiView (all Texas Instruments calculators) associate two different ways:

The TI-92 and the TI-30XS MultiView in "MathPrint Mode" associate to the right, that is

a ^ b ^ c = a ^ (b ^ c) =  

whereas, the TI-30XII and the TI-30XS MultiView in "Classic Mode" associate to the left, that is

a ^ b ^ c = (a ^ b) ^ c =  

An expression like 1/2x is interpreted as 1/(2x) by TI-82, but as (1/2)x by TI-83 and every other TI calculator released since 1996[3] ,[4] as well as by all HP with algebraic notation. While the first interpretation may be expected by some users, only the latter is in agreement with the standard rule that multiplication and division are of equal precedence,[butuh rujukan] so 1/2x is read one divided by two and the answer multiplied by x.

When the user is unsure how a calculator will interpret an expression, it is a good idea to use parentheses so there is no ambiguity.

Calculators that utilize reverse Polish notation, also known as postfix notation, use stack to enter formulas without the need for parentheses. -->

Bahasa Pemrograman

Banyak bahasa pemrograman menggunakan tingkat preseden yang selaras dengan urutan yang biasa digunakan dalam matematika, meskipun ada juga seperti APL dan Smalltalk, yang tidak mempuyai kaidah preseden operator (dalam APL, evaluasi dilakukan secara ketat dari kanan ke kiri; dalam Smalltalk, secara ketat dari kiri ke kanan). Tingkat preseden relatif operators yang ditemui pada banyak bahasa pemrograman bercorak C adalah:

1 ()   []   ->   .   :: Function call, scope, array/member access
2 !   ~   -   +   *   &   sizeof   type cast ++x   --x   (most) unary operations, sizeof and type casts
3 *   /   % MOD Multiplication, division, modulo
4 +   - Addition and subtraction
5 <<   >> Bitwise shift left and right
6 <   <=   >   >= Comparisons: less-than, ...
7 ==   != Comparisons: equal and not equal
8 & Bitwise AND
9 ^ Bitwise exclusive OR (XOR)
10 | Bitwise inclusive (normal) OR
11 && Logical AND
12 || Logical OR
13 ?:   =   +=   -=   *=   /=   %=   &=   |=   ^=   <<=   >>= Conditional expression (ternary) and assignment operators
14 , Comma operator

Contoh:

  • !A + !B(!A) + (!B)
  • ++A + !B(++A) + (!B)
  • A + B * CA + (B * C)
  • A || B && CA || (B && C)
  • (A && B == C)(A && (B == C) )

Lihat pula

Referensi

  1. ^ "Order of Operations Lessons". Algebra.Help. Diakses tanggal 5 March 2012. 
  2. ^ http://syllabus.bos.nsw.edu.au/assets/global/files/maths_s3_sampleu1.doc
  3. ^ "Implied Multiplication Versus Explicit Multiplication on TI Graphing Calculators". Texas Instruments Incorporated. 16 January 2011. Diakses tanggal 29 April 2011. Templat:Citation not found
  4. ^ "Google cache for: Implied Multiplication Versus Explicit Multiplication on TI Graphing Calculators". Texas Instruments Incorporated. 23 Apr 2013. Diakses tanggal 10 May 2013. 

Pranala luar