PDA

View Full Version : Why do we need math in programming?



LinuX-M@n1@k
July 23rd, 2008, 03:15 PM
That's my question. ;)

LaRoza
July 23rd, 2008, 03:17 PM
Because it forms the basis for all computer technology?

saratchandra
July 23rd, 2008, 03:20 PM
Programming is mathematics.

LaRoza
July 23rd, 2008, 03:23 PM
Programming is mathematics.

Reality is mathematics.

LinuX-M@n1@k
July 23rd, 2008, 03:23 PM
Because it forms the basis for all computer technology?

Well.. Okay... But where is the math in python for example? I don't need digits to make a script, do I? I mean... well I do need 0 and 1 :lol:

LoneWolfJack
July 23rd, 2008, 03:27 PM
You don't necessarily need a degree in mathematics do be a good programmer (that's what they like to tell you to sell their courses).

However, in the professional field, you will encounter a lot of mathematical problems where you won't expect them... you can usually get by with trial and error, but then you will have a problem with your customer refusing to pay for the extra time...

If you're doing just web programming for example, you will barely need any math beyond the most basic stuff. If you intend to venture into openGL programming... well... that's something you could very well use a degree in mathematics for... makes life so much easier... :)

LaRoza
July 23rd, 2008, 03:28 PM
Well.. Okay... But where is the math in python for example? I don't need digits to make a script, do I? I mean... well I do need 0 and 1 :lol:

You didn't ask that.

You don't really need to know much about math in many languages.

Joeb454
July 23rd, 2008, 03:29 PM
Reality is mathematics.

I guess Mathematics is the basis of everything.

tamoneya
July 23rd, 2008, 03:31 PM
often in programming you have to simulate the real world with models. The easiest way to do this is with a set of equations. As a programmer you need to have pretty good understanding of this in order to really excel. You can get by without them but it will be simpler for you if you just get good at math.

Kadrus
July 23rd, 2008, 03:32 PM
Mathematics is a very important factor in programming and Computer Sciences,specially in AI,impelemtations,etc.In addition it plays a very important role in game programming,game engines so does Physics.And math is used a lot in computational geometry,data structures algorithms,boolean,boolean logic.etc..

Wybiral
July 23rd, 2008, 03:32 PM
Understanding math gives you a better intuition about your designs. If you don't have some kind of understanding/intuition about the difference between n, n^2, log(n), n!, etc, it's going to be very hard to visualize the efficiency of your algorithms. Not to mention that a lot of applications actually require math as part of the functionality.

ARhere
July 23rd, 2008, 03:37 PM
That's my question. ;)

:lolflag: You must be in college working through Calc. II or something similar. Don't give up!!

Engineering is product from Math and Physics. If you want to be an Electrical Engineer, you must complete a Math minor at minimal. If you are interested in Software Development, you need up to Calc. I. (I am not sure on this, someone correct me.)

In my limited programming experience, every other line was a math equation of some sort. So if you want to be in technology, learn to love it!

-AR

NovaAesa
July 23rd, 2008, 03:37 PM
Say you are asked to write a programme that sums the numbers between 205 and 204493. Someone without a bit of maths knowlegde might write a for loop. Someone with a bit of maths knowledge will be able to solve it with a simlpe one line command.

LinuX-M@n1@k
July 23rd, 2008, 03:42 PM
:lolflag: You must be in college working through Calc. II or something similar. Don't give up!!

Engineering is product from Math and Physics. If you want to be an Electrical Engineer, you must complete a Math minor at minimal. If you are interested in Software Development, you need up to Calc. I. (I am not sure on this, someone correct me.)

In my limited programming experience, every other line was a math equation of some sort. So if you want to be in technology, learn to love it!

-AR

I'm in high-school and I never heard of "Calc. II" :D

Thank you all ;)

ARhere
July 23rd, 2008, 03:44 PM
I'm in high-school and I never heard of "Calc. II" :D

Thank you all ;)

TRANSLATION: Thanks for the Firehose!

-AR :lolflag:

Tomosaur
July 23rd, 2008, 03:52 PM
Depends what you want to do with programming. If you ever want to make a game with physics (or a 3d game or whatever), or represent a 'real world' scenario, chances are you're going to need at least a high school education in mathematics.

If you're going to write the software to launch a rocket into space, then you're going to need a very advanced understanding of maths and physics and whatnot.

