Math and Programming

2 views
Skip to first unread message

Christian Catchpole

unread,
Jul 26, 2008, 9:20:36 PM7/26/08
to The Java Posse
When I was a teenager, I was programming my commodore 64 with
assembler and dreaming of growing up to be a "prestigious fancy-pants
software engineer". My maths wasn't especially strong, in that I
wasn't doing advanced calculus or the stuff the other nerds were
doing. I was thinking the same thing as the guy who ask the question,
"gee, I bet I need all that advanced math to be a professional
programmer".

I have found that you need surprisingly little math to program. I
would suggest the core skills are..

- Knowing number bases. Binary and Hex and how they relate to
decimal. For instance you just end up remembering
1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65535 (is
that because its the total memory of my commodore 64?) etc and knowing
255 (an 8 bit, 256 range including zero) is hex FF (and negative 1 in
some circumstances)
- Bitwise And / Or and Xor operators.
- Basic integer math is used array indexes etc.

All the logic related to data structures I learned from using and
creating data structures. But if you can learn it from a math
subject, so be it.

The occasional floating point and more complex math might come in
doing modulus operations or calculating hash buckets using prime
numbers. But generally, you don't end up doing much of that anyway.

Of course specific fields like crypto, finance etc have their own
math, but that's related to the field, not general computing.

Other may disagree, so don't take my word for it, but this is the
little math I needed to get started. Again, its more about thinking
in terms of data structures, program flow and booleans.

Reinier Zwitserloot

unread,
Jul 27, 2008, 1:01:21 AM7/27/08
to The Java Posse
I don't really agree with this, because programming as a field is just
way too large. waaaay too large. Also, you didn't name any actual
field except moderately advanced algebra (number bases and a
rudimentary understanding of particular operations of base-2 number
systems: and, or, xor, shift, rotate). Also note that stuff like 2's
complement and modulo number systems, both of which are required to
understand why 'FF' can mean '-1' in certain circumstances, are
sufficiently out there for standard math that not even the most
hardened course on mathematics will -ever- even touch upon those
subjects. If you're going to hear about it at all, you're either doing
your PhD in something math-related, or, you're getting a course
focused on computers, and the actual mathematical basis for that stuff
can usually be discarded, as you're unlikely to make a name for
yourself redesigning chips from scratch).

I'll prove my point with a few specific fields.

FIELD 1: Computer Graphics.

If you're going to write 3D engines, you'll need to know a lot of math
and you really need to have a feel for math. In an earlier age you may
have discovered new ground in Math and have some proofs or theorems
named after you. All the way from advanced algebra (number bases and
doing math with modulo), matrix math, calculus, geometry, and so much
more. You really need to be a wiz with the geometry of course, but,
really, you need to thoroughly grok it all.

I actually know a fine example to prove my point. Behold, Carmack's
inverse square root: http://www.codemaestro.com/reviews/9 (warning,
code is commented with colourful language. Also, may make your head
explode. You've been warned!)

However, a lot of math tends to focus on precision. In the age of
calculators, this trend has only intensified: If the answer is 'square
root of 2', then you just can't get away with '1.414' anymore.
However, in computers, you get the opposite. It's not only perfectly
acceptable to just get close, it is usually of the utmost importance,
and finding creative ways to get close enough is where the real
innovation lies. At least the math commonly employed in computer
graphics is at least somewhat covered in your usual garden variety
high school and college generic maths degree. At least, here in
europe. The 2 years of math I received in my freshman and sophomore
year in the US would be laugh out loud hilarious if it wasn't so sad,
unfortunately.

Math needed: Almost all the common fields.

FIELD 2: Cryptography

A niche field with a lot of niche math involved. It's really its
entire own little math world, but here too the rule holds, perhaps
even more than for 3d stuff: You really need to understand and have a
natural inclination for math, or you're not going to be doing anything
new, and, in fact, you'll have a real problem even keeping up with the
rest.

