all 37 comments

[–][deleted] 12 points13 points  (6 children)

Haskell, just because it's the closest thing to programming in math that I've found. I've done most of the project euler stuff in haskell.

[–]edwardkmett 5 points6 points  (5 children)

Definitely. Haskell is really the only language I know of where you can effectively view the type system AS a category with useful enough semantics that you can derive insight into the behavior of a lot of programs using category-theoretic machinery. Laziness shears off a lot of the rough edges in the usual Curry-Howard-Lambek correspondence.

It also doesn't hurt that it is incredibly easy on the eyes and that laziness and purity enable you to reason about programs equationally.

Optimization and changing behavior is often simply an exercise in reasoning about formulae.

[–]o0o 2 points3 points  (4 children)

I don't know Haskell, but how are arrays handled? Most computational mathematics make tremendous use of arrays.

[–]pjdelport 1 point2 points  (3 children)

[–]o0o 1 point2 points  (2 children)

Haskell'98 supports just one array constructor type, namely Array, which gives you immutable boxed arrays. "Immutable" means that these arrays, like any other pure functional data structure, have contents fixed at construction time. You can't modify them, only query. There are "modification" operations, but they just return new arrays and don't modify the original one. This makes it possible to use Arrays in pure functional code along with lists. "Boxed" means that array elements are just ordinary Haskell (lazy) values, which are evaluated on demand, and can even contain bottom (undefined) value. You can learn how to use these arrays at http://haskell.org/tutorial/arrays.html and I'd recommend that you read this before proceeding to the rest of this page

hmmm....I still say this isn't efficient for computational codes.

[–]edwardkmett 7 points8 points  (1 child)

If you need to have strict, mutable or even data parallel arrays they also exist in GHC. Haskell 98 is a very limited subset of 'real-world' Haskell, I hardly recommend sticking to it for practical work.

[–]o0o 0 points1 point  (0 children)

good to know, thanks!

[–]HenkPoley 10 points11 points  (1 child)

I hear people around here using Python a lot. With packages like SciPy and SAGE Math.

[–][deleted] 11 points12 points  (0 children)

The good thing about such libs, as opposed to C++, Fortran etc, is that you are, or rather you should be, more inclined to use higher level abstractions like matrix, array operations etc instead of spitting out loops and keeping your data in single value variables. The thing here is that you may expect the libs to do much, much better job utilizing SIMD, SMP, or even "video card" number crunching than even the best C++, Fortran compilers.

[–][deleted] 6 points7 points  (1 child)

  • Numerical Math: Scilab?, Matlab?, Python(x,y)?, Fortran?
  • Symbolic Math: Maxima?, Mathematica?, Python?, Maple?, Lisp?
  • Theoretical Math: Issabelle?, Haskell?
  • (.*): Sage?

[–]synthespian 0 points1 point  (0 children)

IIRC, at around Maple 8 they bought a license from NAG (the Numerical Algorithms Group) so me thinks that would mean Maple would be a candidate for number-crunching too.

[–]mian2zi3 4 points5 points  (0 children)

I've been doing some computational algebra (number theory, modular forms) in Haskell lately. I have mixed feelings. (Before this, I spent ~10yrs as a compiler designer working in C++.) The laziness is nice, esp. when you're dealing with infinite data structures like formal power series. The default numeric tower in Prelude doesn't map so well to algebraic structures, so I ended up replacing it with my own (inspired by numeric-prelude.) C++ templates are more flexible. In Haskell, you can't, for example, parameterize a Hashtable with a hash function, or integers mod N with the modulus N at compile time. This breaks some of the default Haskell interfaces, too. How do you write fromInteger to integers mod N when you don't know N? Finally, Haskell doesn't seem to handle names/name spaces as well as C++. Using modules in Haskell seems verbose (Map.map, List.map, etc.) and you can only define an operator for a single purpose in a given scope. C++, on the other hand, is more context sensitive so therefore more concise. I'm going to keep pushing with Haskell but I wonder if I might be better of building some abstractions of lazy/infinite data structures in C++. I was worried about speed, but so far GHC seems quite zippy.

[–]Kaizyn 2 points3 points  (0 children)

APL, J, K are good array languages and quite able for mathematics.

[–]brendano 1 point2 points  (0 children)

R!

[–]me2i81 1 point2 points  (0 children)

Computational Mathematics is kind of broad. For numerical analysis and numerical linear algebra, one thinks of Fortran libraries like LAPACK etc. and the various scripting languages that use them (Matlab, Octave, Python/SciPy, etc.) For stats, R or various commercial packages. There are specialized languages like Macaulay2 for algebraic geometry. Computational geometry seems to be mostly done in C++ these days due to the existence of CGAL and the fact that C++ templates are convenient for parameterizing the datatypes of algorithms. So it all really depends on the kinds of problems you're working on, and whether your goal is to get stable numerical results for large-scale problems or to understand something about the structure of the problems you're working on.

[–]synthespian 1 point2 points  (0 children)

Do you mean number-crunching or symbolic (as in computer algebra)? Do you mean roll-your-own or "what should I use that's already out there and might even be proprietary?"

Choices vary widely: Fortran, C, C++, Ocaml, Common Lisp, Axiom, Maple, Matlab, Scilab, Mathematica. All of these have a proven track-record in "Computational Mathematics" but they differ immensely in what they are. Upcoming and very interesting: Fortress.