If you want to make a text game, you don't really need maths.

If you want to start doing clever stuff in programming, you'll probably need a 'better than average' grasp of mathematics. There's a great example somewhere of, I think, a section of code used in Quake or Doom or something, where a very clever little bitshift operation was used to draw accurate proportions or something like that. If I can find it I'll point you to it.

Aeph
July 23rd, 2008, 03:53 PM
Say you are asked to write a programme that sums the numbers between 205 and 204493. Someone without a bit of maths knowlegde might write a for loop. Someone with a bit of maths knowledge will be able to solve it with a simlpe one line command.

This essentially the reason. You want your program to do thing in the most efficient way possible, and having the program do all the calculations is not always the most efficient strategy.

era86
July 23rd, 2008, 04:30 PM
Manipulation of symbols following a common syntax to produce any desired result or procedure? I think mathematics is essential for understanding and explaining ANYTHING!

ankursethi
July 23rd, 2008, 04:32 PM
@LinuX-M@n1@k
I just passed high school, and will be joining a CompSci course in a local college next month.

(I'm using several math-related terms here. Wikipedia is your friend.)

I can tell you why you hate maths. It's because the stuff they teach you in high school is NOT maths. Yes, they call it maths and it has a passing resemblance to real mathematics, but it's really just a bunch of related formulas thrown together in a haphazard way.

I hail from India, and we eat maths for breakfast here. The first thing *any* high school kid here does is throw away the official textbook assigned to us by the NCERT and buy a real mathematics textbook (You can download NCERT textbooks for free on their website. As opposed to the maths book, the Physics textbook is exceptionally good for an introductory course.)

Maths is not about learning formulas and applying them to random problems in textbooks. Maths is much more. It can be thought of as :
1. a formalization of what we like to call "common sense". Learning maths will help you reason better about everyday situations.
2. a set of tools (like a Python module) to help you solve common, everyday problems.
3. a set of tools to help you "simulate" real life situations and find optimal ways of doing things (linear programming?).
4. a way to visualize and reason about numerical data available to us (statistics?).

The list is endless. Like programming, there are many "languages" of mathematics. You'll use a different set of concepts and notations for combinatorics and a different set for calculus.

Go to the #math IRC channel on FreeNode, or a Usenet/Google group on math and ask for advice. The guys there will surely point you to nice books on maths which will make the subject enjoyable (or at least bearable). Better yet, ask your teacher at school.

And one more thing: I've been reading "Introduction to Algorithms" by Cormen etc. and trust me, it's all about maths. I'm wishing I'd done more maths back in high school.

pmasiar
July 23rd, 2008, 04:40 PM
Math is exercise for your brain.

Programmer's work is handle complex abstractions which might or might have not memorable real-world model, and do it in head (using some notation to aid the building of the mental model in head). Comparing to that, high-school math is rather simple.

Also, algebra teaches you attention to the detail. Exactly as in programming.

In real life programming, some programmers can get away without using any high math: databases, compilers, operating system use in most cases integer numbers (as reference to other objects). Some application areas also do not require hard math (genetics is pattern matching, web applications etc). In other areas (math models in physics, financials, image and voice processing), hard math is required.

IMHO (and I might be wrong) if you are not patient enough to solve your algebra, you will have hard time to debug your programs.

Kadrus
July 23rd, 2008, 04:42 PM
The benfits of Math in programming are:
Mathematical logic
Boolean logic and other ways of modeling logical queries; the uses and limitations of formal proof methods.
Number theory
Theory of proofs and heuristics for finding proofs in the simple domain of integers. Used in cryptography as well as a test domain in artificial intelligence.
Graph theory
Foundations for data structures and searching algorithms.
Type theory
Formal analysis of the types of data, and the use of these types to understand properties of programs, especially program safety.
Category theory
Category theory provides a means of capturing all of math and computation in a single synthesis.
Computational geometry
The study of algorithms to solve problems stated in terms of geometry.
Numerical analysis
Foundations for algorithms in discrete mathematics, as well as the study of the limitations of floating point computation, including round-off errors.
--
A programming language such as Mathematica which is known as a CAS was developed for mathematical domains and one of it's features is Mathematical Functions (http://en.wikipedia.org/wiki/Function_%28mathematics%29)

ankursethi
July 23rd, 2008, 04:53 PM
By the way, don't be scared of maths. It's actually easier than you think. Just read the theory properly and reason about it before diving into difficult problems.

tamoneya
July 23rd, 2008, 05:53 PM
I'm in high-school and I never heard of "Calc. II" :D

Thank you all ;)

