Why using linear integer programming (ILP) though it is NP-Complete? - np-complete

The question may be stupid but it really confuses me for a long time.
I read a lot of papers in wireless sensor network. Many researchers model their problems into the form of ILP. However, ILP is NP-Complete so it is not efficient for solving a problem.
So why people write their problems into the form of ILP? Do they do that to make their problem clear to see and easy to understand? Or do I make some mistakes understanding the relations between ILP and NPC?
I am really appreciated that you can help me to solve this question.

Although the question might be considered off-topic, there are basically a few points to address.
You are right that general integer linear programming is NP-hard.
If a specific problem needs to be solved and general integer linear programming is the most specific way to formulate it, then nothing can be done about it; some problems are just hard to solve.
In some cases, it is possible to use the LP relaxation instead, either as a heuristic or some approximation ratio can be proven.
The key point here is that integer linear programming is a widespread formalism for expressing problems. Basically I understand your question as the follwing one.
"Why do people use a model that is algorithmically hard to solve to
describe practical problems?"
Well, if that shortcoming could be circumvented in general, it would be a good idea to express every problem there is in terms of sorting, which is algorithmically easy.

NP-hard refers to the complexity of algorithms in the worst case. For most NP-hard problems, we have effective algorithms (heuristic or exact) that perform well most of the time, even if they do not perform well in the worst case. ILP is therefore a very useful tool in practice, even if there are some problems that it doesn't do well on.
I have a hammer. There are some jobs that my hammer is just no good for, or would take a very long time on. But it's still a very useful tool, because it can do a lot of jobs for me very well.
ILP is, in many ways, the same thing.

Related

Math solver with steps

I have a very hard time with math yet I always seem to find myself in ever increasingly difficult math courses. Over the years I have amassed a small 'fortune' of various scripts and programs. They are written in a variety of languages, from C to Java to Python and even a few in Lisp (I like to fool around with different languages). These are great for getting fast answers or checking my homework, but not so great for showing how those answers were gotten. My question is how would I go about adding a 'solver' aspect to these various programs? It doesn't need to be language specific, but just a concept or maybe a specific word or definition would be of immense help. I basically want to do a Wolfram Alpha type program, where you punch in the problem and it shows a step by step solution. I have spent the last couple of days researching this, but I am always redirected towards an app or, frustratingly, to Wolfram Alpha itself. Any suggestions would be much appreciated. Thank you.
What categories of math are you talking about?
There does not seem to be a universal math solving program, what you mentioned sounds to me like the concept of a complicated math system(like MatLab).
And for, I think, a large scale of mathematical problems, the algorithms for computer programs to solve them differ from our ways to solve them.
Rather than a universal algorithm to achieve your goal, I think you can divide your problem into pieces, and achieve them with different sets of programs, there is a thesis Symbolic Integration by Joel Moses, the first chapters give a good view of how to divide a math problem into programmable cases(in the example of solving quadratic equations), and the last hundred pages is a set of algorithms for solving irrational integration, interpreted in LISP.

