Where the Algebraic properties come from
Why addition and multiplication (as repeated addition) are commutative and subtraction and division is not?
Why multiplication (as a repeated addition) distributes over addition?
Because, surprise, addition is a captured (by the mind of an external observer) abstract notion of putting or morphing together. It has been generalized and abstracted out as a binary operation, and when two things come together it is immaterial which one comes “first” - the result, whatever it is, will be the same. There is no notion of “first” and “second”. These are only in the mind of an external observer.
The tradition says that the Buddha proclaimed the fundamenal principle that whatever is compound (being put together) is impermanent and will eventually fall apart. This is true for the Universe outside of our heads (actually our heads are just processes in it), but the other people have created abstract concepts which, they claim, are absolute, ideal and eternal (what a bullshit, lmao!).
There is, however, a “higher precedence” of what we call “reality” over any abstract concepts of the Mind, and every fundamental concept could, in principle, be traced back to the actual repeated pattern (caused by a particular phenomena) it has been generalized from. At least this is how our minds emerged from the evolution - we just create, maintain and use “grossly oversimplified (and hence useful!) maps” of the shared environment inside our heads.
So, why the basic algebraic properties are as they are?
Putting together two things is relative, which means that which one is added to which is, literally, a matter of a point of view. Rotate the observer around the observed locality, and it is the other way around. This (and only this) is what behind commutativity of addition.
In our evolved spoken language we say 2 and 2, for referring to a process of putting tougher, and we say 2 times 2 to indicate how many times we add (to itself). These are results of a intuitive capture and a proper generalization.
The problem with a language, as every mathematician knows, is that it is ambiguous and the names we use are grossly over-loaded and only seem to mean (refer to) the same “thing” (concept).
Multiplication of Naturals (which is indeed a repeated addition) is not the same as multiplication of Reals or by a Real Number (which is scaling). Very clever people “disentangled” and partitioned the mess into individual algebraic systems, by explicitly declaring which Set and which operations we may use. Then they have classified such algebraic system and observed some commonalities.
We use very clever tricks to create a full Numeric Tower by casting Numbers between Number Systems (crossing an abstraction barrier, literally) but there is nothing in the Universe that corresponds to our mental tricks. Mother Nature does not even count.
So the most universal, fundamental and general recurring pattern we have captured and generalized is putting together as addition. The properties of addition are “universal”, up to and including associativity. Then is becomes too abstract for this Universe.
Where that associativity comes from? The binary operation has to produce the result of exactly the same kind as its argument. As long as it does, the order of composition is immaterial. Some people would say that this Closure property is the most fundamental about the Number abstractions.
Notice that in the Universe this property is very rare, because addition or “composition” usually produces structurally different results, which means a different kind of outcome, which we may call crossing an abstraction barrier.
No surprise that subtraction and division may cross the abstraction barriers of our Number Systems, so they are not proper operations of an algebraic system.
Function composition is actually concatenation (pipe-lining) so it is associative (it does not matter which parts of a pipe one connects first) – the result will be the same. So, is DNA synthesis (actual assembling of a chromosome) is forms a Semigroup?
The further we get, by adding the abstract notion of an identity element (zero for addition), the further we wander away from What Is deeper in the real of what we think there Is. Mother Nature has no no-ops of any kind, it either “clicks” or not.
Our Monoids are already a gross over-generalization - they occur only in the realm of too abstract Numbers and nowhere else. There are reasons why people of the past refused to accept negative Numbers, or Irrational Numbers, leave alone Imaginary Numbers. All numbers are imaginary in the first place. We enrich and refine our abstract systems, but the instances of them are nowhere to be found.
It seems that Semigroups is how far we can stretch, because it captures concatenation, which is a particular way of putting together. We have something like this at a molecular level.
Groups are even further away, even if they are useful and seemingly capture lots of abstract patterns, like rotations and certain symmetries. The notion of a Group captures the commonalities of some of our artificial abstractions, just like introspection captures our feelings. These Groups, however, are only (and only) our shared (in the culture) mental constructs, even if the generalizations are valid (properly captured).
Capturing, generalizing, abstracting out and using such precisely-defined abstraction is what Mathematics is (notice the lack of “about”).
One more time. Groups do not occur or exist anywhere. The definitive mantra of all mathematics is that “existence does not required”.
The point is to understand once and for all, that the systems (a Set with an at least one operation) are mental constructs. The abstract structures they seemingly capture are forms or shapes of created by the Mind abstractions. Nothing wrong with that.
The ability to show and prove that two abstract algebraic systems have the same abstract structure (are isomorphic to each other) is quite remarkable, but this is just the precise way of saying that “airplanes look a lot like birds - have almost the same shape”. A lot can be generalized from pictures of arrows between dots with just a few basic notions - direction, counting, links between two dots, and concatenation.
Even the Number Theory could be “put down to earth” just by observing (at another, social level) that it too is socially constructed, and is based on the ability to “see” and define abstract patterns, which require a particular social conditioning.
Prime-ness, by the way, is just this property of not being a result of a repeated addition to itself of any other number. It is not a product, so to speak. A pile of this size cannot be taken apart into any number of equal piles without something left over (a reminder).
This is, indeed, a universal property because it has been properly generalized from recurring patterns which actually occur (just as Natural Numbers themselves), but it has no deeper consequences that cannot be taken into any number of equal parts.
There is no one, except an external observer, to use this property, and only by the virtue of being an observer this property has been captured. This is just an accident of the Universe - well, some piles cannot be taken apart into any number of equal piles, so what?.
The formal reasoning about this observed property is, of course, quite remarkable and is a hallmark of our mental abilities of manipulating abstract symbols. Our ability to use prime numbers in our complex abstractions is, of course, a miracle, but this is a different story.
Yes, we are able to generalize and abstract out, and even produce machines to manipulate our abstractions, and build complex abstractions (out of simpler ones) inside our minds, and then represent and implement some inside our machines. Notice, however, that our machines has been build upon very few, most fundamental, carefully selected properly captured, universal abstractions and nothing else.
The problem is that some, even most of out complex abstractions have no correspondence with (no arrow back to) reality, while we have convinced ourselves (by unverified socially constructed arguments) that they really do. Do you see the veil?
Taking apart, it is said, to the opposite of putting together. But it seems that in the Universe what has been put together is not “supposed” to be taken apart. It will, eventually, due to entropy, but it forms are tend to be “stable” long enough to become building blocks.
Why subtraction is not commutative? Because we have generalized too much. Taking apart of only (exactly) what previously has been put together (as it usually happens in the universe and in Lego) would have no such problem. It does not matter “at which side you pull”.
Lets use an evolved spoken human language. What is an one-half of an one-half? Well, it is one-forth? Which half is which? Does not matter. Why it does not matter? Because a the rule says multiply the denominators, which are always Naturals, and multiplication of Naturals is a repeated addition?
Why 3 times 2 is the same as 2 times 3? Because it does not mater which one is being added to itself the other times, and this corresponds to the notion of an area of a rectangle, which is, of course, a universal one.
What is one-half of one-forth? It is one-eight. But why is one-forth of one-half is also one-eight? Because there is a rectangle of denominators under the hood?.
Notice, that we do not naturally say times, we say of. This is a different kind of multiplication, it just so happens that the rule uses that other notion of times.
And indeed with reciprocals (special case of fractions) we divide by multiplying. Or is it something else?
How do we program?
Well, first we try to capture “just right” abstractions in terms of Sets, First-Order Logic and Algebraic Data Types. These are still in the realm of pure mathematics.
Then we look to see if our abstractions have the shape of some “standard” type-classes. Usually, Semigroup
, Functor
or Monoid
. For data types we usually want Traversable
and/or Foldable
. We may have some Applicatives
, but actually it is a “warning sign” of over-abstraction.
We want to have a Monad
for various reasons, but never for the sake of merely abstraction. Monads are necessary for defining abstraction barriers and to compose as we compose ordinary functions (it will be nesting of lambdas under the hood).
It is of the second importance that they are (instances of) Monoids
and Applicatives
and Functors
. Usually we need just one aspect or another.
Once we define our abstract structures (from the problem domain) we implement them in Haskell or Scala 3. Just like with underlying mathematics, everything must be immutable.
Haskell is much more preferable due to the operational properties of evaluation using graph reduction. This is as if one evaluates with a pen and paper - completely secure. It is even on another, much higher realm from an imperative sequential machine code. The “security” is absolute and total.
Scala 3 is also good as long as one stays in its pure functional subset and build-up lazy expressions to be evaluated by an embedded interpreter. This is how advanced libraries ought to be build - as layers of DSLs.