tags:

views:

3192

answers:

29

I've heard many times that all programming is really a subset of math. Some suggest that OO, at its roots, is mathematically based, but I don't get the connection, aside from some obvious examples:

  • using induction to prove a recursive algorithm,
  • formal correctness proofs,
  • functional languages,
  • lambda calculus,
  • asymptotic complexity,
  • DFAs, NFAs, Turing Machines, and theoretical computation in general,
  • and the fact that everything on the box is binary.

I know math is very important to programming, but I struggle with this "subset" view. In what ways is programming a subset of math?

I'm looking for an explanation that might have relevance to enterprise/OO development, if there is a strong enough connection, that is.

+45  A: 

It's math in the sense that it requires abstract thought about algorithms etc.
It's engineering when it involves planning schedules, deliverables, testing.
It's art when you have no idea how it's going to eventually turn out.

Martin Beckett
It's hard to add to that...
torial
Very artistic answer...
Pablo Marambio
Does anyone know what their programs are going to turn out like when they start?
Hugoware
@HBoss: That just means it's always art :)
Mark
I would add a final line: "It's voodoo when you try to explain it to someone else"
bta
+5  A: 

Well, aside from all that...!

Math is used for many aspects of programming such as

  • Creating efficient and smart algorithms
  • Understanding Big O notation
  • Security (such as RSA)
  • Many more... I think that programming needs math to survive. But I wouldn't call it a subset. It's just like blowing glass uses properties of physics, but those artists don't call themselves physicists.
stalepretzel
Right...I fully get how important math is to programming, but I struggle with the subset argument.
moffdub
Math is used in programming. But that doesn't make programming, math.Math is used in finance. Math is used in building cars, building houses. Math is used in calculating how long your holiday should be.Does that mean a holiday, is math?Programming is nothing like math. We solve problems, not equations.Also, I disagree with people saying that logic is a subset of math. It's the other way around. Math is a subset of logic. In that sense, we can easily understand that when we are doing programming, we ARE doing logic, but not math :)
boytheo
A: 

I would say that programming is less about math than it used to be as we move up to 4th Generation Languages. Assembly is very much about math, C#, not so much. Thoughts?

ferventcoder
+7  A: 

if your definition of math includes all forms of formal logic, and programming is defined only by the logic and calculations extant in the code, then programming is a subset of math QED ;-)

but this is like saying that painting is merely putting colored pigments on a surface - it completely igores the art, the insight, the intuition, the entire creative process

one could argue that music is a subset of math by the same reasoning

so i'd have to say no, programming is not a subset of math. Programming uses a subset of math, but requires non-math skills/talent as well [much like music composition]

Steven A. Lowe
+1 for using Q.E.D. Euclid would be proud.
Zach Johnson
+26  A: 

Overall, remember that mathematics is a formal codification of logic.. which is also what we do in software.

The list of topics in your question is loaded with mathematical problems. We are able to do programming on a fairly high level of abstraction, so the raw mathematics may not be staring you in the face. For example, you mentioned DFAs.. you can use a regular expression in your programs without knowing any math, but you'll find more of a need for mathematics when you want to design a good regular expression engine.

I think you've hit on an interesting point. Programming is an art and a science. There are a lot of "tools of the trade", and you don't necessarily sit down and do a lot of high-level mathematics in order to simply write a program. In fact, when you're programming, you many not really being doing much mathematics or computer science.

It's when we start to solve difficult problems in computer science that mathematics shows up. The deeper you go, the more it will flesh itself out.. often in lower levels of abstraction.

There are also some realms of programming that you don't necessarily have to work in, but they involve more math. For example, while you can certainly learn a language and write some apps without any formal mathematics, you won't get very far in algorithm analysis without some applied math.

keparo
One could also argue that there is an art to mathematics too, once you get past dealing with the basic theory and get to figuring out proofs for some of the more interesting questions.The result may follow a rigid set of rules, but the process to get to those rules need not (and probably should not) be rigid.
Adam Luchjenbroers
We don't use math, we use logic. Logic is a super-set of math.If there are no numbers involved, it's not math. Math is the subset of logic that deals with numbers.
boytheo
boytheo said "math is the subset of logic that deals with numbers". I /strongly/ disagree. Ask any mathematician, and they will say math includes topology, dealing with shape, and algebra, dealing with structure. Also, if you happen to ask someone who uses ZFC as a foundation for their mathematics, they'll tell you that math is formal logic applied to /sets/, not numbers. Well, except that we use numbers as names for certain sets, i.e. 0={}, 1={0}, 2={0,1}, etc., and think of relationships between such sets in terms of our intuitive understanding of numbers (i.e. 2+2=4, not 2+2={0,1,2,3})
Jonas Kölker
@boytheo- You might can argue that *arithmetic* is a sub-set of logic that deals with numbers, but there is a lot of mathematics that has nothing to do with numbers.
bta
+33  A: 

Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians.

