operator overloading as a math @ programming bridge

10 views
Skip to first unread message

kirby urner

unread,
Jun 2, 2016, 12:38:38 PM6/2/16
to mathf...@googlegroups.com

In telling the story of mathematics, its evolution,
sharing the lore (it's selfish not to), we should
come to the chapter where mathematicians in
a way discover object oriented programming,
in that they discover encapsulation of things
with complicated state, say a 3 x 3 matrix or
bigger, yet able to "multiply" nonetheless.

Here's a paragraph worth quoting:

The notion of Universal Algebra had it origins in a paper of 1884, “Lectures on the Principles of Universal Algebra”, by the great English algebraist James Sylvester. In his paper Sylvester spoke of the reign of Algebra the First, as a science and philosophy, ushered in by the publication of Harriot‟s “Artis Analyticae Praxis” in 1631 (traditional arithmetic algebra), and the reign of Algebra the Second, ushered in by Cayley‟s immortal “Memoir on Matrices”, published in 1858 (abstract multiple algebra). From the standpoint of “Universal Algebra or the Algebra of multiple quantity”, Hamilton‟s Quaternions “are but the simplest order of matrices viewed under a particular aspect”.33 Cayley‟s revolution, Sylvester argues, was rooted in the discovery that matrices, though “an organism composed of discrete parts”, possessed an essential unity and wholeness, such that it “stood revealed as bona-fide multiple quantity subject to all the affections and lending itself to all the operations of ordinary numerical quantity”.34 Sylvester urged that this unification had a metaphysical significance, since it signified the transformation “whereby a multitude is capable of being regarded as an individual, or a complex as a monad.” 35

[from a preprint of Whitehead’s Universal Algebra by Andrew Dawson set to appear in:
Weber, M. & Desmond, W. 2008 Handbook of Whiteheadian Process Thought, [Vol. 2],
Frankfurt: Ontos Verlag, pp.67-86.]

The justifications for calling it multiplication
were all "design pattern" based, which is what
group theory is about, but coding also.  We look
for patterns.  It's like multiplication if there's an
identity and inverses, such that any pair of
inverses, multiplied together give the identity.
The identity "times" any element, gives back
that element, unchanged.  Addition has these
properties too, and indeed we need two operations,
with a distributive relationship, to get from a group
to a full-fledged field.

Mathematicians discovered not only matrices,
but things called "quaternions" could multiply.
But then they already knew polynomials could
multiply, as could their factors, to give these
polynomials in
the first place.  Complex numbers...
There was precedent for wholes with parts being
able to multiply.

The point is "operator overloading" has long
been a feature of mathematics and involves
continually "repurposing" the symbols for
common operators to work with new domains
of object, such a matrices, not just "real
numbers".  Operator overloading is at the
basis of Universal Algebra therefore.

One thing I learned at Portland Pycon, perhaps
belatedly, was @ is now available to be overloaded,
in addition to +, /, //, -, *... and several others.

These have their conventional infix role in that we
say M + N where M and N are addable objects,
not (+ M N).  However, those knowing what's
going on "under the hood" may write M.__add__(N)
showing how methods "belong to their types" in
this notation, versus being applied from outside.

It's the method __add__ they all have in common,
triggered by +.  __mut__ by *, __matmul__ by @,
and so on.

For those wishing to dive deeper into some fairly
elementary (in the sense of plain vanilla) Python
source code demonstrating the use of @ to do
function composition (just a very short program),
I've published some here:

https://mail.python.org/pipermail/edu-sig/2016-June/011459.html

In conclusion, those looking for where to bridge
coding and mathematics would do well to dive in
to "operator overloading" as a topic.  The intuitions
that excite mathematicians become accessible to
students able to validate against an evaluating
engine, which gives feedback, and real computational
results.

Calculators will nod yield such significant insights.

See if this argument wins any points with the judges?

Kirby


Reply all
Reply to author
Forward
0 new messages