Commutativity vs Associativity

  • Thread starter kenewbie
  • Start date
Again, we can just write a + b + c. But now, commutativity tells us that, in the expression a + b + c, we can switch around the order of the terms themselves, taking care not to mess up the parentheses. So we can also write a + c + b, c + b + a, etc. But if we have a longer expression, say a + b + c + d + e, we can still switch around the orders of the terms themselves,
  • #1
kenewbie
239
0
Commutativity: a + b = b + a

Associativity: (a + b) + c = a + (b + c)

To me these two say the exact same thing: Order does not matter.

How are they different? Surly it is more than the number of values being added, otherwise we would need a new rule for 4 elements, yet another for 5 and so on.

k
 
Physics news on Phys.org
  • #2
They also say that ab=ba and (ab)c = a(bc) infact. The first one says that you can reverse the order of operations and receive the same result. The second says that you can switch around items in the parenthesis and return the same result.

A laymen's explanation as to why this is important is that you can deal with things such as operators where if you define operators A, B, and C, associativity and commutativity may not hold. In fact, with operators, AB in general does NOT equal BA. You can also deal with things called Grassmann numbers which don't commute. Someone else can probably give you a more thorough explanation.
 
  • #3
Pengwuino said:
They also say that ab=ba and (ab)c = a(bc) infact.

Sure, but let us stick to addition. The laws are used all over the place, but it is easier to just discuss one specific case.

Pengwuino said:
The first one says that you can reverse the order of operations and receive the same result. The second says that you can switch around items in the parenthesis and return the same result.

But "switching around items in the parenthesis" is the same as altering the order.

a + (b + c) = b + c + a = a + b + c

k
 
  • #4
Yes, both commutativity and associativity tell you that the order does not matter in a sense, but there is a difference.

The statement (a + b) + c = a + (b + c) implicitly says that we can first add a and b, then add c (giving us the left hand side) or alternatively, we can first add b and c, then add a (the right hand side). Either way, the resulting expressions are equal, so we might as well remove parentheses altogether and just denote the sum a + b + c. So again, associativity of addition tells us that no matter how we group the different possible ways of summing 3 or more numbers using parentheses (grouped in a way as to indicate which two numbers should be added first), we get the same sum, so we can just do without the parentheses.

Commutativity is more of a direct statement about the placement of the numbers. It doesn't matter which of the two numbers are added first, what matters is that if we have a + b, then reversing the order of these two numbers gives b + a, and these two expressions are equal.

So while associativity tells us that instead of (a + b) + c, we could have added b + c first, commutativity tells us that if we switch the order of (a + b) + c, we get c + (a + b), and these last two expressions are equal.
 
  • #5
kenewbie said:
But "switching around items in the parenthesis" is the same as altering the order.

a + (b + c) = b + c + a = a + b + c
Actually it's not... take matrix multiplication as an example:

[tex]\left(\begin{matrix}2 & 1 \\ 1 & 0\end{matrix}\right) \left(\begin{matrix}-2 & -1 \\ 1 & 0\end{matrix}\right) = \left(\begin{matrix}-5 & -2 \\ 2 & 1\end{matrix}\right)[/tex]
[tex]\left(\begin{matrix}-2 & -1 \\ 1 & 0\end{matrix}\right) \left(\begin{matrix}2 & 1 \\ 1 & 0\end{matrix}\right) = \left(\begin{matrix}-3 & -2 \\ -2 & -1\end{matrix}\right)[/tex]
So multiplication of matrices is not commutative. But:
[tex]\left(\begin{matrix}2 & 1 \\ 1 & 0\end{matrix}\right) \left(\left(\begin{matrix}-2 & -1 \\ 1 & 0\end{matrix}\right) \left(\begin{matrix}1 & 1 \\ 1 & -1\end{matrix}\right)\right) = \left(\begin{matrix}-3 & -7 \\ -1 & -3\end{matrix}\right)[/tex]
[tex]\left(\left(\begin{matrix}2 & 1 \\ 1 & 0\end{matrix}\right) \left(\begin{matrix}-2 & -1 \\ 1 & 0\end{matrix}\right)\right) \left(\begin{matrix}1 & 1 \\ 1 & -1\end{matrix}\right) = \left(\begin{matrix}-3 & -7 \\ -1 & -3\end{matrix}\right)[/tex]
Thus matrix multiplication is associative. (Of course, just because this particular product is associative doesn't mean matrix multiplication is always associative, but it's possible to prove that it is in general.) This should at least show you that commutativity is not the same thing as associativity; if it were, then the fact that matrix multiplication is associative would automatically mean that it would be commutative as well.

Note that the operation of addition (on numbers, matrices, vectors) happens to be commutative and associative. So if you say "let's stick to addition" you'll never be able to convince yourself that commutativity and associativity are not the same thing.
 
  • #6
snipez90 said:
So again, associativity of addition tells us that no matter how we group the different possible ways of summing 3 or more numbers using parentheses (grouped in a way as to indicate which two numbers should be added first), we get the same sum, so we can just do without the parentheses.

But doesn't this come from commutativity? If the order in which you add values does not matter, then parentheses have no meaning.

I'm sorry I'm so slow, I just can't see why associativity is needed :/ (or how it is different from commutativity for that matter).

k
 
  • #7
