Programming Mathematics?
Adam asks: "I'm
an undergraduate math and CS major, and as such, I would like to write
some programs that do basic math, from finding perfect numbers to solving
basic algebraic equations--just for fun. However, I only have experience
with Java, and BigInteger and BigDecimal suck pretty hard as far as
writing equations with them is concerned. So, to all you mathematicians
and math lovers, what languages do you program mathematics in, and
why?"
Mathematiticians have invented a language called ML (Meta Language) which is a functional language in which you can write mathematical formulas almost as you would mathematically define them.
In the area of functional progamming you should also consider Common Lisp which is a well known functional language used mostly for AI.
On the properiatry side, many mathematical algorithms get coded in MatLab which provides built-in matrix manipulation and lots of additional libraries (you'll probably find out most of the stuff you want to write is already there...)
In any case, the progamming language should be tightly fitted to the application.
Make even shorter URLs - 8LN.org
I know I'm going to get flamed for this, but here it goes anyway...
I do use a mix'n'match approach to mathematical programming. Usually, I deal with numerical methods, and in principle, all languages are good. However, I find that using Fortran95 (see, you were going to flame me) I code faster and easily to-maintain code. The compilers (though not Free as of yet, but see the G95 homepage) produce fast code, which is easy to port between my Linux box and the Tru64, Solaris boxen in some of the labs.
Another good option is python. The numerical extension and the many modules already developed make it really nice (and quite fast). Additionally, you can add C and Fortran routines to it.
For profiling, I tend to use either Octave or Scilab, and then convert that on to F95
For non-numerical stuff, macsyma is quite nice
I'm surprised APL hasn't been mentioned. I wrote a few lines of APL a hundred years ago, and it's certainly not as popular as it used to be, but it was designed as a mathematical programming language. A couple of resources, obtained with Google, using this search rule. http://whatis.techtarget.com/definition/0,,sid9_gc i213454,00.html
http://www.engin.umd.umich.edu/CIS/course.des/cis4 00/apl/apl.html
Depends entirely on what you want to do:
Mathcad or mathematica can to calculations from a graphical interface, but are difficult to program and slow for anything requiring big loops.
matlab is a higher level language like the two above, but isn't a graphical interface, so it's easier to do things a little more complicated.
fortran is the mathematical workhorse for small to medium programs with hard maths. The style is reasonably intuitive. In addition, a familiarity with fortran will never go to waste, since the scientific community has been using it for 35 years, and there's a lot of legacy code. There's free compilers too.
c, c++ are the mathematical workhorses for medium to large programs. In general, better data structure handling than fortran, and fewer mathematical libraries. Most CFD code and indeed most finite element code is written in some brand of c. I think that it would be fair to say that professional programmers know about c, where scientists who do some programming know fortran. There are free compilers for c as well.
Choose one to meet your project size and execution speed required.
Why are you writing these programs?
If it's to help you understand the problem, you can use any language... and ML or applications like MathLab and Maple are probably best since they allow you to focus on the math, not the programming.
If it's because you are interested in working as a scientific programmer then you need to focus on the primary languages used in the field: Fortran, C and possibly Ada.
Fortran, as others have pointed out, isn't *that* bad. Unfortunately most Fortran programmers *are*. Too many people with a scientific background thought "it can't be that hard to write code" and they're right -- it's not hard to write code. It's hard to write good code.
C is the probably the standard language now, and has the benefit that the skills are portable.
Ada is now pretty much a niche language, but you may see it at defense companies and it has a cleaner OO implementation than C++. For the same reason, you might see java compiled into native code (e.g., with gjc).
For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
quite to the contrary, there is no better time to experiement than the present, with your current level of knowledge. You should be messaing around, trying things, seeing what works. Maybe you shouldn't attempt to sell your work as a fast, small competitor to Mathematica, but, by all means, experiment.
The more you have played around with this stuff on your own, the more you will get out of those classes when you take them. Never let anyone succeed in scaring you away from trying.
When I was taking numerical methods, I was in there because I had to be. There was another student in there with way less "raw mathematical talent" than me, but who was doing much better at "getting it" than I was because he was going home and messing around with the stuff on his computer. In fact, during the course he noticed an interesting pattern in his graphs, and brought it to the professor. If I recall correctly they published a paper on the result.
Theory is important, too, but the real way that theory is developed is that people mess around with stuff for a long time, develop some intuition, and then try to formally show that their intuition is correct. In classes they try to do this in the opposite direction--"here's the theory, try to develop some intuition about it".
You will be way ahead of the game if you already have experience trying stuff.
Liberty uber alles.
ok, I just looked it up, here's a blurb from the documentation:
One thing I would advise you--use visualization aggressively. There was a tendency in mathematics for a long time to de-emphasize the geometrical/physical aspects of systems as being sort of extraneous--i.e., it doesn't matter what the parabola looks like, just what its mathematical properties are. Well, in short, this is stupid. Your visual cortex is an amazingly powerful processor, and it's dumb to tie one of your brain's hands behind its back just because someone a few centuries back had a theoretical axe to grind.
Always ask yourself "is there some way I can visualize what's going on here?". You will leap far ahead of where you would be otherwise.
good luck.
mike
Liberty uber alles.