Highlights here include the intriguing field of modulo algebra and
certain obscure math hypotheses (such as the prime-related stuff, like
riemann's and mersenne), most of which never get covered in non-crypto-
specific math courses, even really advanced ones. Here too, matrices
rear their head. You'll also need to healthy dollop of creativity
here, because the most difficult job of anyone doing crypto is
figuring out how to break crypto algorithms.

This field is -really- small. Tiny, in fact. Most folk involved in
crypto spend all, or the vast majority, of their time on protocols and
systems analysis. Even Bruce Schneier probably spends less than 2% of
his time tearing apart actual crypto algorithms. If you really know
this stuff, the NSA might want to talk to you, though.

You don't need to know jack about the specifics of floating point
math, though, just to give an example.

Math needed: A lot of algebra. Crypto is a very specialized field.

FIELD 3: Front-End work.

This is a big field, and for many applications, all that's really
difficult for the entire project. For this you need to know absolutely
no math, not even number bases and the 'assembly' set of operations.
In fact, if you have trouble grasping the concept that '5 + 5' is 10,
you can still program this stuff and excel at it, assuming your
difficulty lies in some obscure form of dyslexia, and not because
you're an idiot. If you want education (other than programming pur
sang), you should look into design and usability engineering
principles like Fitt's law (the time it takes to perform an action is
linear to the size of the object you need to go to times the distance
you have to travel to get there, at least where mouses are concerned,
though you can get around Fitt's if the target is in a screen corner.
That's good stuff to know as a usability engineer!). As far as innate
skills, you really need to have a basic grasp of utility. A lot of
programmers are absolutely -incapable- of understanding this, and as a
result, a lot of programs are about as clashingly ugly as vomited on
turd. Fortunately the programming world is starting to understand the
importance, with the whole 'web 2.0' movement putting a lot of focus
on utility, as well as Apple being more popular than ever.

Math needed: Not one iota. Knowledge about the golden ratio might
help, but if you have a feel for beauty you tend to identify the
golden ratio without even knowing that it IS a ratio, that it exists,
and that you can calculate it. You really just need to know the
number, you don't need to know the why, what, or how. I don't call
that 'math'.

FIELD 4: Web Scaling

If you're writing software for huge web companies that need their
stuff to scale, you need to have a good grasp of fundamental
informatics, a fairly specialized field, as well as a good general
feel for math. This is important, because you'll need to come up with
schemes to cheaply assign tasks into processes which can spew results
back in no more than LOG(n) the amount of data your system has, and if
that's not possible, you'll need to find a way to distribute the job
to a large bunch of servers in a way that the act of distributing it
is itself LOG(n) or smaller. There aren't any specific number problems
you will be solving here, you just need a good 'feel' for things. This
is a bit of a theme: For a lot of cutting-edge programming work you
need to thoroughly grok math in general just so your brain can make
the right connections to get the job done.

You can study for a decade, but, if you don't really get it, you'll
never be able to put all that math you learned to use.

FIELD 5: Programming Languages

Let's say you want to make a new programming language. Set theory can
help you, but mostly it helps to have a good understanding of
processes. Stuff like regular expressions actually came from the math
world, for example. Also, it helps if you can spot a way to generalize
a language. LISP is still the most math-like elegant approach to
designing a programming language. Then again, for java, it looks like
the authors shoved all the math out the window and just grabbed a
bunch of convenient stuff together from various languages, put in
absolutely no effort to turn it into an elegant whole, and just got
down to business and programmed up a good language, then spent some
money on the best marketing -ever- done in the name of a programming
language, and here we are: Java.

Evidently it's not a necessity here.



So, there it is. You either need a truckload of math and a good
feeling for it, or, you don't need any whatsoever. Good news for all
involved: If you're a giant math head, there's a big range of jobs
that only you and the tiny fraction of this planet that shares your
skills can do, and nobody can butt in on you, and if you don't,
there's an even larger range of jobs that'll do you just fine. Though,
I firmly believe that programming itself requires a certain type of
mind that's hard to study for.

On Jul 27, 3:20 am, Christian Catchpole <christ...@catchpole.net>
wrote:

Peter Becker

unread,
Jul 27, 2008, 1:53:15 AM7/27/08
to java...@googlegroups.com
There are some areas where math skills can be helpful that you have
not mentioned:

- numerical analysis: any type of simulation work. In a way the
boundaries between numerical analysis and CS are pretty blurred. I
once worked on a project where people tried to use finite element
methods on multigrids (grids with different detail levels in different
areas) distributed on massive parallel systems. You need a very good
grasp of numerical analysis and parallel computing to do anything
halfway decent in that area. And there are plenty of applications from
weather forecasts to crash simulations