No, you're not being slow, my explanation wasn't clear enough. Rather, I danced around the usage of the word order. Note that associativity is a statement about the order of operations. Yes, in the end, we might as well denote a + b + c as the 6 different possible ways of writing the sum of three numbers. But these are axioms, so we are really working with obvious statements, but ensuring that the conceivable difficulties are taken care of.

So for associativity, we are worried about how the terms are grouped together. Which numbers should be added first? The answer is that the order of OPERATIONS does not matter as long as the order of the operands are not changed (think about what this means for a minute). Keeping my previous explanation in mind, we simply place parentheses around the terms that we indicate should be added first. The problem is that if we add b and c first, and then a, then this sum is conceivably different from adding a and b first and then c. Of course, our axiom tells us that the sum is the same. So that adding b and c first then adding a is a + (b + c) and this is the same as adding a and b first, then c. Notice that we write this as a + (b + c) = (a + b) + c, so we are simply placing parentheses around the terms in which we think should be added first, but we are NOT changing the sequence of the actual operands. We are not saying that a + (b+c) = (b+c) + a because this is reversing the order (or changing the sequence) of the operands a and (b + c). Associativity only allows us to place parentheses around terms in which we think should be added first, and tells us that it doesn't matter where we place the parentheses as long as the sequence of the operands is not changed. In other words, it justifies a change in the order of operations, provided that the order of the operands is not changed.

On the other hand, commutativity is concerned with the conceivable problem that reversing the sequence of operands in a sum might give us a different number, but this is not true. Hence, adding a pair of numbers does not depend on the order in which we add them. We are no longer talking about the order of operations, but rather the order of the operands. In the above case for commutativity, we can't really say anything about the order of operations, since we only have two numbers (for instance, it doesn't make sense to say "add a first and then b"). But we can talk about the sequence of the operands, specifically, if we reverse the order of the two numbers, our sum will not change, i.e. a + b, where a comes before b in the sequence of operands, is equal to b + a, where the sequence of operands has been reversed (b now comes before a).
 
Last edited:
  • #8
diazona said:
Note that the operation of addition (on numbers, matrices, vectors) happens to be commutative and associative. So if you say "let's stick to addition" you'll never be able to convince yourself that commutativity and associativity are not the same thing.

Aha. That's a good point, thank you.

I appreciate the example with the matrices, even though I do not know how to operate on those yet.

Do you happen to have a more basic example where one holds and the other does not?

From Wikipedia:

"The associative property is closely related to the commutative property. The associative property states that the order in which operations are performed does not affect the final result as long as the order of terms is not changed. In contrast, the commutative property states that the order of the terms does not affect the final result."

I think I am perhaps starting to see the difference. Associativity = the order of the operators. Commutativity = the order of the values. When you alter the parentheses of an expression, you are changing the order in which the operators are executed.

So, let me test myself and please let me know if I am wrong.

a + b = b + a .. by commutativity
a + b + c = c + b + a .. by commutativity
(a + b) + c = c + (a + b) .. by commutativity
c + (a + b) = (c + a) + b .. by associativity
c + (a + b) = c + a + b = a + b + c .. by associativity, then by commutativity
(a + b) + (c + d) = a + b + c + d = a + d + b + c = (a + d) + (b + c) .. by associativity, then by commutativity, then by associativity again.


k
 
  • #9
snipez90 said:
The answer is that the order of OPERATIONS does not matter as long as the order of the operands are not changed (think about what this means for a minute)

Yep, that was the part I never got. I appreciate the help, your explanation added a lot and the difference between the two finally sunk in :)

Thanks again,

k
 

FAQ: Commutativity vs Associativity

What is the difference between commutativity and associativity?

Commutativity refers to the property of an operation where changing the order of the operands does not change the result. In other words, the order in which the operation is performed does not matter. Associativity, on the other hand, refers to the property of an operation where grouping of the operands does not affect the result. This means that changing the grouping of the operands will not change the final result.

How do commutativity and associativity affect mathematical operations?

Commutativity and associativity are important properties in mathematics as they help simplify complex operations. For example, in addition, commutativity allows us to change the order of the numbers being added, while associativity allows us to group the numbers in any way we want. This makes it easier to perform calculations mentally or using a calculator.

Can commutativity and associativity be applied to all mathematical operations?

No, not all operations are commutative or associative. For example, subtraction and division are not commutative, as changing the order of the operands will result in a different answer. Additionally, exponentiation is not associative, as changing the grouping of the operands can lead to a different result.

What is the significance of commutativity and associativity in computer science?

Commutativity and associativity are important concepts in computer science, particularly in programming and data structures. Understanding these properties can help optimize code and improve performance. For example, in parallel computing, the order of operations can be rearranged based on commutativity and associativity to increase efficiency.

Are there any real-world applications of commutativity and associativity?

Yes, commutativity and associativity have many real-world applications. They are used in fields such as cryptography, where operations need to be performed in a specific order to ensure security. They are also used in database design, where grouping of data can affect the results of queries. In addition, commutativity and associativity are applied in various industries to increase efficiency and simplify complex operations.

Similar threads

Replies
4
Views
3K
Replies
7
Views
943
Replies
3
Views
1K
Replies
14
Views
2K
Replies
4
Views
2K
Back
Top