How can I learn higher-level programming-related math without much formal training? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I haven't taken any math classes above basic college calculus. However, in the course of my programming work, I've picked up a lot of math and comp sci from blogs and reading, and I genuinely believe I have a decent mathematical mind. I enjoy and have success doing Project Euler, for example.
I want to dive in and really start learning some cool math, particularly discrete mathematics, set theory, graph theory, number theory, combinatorics, category theory, lambda calculus, etc.
My impression so far is that I'm well equipped to take these on at a conceptual level, but I'm having a really hard time with the mathematical language and symbols. I just don't "speak the language" and though I'm trying to learn it, I'm the going is extremely slow. It can take me hours to work through even one formula or terminology heavy paragraph. And yeah, I can look up terms and definitions, but it's a terribly onerous process that very much obscures the theoretical simplicity of what I'm trying to learn.
I'm really afraid I'm going to have to back up to where I left off, get a mid-level math textbook, and invest some serious time in exercises to train myself in that way of thought. This sounds amazingly boring, though, so I wondered if anyone else has any ideas or experience with this.
If you don't want to attend a class, you still need to get what the class would have given you: time in the material and lots of practice.
So, grab that text book and start doing the practice problems. There really isn't any other way (unless you've figured out how osmosis can actually happen...).
There is no knowledge that can only be gained in a classroom.
Check out the MIT Courseware for Mathematics
Also their YouTube site
Project Euler is also a great way to think about math as it relates to programming
Take a class at your local community college. If you're like me you'd need the structure. There's something to be said for the pressure of being graded. I mean there's so much to learn that going solo is really impractical if you want to have more than just a passing nod-your-head-mm-hmm sort of understanding.
Sounds like you're in the same position I am. What I'm finding out about math education is that most of it is taught incorrectly. Whether a cause or result of this, I also find most math texts are written incorrectly. Exceptions are rare, but notable. For instance, anything written by Donald Knuth is a step in the right direction.
Here are a couple of articles that state the problem quite clearly:
A Gentle Introduction To Learning
Calculus
Developing Your Intuition For
Math
And here's an article on a simple study technique that aims at retaining knowledge:
Teaching linear algebra
Consider auditing classes in discrete mathematics and proofs at a local university. The discrete math class will teach you some really useful stuff (graph theory, combinatorics, etc.), and the proofs class will teach you more about the mathematical style of thinking and writing.
I'd agree with #John Kugelman, classes are the way to go to get it done properly but I'd add that if you don't want to take classes, the internet has many resources to help you, including recorded lectures which I find can be more approachable than books and papers.
I'd recommend checking out MIT Open Courseware. There's a Maths for Computer Science module there, and I'm enjoying working through Gilbert Strang's Linear Algebra course of video lectures.
Youtube and videolectures.com are also good resources for video lectures.
Finally, there's a free Maths for CS book at bookboon.
To this list I would now add The Haskel Road to Logic, Maths, and Programming, and Conceptual Mathematics: A First Introduction to Categories.
--- Nov 16 '09 answer for posterity--
Two books. Diestel's Graph Theory, and Knuth's Concrete Mathematics. Once you get the hang of those try CAGES.
Find a good mentor who is an expert in the field who is willing to spend time with you on a regular basis.
There is a sort of trick to learning dense material, like math and mathematical CS. Learning unfamiliar abstract stuff is hard, and the most effective way to do it is to familiarize yourself with it in stages. First, you need to skim it: don't worry if you don't understand everything in the first pass. Then take a break; after you have rested, go through it again in more depth. Lather, rinse, repeat; meditate, and eventually you may become enlightened.
I'm not sure exactly where I'd start, to become familiar with the language of mathematics; I just ended up reading through lots of papers until I got better at it. You might look for introductory textbooks on formal mathematical logic, since a lot of math (especially in language theory) is based off of that; if you learn to hack the formal stuff a bit, the everyday notation might look a bit easier.
You should probably look through books on topics you're personally interested in; the inherent interest should help get you over the hump. Also, make sure you find texts that are actually introductory; I have become wary of slim, undecorated hardbacks labeled Elementary Foobar Theory, which tend to be elementary only to postdocs with a PhD in Foobar.
A word of warning: do not start out with category theory -- it is the most boring math I have ever encountered! Due to its relevance to language design and type theory, I would like to know more about it, but so far I have not been able to deal...
For a nice, scattershot intro to bits of many kinds of CS-ish math, I recommend Godel, Escher, Bach by Hofstadter (if you haven't read it already, of course). It's not a formal math book, though, so it won't help you with the familiarity problem, but it is quite inspirational.
Mathematical notation is is akin to several computer languages:
concise
exacting
based on many idioms
a fair amount of local variations and conventions
As with a computer language, you don't need to "wash the whole elephant at once": take it one part a at time.
A tentative plan for you could be
identify areas of mathematics that are interesting or important to you. (seems you already have a bit of a sense for that, CS has helped you develop quite a culture for it.)
take (or merely audit) a few formal classes in this area. I agree with several answers in this post, an in-person course, at local college is preferable, but, maybe at first, or to be sure to get the most of a particular class, first self-teaching yourself in this area with MIT OCW, similar online resources and associated books is ok/fine.
if an area of math introduces too high of a pre-requisite in terms of fluency with notation or with some underlying concept or (most often mechanical computation and transformation techniques). No problem! Just backtrack a bit, learn these foundations (and just these foundations!) and move forward again.
Find a "guru", someone that has a broad mathematical culture and exposure, not necessarily a mathematician, physics folks are good too, indeed they can often articulate math in a more practical fashion. Use this guru to guide you, as he/she can show you how the big pieces fit together.
Note: There is little gain to be had of learning mathematical notation for its own sake. Rather it should be learned in context, just like say a C# idiom is better memorized when used and when associated with a specific task, rather than learned in vacuo. A related SO posting however provides several resources to decipher and learn mathematical notation
Project Euler takes problems out of context and drops them in for people to solve them. Project Euler cannot teach you anything effectively. I think you should forget about it, if it is popular it does not mean anything. You cannot study Mathematics through Project Euler as it contains only bits and pieces(and some pretty high level pieces) that you're supposed to know in order to solve the problems. Learning mathematics means to consider a subject and a read a book about it and solving exercices or reading solutions, that's how you learn math. If it so happens that through your reading you find something that is close to some project euler thing, your luck , but otherwise Project euler is a complete waste of time. I think the time is much better invested choosing a particular branch of mathematics and studying that. Let me explain why: I solved 3 pretty advanced Projec Euler problems and they were all making appeal to knowledge from Number theory which I happened to have because i studies some part of it. I do not think Iearned anything from Project Euler, it just happened that I already knew some number theory and solved the problems.
For example, if you find out you like number theory, take H. Davenport -> Hardy & Wright -> Kenneth & Rosen's , study those.
If you like Graph Theory take Reinhard Diestel's book which is freely available and study that(or check books.google.com and find whichever is more appropriate to your taste) but don't spread your attention in 999999 directions just because Project Euler has problems ranging from dynamic programming to advanced geometry or to advanced number theory, that is clearly the wrong way to go and it will not bring you closer to your goal.
This sounds amazingly boring
Well ... Mathematics is not boring when you find some problem that you are attached to, which you like and you'd like to find the solution to, and when you have the sufficient time to reflect on it while not behind a computer screen. Mathematics is done with pen and paper mostly(yes you can use computers .. but that's not really the point).
So, if you find a real-world problem, or some programming problem that would benefit from
you knowing some advanced maths, and you know what maths you have to study , it can be motivating to learn in that way.
If you feel you are not motivated it is hard to study properly.
There is also the question of what you actually mean when you say learn. Does the learning process stop after you solved the problems at the end of the chapter of a book ? Well you decide. You can consider you have finished learning that subject, or you can consider you have not finished and read more about it. There are entire books on just one equation and variations of it.
The amount of programming-related math that you can learn without formal training is limited, but it's more than enough. But maybe you can self-teach yourself.
It all boils down to your resources and motivation.
To know mathematics you have to do mathematics not programming(project euler).
For beginning to learn category theory I recommend David Spivak's Category Theory for the Sciences (AKA Category Theory for Scientists) because its relatively comprehensible due to many examples that enable understanding by analogy and which quickly builds a foundation for understanding more abstract concepts.
It requires the ability to reason logically and an intuitive notion of what is a set. It proceeds from sets and functions through basic category theory to adjoint functors, categories of functors, sheaves, monads and an introduction to operads. Two main threads throughout are modeling databases in terms of categories and describing categories with annotated diagrams called ologs. The bibliography provides references to more advanced and specialized topics including recent papers by Dr. Spivak.
An expected outcome from reading this book is the capability of understanding category theory texts and papers written for mathematicians such as Mac Lane's Category Theory for the Working Mathematician.
In PDF format it is available from http://math.mit.edu/~dspivak/teaching/sp13/ (the dynamic version is recommended since its the most recent). The open access HTML version is available from https://mitpress.mit.edu/books/category-theory-sciences (which is recommended since it includes additional content including answers to some exercises).