E. W. Dijkstra

Mark Cidade
+22  A: 

OK, I was a math and CS major in college. I would say that if the set A is Math and the set B is CS, then A intersects B. It's not a subset.

It's no doubt that many of the fathers and mothers of computer science were Mathematicians like Turing and Dykstra. Most of the founders of the internet were either Phd's in Math, Physics, or Engineering. Most of the core concepts of computer science come from math, but the act of programming isn't really math. Math helps us in our daily lives, but the two aren't the same.

But there is no doubt that the original reasoning behind the computer was to well, compute things. We have come a long way from there in such a short time.

Charles Graham
I would agree - math forms a major part of most computer systems, but programming isn't necessarily math. As I see it, the core foundation of most programs is the logic they represent. Logic and math are different, although related.
Dr8k
n doubt || no doubt?
troelskn
A: 

I don't believe I've heard that programming is a subset of math. Even the link you provide is simply a proposed approach to programming (not claiming it's a subset of mathematics) and the wiki page has plenty of disagreements in it as well.

Programming requires (at least some) applied mathematics. Mathematics can be used to help describe and analyze programs and program fragments. Programming has a very close relationship with math and uses it and concepts from it heavily. But subset? no.

I'd love to see someone actually claim that it is one with some clear reasoning. I don't think I ever have

Just because you can use mathematics to reason about something does not imply that it is, ipso facto, a mathematical object. Mathematics is used to reason about internal combustion engines, radioactive decay and juggling patterns. Using mathematics is not doing mathematics.

Philip Rieck
A: 

It's half math, half man speak, duh.

shogun
+18  A: 

Einstein was known in 1917 as a famous mathematician. It wasn't until Hiroshima that the general public finally came around to the realization that physics is not just applied mathematics.

When people don't understand something, they try to understand it as a type of something that they do understand. They think by analogy. Programming has been described as a field of math, engineering, science, art, craft, construction... None of these are completely false; it borrows from all of these. The real issue is that the field of programming is only about 50 years old. People have not integrated it into their mental taxonomies.

Alan Hensel
+3  A: 

The foundation of everything we do is math.

Luckily, we don't need to be good at math itself to do it. Just like you don't need to understand physics to drive a car or even fly a plane.

Telos
Actually, it's hard to fly a plane without understanding basic physics. It's all about energy, momentum, force vectors, velocity vectors - things going as the square of speed, etc.
Mike Dunlavey
Nah, I've flown a plane (briefly.) It was easy, and I really know nothing of the physics behind it. All you need to do is keep the wings level, really.
Telos
@Telos: yeah, I've done that too and -in normal conditions- is not that complicated. Of course, I would be more reassured knowing that the pilot of my plane knows at least the basics of physics ;)
nico
+2  A: 

I would say...

It's partly math, especially at the theoretical level. Imagine designing efficient searching/sorting/clustering/allocating/fooifying algorithms, that's all math... running the gamut from number theory to statistics.

It's partly engineering. Complex systems can rarely achieve ideal levels of performance and reliability, and software is no exception. A lot of software development is about achieving robustness in the face of unreliable hardware and (ahem) humans.

And it's partly art. Creative and idiosyncratic software design often comes up with great new ideas... like assembly language, multitasking operating systems, graphical user interfaces, dynamic languages, and the web.

Just my 2¢...

Dan
+2  A: 

Math + art + logic

I've taken Algebra... nothing felt logical about it - LOL
Hugoware
+1  A: 

If you just want the design specs handed out to you by your boss, then it's not much math but such a work isn't fun at all... However, coming up with how to do things does require mathematical ideas, at least things like abstraction, graphs, sometimes number theory stuffs and depending on the problems, calculus. Personally, more I've been involved with programming, more I see the mathematical side to it. However, most of the times IMO, you can just pick up the book from library and look up the basics of the thing you need to do but that requires some mathematical grasp upfront.

You really can't design "good" algorithms without understanding the maths behind it. Searching in google takes you only so far.

pvsnp
+1  A: 

Programming is a too wide subject. Good software based not only on math (logic) but also on psychology, linguistics etc. Algorithms are part of math, but there are many other programming-related things besides algorithms.

Sergei Stolyarov
+1  A: 

As a mathematician, it is clear to me that Math is not equal to Programming but that the process which is used to solve problems in either discipline is extremely similar.

Solving a higher level mathematics questions requires analytical thinking, a toolbox of possible ways of solving problems, experience with the field, and some formalized ways of constructing your answer so that other mathematicians agree. If you find a particularly clever, abstract, or elegant way of solving a problem, you get Kudos from your fellow mathematicians. For particularly difficult math problems, you may solve the problem in stages, and codify your stage arguments using things called conjectures and proofs.

I think programming involves the same set of skills. In programming, the same set of principles applies to the solving and presenting of solutions to problems. When you have a partial solution to a programming dilemna, you include it as part of your personal library and use it as part of another bigger problem later. These skills seem very similar to the skills used in mathematics.

The major difference between Math and Programming is the latter has a lot more in common between different disciplines of programming than Math does. Two fields of mathematics can be very, very different in presentation and what is used to communicate the field. By contrast, programming structures, to me at least, look very similar in many different languages.

David Wees
A: 

You can actually argue that math, in the form of logical proofs, is analogous to programming --

Check out the Curry-Howard correspondence. It's probably more the way a mathematician would look at things, but I think this is hitting the proverbial nail on the head.

Tyler
+11  A: 

There's a lot of confusion here.

First of all, "programming" does not (currently) equal "computer science." When Dijkstra called himself a "programmer" (more or less inventing the title), he was not pumping out CRUD applications, but actually doing applied computer science. Let's not let that confuse us-- today, there is a vast difference between what most programmers in a business setting do and computer science.

Now, the argument can be made that computer science is a branch of mathematics; but, as Knuth points out (in his paper "Computer Science and its Relation to Mathematics", collected in his Selected Papers on Computer Science) it can also be argued that mathematics is a branch of computer science.

In fact, I'd strongly recommend this paper to anyone thinking about the relationship between mathematics and computer science, as Knuth lays out the territory nicely.

But, to return to your original question: to a practitioner, "enterprise/OO development" is pretty far removed from mathematics-- but that's largely because most of the serious mathematics involved at the lower levels of operation have been abstracted away (by compilers, operating systems, instruction sets, etc.). Similarly, advanced knowledge of the physics of the internal combustion engine are not required for driving a car. Naturally, if you want to design a more efficient car....

Michael Dorfman
I agree. And if I may elaborate, what most universities in the anglosaxon tradition call "computer science" is more similar to what should be called "software engineering". Conceptual modelling, effort estimation and other tasks that us developers carry out daily are nothing to do with science.
CesarGon
+5  A: 

Disclaimer: I work as an IT consultant and develop mainly portals and Architecture stuff. I have a Psychology degree. I never studied Maths in University. And i get my job done. And usually well. Why? Because I don't think you need to know Maths (as in 'heavy' Maths stuff) to write code. You need analytical thinking, problem-solving skills, and a high level of abstraction. But Maths does not give you that. It's just another discipline that requires similar skills. My studies in Psychology also apply to my daily work when dealing with usability issues and data storage. Linguistics and Semiotics also play a part.

But wait, just don't flame me yet. I'm not saying Maths are not needed at all for computers - obviously, you need real Math skills when designing encryption algorithms and hardware and etc -- but if, as lots of programmers, you just work an a mid/low level language (like C) or higher level stuff (like C# or java), consuming mostly pre-built frameworks and APIs, you don't really need to understand the mathematical principles behind Fourier transforms or Huffman trees or Moebius strips... let someone else handle that, and let me build value on top of it. I am not stupid. I know the difference between linear and exponential algorithms and data structures and etc. I just don't have the interest to rewrite quicksort or a spiffy new video compression technique.

axel_c
You're absolutely right: you do not need to know math to code, just as you do not need to know about mechanics to drive a car. That doesn't of course mean that programming is not based on maths. Or that anyone could have built a car without knowing about mechanics for that matters...
nico
+1  A: 

The difference between programming and pure mathematics is the concept of state. A program is a state machine that uses logic (maths) to transition between states. The actual logic used to transition between states is usually very simple, which is why being a math genius doesn't necessarily help you all that much as a programmer.

Joeri Sebrechts
+2  A: 

The difference between programming and pure mathematics is the concept of state.

Have a look at http://en.wikipedia.org/wiki/Dynamic_logic_(modal_logic). It's a way of mathematically analyzing things changing through time. Also, Hoare triples is a way of formalizing the input-output behavior of programs. By having some axioms dealing with sequential composition of programs and how assignment works, you can perfectly well deal with state changing over time in a mathematically rigorous way.

If the math you know is insufficient, "invent" some new math to deal with what you want to analyze. Newton and Leibniz did it for analysis (aka calculus, I think). No reason to not do it for computation and programming.

Jonas Kölker
+1  A: 

I think math != programming :P

Giancarlo
+2  A: 

Part of the reason I'm a programmer is because I don't like math. I have no problem with math itself, and I'm fine with it conceptually, I just don't like doing calculations by hand. When I found I could tell a computer what the math problem is and let it do the calculating for me, a life-long passion and career was born.

To answer the question, according to my alma mater, math == programming since they allowed me to take Intro to C++ to fulfill my math requirement.

Edit: I should mention my degree is in telecommunications which, at the time, had only the standard liberal arts math requirement of one semester.

Michael Itzoe
I don't understand. How can you "tell a computer what the math problem is ...". Computers don't solve problems, they just give answers. You still have to solve it yourself.
ldigas
Computers don't even give answers. Computers follow instructions blindly. If those instructions result in an answer, that's great. If not... thats not so great.
boytheo
Yes, well ... now we're entering lexicography ... mind though, that english is not my main lang., but I do believe the point has gone through.
ldigas
A: 

If it doesn't involve numbers, it's not math.

Some people may try to extend the definition of "math" beyond dealing with numbers. But that basically makes the word "math", useless. If you extend the meaning of a word till who knows what it means... you can't really communicate using that word.

I could say that doing stuff with numbers isn't math, it's... physics. If I extended the definition of physics. It would be a BAD definition, but I could do it. I'd be wrong, but I'd still have defined it that way.

The same thing for saying programming is math, or that doing stuff that doesn't involve numbers, is math.

Simple rule: NO NUMBERS = NOT MATH

Programming is about using logic. But logic is a super-set of math.

For example, if A is inside B, and B is inside C, then A is inside C. Now... at no point have we talked about numbers. I might be talking about my coin that's inside my wallet that's inside my pocket. THAT is logic. Logic talks about things. Things can be numbers, but things can be not numbers too. A coin is not a number.

Math is the subset of logic that deals with numbers.

If you say that math=logic, then... you've basically made the term "logic" and "math" useless.

math is inside of logic.

math does not contain logic, it is contained by logic

Anyone who says otherwise is probably a bad programmer and a good mathematician trying to make him self feel better.

boytheo
Math = numbers is reductive and naïve. See for instance the very interesting paper by Sundar Sarukkai "Revisiting the 'unreasonable effectiveness' of mathematics" that you can find here: http://www.ias.ac.in/currsci/feb102005/415.pdf
nico
What do you think about group theory?
Andreas Rejbrand
-1. Logic is a subset of math. You are meaning arithmetic, which is a subset of math.
Luca
So algebra is not math … interesting.
Konrad Rudolph
+10  A: 

Doesn't mention programming, but idea is still relevant.

Jim
+1 for xkcd. :)
jb
A: 

It's interesting to compare programming with music too. In UK, anyway, there are computing based undergrad university courses that will accept applicants on the bases of music qualifications as supposed to computing due to the logic, patterns, etc. involved.

Ross
*as opposed to..
adam0101
A: 

Programming may have originally started as a quasi-subset of math, but the increasing complexity of the field over time has led to programming being the art and science of creating good abstractions for information processing and computation.

Programming does involve math, engineering, and an aesthetic sense for good design and implementation. Algorithms are an extension of mathematics, and the systems engineering side overlaps with other engineering disciplines to some degree. However, neither mathematics nor other engineering fields have the same level of need for complex, flexible, and yet understandable abstractions that can be used and adapted at so many different levels to solve new and evolving problems.

It is the need for useful, flexible, and dynamic abstractions which led first to the creation of function libraries, then class/component libraries, and in more recent years design patterns and service-oriented architectures. Although the latter have more of a design focus, they are a reaction to the increasing need to build high-level abstractional bridges between programming problems and solutions.

For all of these reasons, programming is neither a subset nor a superset of math. It is simply yet another field which uses math that has deeper roots in it than others do.

Joel Hoff
A: 

don't think.write what you know.know what you write.Don't write what you think. You all are distilling this blog's importanceand effectiveness.

goodbrain2010
A: 

Math is the purest form of truth. Everything inherits from math.

Amen.

zubinmehta