Calc II is the second semester of college calculus. Here is the way to think about it in high school terms:

AB Calc = Calc I
BC Calc = Calc I + Calc II

LittleLORDevil
July 23rd, 2008, 06:32 PM
Discrete Math in College gave me a rough time, I take Discrete II next semester. ](*,)

era86
July 23rd, 2008, 06:38 PM
Discrete math, is that the one with graphs and circuits? I had a tough time with that too, though it related closer to programming than some other math classes I took.

LittleLORDevil
July 23rd, 2008, 06:39 PM
Discrete math, is that the one with graphs and circuits? I had a tough time with that too, though it related closer to programming than some other math classes I took.
I don't remember circuits, it was with logic and proofs. Such as proving a number is even or what not. A lot of Knights and Knaves problems.

Riffer
July 23rd, 2008, 06:41 PM
I don't know about math for programming, but as a Hgh School teacher, I hear "Why do I need Math? I'll never use it." The reasons are pretty much as 'ankursethi' pointed out. Its not about learning formulas and the like, but to think and problem solve in a linear fashion. I would think that would be a great asset for programming.

tamoneya
July 23rd, 2008, 07:09 PM
I don't know about math for programming, but as a Hgh School teacher, I hear "Why do I need Math? I'll never use it." The reasons are pretty much as 'ankursethi' pointed out. Its not about learning formulas and the like, but to think and problem solve in a linear fashion. I would think that would be a great asset for programming.

way of thinking +1

Lster
July 23rd, 2008, 07:17 PM
Maths is central to a lot of things though. Maths is really just problem solving.

This reminds me of an XKCD which makes quite a good point:
http://xkcd.com/435/

cacycleworks
July 23rd, 2008, 07:35 PM
That's my question. ;)

It is for when: After you graduate from college and get your job as a software engineer and the PhD scientist walks into your cubical/office/cell with a "dumb question":

Chris: if we use the management & control card to insert data into the stream, what max bitrate can we get? Our box had all kinds of dedicated cards to insert data, cards that could process up to 2 Gbps. The M&C card had to use the powerpc processor to do long address fetch and write cycles between 2 memory addresses. Neither the board nor the chip had any DMACs (direct memory access controllers). With DMA, your processor tells the DMAC what to do and then it can haul butt at moving bits.

Given the clock cycles (3oo Mhz?) and looking at the timing, it was like 4 or 6 cycles each way. I wrote out the equation on the whiteboard (faster than I'm telling this) and ended up at 4Mbps.

After a few weeks of engineering towards this effort, we were able to coax 4.2Mbps. The first iterations were in the mid 3s until I studied the assembly code and wrote a function for what we wanted in assembly.

There's my maths story. I'm not that good at teh maths, but in that moment, I felt smart. :)

:) Chris

era86
July 23rd, 2008, 07:57 PM
I don't remember circuits, it was with logic and proofs. Such as proving a number is even or what not. A lot of Knights and Knaves problems.

Ah yes.. proofs. 1 problem takes up an entire 5 pages to prove!:lolflag:

LinuX-M@n1@k
July 23rd, 2008, 08:27 PM
...
I can tell you why you hate maths.
...
No, no.. I never said I hate maths! I even like it. I was just wondering where in programming I would use it.

Lster
July 23rd, 2008, 09:53 PM
For some good examples of maths and programming, look at Project Euler.

http://projecteuler.net/

Reiger
July 23rd, 2008, 10:07 PM
No, no.. I never said I hate maths! I even like it. I was just wondering where in programming I would use it.

The moment you dive into Functional Progamming ...

Also; talking about math... http://xkcd.com/135/ It's a lifesaver. ;)

