

Striking parallels between mathematics and software engineering - datascientist
http://radar.oreilly.com/2015/01/striking-parallels-between-mathematics-and-software-engineering.html

======
evincarofautumn
Linear algebra got a lot easier for me when I realised that matrices are just
linear functions, and matrix multiplication is function composition.

Abstract algebra and category theory give you incredibly useful program and
API structuring techniques; you can get lots of nice properties for free by
following these well-worn existing patterns, even more so than OOP design
patterns. We make use of them a lot in Haskell, but they’re basically
language-agnostic.

Even simple algebraic manipulations, like noticing that “return” is
distributive over a conditional:

    
    
        if x then return y else return z
    
        return (if x then y else z)
    

Are very useful for restructuring programs to be more readable.

~~~
Natsu
There's also this:

[http://www.haskell.org/haskellwiki/Curry-Howard-
Lambek_corre...](http://www.haskell.org/haskellwiki/Curry-Howard-
Lambek_correspondence)

~~~
evincarofautumn
This one is beautiful as well.

It was mind-opening for me to think of types in terms of provability
(intuitionistic/constructive logic) rather than truth (classical logic). The
only way to prove that a function returning a value of type T actually halts
(and therefore does not actually “return” bottom/void) is to run it and obtain
that T value, i.e., to find the object that the type claims exists.

------
sedachv
This is why one of the most valuable uses of time for mathematicians and
especially software engineers is to study the historical development of
techniques and technologies. Understanding how matrices are a product of the
quest for finding solutions to systems of linear equations gives you a much
better idea for when and how to apply matrix techniques. Most math textbooks
limit themselves to "The determinant is defined by ad-bc" which on its own is
an almost completely useless fact to know outside of taking an exam.

Software engineering is much worse in terms of useless complications developed
by people who don't know previous solutions (angular.js? Great! Have you ever
heard of dataflow programming? Constraint satisfaction? Dynamic binding? No?
No wonder angular is such a piece of shit).

~~~
sdenton4
To be a bit contrarian, linear algebra is waaaay more useful than just as an
outgrowth of solving systems of equations.

My own point of view is that linear algebra is by far the most successful part
of mathematics: 'Most' questions you can come up with have satisfactory
answers. This is in contrast to, say, number theory, where there's a bunch of
nice elementary results and a lot of interesting questions that seem nigh
impossible to solve.

As a result, it's a pretty common game in mathematics to start with something
new or difficult that you want to describe, and then do your level best to
turn your questions into linear algebra problems so that you can actually get
answers. The extent to which this doesn't work is the extent to which you need
to develop new ideas. (One example of such an approach is algebraic graph
theory. Turn a graph into an interesting matrix, and then use the linear
algebraic properties of that matrix to describe interesting properties of your
graph.)

~~~
alicez
Linear algebra is one of my favorite subjects. Its design is beautifully
simple, yet extremely powerful. Half of modern machine learning (and all of
Matlab) is built on matrix algebra. And the existence of fast software for
numeric linear algebra makes it practically applicable.

The link to graph theory is beautiful, too. Entries in an matrix can represent
edge weights, and taking a random walk on a graph can be represented as a
matrix-vector multiplication, and the stationary distribution is the singular
vector. How cool is that? When you start to link together abstractions from
different fields of mathematics and science, you get these fantastic insights
that are just mind bogglingly awesome. This is what makes all the pain of
wading through an ocean of symbols and equations worthwhile, imho.

------
tel
If you can find a way to get a hold of it, Saunders MacLane's _Mathematics:
Form and Function_ is a _tremendous_ book for understanding how math arises
from the world and reflects it. What's written here is a lot more specific
than that, of course, but if this illustration interests you then it might be
a good book to try digging into a little bit.

On the other hand, while I am always cognizant and amazed by the POV of math
as a human construction, there's something a little otherworldly about it from
time to time. In the same way that you sometimes hit a code design which
_feels so damn good_ , Math, especially older math, is just a huge collection
of these. Somehow, despite this all coming, apparently, from our minds, we hit
on these design decisions that are just so sweet that they last millennia.
This is what inspired things like Voyager---maybe it's hubris, but it just
_has_ to be the case that aliens speak mathematics.

So, I encourage anyone excited by this: math isn't "hard", it's just big and
wonderful. You'll never finish learning it, but the journey will be
incredible.

I'll leave this linking two more great resources (edit: to be clear, really
the first one is the great resource... the second is just me talking, not
really great at all). First, Paul Erdös, a famous mathematician who perhaps
specialized in combinatorics, loved this idea I espouse above. In his mind,
God had a small number of "proofs" in his mind when he designed mathematics.
These are so wonderful that their beauty is completely self-evident. After
Erdös "stopped doing math" (passed away) people compiled some of his Proofs
from The Book along with others they imagine he would have so regarded into a
great text book called, unsurprisingly, _Proofs from The Book_ [0].

Finally, I'll self plug a little essay I wrote, actually in another HN
comment, a while ago about learning mathematics.