J Language for learning math - "Math for the Layman"

Working programmer looking for a math refresher or just developing mathematical thinking. Saw J Language http://www.jsoftware.com/jwiki/Books
The book "Math for the Layman" claims that the J language makes math easier to learn by providing interactive tools and simpler notation than conventional math. Can someone confirm this from experience, specifically for learning mathematical thinking? I thought I'd try a programming approach and maybe pick up a new language along the way. If not, I have my text books ready.
Is this worth my time?
Thank you.
Learning can never be a waste of time. I'd say go for it, without knowing anything about J.
The math that I learned was acquired without the benefit of computers. I have no experience with J, so I can't comment on that.
I personally don't think that a computer language will make you a mathematician. If you've never taken calculus I don't see how a language or different notation will necessarily make it better or worse. It needs to have complementary sources to really learn it well.
It may help since you're literate with computers, but the math will still take as long as it takes. It's one thing to program a Bessel function; it's another to understand the differential equation it comes from, the problems it solves, orthogonality and relationships to other functions, etc.
Linear algebra is one area that greatly benefits from computer analysis. The rules aren't too difficult, and computers save on the repetitive grunt work.
Another important bit is motivation. I found that studying something for the sake of solving a particular problem was always important, especially with math. Knowing how it would help me understand a problem in physics or engineering was a great motivator. What will your motivation be?