Kadrus
July 23rd, 2008, 10:15 PM
Functional Progamming
True,functional languages are embellishments to the lambda calculus.
And functional programming languages tend to have an academic purpose.
And functional languages use recursion (http://en.wikipedia.org/wiki/Recursion_%28computer_science%29) to loop.
So math in programming comes into functional languages.

ad_267
July 23rd, 2008, 10:20 PM
Well I'm an engineering student and most of the programming I do is mathematical.

Things like solving differential equations numerically and solving systems of linear equations.

Kadrus
July 23rd, 2008, 10:28 PM
Everything on an academic level and related to programing uses maths and physics.
Like Electrical and Computer Engineering,Computer Science,Artifical Intelligences,Implemenations,etc..
But if you are programming as a hobby and don't intend to study programming on a higher academic level which includes language implemeation,AI,robotics,compilers..I don't think you really gonna use it,unless you're programming games.

Jessehk
July 24th, 2008, 12:33 AM
Reality is mathematics.

No, reality is modelled by mathematics.

Lux Perpetua
July 24th, 2008, 03:53 AM
For some good examples of maths and programming, look at Project Euler.

http://projecteuler.net/Those are more programming applied to mathematical problems rather than mathematics applied to programming.

I think a good example of mathematics being relevant to programming is in designing efficient algorithms and generally in analyzing the efficiency of algorithms. For example, quicksort takes expected O(n*log(n)) time to sort a randomly shuffled list of n items, whereas insertion sort takes expected O(n^2) time. Firstly, that statement doesn't mean anything to you unless you know a bit of math. Secondly, to obtain those facts, you have to know how to solve recurrence relations, which requires more math.

When most people think of math, they think "numbers" (OP included, I gather). To me, mathematics is actually the study of all things that can be formulated precisely. If you look at it that way, then programming is pretty much a branch of mathematics!
No, reality is modelled by mathematics.No, mathematics itself is the true reality. :-)

pmasiar
July 24th, 2008, 04:46 AM
No, mathematics itself is the true reality. :-)

Math models are computable approximation of reality - we knowingly cut corners so it will compute fast enough. Math is at the same time less exact (missing many details) and more: we can easily have numbers smaller than quantum particles (which cannot have any meaning according to our knowledge of the world today) and bigger than number of atoms in the whole universe. Math is not restricted to reality: it is guided by it's own laws and logic. That's why we have ie. Euclid geometry and two different non-euclid ones. Math is not concerned in learning about real world - it is useful tool when describing real world, but math is not limited to it.

slavik
July 24th, 2008, 05:42 AM
mathematics is more to teach you to solve problems than being some kind of a tool.

computer science is a tool to solve mathematical problems, but if you dig into theoretical computer science, it involves lots of math that you just do (much like physics and chemistry). at that point, you don't use math, you speak it.

guess my point is twofold: math is a language of advanced theory is sciences and the lower level math is good to develop problem solving.

to extend pmasiar's point if approximating reality using math, did you know that you can do square roots of non-perfect square (set of z, such that z is n*n where n belong to positive integers) using derivatives (and it is easier even in your head).

then there is the minimum/maximum in parabolas which is (-b)/(2a) which comes from the derivative of the quadratic formula.

Now to draw a parallel to computer languages:
in the beginning you learn print(), then you learn about variables, loops, references/pointers. then you move on to data structures. then finally, in the "real world" all that learning simply goes away and you stop thinking about how print() works, you just speak the verb without thinking how it works (you start caring again when print becomes too slow for your needs).

Tart
July 25th, 2008, 07:21 PM
That's my question. ;)
Math is the key to the universe!

I have some experience programmers who doesn't really know math. At work our department constantly deals with various mathematical models, optimizations, simulation, etc. These are not some abstract problems; these are models of our company’s operations, real life situation. I’m mathematician, I can build the model, express everything in equations, however I’m not a programmer and I don’t want to be. I use high level math programming languages, to do my work. But we need programmers to integrate models with our systems. I hate working with programmers who don’t know math. They cannot do anything I have to do almost everything my self. Find most efficient algorithms; chew out all to the smallest detail, because some of them even don’t know even how to do matrix multiplication. Even if they write the code, I have to check it myself because they don’t know how to make sure it does the right things. Now, why do we need such programmers? I would fire them, if I could. If I learn low level language such as c++/java we would have no need for them, because it would be faster for me to do everything. But I rather spend time learning math/statistics.

hockey97
July 26th, 2008, 12:17 AM
ok, sorry to bud in. Since this topic is about math.

I would like to know if their is any good websites that could teach math.

like from college algebra to calk.

I am ok in math but not a master of it and currently haven't had a class in math for a year and would like to start praticing it to help me not to get rusty.

//now back on topic:

I think math is very important in programming. The reason it gives you a better view and control on your scripts.
If you plan on doing hardcore programming math will be a huge part of it.

