
Programming Programming Languages, Interpreters, and Compilers  Assembly, Declarative, Machine, Object Oriented, Iterative 
 LinkBack  Thread Tools  Display Modes 
February 27th, 2011, 01:43 PM  #1 
Joined: Jan 2011 Posts: 1  Best Programming Language for Mathematics?
I am trying to make a quick program right now. It goes as follows, pick two random real numbers between 0 and 1 (call them x and y). Then compute (1  (xy/2))/(xy/2). Do this algorithm 10000 times or so, and compute the average or Expected Value. Any tips?

My Computer Forum is free to register and we welcome everyone! 
March 15th, 2011, 03:38 PM  #3 
Joined: Feb 2011 Posts: 3  Re: Best Programming Language for Mathematics?
PARI/GP Code: gp> r()=random/2.^31 gp> t=vector(1000); gp> s=0.;for(i=1,1000000,x=r();y=r();k=x*y/2;s=(1k)/k;if(s<1000,t[truncate(s)]++));s/1000000 385.8625022118101423434752171 ploth(x=1,1000,t[truncate(x)]) 
August 23rd, 2011, 02:49 AM  #4 
Guest Joined: Posts: n/a  Re: Best Programming Language for Mathematics?
I use Mathematica, Fortran, C++, and C# on a regular basis. As far as getting the job done in the shortest amount of time, and the easiest way possible, Mathematica is the best hands down. I used to use MatLab but don't bother any more. It is a child compared to what Mathematica can do. The only time I ever use anything else is when I need more speed or memory. If you need more speed, Mathematica can call directly to the CLR or Java, which is why learning C# or Java would be a good start. You can just write the one function in C# that is causing the bottleneck and call it. If you still need more speed C# and Java can both call Native and so Fortran is by far the fastest, or you can call some optimised library. The only time when mathematica can't be used efficiently is when you are memory restricted...there is simply no way to efficiently control memory allocation with mathematica. In this case I use C++. OO is really a fantastic way to program and if you are looking for a real programming language then either C# or C++ should definitely be it. A well written piece of object oriented code is so simple, intuitive and easy to understand that you almost don't need any comments whatsoever. When your projects start getting really big is when it really shines: no matter how many lines of code you add the complexity of what you are doing increases very little. 
September 1st, 2011, 10:45 AM  #5 
Joined: Sep 2011 Posts: 13  Re: Best Programming Language for Mathematics?
I think it depends what you want to do. I used MATLAB extensively in university. It suited all my numeric needs very well. I studied electrical engineering. I’m sure Mathamatica is more powerful but it is also more expensive. Both of these pieces of software are outside the affordability for most individuals and likely won’t be used after university. Maple and Axiom are two other alternatives for symbolic math. Axiom is open source written in lisp and is easy to install on both windows an lynix. Octave is a free version of MATLAB. You may have trouble installing it on windows. I haven’t tried installing it on windows but I did try installing it in the, VM ware virtual machine which the windows version of sage runs on. I wasn’t successful. In the future I may try installing it via cygwin. One plus of Octave over MATLAB is it is that Octave is open source so you can see exactly how the numeric libraries (linpac, Lapack, …) are used. These libraries are written in FORTRAN which excels for numeric computation and is still used extensively in scientific computing. There are c and java versions of these libraries which may be better suited for windows. You will find that on windows Fortran compilers may be expensive and may not easily interop with windows programs written in other languages. However, you can use lynx versions of the gcc fortran compilers (e.g. gfortran) through cygwin or minsys. My recommendation is learning python and doing your numeric computations (at least for prototyping) though scipython. It provides a MATAB like syntax. There is a piece of software called Sage which is written in python which integrates many mathematical software packages including pari. Python is also very portable because there are c versions, java versions and dotnet versions all of which presumably can both be run on windows or lynix. I would not recommend learning Java directly. The syntax is very cumbersome for mathematics. Many languages can be run in java indirectly through bsf (bean scripting framework) including Jython which is the java implementation of python. Jython uses bsf and can call java classes directly. The language I would recommend learning for the java runtime environment is scala because it can be complied to both the java and dot net byte code. It will also introduce you to functional programming which makes programming computer algebra systems much easier. 
September 13th, 2011, 01:38 PM  #6 
Site Founder Joined: Dec 2007 Posts: 414  Re: Best Programming Language for Mathematics?
For mathematics I like Maple very much. This being said, this isn't really a programming language and there's only that much you can do with it. However, in terms of mathematical software, it's really great (Mathematica is good also, although I haven't used it much).

September 27th, 2011, 07:07 PM  #7 
Joined: Jun 2011 Posts: 13  Re: Best Programming Language for Mathematics?
I use QB45 for everything  for it lets you THINK about the task instead of mindless arbitrary syntax of prog code. It is almost like writing English! Bill Gates of course torpedoed QB45 with his SP2 bodge fix in XP But now there is QB64 (free download  find it in Google) which is 10 x faster. 
September 28th, 2011, 12:14 AM  #8 
Site Founder Joined: Dec 2007 Posts: 414  Re: Best Programming Language for Mathematics?
Oh wow ! QBasic ! When I was 6 year old I remember having my first introduction to computing in school (it was 1989 back then ...) and we were initiated to Basic programming. After that, I kept using QBasic as my first choice programming language for a good few years (it's also good for chip programming). Actually, I didnt even know QBasic was now called QB45 and was still alive ! 

Tags 
language, mathematics, programming 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Mathematics involved in CS  johnny  Computer Science  10  April 30th, 2010 12:40 PM 
What's your favorite programming language?  johnny  Programming  16  April 30th, 2010 12:08 PM 