- information retrieval: maybe not obvious, but there's a lot of
statistical analysis in many approaches in that field. Not to forget
that to publish anywhere decent you have to do proper experiments,
which is math-related (albeit a skill of its own). You might also find
some graph theory in there.

- GIS: plenty of graph theory in there

- data warehousing/BI: lots of numerical analysis, maybe some graph theory

That's not very likely to be a complete list either. But I agree: in
many areas you don't really need deep math skills. And if you do, you
usually need only some fields, e.g.:

- logic
- universal algebra
- graph theory
- numerical analysis
- linear algebra
- statistics

To some extent I would claim that all the fields above can be useful
in many situations though. Knowing some formal logic makes reasoning
about code easier, universal algebra helps with data structures and
architecture, graph theory can help with many problems (think knapsack
problem or traveling salesman), numerical analysis tells you how to
estimate complexities, linear algebra is essential for understanding
transformations in vector graphics (Java2D, OpenGL), statistics can be
cool if you do large-scale testing. In none of these areas you really
need formal training, but it can help.

It's similar to the question if you should learn programming or CS.
And I guess if you learn CS properly they will teach you basic skills
in most of the skills above (particularly if you studied CS in a math
department as I did :-) ).

I'd employ people without formal math skills, but I have certainly
used mine over the years.

Peter

Christian Catchpole

unread,
Jul 27, 2008, 6:10:55 AM7/27/08
to The Java Posse
While good class libraries can protect you from most of the bit
shifting, you still need to know the significance of bitwise AND and
0xFF when you read() a byte into an int, using Java. :)

Michael Neale

unread,
Jul 27, 2008, 6:34:22 AM7/27/08
to The Java Posse
I agree with Reinier:

I have noticed 3 relevant fields of study in my career so far:

1) Statistics - I never paid enough attention to this at uni (or
school - I usually did the minimum I could get away with), and regret
it on a monthly basis.
2) Discrete mathematics/logic - once again, something I should have
paid a lot more attention to. Relevant on a daily basis. But I
occasionally refresh my memory. Plenty to read online for this.
3) More advanced forms of calculus and algebra (I like to study
programming languages, more out of interest, and once again, I regret
skipping certain classes, and I find it hard to pick up casually this
area of mathematics).

Interestingly, none of these things were at high school/college level,
or even first year university level, it was generally in the senior
years only (I did Elec. Eng, which is reasonably heavy on the
mathematics side - sadly I have had no use for complex mathematics so
far... but one day, those skillz will come in handy I just know it !).





On Jul 27, 3:01 pm, Reinier Zwitserloot <reini...@gmail.com> wrote:

Reinier Zwitserloot

unread,
Jul 27, 2008, 2:44:33 PM7/27/08
to The Java Posse
Wow, statistics. How could forget that one? A fine addition to the
list, Peter.

@Michael: Maybe the specifically useful fields were only given at
college level, but math is something you sort of build up. As I
repeatedly mentioned in my post, I think a general math mindset helps
for all sorts of things in programming. That starts all the way back
when you learned your multiplication tables. However, your point is
still valid: the directly applicable math fields for programmers is
generally so specific, you'll never really get a lot of it in a
standard math course.
> ...
>
> read more »

Christian Catchpole

unread,
Jul 27, 2008, 4:38:42 PM7/27/08
to The Java Posse
Reinier, I'm a little confused. You said you disagreed with my
original post, but I thought I was suggesting that the math we did at
high-school has little relevance. But the math we do need is very
narrow. Are you suggesting that even though its narrow, its not as
simple as I suggest? I guess its all relative. I thought it was
easy, but perhaps others found it difficult. I constantly surprised
by juniors (and even seniors) who know less about "the basics" than I
would expect them too.

Christian Catchpole

unread,
Jul 27, 2008, 5:05:50 PM7/27/08
to The Java Posse
But having said that I sometimes surprise myself with the stuff I
don't know. I've had conversations with Peter (Becker) and read his
posts where I think "gee, I missed the boat on that one.. I hadn't
thought about that before." But thats IT I guess. Its all a rich
tapestry.

