Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Programming Mathematics?

Cliff posted more than 12 years ago | from the coding-by-numbers dept.

Programming 64

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?"

cancel ×

64 comments

Sorry! There are no comments related to the filter you selected.

C (Reason: You can type more than that for your s (0)

Anonymous Coward | more than 12 years ago | (#2900205)

C

Post Comment
Lameness filter encountered. Post aborted!
Reason: You can type more than that for your comment.

http://www.nr.com/ (0)

Anonymous Coward | more than 12 years ago | (#2900210)

http://www.nr.com/

Functional Languages (2, Informative)

Tomah4wk (553503) | more than 12 years ago | (#2900264)

Funtional languages like haskell are very good for doing maths, especially large dynamic sizedd matrix math. The language has a built in list type (thing self memory managing dynamic array) and the language is functional, so the programming style is very mathematical. If you use an environment like hugs (see google), you can do all your programming and use in the same system, which i personally like alot. Fortran is also popular for engineering types, as i believe it has built in matrix math functions, howeverdont quote me on that.

Re:Functional Languages (1)

Kirruth (544020) | more than 12 years ago | (#2900292)

Haskell and Hugs would be good choices: the wonderful thing about functional languages is you can create a very high level of abstraction, which is great for solving maths and engineering problems. Go to: http://www.haskell.org [haskell.org]

Lisp/Scheme and ML would also be good choices.

Mathcad or Matlab (1)

eXtro (258933) | more than 12 years ago | (#2900278)

As far as programming mathematics go, Mathematica and Matlab seem to be the most accepted programming languages. Mathematica seems to be used somewhat more by mathematicians, Matlab somewhat more by engineers. I assume that by programming mathematics you mean to apply mathematics to solve some problem. I've used Matlab extensively and it has a relatively C like syntax, but it understands things like matrices, complex variables and has a slew of built in mathematical operators. Mathematica can do symbolic mathematics, Matlab doesn't.


There are Open Source variants of these, a few of which I have used as well as some I haven't. Try them out, there are student editions of the commercial packages.


rlab [freshmeat.net]


SciLab [freshmeat.net]


Octave [freshmeat.net]
Euler [freshmeat.net]


Q [freshmeat.net]


Kalamaris [freshmeat.net]
Good luck, perhaps you can review these packages and post a response.

Re:Mathcad or Matlab (2)

AntiNorm (155641) | more than 12 years ago | (#2905425)

Mathematica can do symbolic mathematics, Matlab doesn't.

Actually, Matlab can do symbolic math. It's kind of a pain though, IMO. It's been a while since I've worked with Matlab, but IIRC the syntax is something close to:

Y=sym('x^2+3x-4=0');
solve(Y,x);

C++ is fine (1)

MJArrison (154721) | more than 12 years ago | (#2900286)

When I wrote my graphing calculator (and other math functions) calculator, I used C++. Keep in mind that you probably don't need the precision of anything more than a 32 bit number. Having 15 decimal places is just fine for nearly all applications, and it's overkill for most.

As far as large numbers is concerned, I don't have any real experience in this. But do a google search on "infinite precision library" and you'll see that there has been some work done already in this area.

Languages for Mathematicians by Mathematicians (5, Informative)

epsalon (518482) | more than 12 years ago | (#2900298)

Mathematiticians have invented a language called ML (Meta Language) [bell-labs.com] 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 [cmu.edu] which is a well known functional language used mostly for AI.

On the properiatry side, many mathematical algorithms get coded in MatLab [mathworks.com] 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.

Re:Languages for Mathematicians by Mathematicians (1)

kasj (205481) | more than 12 years ago | (#2900424)

In addition, to manipulate symbols, many use Maple
and/or Mathematica. These are commerical software
though; does anyone know of free work-alikes?

Re:Languages for Mathematicians by Mathematicians (1)

-alex- (21515) | more than 12 years ago | (#2902471)

GPL'ed version of Macsyma (commercial package, is it still around?) by the name of Maxima:
http://www.ma.utexas.edu/maxima.html
and here is BIG list:
http://sal.kachinatech.com/A/1/

MATLAB also has a builtin implementation of the Maple kernel. There is integrated functionality, but sometimes you can see the seams, so to speak.

MATLAB is great for numerics, as is Octave a GPL'ed MATLAB-alike system.
-
-alex-

The Joyth of Lithp (2)

n8willis (54297) | more than 12 years ago | (#2902348)

This reminds me of something cool you get for free with Common Lisp: arbitrary precision integers. Very nice treat for discrete or algebraic problems.

A couple of years ago at the ACM collegiate programming contest, one of the problems was to write a program which would return the ones-place digit of n! for any n between, like 1 and 10,000 (or something huge like that). One of our guys came up with a solution, but afterwards our professor reminded us that we could have just generated the list with a simple CL program, slapped it into a lookup table, and had a constant-time solution to the problem. That would have impressed the judges....

Nate

Re:The Joyth of Lithp (1)

Math421 (38107) | more than 12 years ago | (#2902589)

The ones digit of n! is 0, for any n greater than 5. Once you've multiplied 5 in there, all factorials larger than that are multiples of 10, so their ones digit is zero.

Re:The Joyth of Lithp (1)

wmulvihillDxR (212915) | more than 12 years ago | (#2902755)

Don't you love how those CS types like to ignore Math even though CS=Math? Here is the program:

switch n {
case 1: return 1;
case 2: return 2;
case 3: return 6;
case 4: return 4;
default: return 0;
}

Re:The Joyth of Lithp (1)

sir99 (517110) | more than 12 years ago | (#2903258)

Heh. I misread it and thought he meant the first digit, which would be a little more interesting.

Re:The Joyth of Lithp (2)

n8willis (54297) | more than 12 years ago | (#2915561)

Yeah yeah, I guess what I meant was "least significant digit" or something like that. I forget how it was actually expressed.

Going to need more info... (1)

merkac (553485) | more than 12 years ago | (#2900313)

Going to need a little more info here probably.

If the target audience is just you, then you can do mathematics in just about any language you want. Consider it a challenge to try and write an algebraic manipulator in C - but it's possible (albeit possibly very very ugly).

Since most programming is logic (a branch of mathematics), many people think it should be easy to code arbitrary mathematical ideas in code: it's not. Mostly you need some sort of well defined problem to solve and then writing a specific solution - e.g. writing code to figure out the sum of all the primes less than 1000 isn't too hard. But trying to write a program that will accept arbitrary input and sum that given sequence is hard: e.g. the program should be able to have a user input: i want the sum of all numbers between 12 and 12^12^12 which have no 7's in them.

This later wouldn't be too hard to hardcode but would be quite a challenge to write a general engine which would accept this type of input.

To summarise the summary of the summary: Pick a specific problem, pick a specific language and go for it. Otherwise but a copy of Matlab (or go with Octave) and knock yourself out :) -- merkac

Re:Going to need more info... (2)

divbyzero (23176) | more than 12 years ago | (#2901646)

Your answer, while true for edit-compile-run languages (C, C++, Java, Fortran, etc), is not true for fully interactive languages (Lisp, ML, Perl, Python, TCL, etc). In an interactive language, there's really no such thing as hardcoding; the program is not run monolithically, but defined in small reusable pieces which you can recombine at runtime using the full expressiveness of the language.

Re:Going to need more info... (1)

sir99 (517110) | more than 12 years ago | (#2903323)

i want the sum of all numbers between 12 and 12^12^12 which have no 7's in them.
Good luck getting that one to terminate before the Universe collapses again...

Godel theorem: we can't answer everything at once. (1)

bgins (446545) | more than 12 years ago | (#2907852)

Let's take this question as an example.

If you say that you want the sum of all numbers between 12 and 12^12^12 with no 7's in them, any semi-properly trained (or is it brainwashed, I'm not sure) math person like me will tell you first that they are interpreting the question thus:

Find the sum of all positive integers between 12 and 12^(12^12) inclusive which have no 7 digits in their decimal representation .

Next, they will ask you whether you want leading digits, i.e. like what a truncated floating point representation would give you, or whether you want an exact integer solution. Given that the sum would have on the order of 18*10^12 digits, they would probably assume you want a floating point representation of it.

Then they would tell you it is approximately ten to the above number, and pat themselves on the back, confident that one really doesn't need to know anything more (why the hell would one?).

All of this can be done on paper in less than 5 minutes, with the use of a calculator with base ten logarithms.

[Hint: if N=the upper bound and k=log(N) to the base ten, and ignoring the "trivial" lower bound, the fraction of numbers between 1 and N with no 7's is going to be about (0.9)^k, while the average value is going to be about (N+1)/2. This gives a sum of .5*90^k where k = 12^12 * log(12).]

The above reasoning is good enough to nail down the order of magnitude of the number; in fact, you can get a little more precise (see below).

I agree it would probably be extremely hard if not impossible to write a general engine for use with arbitrary math problems (having say a well-defined real or complex number as an answer). For one thing, to decide even whether to use asymptotics and give a real-valued numerical estimate, to solve exactly as an arbitrary-precision integer, or a "closed form" expression (using combinatorics or number theory or Fourier analysis and accepted formulas like Bessel functions or Stirling numbers as appropriate). Nevertheless, within a reasonable range of computability, programs like Mathematica already do just that. They probably don't solve this problem, because they are engineered to solve using known algorithms for commonly needed types of solutions.

(Now I am going to just dream:) To really solve such problems efficiently, one would need a database or research query mechanism to classify problems by known methods of solution in specific problem domains. That would really be cool if such an infrastructure existed that a program could tell you what methods are known that even apply to your problem, beyond a mere predefined set of problem ranges. Does anyone know if such 'expert systems' exist or are conceivable in the foreseeable future?

P.S. A slightly titillating but related problem is the sum of all k-digit positive integers containing at least one 7, allowing leading 0's for simplicity. For example, if this sum is T_k, then the sum S above is approximately

S = N*(N+1)/2 - 11*12/2 - T_k
where the approximation stems from the fact that k is not integer. One can give a ballpark estimate for T_k of about .5*90^k using the above heuristic, but a precise formula can also be given (either using the inclusion-exclusion principle and binomial coeffiecient formulas, or some other combinatorics argument). T_k is a given ratio of the sum S_k of all k-digit integers 00...0 to 99...9:
S_k = (10^k)*(10^k - 1)/2,

T_k / S_k = 10*(.1)^k + 2d/81 * (.9)^k; (d=7)
What all this shows is that the dominant term of T_k is 14/81 * (90)^k, which vanishes compared to S_k and S, so that not only the magnitude or logarithm, but the actual mantissa of the number in question (S), can in fact be computed fairly accurately if we ignore the fact that k is not an integer.

The point? A question: does anyone forsee the day that a computer will be able identify, on the fly, what sort of reasoning is possible and appropriate to general mathematical questions??? My quess is that we are far too idealistic about questions like this, which involve AI, because we are far too naive (and unconscious) about the sophistication of our own thinking. However, it is very conceivable that an expert system can account for known methods of reasoning and be able to discriminate as to when they are appropriate for given questions.

Lastly, lest the original poster may think we have forgotten him or her, I'll have to agree with others that many languages are useful, but in math, often a pencil and paper (or a desktop calculator) -- and some mathematical reasoning -- is all you're going to need to solve a problem or to entertain yourself. It does help to have a little background in computability and numerical analysis, but playing around with ANY computing language will also give you background that would help in learning these subjects. Personally I have used C/C++, mathematica, maple, fortran, assembly, Commodore basic, quickbasic, a TI-82, an old HP calculator, or even javascript or the windows NT command shell(!) to explore, compute, demonstrate or entertain myself with math questions (depending on what was at hand).

Programming maths (3, Informative)

d-Orb (551682) | more than 12 years ago | (#2900367)

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 [sourceforge.net] ) 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

Macsyma and Maxima (1)

mschaef (31494) | more than 12 years ago | (#2900609)

The Macsyma company has gone out of business, but there's a good free (open source) version known as Maxima.

http://www.ma.utexas.edu/users/wfs/maxima.html

A very sad side note to this is that the individual largely responsible for spearheading this piece of work, William Schelter, has recently passed away. He was also the maintainer of GNU Common Lisp. Rest In Peace.

-Mike

Python is perfect for programming Math (1)

Ursus Maximus (540370) | more than 12 years ago | (#2900401)

Hello. I am a mathematician and physicist who uses Python. Python is very easy to learn and use, but is also extremely powerful, especially whre math is oncerned. Python comes with built-in libraries that do all of the hard work. Num.py is a built in library that handles all the sophisticated mathematical functions you will ever need, and does so quickly, easily, and efficiently. Really, you should check it out. You can learn the core Python language in two or three hours by doing an online tutorial that can be found at http://www.awaretek.com/plf.html which site also contains links to everything you need to learn and use Python ;-)))

APL - A mathematical programming language (3, Insightful)

jcwren (166164) | more than 12 years ago | (#2900481)

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 [google.com] , using this [google.com] search rule. http://whatis.techtarget.com/definition/0,,sid9_gc i213454,00.html [techtarget.com] http://www.engin.umd.umich.edu/CIS/course.des/cis4 00/apl/apl.html [umich.edu]

Re:APL - A mathematical programming language (3, Insightful)

renehollan (138013) | more than 12 years ago | (#2900501)

Ah yes, APL... the only language in which you can invert a matrix with three characters, one of which is a backspace. (quad, backspace, divide; also known as domino).

Seriously, though, APL let me do my arithmetical stats course assignments in the 30 minutes before class, many, many moons ago.

That said, I think that Mathematica or even MatLab would be better suited for what you want to do.

Re:APL - A mathematical programming language (1)

BdosError (261714) | more than 12 years ago | (#2903342)

Ok, crack head moderators, how is this parent post Offtopic?

Re:APL - A mathematical programming language (1)

dbremner (16330) | more than 12 years ago | (#2905208)

I'll second that.
Morgan Stanley has a GPLed implementation for most Unices called A+ [aplusdev.org] .
For a reference, pick up APL: the Language and its Usage, Learning APL: An Array Processing Language,
or Ken Iverson's A Programming Language, from which the name of the language is derived.
A modern variant which uses ASCII characters is K [kx.com] . Free as in beer, for FreeBSD, AIX, Linux, Win32.

Re:APL - A mathematical programming language (0)

Anonymous Coward | more than 11 years ago | (#2921817)

It is very misleading to call K free! True you can get an _evaluation version_ which is quite useful. Though with significant limitations. To actually use the language commercially requires a very expensive licence. If you have to ask, it is too expensive;-) Its target market is Wall Street. Obtaining an unrestricted "research" licence is not too hard though, and that is quite useful in nonprofit, academic or personal use settings.

~gheil
J _is_ free though, and is really on topic as a mathematical language. J also has ports to some WinCE (and sons) platforms, making it useful as a portable tool.

Re:APL - A mathematical programming language (1)

dbremner (16330) | more than 12 years ago | (#2922700)

J is free, neat! Last time I looked at it, it was shareware. I've never run into a limitation on K, but I haven't written that many large programs in it. The commercial K license is $7500, or so last I heard. Nowadays KX seems to be marketing the database, not the language.

Re:APL - A mathematical programming language (0)

Anonymous Coward | more than 11 years ago | (#2920728)

For those who want to see what the inventor of APL is up to (APL was originally a notation for teaching mathematics) Look into J, http://www.jsoftware.com. It is fast efficient, modern. with lots of GUI hooks and Linux ports and
under continuing development and a very active user community. But the best part is its syntax is something a mathematician will love, operators, metaoperators, tacit expressions, OO methods, LAPack, memory mapped files, FFTs, regular expressions on and on. Oh and it is FREE too,
though there is a Pro version that includes a debugger and you can lock code with it.

If you need ultra efficiency i highly recommend
K (http://kx.com) this thing is a Cheeta faster than anyone on this forum can write C code, really compact and arguably has a more powerful, if far simpler syntax than J. The entire executable is
150K. Great for math programming too, but the training wheels are off: you have access to raw machine datatypes and can overflow, etc with no automatic type conversions like in other APLs and interpreted languages.

fortran (5, Informative)

tony_gardner (533494) | more than 12 years ago | (#2900548)

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.

Re:fortran (2)

drudd (43032) | more than 12 years ago | (#2900604)

The latest version of matlab that I've seen (6) has a graphical interface, although I don't use it.

As other posters have mentioned, it really comes down to what you are doing. If I want to solve a single ODE, or integrate a single function numerically, matlab is the way I would go.

When I start solving very large systems of equations (N-body simulations) it is usually rewarding to develop software tuned to that task in a lower level language such as C or Fortran.

Java might not be bad either if you're just playing around, but I know that they place artificial limits on floating point operations in order to try to maintain absolute consistency (i.e. intel chips have somthing like 80 bit internal acuracy which jvm's are forced to artificially limit in order to match other systems).

Doug

Re:fortran (1)

ghamerly (309371) | more than 12 years ago | (#2901117)

I think that when he said "gui", the first poster was referring to "typeset mathematics". Mathematica and Maple have this, but Matlab does not (but matlab does have a maple plugin). Yes, though, the latest version of matlab has a windowed user interface.

Re:fortran (0)

Anonymous Coward | more than 12 years ago | (#2902885)

The standard (and what most other systems implement) is 64bit doubles.

Intel's internal FPU registers are 80 bits.

I know you all hate chipzilla here, but reality is the other way around in this case.

Matlab and Mathematica (1)

e271828 (89234) | more than 12 years ago | (#2902664)

I agree with the parent that the tool for the job depends on what you want to do, but I must disagree with the parent's evaluation of Matlab and Mathematica. I have used both, and here are my thoughts on them.

Both have their own language backed by a huge collection of built-in functions. Mathematica's strength is in symbolic calculations: Solve[a x^2 + b x + c ==0,x] will give you the standard formula for a quadratic in a,b, and c. Matlab excels in numerical computations, especially on vectors and matrices. You can do numerical stuff in Mathematica and symbolic stuff in Matlab, but those aren't their strengths.

I would not say that either is easier to program than the other. You can write programs for either using your favorite text editor. One thing common to both languages is that though they have "for" loops, such loops are generally an inefficient way of doing things. Applying functions to entire lists in Mathematica or to vectors in Matlab will be a lot more efficient. You will have to get used to this "vector" way of thinking.

Whether either of these is applicable to the ask slashdotter's situation depends very much on his goals. Solutions to algebraic equations become one-line commands in these languages; if you are seeking the thrill of programming the solution yourself from first principles, use one of the standard programming languages others have described. If you want to make deeper investigations, you will likely get there sooner using one of these programs than starting from scratch.

Both packages also allow you to call (and call from) C programs - useful for intensive stuff that is better done directly in C.

Also worth noting is that both these software packages cost money! Your university may have them on their lab computers, but if you want to use them (legally) at home, you will have to shell out $100-$150 for a student license. Thankfully the student versions are pretty much full-featured. Your university might have special deals with these companies; mine sells student Matlab for about $30. Single non-student licenses are very expensive (about $1000 for Mathematica and $2300 for Matlab, I believe)

Re:Matlab and Mathematica (1)

drini (120042) | more than 12 years ago | (#2904936)

there's a free clone-like of matlab called octave
I don't know about a mathematica clone (since it's much more complex to program symbolic stuff)
but there are free programs following the same style (as mupad, khalamaris, etc)

Smalltalk (1)

Calomnious Awkward (459373) | more than 12 years ago | (#2900567)

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

Smalltalk is OO and has some better alternatives for arbitrary long integers. All numbers are objects, and understand appropriate operations (methods/or messages in ST) no problem calculating something as "12090 factorial"
You can download [squeak.org] OSS at Squeak [squeak.org]

Re:Smalltalk (1)

TulioSerpio (125657) | more than 12 years ago | (#2902658)

Alos, you have fractional numbers, estored as numerador/denominador (I don't know how to say in english) like 1/3, without loosing precision.

if you have (1/3) * (1/9) you get (1/27), not .333333333 * 0.999999999 = 0.037037

Re:Smalltalk (0)

Anonymous Coward | more than 12 years ago | (#2902919)

Squeak is fun, but its performance is badly lacking for non-trivial codes.

Better to find a high level interpreted language that has wrapper libraries for the various high performance FORTRAN kernels.

Javascript (1)

Pierre (6251) | more than 12 years ago | (#2900613)

Well there is always Javascript...

http://www.uiowa.edu/~itsarcs/jni/seosl/

ML (1)

rm-r (115254) | more than 12 years ago | (#2900675)

Fortran is used a lot traditionally by Maths and Physics types, in British universities at least. The language I would reccomend however is ML, I just graduated from uni and I remember that this was the language used by all the lecturers who would describe Computer Science as a branch of Mathematics. It's very easy to use if you're used to mathemtical formulae, logic and all that stuff, I remember it being very easy to define Finite Autonoma and Grammar Parsers (I didn't get into it big style but if there's one language I was going to code a Turing machine in it'd be ML) I imagine you'll find it easy enough to define your problem in the context of one of these.

Why? (3, Insightful)

coyote-san (38515) | more than 12 years ago | (#2900756)

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).

free fortran that supports later than F77? (0)

Anonymous Coward | more than 12 years ago | (#2901283)

I mean, for simple student code F77 isn't too bad, but it sure would be nice to get the newer features of the language (like free formatting, just as an example) without paying an arm + leg. By free I mean free speech or free beer, if it was free beer I couldn't talk about that'd be OK too :-). [student budgets being what they are and all...]

you have taken numerical mythods right? (2)

bluGill (862) | more than 12 years ago | (#2900789)

Just in case (and for any non-math people reading this) Do not write programs to do math brefore you take a numerical mythods class, and a theory of computing class.

You need to understand the limits of numbers on computers, what the error is, and so on before you can write a program that is worth touching.

Likewise you need to understand the halting problem (though not as deep), and other problems in fundamentals. (Gurdel incompletness).

Without the proper background (which a good CS program will make avaiable for you, and probably require), you cannot do this right. Of course once you have the right background language is an implimentation detail. While ML, APL, and MatLab (and a few I missed) have a lot of things to help with math, you can use any language you want to and get the job done.

Re:you have taken numerical mythods right? (0)

Anonymous Coward | more than 12 years ago | (#2900955)

Not to flame overly, but this is a load of crap.

what the hell goes the halting problem, or "Gurdel's" (Goedel's) incompletness theorem have to do with writing a numerical code. So not all problems are soluble. boo frikkin hoo. most are, and the ones which aren't are not likely to be of interest to someone who's just started, like our questioner. It's true that in some problems you'll have to pay attention to the limitations of the compiler and processor, but these are few and far between. (admittedly I've been dealing with them in the last few days dealing with an implementation of a nonequilibrium reaction model for hydrogen-air).

To go out on a limb: It is IMPOSSIBLE to learn numerical methods in a class. the only real way is to dive right in. Everybody makes mistakes. It's what life's all about. numerical modelling is a piece of piss for anyone who's prepared to believe that their code might not be right the first time.

Good luck.
I wish I had mod points (or could be bothered logging in).
Tony Gardner.

Re:you have taken numerical mythods right? (3, Insightful)

msouth (10321) | more than 12 years ago | (#2901156)

Just in case (and for any non-math people reading this) Do not write programs to do math brefore you take a

numerical mythods class, and a theory of computing class.

You need to understand the limits of numbers on computers, what the error is, and so on before you can write
a program that is worth touching.


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.

Re:you have taken numerical mythods right? (1)

Kirruth (544020) | more than 12 years ago | (#2905740)

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.

Oh definitely. I found playing around with Hugs (the Haskell interpreter/compiler) way cool. Of course, it helps to get an education in numerical methods (at the least so you know how the tools work in the background), but getting a feel for things in real time helps alot

Depends... (2)

coyote-san (38515) | more than 12 years ago | (#2901396)

That depends on the problems he's interested in.

If he's trying to solve continuous problems, he needs to get a copy of Numerical Recipes and start working through it. Ideally solving real problems that can be checked analytically or by running simulations - it's important to learn deep in your gut just how easy it is to write code that looks good but produces garbage.

But if he's interested in discrete math problems, something that the original question hinted, then he needs to get an arbitrary math package and learn an entirely different type of programming. In this case a numeric methods class is irrelevant.

Re:you have taken numerical mythods right? (1)

Bazzargh (39195) | more than 12 years ago | (#2906082)

Bull. Maths is not all numerical approximation.

It looks like it has escaped your notice that MatLab, and a 'few [you] missed' like Mathematica ad Pari, are quite capable doing symbolic mathematics - such as eg finding the factors of polynomials, integration, differentiation, etc. See here to get started: http://www.symbolicnet.org/

It is also quite possible to work with represetations of numbers as intervals instead of plain ol' floats, so that the results of the calculation give you error bounds, in a more automated way (without as much need for a numerical method course, in other words). Plenty of research cited here: http://liinwww.ira.uka.de/bibliography/Math/intari th.html

See also the XSC system which builds this error calculation into languages like Pascal:
http://www.xsc.de/

I find it mystifying that you would consider an understanding of 'Gurdels'(sic) incompleteness theorem necessary to write decent computer programs.
-Baz

UBASIC (1)

honcho (69284) | more than 12 years ago | (#2900920)

Take a look at UBASIC [utk.edu] . From the documentation:
Version 8 of UBASIC has the high precision real and complex arithmetic (up to 2600 digits) of previous versions, but adds exact rational arithmetic and arithmetic of polynomials with complex, rational, or modulo p coefficients, as well as string handling and limited list handling capabilities. In addition UBASIC has context-sensitive on-line documentation (read ubhelp.doc for information).
It doesn't give the greatest performance it the world, but I've used to for everything from prime searching to looking for narcissistic numbers [geocities.com] .

scheme (2)

austad (22163) | more than 12 years ago | (#2901050)

As much as I hate Scheme, it worked nicely for writing mathematics programs when I went to the U of MN.

Maple from U of Waterloo (2, Informative)

Capt_Napalm (121561) | more than 12 years ago | (#2901249)

The University of Waterloo has a program called Maple [maplesoft.com] . It's fairly easy to pick up, available for Windows, UNIX, Linux and Macs, not horribly expensive, and very powerful. There's also piles of add-on packages created by other mathematicians.

If you're looking for something on the numerical analysis end, try Octave [octave.org] . It's like MatLab but free.

Maple! (2, Informative)

bje2 (533276) | more than 12 years ago | (#2902043)

I went to Lehigh University and we had Maple V [maplesoft.com] available on our on campus network...it's an extremely powerful mathematics application...

it's not really a programming language, but it does allow you the ability to create variables, your own functions, etc...by far the most powerful featues are it's graphing capabilities and it's ability to find integrals and derivatives of equations that you'd never dream of trying to solve by paper and pencil...

the only downsides are it takes a while to get used to (the manual is huge!), and the program itself is a bit of a memory hog...other then that it's great...

perl and Math::Pari (4, Informative)

msouth (10321) | more than 12 years ago | (#2901309)

There's a mathematician who used to be quite active in developing Perl's regular expression code (Ilya za[something]) who created a Perl module that lets you use a very powerful and extensive mathematical library called PARI. I believe the extension is called Math::Pari, and it's available on CPAN.

ok, I just looked it up, here's a blurb from the documentation:


Package Math::Pari is a Perl interface to famous library PARI for
numerical/scientific/number-theoretic calculations. It allows use of
most PARI functions (>500) as Perl functions, and (almost) seamless merging
of PARI and Perl data.


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

Re:perl and Math::Pari (2)

Daniel Dvorkin (106857) | more than 12 years ago | (#2904480)

A little OT here, but I've just got to comment on this ...

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.

Well, sometimes that's true and sometimes it's not. The fact is, some people are more visually oriented and some people are more numerically and symbolically oriented -- the way one of my Dad's professors (back when he was a math student, they had to draw their graphs, by God!) was that there are two types of people in the world, geometers and algebraists. Me, I'm an algebraist: sometimes it's useful for me to see a visual representation of a problem, but more often than not, not only don't I care what it looks like, trying to think about it visually makes it harder for me to solve.

Ultimately, what matters is solving the problem (or proving the theorem, or whatever.) In most branches of mathematics, there are both algebraic and geometric ways to get a solution. Neither one is "better" in some abstract sense, but one or the other will generally work better for an individual.

Re:perl and Math::Pari (2)

msouth (10321) | more than 12 years ago | (#2904589)

You are right. I didn't intend to go to the other extreme. What I should have emphasized is that visualization can often make a remarkably valuable contribution towards insight or understanding, and often it does so in places that are not traditionally approached through visualization.

I can certainly believe that there are situations or mental dispositions for which this is not the case, and they may even be the majority.

C/C++ for sure (1)

krs-one (470715) | more than 12 years ago | (#2903153)

After reading a lot of the book Numerical Recipes in C, I have to say that C/C++ are the best languages to program mathematics in. They are both fast, and with the OOP part of C++, you can really get some cool results.

For example, all serious games out there that use OpenGL or DirectX are all programmed in C/C++. Why? Because its the best language for the job. And since everyone knows that games are very mathematically intensive, and most of their languages are C/C++, you can make the logical postulate.

-Vic

Re:C/C++ for sure (1)

bgins (446545) | more than 12 years ago | (#2909319)

It doesn't sound to me like the poster wants optimized code to do one thing thousands of times. It does sound like they want a framework to try out different problems and learn mathematical algorithms and programming. Many good suggestions have been mentioned. One other, similar to Matlab or Maple, is MuPad (http://www.sciface.com), which has free trial versions and supports many OS's.

Re:C/C++ for sure (1)

lightray (215185) | more than 12 years ago | (#2909437)

How did NR ever lead you to believe that numerical programs can be cleanly written in C? The C code in Numerical Recipes is terrible. The authors basically transplanted their Fortran code directly to C, resulting in unreadable programs. They ignore C conventions, for example by using Fortan-style arrays based at 1 instead C's 0-based arrays. Variable names are most often uninformative, at most two letters. Furthermore their algorithms often implement special rather than general cases of the problems they seek to solve. Finally, while the prose can enlightening, it's been questioned whether the authors are even qualified to write such a book. But don't take my word for it, read NASA/JPL's page `Why not use Numerical Recipes [nasa.gov] ,' which begins with the statement, ``We have found Numerical Recipes to be generally unreliable.''

On the topic of OpenGL, your logic doesn't follow. The mathematical content of the 3D graphics routines is implemented within the OpenGL library (not so much the game itself), and these routines are implemented in C, assembly, and hardware, not because these media provide for the most eloquent expression of mathematics, but because they provide for the fastest implementation, and speed is of primary importance in 3D graphics.

You are right that C++ has some interesting applications in mathematics. See for example Yet Another Computer Algebra System [xs4all.nl] .

Fortran for most, Matlab and C for some (1)

3x3eyes (136763) | more than 12 years ago | (#2903836)

Most of the numerical stuff I write is in Fortran90, and a lot of the older code you find is also in Fortran. Sometime C and Matlab comes in handy for specific task. Depending on what you do, I would say C and Fortran would be your best bet.

Re:Fortran for most, Matlab and C for some (0)

Anonymous Coward | more than 12 years ago | (#2904298)

Fortran is spelled FORTRAN, not Fortran. Just like BASIC is spelled BASIC, not Basic, and COBOL is spelled COBOL, and not Cobol. And as a FORTRAN programmer, you should know better :).

~~~

Another possibility... (1)

jellisky (211018) | more than 12 years ago | (#2904460)

... even though it's more of a data language than anything else, is IDL. (Forgot the company that produces it, though, sorry.) It's fairly intuitive, has a lot of great functions and makes some of the greatest plots of any language I've ever seen. (Which is why it's perfect for data visualization...) Truthfully, as a theoretical scientist, I've used FORTRAN, C++, Java, IDL, MatLab, Mathematica, Maple, and Pascal for varying projects. It all really depends on what you want to do. And since other have mentioned much of that, I'll leave it at that. -Jellisky

Scheme and SICP. (2)

Christopher Cashell (2517) | more than 12 years ago | (#2904517)

I'd give Scheme a try. It's a functional language, and a dialect of lisp. It's design makes mathematically oriented programming fairly intuitive.

Additionally, one of the best Computer Science books ever written, Structure and Interpretation of Computer Programs [mit.edu] , utilizes Scheme. Ths book takes a strong math styled for programming, particularly in the first chapter, and I think it'd be a great way to get yourself started.

Also, the book is available online, full text, for free here [mit.edu] .

I use good old bc (1)

linuxdoctor (126962) | more than 12 years ago | (#2907177)

If the kinds of math you want to do is calculator style stuff then `bc' is my choice.

This old chestnut is an arbitrary precision desk calculator with a C-like programming syntax. So, if it's the sort of stuff that you would do in C/C++ or Java but to play with really large numbers, the bc is the way to go.

Lisp for symbolic stuff (you mentioned algebra)... (0)

Anonymous Coward | more than 12 years ago | (#2913126)

It's a fantasticly flexible language even if it's syntax is a bit different from most other languages. It has fantastic support for manipulating symbolic expressions directly, so you don't have to spend time writing symbol libraries before you get started.

I had to write routines to do algebraic simplification and simple symbolic derivatives for a class once and it was *maybe* 30 lines of common lisp code. Check out CMU CL, GCL, clisp, or any of the scheme implementations for details. Paul Graham has published some good books on lisp to get you started (although one is out of print).

Enjoy!

fyi,
ac
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?

Submission Text Formatting Tips

We support a small subset of HTML, namely these tags:

  • b
  • i
  • p
  • br
  • a
  • ol
  • ul
  • li
  • dl
  • dt
  • dd
  • em
  • strong
  • tt
  • blockquote
  • div
  • quote
  • ecode

"ecode" can be used for code snippets, for example:

<ecode>    while(1) { do_something(); } </ecode>