Math, programming, and learning [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
It has been discussed on this site before about the relationship between math and programming, and whether one is a subset of the other, etc.
In my recent study of programming, I've found myself more and more wishing I was better at math. You all know the scenario when programming books start to generalize something in a math way ("Therefore, we may say that for all <some single letter>, <lots of letters>"). My eyes glaze over in such situations. I know that that is mostly due to me being stupid, but it seems that if I could just improve my higher math skills, maybe I could get more out of such things.
Major question: Is math indeed something one can "get better at," or is your brain kinda either wired for it or not?
Important follow-up question: If the answer to the above is yes, then what are some ways to go about it?
I think anyone can get better at math. You just have to be determined and practice.
Part of the problem is that math books tend to be written by mathematicians who ceased being math novices decades ago. What you want is books geared to your level and which contain material you can work with.
Some recommendations:
If you can find a copy, get Mathematica and a good book on it (the Schaum's outline is actually pretty good and cheap). I use it all the time to visualize things.
As a programmer, you probably want to aim more for discrete mathematics than calculus.
The Concrete Mathematics book mentioned elsewhere is excellent.
Most introductory discrete math texts have good coverage of the things like logic, sets, combinatorics, probability, graph theory, etc. My school used Rosen's text which I liked.
Linear algebra is useful if you are going to do 3D graphics programming. Most intro texts for engineers will teach you what you need to know. Linear Algebra Done Right is probably the best on "real" linear algebra if you want something more theoretical.
Look for books by Martin Gardner and play with his puzzles. He's an excellent writer and teacher.
Remember that math doesn't change that much. You can get used books for cheap on Amazon and in used bookstores. I always look for the n-1 version when I buy textbooks.
When you first started learning English all those "symbols" (letters) looked like gibberish to you. I'm sure that at some point you were frustrated over your lack of understanding. But slowly, and gradually you began to understand them.
Eventually you were able to construct your own words and sentences using these symbols. After being corrected on it's structure and grammar for years you now have a command of the language.
Math is just like that. Your eyes glaze over because you haven't learned the language. Maybe in school you didn't particularly enjoy math because you didn't see any practical applications for it. Certainly the way we teach math to our students is atrocious, so it is no wonder why many get through school without being well versed in it (for further reading, check out A Mathematician’s Lament which discusses how horrible our current method of teaching math is).
However, it is never too late to get up to a degree of proficiency that will allow you to read many academic Computer Science writings. Start out with Pre-Calculus at your local community college at night (to brush up on everything you have forgotten). Then move on to Calculus and after that take Discrete math. Honestly, this is all the math you will need 99.99% of the time. In less than 2-3 semesters you can be fully caught up and you'll no longer have your eyes glaze over when reading something with some mathematical roots.
I can share my experience...
I have been terrified of math since grade school. Hated it, didn't get the point, didn't pursue it.
By contrast, I have always been fascinated by computers. I study programming from a "need to know"- I can't stand not understanding computers and programming from the lowest to highest levels. I am almost completely self-educated, and have a career as a programmer/architect.
Last year, at my wife's urging, I began to go back to college. I signed up for a remedial Algebra class, knowing it was going to be a pain. It wasn't.
Somehow, through all the years of learning to develop OO software, it seemed that I had tricked myself into learning how to think mathematically. The concepts just weren't that difficult anymore. It may be that I had learned to think in terms of complex systems made up of smaller, less complex ideas.
I am now researching game development, and that is some seriously math-oriented programming. WAY more so than the business development I've been doing to this point. However, I don't find it so daunting because it's applied mathetmatics. Working to solve practical problems seems to make the study less tedious and far more interesting. I have found Wikipedia and Wolfram's Mathworld to be helpful. If you already know how to program, you're ahead of the game learning math.
I'd say it's certainly something anyone can get better at. It takes time and patience and some texts are obscenely dense as far as the notation involved, but if you're willing to put the time in, I think it shouldn't be too horrible.
I'd check out Wikipedia's list of mathematical symbols, and keep if nearby whenever you see a large blob of symbols pop up. Translate them one at a time and put them together in the way that makes the most sense to you (or ask us a few times until you get the hang of it).
It's both. You can get better at math. But you're also indeed limited/endowed by the particular wiring in your brain. What that means is that most likely you can improve your current mathematical skills. However, because of your mental hardware's limits, you may never discover a new theorem.
And when it comes to improving, I think the way as always is to practice. To read mathematical literature, to try to solve mathematical problems and eventually, develop an outlook where you are able to break, as a matter of habit, real-world conundrums you see before you down in mathematical terms.
As for programming's relation with mathematics, I think there's a pretty strong one. In fact, one could argue that a program is nothing but a proof of a theorem, the requirements document being all the inputs to the proof.
Your skills get rusty if not used and knowledge fades with time if not used.
If you don't use your math skills you soon have no math skills. Continuous new learning and practice of the skills you already have will lead to you one day being a math/programming master.
Project Euler has lot of math problems that can only be solved through programming. The problems get more difficult but build on the skills and knowledge acquired in your previous solutions.
I also buy some interesting textbooks at second hand book shops. Their cheap and slowly your skills improve. I use them in conjunction with MIT Open Course ware.
A fun way to practice math is http://projecteuler.net/.
Although it's less systematic/effective than doing a course or reading a textbook.
I know exactly how you feel. I've always wanted to learn more Math, but as I was unable to do it at college after school (not enough space) and not able to take it at university (not able to with a CS degree) I'm still yet to study Math formally since the age of 16.
Math is something that anyone can learn. Some will argue that it gets harder with age but I've met people going on for 60 that are taking Math classes with ease. There's one woman at my university that's going on for 70 and she's a few months off of graduating with a degree in a Mathematics related field. If you want to learn Math then now is the right time, although I'll be the first person to say that it is not easy. Whilst you'll find many of the problems extremely easy with programming experience you'll still find that going through a set of problems takes a lot of time out of your day. I almost finished the MIT OpenCourseWare course on Linear Algebra, then ended up getting a new part-time job, working 10 hours a day, 7 days a week, and forgetting the majority of what I had learnt.
That being said, if you have the time and true dedication I can recommend some links to video lectures that may just help you get on your way.
Pre-Calculus Algebra
Pre-Calculus
Calculus
Applied Probability
Introduction to Statistics
Differential Equations
Linear Algebra
I'm not saying that this is what you need to know. This is what I've set out to learn myself before I graduate from my CS degree, so feel free to pick and choose whatever you feel is best for you.
Studying math is like getting a classical education, one specially suited for programmers and other computer professions. And math's the sort of thing that you can appreciate more as you get older. You realize that it's not about grinding out answers so much as it's about thinking deeply and conceptually. The "answers" you might grind out make a lot more sense that way.
At one time, I would have recommended taking a geometry course, and take some time to learn how to prove theorems, see how the concepts flow together. These days, though, I'd say it may be better to take a course in discrete mathematics. It's much more practical, and there's a lot more variety, but there's still enough theory in there to make it challenging if you want.
Discrete math also provides you with programming challenges you might not have thought of before. Maybe you can hack up a good heuristic to solve an NP-complete problem, like an N-city Traveling Salesman problem. Maybe even come up with a couple solutions, and test which ones work best in which circumstances.
(I never took CompSci classes in college. You can probably tell.)
Go to the local community college and sign up for Calculus 1. This covers functions in the mathematical sense, and has a rigorous refresher course on algebra, and will use just enough of the symbols to get you ahead.
First of all, I would recommend Steve Yegge's Math For Programmers. It pretty much sums up your struggle.
And now I would like to tell a personal story. I was a double major in Math and CS. I learned a lot in the Math classes, but I honestly didn't appreciate it as much as I should have. I will tell you that a lot of things that I did have helped me in my programming career. And it's not about some formula or knowing calculus, or any of that stuff. It's that a solid Math background teaches you how to think in order to solve a problem. To me, that's the Math that you need.
1) Yes.
2) Explore mathematical questions which sound interesting. Buy/read books that give you the information needed. Repeat.
It can absolutely be learned. I personally had the most benefit from the math (especially proof) courses I took in college.
Recommended courses:
Discrete Math
Mathematical Thought
Abstract Algebra
any other proof courses
Recommended book:
The Nuts and Bolts of Proofs, by Antonella Cupillari
I strongly recommend trying to take one or more of these courses at a school of some sort. Find a local college and audit a course.
A 2nd vote for Lockhart's "A Mathematician’s Lament", which recommends that math be taught like painting, poetry, or music -- not for it's practical usefulness but for simple pleasure:
There’s no
ulterior practical purpose here. I’m just playing. That’s what math is— wondering, playing,
amusing yourself with your imagination.
Look at the diagrams in a recent Knuth paper, Dancing Links, and tell me he wasn't having fun making those.
Part of the problem is that a few mathematical symbols convey a heck of a lot of information. If you are reading a normal programming book, it is full of words and code. Neither of these is super verbose (although I often have to slow down much more on code than normal words). However one complicated mathematical equation can easily be a screen full of programming code or words. We have all sorts of simple notations that convey complex processes.
Another issue is that notation is standardized but not exactly. Different books use slightly different notation so it takes a while to get used to it. Also many textbooks leave out key steps in mathematical proofs or even examples. Sometimes even college professors puzzle themselves with the missing steps in a given proof in a textbook and then give their own proof, or give a slightly modified one over the one in the book because they learned it differently or can't recreate the missing step exactly which takes the proof in a different direction.
So anyway just because your eyes glaze over doesn't mean you have to give up. The first time you see the equations you will probably be in read the english text mode and have to pause to consider them. Going over them slowly and paying attention to what all the symbols mean one step at a time may yield the answer for you. If there is some notation you haven't seen before, there is probably an intro chapter or appendix explaining the notation, so check there. Finally, look for other sources. Use google/wikipedia to look up equations for the concept and you may find a derivation and/or proof that you can follow. Additionally the other one may help you to understand the current proofs/derivations better. Even if your understanding of the proof/derivation does not improve, your additional research will probably aid in your understanding of the equation.
I think there are two things to learning math:
1. Learning the general techniques. Ie how to add two fractions, how to differentiate, integrate.
2. Learning to problem solve and apply math to the real world.
I think by picking up math textbooks yo will learn 1. Many math textbooks are organized by section where there will be a few pages showing you a technique and then a bunch of problems. The problems tend to be related to the technique that you just learned and very similar. Ie a section on logarithms will have all problems on logarithms and probably won't include any polynomials. By doing the problems in the section you will learn the techniques. The more problems you do the faster you will get and the more you will understand the concepts. Many times you will find if you work through the problems without explicitly memorizing the formulas, you will find that after you do enough the required formulas will be implicitly memorized. Ultimately if you are having trouble looking at probability formulas you will want to read a probability book. If you are having trouble with sum notation you will want to consult that section of an algebra book, etc...
To learn 2 I think math textbooks don't help as much because each section tends to have problems related to that section. Occasionally there are a few "mixed review" problems or a "chapter review" which mixes problems, but they are typically far in between. Science textbooks like Physics, Biology, Chemistry, etc. tend to be better for this. There you often read the problem, lay it out, and end up using a variety of mathematical tools to to solve it. Sometimes calculus, linear algebra, and geometry all within the same problem. The value here is that it teaches you to problem solve. Generally the SAT/GRE do not test if you know how to do Algebra, they test if you know how to apply it to the real world, and the science problems really help you here. Also programming in general is about problem solving and the better you get at problem solving the better you'll be at programming. Basically in programming you take problems, create a mental model, design a solution, and then model it in your programming language of choice. This is similar to say Physics. You look at the problem, extract a mathematical model, design a solution, right down some equations with the model of the solution, then plug numbers in. I highly recommend physics because after my college physics class word problems became simple for me and they used to be quite difficult (though not impossible).
In day to day programming you probably won't use more than algebra and logic (for if statements and loop conditions). There are some places that use high math like computer games, cryptology, data mining, etc. but for a typical business application you probably won't use more than algebra and logic and maybe a bit of set theory (the stuff so basic you already internalized it). Even in places that use high math (like financial companies) often the business users (or some industry literature) will have done the higher math and you will just need to implement the equations (with some algebra). I only mention this because most programming books don't have more than algebra and logic either, unless you are reading textbooks on Algorithm Analysis (Introduction to Algorithms), Artificial Intelligence, or some other research area. General application books on how to do things are usually short on math.
But depending upon what you are reading math can help. For most computer science algebra + discrete math should be enough. Couple that with some physics practice and you should be good to go. It may still be a slow go but you should have the proper background.
I like combinatorics and algorithms - having fun you learn faster.
study study study!
wikipedia is actually a fairly good math reference. start with something you're interested in learning and follow links until you understand all the building blocks for that initial thing.
practice practice practice!
Schaum's outlines are good for this. If you're interested in probability (which touches on combinatorics), see 50 Challenging Problems in Probability.
Short answer:
There may be people who are to stupid to get good a maths. But those people generally are to stupid to program, too.
So if you have some skills in programming, you might consider yourself smart enough to learn maths as well.
Note: I know there are smart people with a serious math learning disability, but I think thats more like an exception.
I would also recommend project euler While it does not exactly teach math, it gives you problems that you can then look up how to solve. I've always preferred solving actual problems instead of just learning theory.