[http://jspha.com/posts/there_is_no_royal_road_to_mathematics...](http://jspha.com/posts/there_is_no_royal_road_to_mathematics/)

[0] [http://www.amazon.com/Proofs-THE-BOOK-Martin-
Aigner/dp/36420...](http://www.amazon.com/Proofs-THE-BOOK-Martin-
Aigner/dp/3642008550)

~~~
gizmo686
The reason that you notice it more with older math, is that older math is
older, and has had more time to be improved.

Imagine if you had an API that had been in use and continuously improved for
millenia.

~~~
tel
Continuously improved is important to note too. Backwards compatibility isn't
really a thing in mathematics. You simply have to create enough value and
teach people how to use your new mechanism.

------
daniel-levin
As someone who grew up writing code, and is now studying mathematics at a
tertiary institution, I was quite surprised to read that parallels between
mathematics and software engineering are 'surprising'.

On the contrary, mathematics has formed the basis (no pun intended) of so much
software engineering. Take for example the very concept of a
function/subroutine/method/ \- this comes straight from the world of
mathematics (albeit with minor modifications to make it convenient).

The algorithms that do all the heavy lifting in order to facilitate this web
browsing experience are all grounded in mathematics - memory management in
your kernel, database {everything}, even HTML layout management! The whole of
complexity and asymptotic analysis is actually just mathematics.

Many of the pioneers in computer science originated as mathematicians. Alan
Turing, John McCarthy and Donald Knuth for example.

It may not seem like it on a daily basis writing CRUD apps in an OO language,
but software engineering is inextricably linked to mathematics. Such results
are the furthest from surprising!

~~~
lstyls
You are confusing software engineering with computer science. Most HN users
certainly know that the fundamental theories of computation are rooted in
rigorous mathematics. The point of the article is is to share the insight that
mathematical notation is itself a constructed system, much like complicated
software implementations, and which via design decisions provides users with
powerful abstractions.

Did you even read the article before lecturing us about Turing and Knuth??

------
williamstein
There's a concrete object-oriented Python implementation of much of abstract
algebra is Sage. You can see some of that here:
[https://github.com/sagemath/sage/blob/master/src/sage/struct...](https://github.com/sagemath/sage/blob/master/src/sage/structure/element.pyx)

(Disclaimer: I'm a Sage developer.)

~~~
eliben
That's pretty interesting, thanks for sharing.

------
jonsen
I've just started reading
[http://en.m.wikipedia.org/wiki/Where_Mathematics_Comes_From](http://en.m.wikipedia.org/wiki/Where_Mathematics_Comes_From)

It's about math as a human construction. Very comforting to see ones inner
metaphores and mental models of math "legitimised" and exposed in a scientific
framework. One could hope for a companion: Where Software Engineering Comes
From.

~~~
alicez
Cool! Thanks for the link. I've not read that book, but it looks very
interesting and related. It great to see others' perspective on math as a
human construction.

Another book on the topic of history of mathematics is "Journey Through
Mathematics" by Enrique Gonzalez-Velasco. From its back cover:

"This book offers an accessible and in-depth look at some of the most
important episodes of two thousand years of mathematical history. Beginning
with trigonometry and moving on through logarithms, complex numbers, infinite
series, and calculus, this book profiles some of the lesser known but crucial
contributors to modern day mathematics."

------
placebo
I've had a similar realisation regarding the parallels between software design
and scientific theories. In science you have observed phenomena, and you try
to find the best (preferably simplest) theory/abstraction that will both
explain them and also be able to explain phenomena that you haven't observed
yet. In software engineering, you have a set of current requirements and you
try to find the best (and hopefully simplest) architecture/abstraction that
will meet the current requirements but also be able to naturally accommodate
requirements that you haven't foreseen. Both science and software engineering
try to devise abstractions that try to convey some "higher truth" than the
given data, and both invariably need to be reassembled into a higher
abstraction when reality doesn't agree with them, but the test of a good
scientific theory as well as a good software architecture is how long can the
abstraction hold until something doesn't fit the model.

------
dkarapetyan
It wobbled around a little bit but the main idea that mathematics like
software is a human construction and that just like all human constructions it
is susceptible to encoding historical accidents as truths is a good point.

The other theme in the article about algebra and minimally acceptable
abstractions for accomplishing a goal is unfortunately nowhere to be found in
software.

------
eliben
Interesting. While I agree with the general premise (a lot of mathematics is a
human-made construction), the concrete examples she provided feel somewhat
forced. Especially the comparison to OOP - I personally don't see how it adds
to understanding the various subdivisions defined by abstract algebra.

~~~
CurtMonash
That's because the inheritance in abstract algebra is so bloody obvious. At
least when I studied math, it was the first subject in which the template was:

Let's define something, and consider what we can figure out about it.

Now let's add another property, and see what we can figure out.

Now let's add yet another property, and see what happens.

Etc.

One winds up familiar with the whole progression group --> abelian group
(although not much time is spent on that one) --> ring --> integral domain -->
unique factorization domain --> principal ideal domain --> Euclidean domain
--> field.

~~~
tel
This sort of subtyping tree available in abstract algebra isn't the same as an
inheritance tree. Inheritance merely layers constructors.

What you really want to consider is interface subtyping and layering.
Actually, more than just interfaces you want to also carry along laws. For
instance, a group is a monoid with an inverse operation appended (interface
concatenation) cut down by the fact that the inverse operation must be "nice"
(law concatenation). If you only append the interfaces you end up with free
structures.

------
swatow
I don't think it is ever tenable to claim that mathematics is purely a human
construction. The Formalist viewpoint is that mathematics is just the
manipulation of symbols, according to certain rules. But Formalists accept
that these rules regarding manipulation of symbols are themselves
mathematical. That is, the Formalists are actually Platonists with regard to
metamathematics. The Platonist says "1 + 1 = 2 is a meaningful, true
statement" while the formalist says "that P is a correct proof that 1 + 1 = 2,
is meaningful, true statement".

~~~
evincarofautumn
A middle ground seems reasonable. The naturals probably correspond to a
physical phenomenon—it seems to be possible to have, say, 1 proton—but I have
deep doubts about the existence of the reals.

------
z3t4
Math is good for explaining some logic, but I wish it was more verbose and
used less global scope.

