You are not logged in.

#1 2011-09-15 14:31:55

jlindgren
Member
Registered: 2011-02-27
Posts: 260

Programming language for mathematics (e.g. complex numbers)?

I'm looking for a programming language that will allow me easily to manipulate complex numbers.  Specifically, I need to be able to do things like multiply complex numbers and raise e to complex powers.  The most important thing is that the code needs to be readable, so that it can be understood by someone with relatively little programming background.  C (which is normally my preferred language) is not an option because complex numbers aren't part of the language and would have to be implemented with structures and helper functions.  Maxima is a possibility, but I would prefer something with a more normal (C- or Java-like) syntax.  Maple has a better syntax, but it's proprietary and expensive.  Are there any other options out there?

Offline

#2 2011-09-15 14:41:35

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: Programming language for mathematics (e.g. complex numbers)?

If you like Python try NumPy/SciPy packages.

If you need a matlab-like language try octave, or for a comple mathematical software solution try Sage.

If you want to have C/Java style syntax then C++ could be a way to go, a complex number class with operator overloading is not a hard thing to write, but you can find plenty of it across the web.
edit: the C++ standard library has a complex number implementation.

Last edited by ijanos (2011-09-15 14:51:28)

Offline

#3 2011-09-15 15:53:25

jlindgren
Member
Registered: 2011-02-27
Posts: 260

Re: Programming language for mathematics (e.g. complex numbers)?

The C++ implementation looks promising.  Thanks!

Offline

#4 2011-09-15 15:56:45

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: Programming language for mathematics (e.g. complex numbers)?

D (v2) has a std.complex module and a syntax very close to C:

import std.complex, std.stdio;

void main() {
	writeln( complex(1,1) ^^ complex(2,2) );
}

This returns:

-0.265654+0.319818i

Is that correct? smile

Edit: ^^ means power.

Edit 2: According to WolframAlpha, it is.

Last edited by stqn (2011-09-15 16:13:29)

Offline

#5 2011-09-15 17:28:56

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: Programming language for mathematics (e.g. complex numbers)?

Complex numbers are part of the C programming language in the latest standard, c99.  Just #include complex.h and compile with -std=c99 (gcc).

see http://en.wikipedia.org/wiki/Complex.h.

Offline

#6 2011-09-16 02:22:50

Renan Birck
Member
From: Brazil
Registered: 2007-11-11
Posts: 401
Website

Re: Programming language for mathematics (e.g. complex numbers)?

Python + NumPy/SciPy might be what you're looking for.

Offline

#7 2011-09-16 03:06:40

jlindgren
Member
Registered: 2011-02-27
Posts: 260

Re: Programming language for mathematics (e.g. complex numbers)?

Thanks for all the replies.  I had no idea there were so many options out there!  I'll probably take what C99 has to offer since I'm most familiar with that language already.

Offline

#8 2011-09-16 16:47:56

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: Programming language for mathematics (e.g. complex numbers)?

I work with complex numbers frequently, I personally prefer writing all of my simulations and calculations using GNU/octave.  Some of the benefits include built in functions for operating on complex numbers, it's a language designed for mathematical calculation, and plotting data with gnuplot is easy as pie.

If you are looking for something a little more robust (as in trying to build a program with a gui interface or a bigger program that just happens to use complex numbers frequently) I'd probably suggest python as an alternative, as it is a full easy to use language with built in support for complex arithmetic.


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#9 2011-09-16 19:59:54

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,615

Re: Programming language for mathematics (e.g. complex numbers)?

stqn wrote:
-0.265654+0.319818i

Is that correct? smile

Yes.

To the OP, have you looked at Maxima?  It is not a general purpose language, but it is scriptable, integrates with GNUPlot, has GUI front ends (wxMaxima), and exports equations and results nicely to LaTex.

Oh, and it handles complex numbers like a dream.  It even makes Laplace transforms a breeze.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#10 2011-09-16 20:51:05

jlindgren
Member
Registered: 2011-02-27
Posts: 260

Re: Programming language for mathematics (e.g. complex numbers)?

ewaller wrote:

To the OP, have you looked at Maxima?  It is not a general purpose language, but it is scriptable, integrates with GNUPlot, has GUI front ends (wxMaxima), and exports equations and results nicely to LaTex.

Oh, and it handles complex numbers like a dream.  It even makes Laplace transforms a breeze.

I use Maxima often.  As I said in my original post, I wanted something with a more C-like syntax.  Since "rockin turtle" has pointed out that C does in fact have support for complex numbers, I've taken that route.

P. S.  The project (which is done now) was to implement an FFT, first of all to test my own knowledge of the algorithm and possibly to give a presentation on later -- maybe I should have mentioned this earlier.

Offline

#11 2011-09-17 11:06:17

xamaco
Member
From: Corsica, France
Registered: 2010-04-05
Posts: 87

Re: Programming language for mathematics (e.g. complex numbers)?

I'm not sure about what you want to do with complex numbers, but have a look at the calc package. It handles complex numbers natively and it's programmable (looks like C (one of the most beautiful language in the world IMHO smile) ).

Last edited by xamaco (2011-09-17 11:06:50)

Offline

#12 2011-09-18 19:18:12

jacmoe
Member
From: Denmark
Registered: 2011-09-11
Posts: 11
Website

Re: Programming language for mathematics (e.g. complex numbers)?

I am slightly surprised that no one mentioned Lisp.
It's the perfect language for mathematics. smile
It's written #c(r i), where r is the real part and i is the imaginary part.
Of course, Lisp might not be your cup of tea, but it's the most mathematical language I know of.

Last edited by jacmoe (2011-09-18 19:18:32)


Less noise. More signal.

Offline

#13 2011-09-18 19:38:57

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,615

Re: Programming language for mathematics (e.g. complex numbers)?

jlindgren wrote:

...The project (which is done now) was to implement an FFT, first of all to test my own knowledge of the algorithm and possibly to give a presentation on later -- maybe I should have mentioned this earlier.

Although this is moving off topic, If you really want to understand the FFT, have you looked at how it is implemented in a DSP?  Configuring hardware address generators to generate the butterfly sequences is what really drove it home for me. 

Here is a link to a low cost development system: http://www.ti.com/tool/tmdx5535ezdsp

It might make for an interesting presentation


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#14 2011-09-18 19:54:11

jlindgren
Member
Registered: 2011-02-27
Posts: 260

Re: Programming language for mathematics (e.g. complex numbers)?

I think that's a little beyond me at this point, ewaller, but thanks. smile

Offline

#15 2011-09-19 02:51:29

Nisstyre56
Member
From: Canada
Registered: 2010-03-25
Posts: 85

Re: Programming language for mathematics (e.g. complex numbers)?

jacmoe wrote:

I am slightly surprised that no one mentioned Lisp.
It's the perfect language for mathematics. smile
It's written #c(r i), where r is the real part and i is the imaginary part.
Of course, Lisp might not be your cup of tea, but it's the most mathematical language I know of.

I'm surprised nobody suggested Haskell. It's practically executable math.


In Zen they say: If something is boring after two minutes, try it for four. If still boring, try it for eight, sixteen, thirty-two, and so on. Eventually one discovers that it's not boring at all but very interesting.
~ John Cage

Offline

#16 2011-09-19 03:08:42

davidgurvich
Member
Registered: 2010-02-11
Posts: 118

Re: Programming language for mathematics (e.g. complex numbers)?

There's always fortran if you need performance.  Fortran has builtin type Complex.  If you want arbitrary precision there are a few packages available for fortran90 or later.

Python has some good features and is highly recommended if you don't need high precision with speed.

Offline

#17 2011-09-20 04:03:18

vae77
Member
Registered: 2010-07-02
Posts: 75
Website

Re: Programming language for mathematics (e.g. complex numbers)?

davidgurvich wrote:

There's always fortran if you need performance.  Fortran has builtin type Complex.  If you want arbitrary precision there are a few packages available for fortran90 or later.

Python has some good features and is highly recommended if you don't need high precision with speed.

Since I know NumPy/SciPy and are very fast since they were written using C and Fortran.

Offline

Board footer

Powered by FluxBB