Math is fun when you know how you can use it otherwise you lose interest in learning it if you don't know what you can use with it.

I now struggle trying to master the math as much as possible because I can see what's ahead.

math can show you in your head what can be problems and also gives you more control on devices.

slavik
July 26th, 2008, 12:45 AM
your company employs programmers that don't know matrix multiplication? you're kidding, right?

saratchandra
July 26th, 2008, 12:57 AM
Programming is a subset of mathematics, not the other way around:)

Diabolis
July 26th, 2008, 01:50 AM
Discrete Math in College gave me a rough time, I take Discrete II next semester. ](*,)

I loved discrete math, except the part in which I had to do mathematical induction.


Maths is central to a lot of things though. Maths is really just problem solving.

This reminds me of an XKCD which makes quite a good point:
http://xkcd.com/435/

That just sums it all up.

http://imgs.xkcd.com/comics/purity.png

I really understood maths usefulness after learning algorithms analysis and measuring the complexity of "for loops". I loved to find their cost with a summatory.

slavik
July 26th, 2008, 03:00 AM
which breaks down when you have a non-comparison based sorting algorithm :)

softest bullet ever shot
July 26th, 2008, 03:07 AM
Sorry if this answer has been given, but even if you don't necessarily see mathematics in programming, the brain cells that you train by doing math are also used in programming.

A math teacher I know used the analogy of lifting weights for football. A person uses the bench press, not because they are on their back trying to push heavy things up in the air, but the bench press develops muscles that someone would use in football.

Same thing in math. You train yourself to think analytically, to break down problems into smaller pieces, to go back over your work and find out where you went wrong, etc...

jflaker
July 26th, 2008, 03:15 AM
That's my question. ;)

Actually, I am not very good at math in general, but can get basic algebra....beyond that, I get lost.

In business, which is where a majority of programming will take place, you will need math, or at least understand equations to program business rules into your programs for likes of reporting or inquiry screens........

In business, most of the math has been figured out somewhere along the way through someone's manual process which they feel can be automated. So, you would basically take what they had already done and plug it into your program(s) to get the desired results.

Unless you are programming for scientific purposes, you are unlikely to have to figure out the actual equations for yourself. You will likely have a business unit "owner" giving you their calculations.

At least, that has been my experience in the last 10 years programming.

slavik
July 26th, 2008, 03:15 AM
Sorry if this answer has been given, but even if you don't necessarily see mathematics in programming, the brain cells that you train by doing math are also used in programming.

A math teacher I know used the analogy of lifting weights for football. A person uses the bench press, not because they are on their back trying to push heavy things up in the air, but the bench press develops muscles that someone would use in football.

Same thing in math. You train yourself to think analytically, to break down problems into smaller pieces, to go back over your work and find out where you went wrong, etc...



that's a nice analogy. you should put it into your sig. :) (and credit the teacher though).

Tart
August 1st, 2008, 02:31 PM
your company employs programmers that don't know matrix multiplication? you're kidding, right?

I was really surprised. I wrote the document, specified matrices, and there was just simple multiplication, inverse, transposition. He came to me asking how to do it. Didn't even bother google for it.

slavik
August 1st, 2008, 04:32 PM
I was really surprised. I wrote the document, specified matrices, and there was just simple multiplication, inverse, transposition. He came to me asking how to do it. Didn't even bother google for it.
isn't matrix multiplication something taught in high school (maybe precalculus)?

either way, a programmer should know the basics of whatever field he is writing code for, whether it is finances, physics, biology, chemistry, mathematics, or anything.

Lux Perpetua
August 1st, 2008, 10:05 PM
isn't matrix multiplication something taught in high school (maybe precalculus)?Typically, no. Matrix multiplication is part of linear algebra, which is an entirely different subject. There are high schools that teach linear algebra (mine taught the equivalent of a half-semester of it), but I think these are by far the exception to the rule. Linear algebra is a college subject.

Matrices and matrix multiplication are something that you don't miss if you've never seen them, and once you see them, you don't know how you ever lived without them.

slavik
August 2nd, 2008, 06:42 AM
I did learn about matrices in high school ... a public school of New York City that wasn't located in Manhattan.

as for living without matrices, it boggles my mind when I think about tensor products :) (matrix multiplication is kid stuff).

ubuntu27
August 2nd, 2008, 07:52 AM
This thread reminds me of this comic related to professional "fields"

http://www.xkcd.com/435/