Is mathematics necessary for programming? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I happened to debate with a friend during college days whether advanced mathematics is necessary for any veteran programmer. He used to argue fiercely against that. He said that programmers need only basic mathematical knowledge from high school or fresh year college math, no more no less, and that almost all of programming tasks can be achieved without even need for advanced math. He argued, however, that algorithms are fundamental & must-have asset for programmers.
My stance was that all computer science advances depended almost solely on mathematics advances, and therefore a thorough knowledge in mathematics would help programmers greatly when they're working with real-world challenging problems.
I still cannot settle on which side of the arguments is correct. Could you tell us your stance, from your own experience?
To answer your question as it was posed I would have to say, "No, mathematics is not necessary for programming". However, as other people have suggested in this thread, I believe there is a correlation between understanding mathematics and being able to "think algorithmically". That is, to be able to think abstractly about quantity, processes, relationships and proof.
I started programming when I was about 9 years old and it would be a stretch to say I had learnt much mathematics by that stage. However, with a bit of effort I was able to understand variables, for loops, goto statements (forgive me, I was Vic 20 BASIC and I hadn't read any Dijkstra yet) and basic co-ordinate geometry to put graphics on the screen.
I eventually went on to complete an honours degree in Pure Mathematics with a minor in Computer Science. Although I focused mainly on analysis, I also studied quite a bit of discrete maths, number theory, logic and computability theory. Apart from being able to apply a few ideas from statistics, probability theory, vector analysis and linear algebra to programming, there was little maths I studied that was directly applicable to my programming during my undergraduate degree and the commercial and research programming I did afterwards.
However, I strongly believe the formal methods of thinking that mathematics demands — careful reasoning, searching for counter-examples, building axiomatic foundations, spotting connections between concepts — has been a tremendous help when I have tackled large and complex programming projects.
Consider the way athletes train for their sport. For example, footballers no doubt spend much of their training time on basic football skills. However, to improve their general fitness they might also spend time at the gym on bicycle or rowing machines, doing weights, etc.
Studying mathematics can be likened to weight-training or cross-training to improve your mental strength and stamina for programming. It is absolutely essential that you practice your basic programming skills but studying mathematics is an incredible mental work-out that improves your core analytic ability.
While advanced mathematics may not be required for programming (unless you are programming advanced mathematics capability) the thought process of programming and mathematics are very similar. You begin with a base of known things (axioms, previously proven theories) and try to get to someplace new. You cannot skip steps. If you do skip steps, then you are required to fill in the blanks. It's a critical thought process that makes the two incredibly similar.
Also, mathematicians and programmers both think critically in the abstract. Real world things are represented by objects and variables. The ability to translate from concrete to abstract also links the two fields.
There's a very good chance that if you're good at one, you will probably be good at the other.
computer science != programming
OK, seriously, I know good and bad programmers who were English and Psychology majors and some that were Computer Science majors. Some very famous guys that I admire as developers didn't have a CS background. Larry Wall(Perl), for example, was a linguist.
On the other hand, it helps to know something about the domain you are working on because then you can at least see if your data makes sense and help your customer/users drill down to what they really want.
And yes, there's the issue of computational complexity and efficient data structures and program correctness. That's stuff you learn in Computer Science and that's useful to know in almost any domain, but it's neither necessary nor sufficient.
I guess I am going to be the first person to say you do need math. As others have said math is not all that important for certain aspects of development, but the fundamentals of critical thinking and structured analysis are very important.
More so, math is important in understanding a lot of the fundamentals that go into things like schedulers, optimizations, sorting, protocol management, and a number of other aspects of computers. Though the math involved from a calculation level is not complex (its mostly High school algebra) the theories and applications can be quite complex as a solid understanding of math through calculus will be of great benefit.
Can you get by without it, absolutely, and you shouldnt let a less then thorough knowledge of math hold you back, but if you had the chance, or the inclination I would study as much math as you could, calculus, numeric theory, linear algebra, combinatorics, practical applications, all of it has both practical and theoretical applications in a wide range of computer science.
I have known people who were highly successful on both sides of the fence (those without a strong focus on math, and those who went to school for physics or math), but in both groups they enjoyed numerical problems and learning about algorithms and math theory.
I have a maths degree, but I can't remember requiring that maths a single time in my career. It was useful in terms of training my mind for logical thinking, but I've not written any code using fluid dynamics, quantum theory or Markov Chains. (The last is the most likely to come up, I suspect.)
Most line-of-business developers won't need advanced maths most of the time. Sometimes knowing trigonometry can help, and certainly being able to understand enough maths to implement algorithms described mathematically can be important - but beyond that? Nah.
Don't forget that most programmers aren't advancing computer science - they're building applications. I don't need to know advanced engineering to drive a modern car, even though that car has almost certainly been improved through advanced engineering.
I would argue that having advanced logic (discrete) math can really help. That along with set theory. When dealing with common computer programs, these disciplines can help a lot. However, a lot of the other math I took in university was calculus, which as far as I can see, had very limited usage. Since 90% (or something like that) of programming is doing business apps with very simple math, I would say that for the most part, you can get by with very little math knowledge. However, a good understanding of boolean algebra, logic, discrete math, and set theory can really put you up to that next level.
I'll go against the grain here and say "Yes"
I switch from Civil Engineering to programming (Concrete Sucks!). My math background consists of the usual first year stuff, second and third year Calculus(Diff EQ, volume integrations, Series, Fourier and Laplace transforms) and a Numerical Analysis course.
I find that my math is incredibly lacking for computer programming. There are entire areas of Discrete math and logic that I am missing, and I only survive due to an extensive library of textbooks, Wikipedia and Wolfram. Most advanced algorithms are based on advanced math, and I am unable to develop advanced algorithms without doing extensive research (Essentially the equivalent to a half-course worth of work.) I am certainly unable to come up with NEW algorithms, as I just don't have the mathematical foundations as the shoulders of giants upon which to stand.
It depends on what you are doing. If you do a lot of 3D programming, knowledge of 3D geometry is certainly necessary, don't you agree? ;-) If you want to create a new image format like JPG or a new audio format like MP3, you are also pretty lost if you can't understand a cosine or fourier transformation, as these are the basics most lossy compression are based on. Many other problems can be resolved better if you know your math rather well.
There are also many other programming tasks you will find do not need much math.
If you find the subject fascinating enough to post this, just go ahead and start learning. The rest will come naturally.
Yeah, there is no need for advanced mathematics - if you are programming commercial - off the shelf software.
However when dealing with hardcore stuff such as:
Calculating trajectories to control
a robot
Creating AI-like applications to
support uncertainty and automatic
reasoning
Playing with 3-D motion and graphics
Some advanced mathematics knowledge might come in handy. And it's not like they are "out-of-this world" problems.
I had to create a software to try to "predict" the necessary amount of paper for an office (and it was hell just to find out the best way to approximate values).
You have to be careful, though, because it is easy to get lost when using advanced things - there is a friend of mine who resorted to using Turing to store the state of a dynamic menu just to display it correctly - humm... perhaps he wnet too far in his imagination.
What type of programming?
In my commercial experience, I have needed no advanced mathematics, but this is heavily dependent on the field you are in.
Computer graphics require a large amount of advanced mathematics. A lot of academic computer programming requires advanced mathematics.
So saying there tends to be a correlation between people who are good at mathematics and people who are good at programming.
I hope this wishy-washy answer helps.
Mathematics are needed for developers in some fields but are almost useless in others.
If you are a game developer and have to work with physics a lot - understanding of math is crucial. If you are working with advanced visual controls - you could not do much without geometry. If you're planning to do some financial calculations - it would REALLY help to have solid knowledge of statistics.
On the other hand over last 5 years I had only 2 or 3 projects where ANY amount of math was required at all. Of these there was only 1 occurrence when a Google search did not help.
At the end of the day even financial calculations are very often something your clients do for you and give you formulas to implement.
So if you're in 'applied software' business you are likely to never use your math degree. If you're in academic software maths are crucial.
I agree with Chris. I would say "Yes", also. But this depends on your market as stated above. If you are simply creating some basic "off-the-shelf" applications or writing tools to help your everyday work...then math isn't nearly as important.
Engineering custom software solutions requires lots of problem solving and critical thinking. Skills that are most definitely enhanced when a mathematics background is present. I minored in Math with my Computer Engineering degree and I give credit to all of my math-oriented background as to why I'm where I am today.
That's my 2 cents, I can tell from reading above that many would not agree. I encourage all to consider that I'm not saying you can't have those skills without a math background, I'm simply stating that the skills are side-effects of having such a background and can impact software positively.
In my experience math is required in programming, you can't get away from it. The whole of programming is based on math.
The issue is not black and white, but more colorful. The question is not whether or not you need math, but how much. The higher levels of math will give you more tools and open up your mind to different paths of though.
For example, you can program if you only known addition and subtraction. When multiplication is required, you will have to perform a lot of additions. Multiplication simplifies repetitive additions. Algebra allows one to simplify math before implementing it into programs. Linear Algebra provides tools for transforming images. Boolean Algebra provides mechanics for reducing all those if statements.
And don't forget the sibling to mathematics, Logic and Philosophy. Logic will help you make efficient use of case or switch statements. Philosophy will help you understand the thinking of the guy who wrote that code you are modifying.
Yes, you don't need much math to write programs. Some programs may require more math than others. More math knowledge will give you an advantage over those who have lesser understanding. In these times, people need every advantage they can get to obtain those jobs.
I've been programming for 8 years professionally, and since I was 12 as a hobby.
Math is not necessary, logic is. Math is horribly helpful though, to say it's not necessary is like saying that to kill a man, a gun isn't necessary, you can use a knife. Well, it is true, but that gun makes it a lot easier.
There are a couple bare minimums, which you should already meet. You need to know basic algebraic expressions and notation, and the common computer equivalents. For example, you need to know what an exponential is (3 to the 3rd is 27), and the common computer expression is 3^3. The common notations for algebra does change between languages, but many of them use a somewhat unified methodology. Others (looking at you LISP) don't. You also need to know order of operations.
You need to understand algorithmic thought. First this, then this, produces this which is used in this calculation. Chances are you understand this or you don't, and it's a fairly hard hurdle to jump if you don't understand it; I've found that this is something you 'get', and not really something you can learn. Conversely, some people don't 'get' art. They should not become painters. Also, there have been students in CS curriculum who cannot figure out why this does not work:
x = z + w;
z = 3;
y = 5;
It's not that they don't understand addition, it's that they aren't grasping the requirement of unambiguous express. If they understand it, the computer should too, right? If you can't see what's wrong with the above three lines, then don't become a programmer.
Lastly, you need to know whatever math is under your domain of programming. Accounting software could stop at basic algebra. If you are programming physics, you'll need to know physics (loosely) and math in 3-dimensional geometry (Euclidean). If you're programming architecture software, you'll need to know trigonometry.
This goes farther then math though; whatever domain you are programming for, you need to soundly understand the basics. If you are programming language analysis software, you'll need to know probability, statistics, grammar theory (multiple languages), etc.
Often times, certain domains need, or can benefit from, knowledge you'd think is unrelated. For example, if you were programming audio software, you actually need to know trigonometry to deal with waveforms.
Magnitude changes things also. If you are sorting a financial data set of 1000 items, it's no big thing. If it was 10 million records, however, you would benefit greatly from knowing vector math actually, and having a deep understanding of sorting at the binary level (how does a system sort alphabetically? How does it know 'a' is less than 'b'?)
You are going to find that as a programmer, your general knowledge base is going to explode, because each project will necessitate more learning outside of the direct sphere of programming. If you are squeamish or lazy about self-learning, and do not like the idea of spending 10+ hours a week doing essentially 'homework', do not become a programmer.
If you like thought exercises, if you like learning, if you can think about abstract things like math without a calculator or design without a sketchpad, if you have broad tastes in life and hobbies, if you are self-critical and can throw away 'favorited' ideas, if you like perfecting things, then become a programmer. Do not base this decision on math, but rather, the ability to think logically and learn. Those are what is important; math is just the by-product.
Of course it depends on what kind of programmer you want to be, or better what kind of programmer your employers want you to be. I think calculus and algebra are essentials, statistic and linear programming is indeed a good tool to have in your briefcase, maybe analysis (derivative, integrals, functions...) could be done without. But if you want to know how things work skin-deep (electronics, for example, or some non trivial algorhytms) "advanced" math is something you'd better not go without anywhere.
Most of the programming I have done involved physics simulations for research including things like electromagnetism, quantum mechanics and structural mechanics. Since the problem domains have advanced mathematics associated with them I would be hard pressed to solve them without using advanced mathematics.
So the answer to your question is - it depends on what you are trying to do.
Advanced maths knowledge is vital if you're going to be writing a new programming language. Or you need write your own algorithms.
However, for most day-to-day programming - from websites to insurance processing applications - only basic maths are necessary.
Someone with a solid mathematical (which is not merely arithmetic) or logic background will cope well with algorithms, variable use, conditional reasoning and data structures.
Not everyone can design a UI.
Not everyone can make efficient code.
Not everyone can comment and document clearly.
Not everyone can do a good algorithm
Mathematics will help you to a point, but only to a point.
I dont think advanced mathemetics knowledge is a requirement for a good programmer, but based on personal experience I think that programmers who have a better grasp at advanced maths also make better programmers. This may simply be due to a more logical mind, or a more logical outlook due to their experiences of solving mathematical problems.
The fundamental concept of maths is the following, devising, understanding, implementation, and use of algorithms. If you cannot do maths then it is because you cannot do these things, and if you cannot do these things then you cannot be an effective programmer.
Common programming tasks might not need any specific mathematical knowledge (e.g. you probably won't need vector algebra and calculus unless you're doing tasks like 3D graphics or physics simulations, for example), but the underlying skillsets are identical, and lack of ability in one domain will be matched by a corresponding lack of ability in the other domain.
Math is a toolbox for creating programs. I recommend Cormen's Introduction to Algorithms. It touches on the more "mathy" stuff.
- Greatest lowest limit (managing resources)
- Random variables (game programming)
- Topological sort (adjusting spreadsheets)
- Matrix operations (3d graphics)
- Number theory (encryption)
- Fast fourier transforms (networks)
I don't think that higher math is a requirement for being a good programmer - as always it depends on what you are coding.
Of course if you are in 3D graphics programming, you'll need matrices and stuff. As author of business software, you'll probably need statistics math.
But being a professional programmer for almost 10 years (and another 10 years amateur) "higher math" is not something that I needed regularily. In about 99.8% of all cases it's just plus, minus, division and multiplication in some intelligent combinations - in most cases it's about algorithms, not math.
Learning higher math, for most programmers, is important simply because it bends your brain to think logically, in a step-by-step manner to get from one thing to another.
Very few programming jobs, though, require anything above high school math. I've used linear algebra once. I've never used calculus. I use algebra every day.
Mathematical knowledge is often useful to a programmer, as are graphic design skill, puzzle-solving ability, work ethic and a host of other skills and traits. Very few programmers are good at everything that a programmer can possibly be good at. I wouldn't agree with any statement of the form "you're not a real programmer unless you can {insert favorite programming ability here}".
But I would be wary of a programmer who couldn't do Math. More so than of one who couldn't draw.
I think it really depends on what you're trying to do, but IMHO, the CS and OS theory are more important than math here, and you really need only the math that they involve.
For example, there's a lot of CS background of scheduling theory and optimization that stands behind many schedulers in modern OSs. That is an example of something that would require some math, though not something super complicated.
But honestly, for most stuff, you don't need math. What you need is to learn the ability to think in base 2 and 16, such as the ability to mentally OR/AND. For example, if you have a byte and within that byte there are two 3-bit fields and 2 wasted bits, knowing which bits are in which fields are active when the byte value is something like 11 will make things slightly faster than having to use pen and paper.
I began programming about the same time I entered my pre-algebra class.. So I wouldn't say math is all that important, though it can help in certain types of programming, especially functional.
I haven't taken Discrete Math yet, but I see a lot of theory stuff with programming written in a math-notation that is taught in this class.
Also, make sure you know how to calculate anything in any base, especially base 2, 8, and 16.
Also, one class that really brought home some concepts for me was this pre-programming class. We got taught unions, intersections, and all that happy stuff and It almost exactly parallels bitwise math. And we covered boolean logic very heavily. What I considered the most useful was when we learned how to reduce complex boolean statements. This was very handy:
(x|y) & (x|z) & (x|foo)
can be simplified to
x | (y & z & foo)
Which I previously did not quite grasp.
Well you generated a number of responses, and no I did not read them all. I am in the middle on this, no you certainly do not need math in order to be a programmer. Assembler vs device drivers in linux are no more or less complicated than the other and neither require math.
In no way shape or form do you need to take or pass a math class for any of this.
I will agree that the problem solving mindset for programming is quite similar to that of math solutions, and as a result math probably comes easily. or the contrary if math is hard then programming may be hard. A class or a degree or any pieces of paper or trophies are not required, going off and learning stuff, sure.
Now if you cannot convert from hex to binary to decimal quickly either in your head, on paper, or using a calculator you are going to struggle. If you want to get into networking and other things that involve timing, which kernel drivers often do but dont have to. You are going to struggle. I know of a very long list of people with math degrees and/or computer science, and/or engineering degrees that struggle with the rate calculations, bits per second, bytes per second, how much memory you need to do something, etc. To some extent it may be considered some sort of knack that some have and others have to work toward.
My bottom line is I believe in will power, if you want to learn this stuff you can and will, it is as simple as that. You dont need to take a class or spend a lot of money, linux and qemu for example can keep you busy for quite some time, different asm langauges, etc. crashable environments for kernel development, embedded, etc. You are not limited to that, but I dont believe that you have to run off and take any classes if you dont want to. If you want to then sure take some ee classes, some cs classes and some math classes..
You need math. Programming is nothing more than math. Any findings of theoretical physics does not become a practical(applicable) implication, unless they are explained in terms of mathematical solutions. None of those can be solved computationally if they cannot be interpreted on computers, and more specifically on programming languages. Different languages are thus designed to solve specific problems. But for the general purpose and wide spread programming languages like java, c, c++ much of our programming tasks involve repetitive(continuous) solution to same problems like extracting values from database, text files, putting them on windows(desktop, web), manipulating same values, sometimes accessing some data from similar devices(but given different brand names, different port and a headache) etc which does not involve more than unitary method, and algebra(counter, some logic), geometry(graphics) etc. So it depends what you are trying to solve.
IMO, you probably need an aptitude for mathematics, without necessarily having much knowledge in the field. So the things you require to be good at maths are similar to the things you require to be good at programming.
But in general, I can't remember the last time I used any sort of advanced maths in day-to-day programming, so no.

Resources