Programming Languages recommended for work in mathematics and to understand computational complexity

10.1k Views Asked by At

I am an undergraduate mathematics student and I am managing to stay a semester ahead of my classes. One way in which I want to use my free time is to learn a computer language(s) that will help me in my mathematical future as someone who wants to work in pure mathematics. Also I am interested in algorithms and complexity theory and classes. I have no background in any language as of now

Question: Which language or set of languages are usually taught to develop a base understanding for programming that also are used by the working mathematicians today? And which set of languages are more oriented towards algorithmic and complexity theory? Is there any intersection between the two?

Thanks in advance guys/gals. Any comment,answer or input is appreciated!!

8

There are 8 best solutions below

1
On BEST ANSWER

For an introduction into programming I would recommend a "script language":

  • Modern script languages (e.g. Python, Ruby) tend to be not the most efficient in hardware usage, but are expressive and great for developing complex programs. Ruby is more elegant than Python IMHO, but Python has lots of great mathematical libraries. So Python would be a good choice.

Then there are the languages which allow one to write fast programs, programs that utilize memory very efficiently and can talk to most hardware:

  • The general purpose languages that allow you to use the hardware very efficiently usually lack in abstraction and have only simple data structures. (C, FORTRAN)

  • C++ with modern libraries is hardware efficient and has advanced data structures.

Sometimes easy portability to different operating systems and hardware is important:

  • Java has the advantage of being quite portable, including its graphical user interface, but is not that expressive compared to modern script languages and used to be no language that uses the hardware efficiently. However that might have changed due to compiler and VM optimizations. E.g. GeoGebra is a mathematics software that is implemented in Java, because of these advantages. Java is probably the most mainstream language today. (E.g. see this ranking).

There are languages which focus on mathematics:

  • Mathematica, Maple, Matlab or R are examples. Each has its strengths.

  • Julia seems to be a promising new language, but I have no experience with it.

Then the occasional surprise:

  • JavaScript. As native language of the web browser it became more and more important over the years. It is an unlikely recommendation regarding mathematics right now, but it might continue to surprise.