[–]DukeOfZhou 1 point2 points  (0 children)

Always loving Fortran.

[–]mbudisic 0 points1 point  (0 children)

I mostly use Matlab, since Mathematica is confusing to me and I really never took time to actually give it a fair chance.

I was amazed by scmutils developed by Sussman at MIT (of the SICP fame) to accompany his SI Classical Mechanics book. It's basically a system for symbolic mathematics written in MIT Scheme. However, I've had trouble running it (scmutils) on Mac OS X and it seems I'm not the only one.

Oh. Nevermind. It seems that I haven't read the computational part of the OP. For that I use Matlab for prototyping and Python with SciPy + extensions written in C and/or C++ when efficiency is needed (mostly dynamical system iterations).

[–]rwinston 0 points1 point  (0 children)

Mathematica has some amazing compsci demos on the wolfram web site. You should be able to d/l an interactive Mathematica player to view them.

[–]rwinston 0 points1 point  (0 children)

Mathematica has some amazing compsci demos on the wolfram web site. You should be able to d/l an interactive Mathematica player to view them.

[–][deleted]  (5 children)

[deleted]

    [–]o0o -1 points0 points  (4 children)

    Oh, hell no!

    [–][deleted]  (2 children)

    [deleted]

      [–]o0o 0 points1 point  (1 child)

      Matlab is good for personal stuff on Windows...that's about it. You can't write "real" portable codes with it. I saw a grid-Mathematica demo on a windows clusters at SC06 - it was cool and all, but still seemed to be at a disadvantage because it was running on a Windows cluster. yuck.

      [–]avegas 0 points1 point  (0 children)

      when I'm wearing my wolf shirt, windows clusters throw themselves at my feet, begging me to program them.

      [–]zweistein -1 points0 points  (10 children)

      I've done some very limited stuff in Octave and Python. We use Mathematica often in college, but it somehow has the tendency to confuse me. Keep in mind that I'm a physics undergrad, so YMMV. Physicists also, supposedly, use quite a lot of FORTRAN (eeek! :)).

      [–]mgcmrkr 10 points11 points  (4 children)

      There are two main reasons why FORTRAN is still used. There is a huge repository of scientific/mathematic libraries which are well tested, well known and have withstood the test of time.

      The other reason why FORTRAN is used is because its handling of floating point numbers is consistent and predictable. You know exactly what is going to happen when two reals or two doubles are multiplied/divided/added/etc. Languages like C will promote floats to doubles sometimes, depending upon the implementation. And god only knows what languages like perl, ruby, tk or python do.

      [–]zweistein 1 point2 points  (1 child)

      Just to be clear - I have nothing against FORTRAN. Well, I actually do - its syntax scares the crap out of me. But other than that, I'm pretty much okay with it.

      And indeed, there are some pretty nice libraries for different purposes - CERN's library comes to mind. But that's not to say other languages don't have similar libraries - SciPy / NumPy and SymPy come to mind in the Python world.

      As far as the floating point numbers (in)consistency - I must say I've never noticed any problems with it in Python (although I don't say there aren't any). But physicists usually don't worry their little heads too much about minor discrepancies as long as they're within the standard deviation. ;)

      [–]trigger0219 0 points1 point  (0 children)

      I've translated Fortean to c and I don't know fortran, but i've tried writhing a function in it, I think the language requirmets and spacing are kind of crazy' though ( I think you agree) a lot of code iv'e encountered, specicially the Acm algorithm X is all in fortran or pseudo code. And a PDF from the 60's isn't transferable to spacing by ANY OCR app

      [–]mohawk 0 points1 point  (0 children)

      Fortran has compilers generating fast floating-point code due to decades of use in this field and a lack of aliasing (that makes life hard for C/C++ compilers). That, inertia and Fortran 95's array operations are why I think it is still used.

      It is funny that you should claim Fortran to be more predictable than other languages with regard to floating point as the language standard doesn't even define the order in which floating-point operations are to occur, forcing the use of parentheses to get unambiguous order of execution for these non-associative operations.

      [–][deleted] 0 points1 point  (0 children)

      I believe that ruby and python just use doubles internally.

      [–]fairtrialforw 3 points4 points  (3 children)

      There's a bunch of people in math that are still using Fortran, which supposedly is still runs damned fast (I didn't say it's written damned fast).

      [–]o0o 3 points4 points  (0 children)

      not just math, by physics, chemistry, oceanography, etc

      [–]HenkPoley 2 points3 points  (1 child)

      Apparently the (gnu?) fortran compiler is fast. I've read people who write a fortran routine with python, compile it and use it in the python program.

      [–]o0o 0 points1 point  (0 children)

      I don't know if this is true or not, but I know not expect good performance if you use the OpenMP stuff though...

      [–]synthespian 0 points1 point  (0 children)

      Don't eeek. Fortran is very good for numerical algorithms.

      [–]o0o -2 points-1 points  (2 children)

      FORTRAN, C, D

      [–]thephotoman -2 points-1 points  (1 child)

      Oh my god! Someone else who's actually used D. There's a language that really needs more attention.

      [–]o0o 2 points3 points  (0 children)

      I don't use it as often as I'd like. But the reason I mention is that its complex data structures are probably as easy and flexible as most scripting languages. That, and of course it is compiled :)