On Jul 28, 6:38 am, Christian Catchpole <christ...@catchpole.net>
wrote:

Reinier Zwitserloot

unread,
Jul 27, 2008, 11:53:29 PM7/27/08
to The Java Posse
My apologies, Chris. As usual, I missed a posse; I haven't completely
finished the last one yet and with that as the context, your intent
becomes more clear. I still think you oversimplified the set of math
you named; you just can't reduce the math-like stuff you need to know
into nice categories as the field of programming is just too large.
However, that's really just a minor nit.

On Jul 27, 10:38 pm, Christian Catchpole <christ...@catchpole.net>
wrote:

Christian Catchpole

unread,
Jul 28, 2008, 12:04:02 AM7/28/08
to The Java Posse
Yeah, as I was writing the original post I was thinking that I may
have just been speaking about my own experience and that others would
be different. So I tried to suggest that at the end. I think there
is a whole area of math that I have never thought of as math, because
I didn't learn it in a math class. Sets and graphs for example.

Perhaps its like my experience with patterns. It all sounded very
scary, then I realized that I knew and was using many of the patterns
- I just didn't know someone had given them names and put them in a
book.

Peter Becker

unread,
Jul 28, 2008, 12:21:45 AM7/28/08
to java...@googlegroups.com
The thing I missed was that it was actually a reference to the podcast.

So some of my comments where a bit redundant with Tor's -- sorry for
that. Normally I hold back until I actually listened to the podcast
before commenting, but I didn't make that connection this time.

Peter

Christian Catchpole

unread,
Jul 28, 2008, 12:44:53 AM7/28/08
to The Java Posse
I can download, sync, listen to a podcast and start a misinformed
flame war before Dick can say "The java posse would like to
thank...". :)

On Jul 28, 2:21 pm, "Peter Becker" <peter.becker...@gmail.com> wrote:
> The thing I missed was that it was actually a reference to the podcast.
>
> So some of my comments where a bit redundant with Tor's -- sorry for
> that. Normally I hold back until I actually listened to the podcast
> before commenting, but I didn't make that connection this time.
>
>   Peter
>
> On Mon, Jul 28, 2008 at 2:04 PM, Christian Catchpole
>

Peter Becker

unread,
Jul 28, 2008, 12:51:12 AM7/28/08
to java...@googlegroups.com
Then it's time for Dick to think about live broadcasting, so you can
finally ring them to complain while they are still talking :-)

Peter

Gabriel Claramunt

unread,
Jul 28, 2008, 10:54:34 AM7/28/08
to The Java Posse
In the first year of my CS degree, I barely touched a computer...
instead we had calculus, (space) geometry and lineal algebra... it was
painful :)
I can't say that much of the stuff has a direct application on
programming, but I think the more interesting part is the side-effect
of (being forced to) learn and apply math (or at least, I like to
pretend that ;) ): abstraction, abstraction, abstraction. You learn to
map and solve complex problems with purely logical tools. I think that
helps to program.
It was kind of disappointing later, when I learned that you should
NEVER trust a computer with a (floating point) calculation...

sherod

unread,
Jul 29, 2008, 3:42:28 AM7/29/08
to The Java Posse
All that pure logic goes out the window when you hit your open source
framework with little doco and even less support.

I think we'd be better off with less logic and more clairvoyance
training :)

On Jul 29, 12:54 am, Gabriel Claramunt <gabriel.claram...@gmail.com>
wrote:

Peter Becker

unread,
Jul 29, 2008, 6:23:08 AM7/29/08
to java...@googlegroups.com
Most OSS frameworks with little docu and even less support are not
worthwhile using; they tend to have other issues, too. Sometimes it is
cheaper to do it yourself.

Peter

DAemon

unread,
Aug 4, 2008, 9:02:00 PM8/4/08
to java...@googlegroups.com
I agree with this. I'm a Pure Maths student, so I'm probably pretty
biased, but the methods of thinking about problems (recently,
particularly solution spaces and isotopies within that space) that you
learn in abstract mathematics courses can really help you out when
trying to design a program or a method.

DAemon

2008/7/29 Gabriel Claramunt <gabriel....@gmail.com>:

Reply all
Reply to author
Forward
0 new messages