Finally you might want to broaden your understanding of programming:

  • The languages above usually follow the imperative programming paradigm, as structured or object oriented languages. However there are alternative approaches to programming, like

  • declarative programming, e.g. Prolog or

  • functional programming (e.g. Lisp, Haskell, Erlang, OCaml, F#).

They excel for certain problems and widen the understanding of programming. Their ideas have connections to logic and theory of computation.

1
On

I would have to recommend Python.

It should be easy enough to pick up the essentials, yet it has advanced mathmatical like features such as tuples, dictionaries.

And quite some interesting libraries that are easy to include, like itertools and numpy.

For instance, following python program solves the famous https://en.wikipedia.org/wiki/Eight_queens_puzzle: (maybe not in the most efficient way, but I think very mathmatically, with permutations and combinations)

import itertools

N = 8

for p in itertools.permutations(range(N)):
    if all(abs(p[b]-p[a]) != (b-a) for a,b in itertools.combinations(range(N), 2)):
        print (p)
9
On

I agree with @Pieter21 that python is your best bet now for general usefulness as a math major, and later on in advanced work in pure mathematics.

For a striking (mind-bending) overview of computation, I strongly recommend Abelson and Sussman's Structure and Interpretation of Computer Programs. You're not likely to use Scheme (a dialect of Lisp) for actual programming projects, but the philosophical content of the book is enlightening.

I don't know of any language that would be particularly useful for thinking about complexity theory.

I think learning C would be a mistake - lots of up front cost before you get to the parts that you care about.

1
On

As a second language for someone with a serious mathematical future, I might recommend AMS $\LaTeX$.

Much as being aware of category theory is useful, being aware of Haskell will be useful.

1
On

For your specific question, a language suited to mathematicians and to understanding computational complexity, I recommend a functional programming language, in particular Haskell or Scheme.

Haskell is a very elegant yet also practical functional programming. Inspired my mathematical notation, it has a very strong type system and a declarative style, reminiscent of mathematical reasoning. In specific with regards to your point of intersection between "a programming language for mathematicians" and "a programming language to understand computational complexity better", I would most strongly recommend Haskell.

Scheme is a dialect of Lisp, one of the oldest languages in existence today, which is inspired on $\lambda$-calculus. Very minimalist, very elegant, and I will almost guarantee you that understanding it will make you a better programmer and a better mathematician. If you want go down this route I recommend following The Little Schemer, an absolutely delightful book by Daniel P. Friedman and Matthias Felleisen.

0
On

I agree with andrepd. I suggest a functional programming language as well.

Standard ML is a very clean language and most beautiful with mathematics. For example, here's how you can construct natural numbers with Peano axioms

datatype n = zero | s of n;

(* Addition *)
infix ADD
fun a ADD zero  = a |
    a ADD (s(b))= s(a ADD b);

(* Multiplication *)
infix MUL
fun a MUL zero  = zero |
    a MUL (s(b))= a ADD (a MUL b); 

val one = s(zero);
val two = s(s(zero));

one ADD two; (* s(s(s(zero))) which is 3 *)
0
On

Depending on what you want to do, I would recommend different languages.

For understanding computational complexity and basic algorithms, python or C.

Python is beginner friendly, and have much better readability than C++ or Java. It's easy to write very clean algorithms with it's clean syntax. It's suitable for your first programming language.

For example, to exchange two integers:

In python:

x, y = y, x

In C/C++/Java

int t = x; x = y; y = t;

C is much older than python, however C is a simple language, with only a few keywords and no advanced OOP constructs. It's also suitable for experimenting with simple algorithms.

C++ is a superset of C which mainly added features for software engineering purpose. If you want to dig deeper into CS from a technical point, C++ or Java is also recommanded.

For learning pure mathematics, Wolfram Language (or widely known as Mathematica) is strongly recommended.

Mathematica was initially developed as a research tool for Mathematicians, however recently it introduced a lot of new functionalities on engineering and general computing.

Factor polynomials, solving differential equations, finding huge eigenvalues, simulating quantum effects, proving simple theorems, making interactive graphics ... you won't find many software can do all these at once. It's a symbolic programming language, which means it can handle exact mathematical expressions instead of just a numerical expression.

In[1]:= Integrate[ Sin[x^2], {x, 0, Infinity}]                                                                                                                          

             Pi
        Sqrt[--]
             2
Out[1]= --------
           2

It would require a lot effort to code that in C or python without external package.

Mathematica also features some syntax for functional programming so you can experiment with different programming paradigms.

For engineering oriented, python, matlab, R is recommended.

Mathematica is a bit short on Engineering because its slower execution and the only double precision support for dense matrices.

Yeah, I mentioned python again, because people have developed countless tools for numerical related usage.

  • numpy: a general array utility, for vectors, matrices, or higher order tensors

  • scipy: The sister of numpy, more useful tools and utilities for linear algebra, signal processing, statistics, image processing, and more ...

  • matplotlib: Plot scientific graphics

  • pandas, scikit-learn, sympy ... and more

MATLAB is developed from ground up for engineering purpose. (It's called MAT-LAB, which means it deal with numerical matrices) It has more dedicated tools for very specific tasks. I'm not a matlab user, so I can't give more info.

R is developed for statistics and data science. It gained substantial popularity in recent years. I'm not an R user, so I can't give more info.

0
On

Python: Consider Python. You may choose to start with simple projects, like a factoring program and a quadratic-equation solver. Thereafter you can create more complex projects once you’ve gotten the hang of things.From a mathematical and scientific standpoint probably the best part is the extensive amount of relevant libraries that are available

Haskell: Another programming language that is growing in popularity is Haskell. This page collects resources for using Haskell to do mathematics.Purely functional nature makes Haskell quite suitable for modeling mathematical problems.

J: The J programming language is most suited to mathematical and statistical programming, especially if you intend to perform operations on matrices

Coq: Coq is basically a theorem prover. Coq works within the theory of the calculus of inductive constructions. It allows the expression of mathematical assertions, mechanically checks proofs of these assertions, helps to find formal proofs, and extracts a certified program from the constructive proof of its formal specification.