4 ms·
I think it's worth revisiting elementary algebra, because the way most of us learned it in grade school doesn't really do it justice. With that said, we abando
by lambdasquirrel 3y ago
I think it's worth revisiting elementary algebra, because the way most of us learned it in grade school doesn't really do it justice.
With that said, we abandoned `ab = ba` because it's not useful for e.g. linear algebra. Elementary algebra is a very specific (but very useful) mathematical "DSL" over the reals. It's also not necessarily going to help you learn to reason about the kinds of abstractions you have whilst programming, per se, because we can't reverse `a . b` to `b . a` when we code either.
Make no mistake, this is a knowledge for knowledge's sake endeavor. A liberal arts of the STEM fields, if you will.
- yakubin 3y agoCommutativity is important for e.g. parallel programming. See e.g. <https://youtu.be/dPK6t7echuA https://youtu.be/dPK6t7echuA>. In the context of linear algebra, it would also be good for folks to know that matrix multiplication (/linear transformation composition) is not commutative.
- MereInterest 3y agoIsn’t it more often associativity that is required for parallel programming? Being able to parallelize “a+b+c+d” only requires associativity to order the operations as “(a+b) + (c+d)”. Sure, there’s additional benefits for memory locality if you can rearrange the term to “(a+c) + (b+d)”, assuming that the four terms are stored in contiguous memory and each sum is computed with vector operations, but that’s not strictly required for parallelization.
- phlakaton 3y agoIn parallel programming, subcomputations may complete out of order. The ability to combine those subcomputations in any order can be pretty useful!
- BeetleB 3y agoThat, though, is associativity, not commutativity. In FP arithmetic, operations are commutative, not associative.
- phlakaton 3y agoIf you receive b before a and combine them as b*a, that's commutative. Both properties are useful in parallel programming, but you may only need one in a specific case, depending on your application.
- GrumpySloth 3y agoBoth are important. I replied to a comment about commutativity, so I focused on that.
- sriram_malhar 3y agoCommutativity has been abandoned? What?! Nothing could be farther from the truth! The requirement for order independence is literally everywhere … where would we be without being able to add or do set unions or lattice joins without fear of getting the order wrong?! Imagine getting two different waveforms when adding one to the other, depending on the order!
- lambdasquirrel 3y agoOrder independence is not a property of general-purpose programming. As much as we'd love for that to go away, it is very much a reality of day-to-day programmers.
- persnickety 3y agoThere's plenty of commutative operations in everyday programming. a = f(c) b = g(d) can be rearranged if f and g take different input data, and calling independent functions is something seen literally everywhere in programming. Optimizing compilers often take advantage of that.
- sriram_malhar 3y agoNot sure what you mean by it not being a property of general-purpose programming. Do you mean it as, "I don't have to account for it in my day-to-day work"? If so, I agree with you, but not quite in the way you mean (I think). We don't account for it just as fish don't have to account for water. The fact that you can swap two rows in an excel file and have the results be unchanged is a property that we just take for granted. It needs to be pointed out how remarkable it is, because there are situations where this doesn't work. Debits and credits in finance are not commutative because of overdraft limits. I'm sure you know all this, so I'm curious what you really mean.
- MereInterest 3y agoI think the argument is more that commutivity of operations is context-dependent, even when the operation is written as multiplication. For example, knowing whether the terms of a multiplication can be commuted requires knowing whether the operands are scalars or matrices.
- yCombLinks 3y agoThat particular part glossed over the details. Commutativity is a property of some groups and not others. It is a property of the "normal" numbers, so we all learn it in school. But there are lots of groups that aren't commutative.
- doubloon 3y agoagree. arithmetic in computer languages do not have a theoretical basis that matches the theory of arithmetic in standard algebra. for example, if a = 0.3 b=0.4 and c=5 as f32 in rust, then the following "well known results" from the article are all false: (b) a+(b+c) = (a+b)+c is false (d) a*(b+c) = a*b+a*c is false (f) (ab)^c = a^c b^c is false (g) a^b a^c = a^(b+c) is false (h) (a^b)^c = a^(b*c) is false https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7a34a46b242f2a12ecb89ae119115660 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- dboreham 3y agoWell there goes the whole CRDT thing...