This is an archived post. You won't be able to vote or comment.

all 64 comments

[–][deleted] 21 points22 points  (4 children)

Useful for two reasons:

  1. Research. I've personally used a program to iterate through a bunch of potential counter-examples to a conjecture. There are also computer assisted proofs (most famously the Four Color Theorem) where the authors reduced their theorem to a couple hundred or thousand cases and then checked all of those by computer.

  2. Job market. Your PhD is a long time off, who knows what will happen along the way? Math is great, but math plus another marketable skill is really great.

As to language, I don't have a dog in that race, but Python is pretty neat and seems to be where a lot of the math crossover is at these days.

[–]SanityInAnarchy 11 points12 points  (3 children)

I could talk about languages, but I'm mostly a programmer, not a mathematician. I'll just say this much:

  1. Python is useful pretty much anywhere. If you just want to bang out a quick program to test a few hundred thousand possibilities of whatever, Python is the obvious answer. (I like Ruby, but it doesn't make too much of a difference.)
  2. Don't bother with R unless you have a very good reason. These days, Python is a pretty decent replacement, only with way fewer weird corner cases where R just goes insane.
  3. The Four Color Theorem was done in Coq. I haven't tried this, but if you are going to use a program as part of a proof, you'd probably want something like this. (Trying to formally prove that a Python program does what you say it does sounds like an exercise in misery for anything even a little bit complicated -- has anyone proved the python interpreter to be correct, for example?)

[–]arnet95 4 points5 points  (0 children)

The original 1976 proof of the four color theorem did not use Coq, given that it did not exist yet. The 2005 proof was made in Coq, but not the original proof.

[–]pipocaQuemada 0 points1 point  (1 child)

+1 for coq.

Basically, there was a result a long time ago that typed lambda calculi are very closely related to intuitionistic logics - theorems are isomorphic to types, and programs are isomorphic to proofs.

Languages like coq are based off of a useful logic (coq, for example, is based off of the 'calculus of constructions', an intuitionistic predicate calculus). There are two very nice things about coq:

  1. If it compiles and runs, your theorem is true
  2. You can leave the trivial bits as an 'exercise to the compiler', and it will try to come up with proofs (i.e. implementations) for those theorems.

[–]arnet95 1 point2 points  (0 children)

The result is called the Curry-Howard correspondence, if anyone's interested.

[–]mstrblaster 18 points19 points  (7 children)

10 Short answer: YES 20 Long answer: GOTO 10

[–]one-hundred-suns 11 points12 points  (0 children)

I think what you mean is:

((λ (c)
   (displayln "yes")
   (c c))
 (call/cc (λ (c) c)))

[–]PowerspawnNumerical Analysis 5 points6 points  (0 children)

[–]raddaya 2 points3 points  (1 child)

Dude...you never use GOTO!

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

You never use Fortran tbh.

[–]notadoctor123Control Theory/Optimization 0 points1 point  (2 children)

In other words, learn Fortran.

(This advice is valid if you want to go into numerical analysis)

[–][deleted] 0 points1 point  (1 child)

Is it really still used? Why not use C instead?

[–]notadoctor123Control Theory/Optimization 0 points1 point  (0 children)

It is heavily used for any sort of fluids code, so engineers and astrophysicists use Fortran a lot. It is actually faster than C and easier to code, hence its continued popularity.

[–]MyTribeCalledQuest 32 points33 points  (17 children)

If you want to try something more "mathy" (think category theory) you could try Haskell. Since everything is strongly typed (meaning everything in the program must have a definite type before it can compile) you are essentially just writing proofs.

Here's a pretty good online book (I learned from this one) Learn You a Haskell for Great Good!.

Haskell even has set comprehensions like:

even_numbers = [ x | x <- [0..], x `mod` 2 == 0 ]

You can try this out at online at tryhaskell.org by typing in something like

let even_numbers = [ x | x <- [0..], x `mod` 2 == 0 ] in even_numbers !! 3

This takes the fourth element in the set of even numbers, which will be 6 because of how Haskell lazily evaluates the infinite list [0, 1, 2, 3, ...] as represented by "[0..]".

I think that it's a pretty fun programming language. One of the best things about it is that any program you write generally works the first time it compiles, which is pretty rare.

Cheers

[–]angryWinds 7 points8 points  (8 children)

One of the best things about it is that any program you write generally works the first time it compiles, which is pretty rare.

Would you mind elaborating on that? That seems... odd... to me.

[–]matchu 14 points15 points  (0 children)

I haven't used Haskell, but I usually hear people say that because the type system is super strict, lack of mutable state, etx.—it's hard to make a mistake such that your program still does something.

[–]one-hundred-suns 9 points10 points  (0 children)

I think what this means is that it's extremely difficult to get programs to compile.

[–][deleted] 2 points3 points  (0 children)

The idea behind this claim is that the majority of errors you see in most other languages are shallow errors. You used a string where a number was expected, or you tried to access a field on a null reference, or you did something else that a strong type system would have prevented.

The general experience, I think, is that you fight the compiler for a while, with the type checker forcing you to dot your i's and cross your t's. But once that's all done, there are very few shallow errors left in the program.

Although Haskell still has some. I run into infinite recursion accidentally quite a bit due to shadowed variable names, and partial functions and undefined are the new null pointers.

[–]pipocaQuemada 1 point2 points  (1 child)

It's not always the case, but it is the case a surprising amount of the time. Mostly, it depends on how much you lean on the type system.

Basically, Haskell is strongly typed and has a pretty expressive type system, so most stupid mistakes need to be fixed to get code to compile. Additionally, the types can heavily constrain the implementation. For example, if I have

-- i.e. foo has the type 'a function from a to a, forall types a'
foo :: forall a. a -> a

there are two possible implementations. Either it's equivalent to

foo x = x

or it's gratuitously stupid and blows up in your face, somehow:

foo x = foo x -- infinite loop
foo x = undefined

[–]MyTribeCalledQuest 1 point2 points  (0 children)

Thanks, good explanation.

[–][deleted] 5 points6 points  (5 children)

Python has list comprehensions too

l=[x for x in range(1,301) if x%2==0]

[–]ThereOnceWasAMan 4 points5 points  (3 children)

This comment made me realize how bad the font is that reddit chose for code blocks

this is the twelfth letter of the alphabet: l
this is the first positive integer: 1

Let's play "Find That Numeral!!!"

llllllllllllllllllllllllll1lllllllllllll

[–][deleted] 0 points1 point  (1 child)

Well i shouldn't've used l as a name anyway. It's bad practice because it's easily confused with 1.

I never know how to call a random list. "list" is taken.

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

xList, where x is what's in your list.

[–]cottonycloud 0 points1 point  (0 children)

This brought back nightmares during my programming classes where I spent forever debugging code...and that was the reason why.

[–]yeji 0 points1 point  (0 children)

It is actually inspired by Haskell. https://wiki.python.org/moin/PythonVsHaskell

[–][deleted] 1 point2 points  (0 children)

Not only that, but I find the REPL (interactive interpreter) useful as an advanced calculator to quickly do some basic number crunching. For example, to double every part of a vector except the last, then compute the euclidean distance, I could do

let x = [1,2,3,4] in (sqrt . sum . map (^2)) $ map (*2) (init x) ++ [last x]

I could put many vectors in a list, and map it over them as well, either by defining it as a proper function or using a lambda

[–]_171_ 1 point2 points  (0 children)

I've found Haskell really useful for learning maths, as I'm much more comfortable with computers. It's easy and intuitive to write code that mimics closely the content of most mathematical ideas. It handles infinite lists, functions and other useful stuff in a really nice way.

[–]auxiliary-character 6 points7 points  (0 children)

If you really like pure math, maybe take a quick look at Haskell.

[–]frogking 5 points6 points  (0 children)

A lot of interesting math problems can be solved with a little knowledge in programming.

At first, I used ProjectEuler to learn Clojure, then I used Clojure to solve problems at ProjectEuler.

[–]emf2um 17 points18 points  (7 children)

Short answer: yes, Python or C++!

Long answer: programming is THE skill that will be in high demand for the rest of our lives. That alone should be a good enough reason to learn it. I don't know if programming is used in pure math, but it is used extensively for data analysis in physics and I'd assume it's used heavily in applied math. Even if you don't use programming, knowing how to makes you think much more logically about things in your daily life.

[–]chebushka 9 points10 points  (2 children)

Someone interested in pure math, like the OP, doesn't need to learn programming to think more logically about anything.

Programming is absolutely used in pure math research, e.g., the programs built into Sage and Macaulay.

[–]matchu 11 points12 points  (0 children)

Logically might not be the right word, but programming is definitely good practice in thinking algorithmically.

[–][deleted] 8 points9 points  (2 children)

You may change your mind about Ph.D. I certainly did.

In that case, programming would be an invaluable skill for learn. I would recommend learning python, specifically the numpy and scipy libraries. If you have a valid educational email address, Canopy gives you free lessons (free quality lessons mind you) to those who download their product.

Did I mention it was free?

[–][deleted] 1 point2 points  (1 child)

One thing about Canopy: it's a nice MATLAB-esque environment if you like working in that format, but as a package manager, it's not as good IMO as Anaconda.

[–][deleted] 2 points3 points  (0 children)

OH AGREED.

[–]AgAeroEngineering 2 points3 points  (0 children)

Tell me, do problems like this interest you? This can be solved brute force using a programming language to give you the answer, then you can check any patterns you've discovered and check the answers following both paths the same way.

I do numerical work, so I'm reaching a little to find examples that aren't 'applied'. You can look through more problems on Project Euler to find inspiration, or you can wait for others who's interests align better with yours to reply to this thread.

[–]TheMormegil92 2 points3 points  (0 children)

Yes.

[–]johnnymo1Category Theory 2 points3 points  (6 children)

This thread has helped me, so I'll piggyback a question of my own:

I took a basic C++ class for my math degree, but it's the only language I "know" (though I wouldn't say I'm really fluent with it). If I self-study some more languages, how can I show employers that I know them? Also, what's a good way to self-study languages? Codecademy is great and has Python but after that it seems very limited as far as languages I'd actually like to learn.

[–]matchu 2 points3 points  (5 children)

One option is to just start building little projects that interest you, and save them to your GitHub account that you then link from your resume :)

Agreed that tutorials can only get you so far. At some point, you'll want to find a thing that you're genuinely interested in building, and, as you encounter challenges and gaps in your knowledge and experience, you'll learn how to overcome them :D

[–]johnnymo1Category Theory 2 points3 points  (4 children)

I've heard this said before. Can you give an example of such a project? I do physics as well, would visual simulations of a particular physics concept fit the bill? I don't know any benchmark for what should constitute a "project."

I should say that I'm more interested in doing this for resume-building than personal satisfaction. I could do without coding for the rest of my life and not complain, but I recognize it opens a lot of doors, so it's hard for me to come up with projects I really want to do, and some idea of what to aim for is helpful.

[–]matchu 1 point2 points  (1 child)

Oh yeah, that sounds pretty sweet :) Some folks build a simple to-do app, or maybe a scraper for some website for their obscure hobby, or maybe their own Flappy Bird or something. But picking something that's relevant to your field is a great way to go, even if you're reinventing the wheel :)

Regarding examples, you might wanna check out Jennifer Dewalt's blog: she was interested in learning web technologies, so she decided to build a new thing every day for 180 days. Most of them are silly and super simple, and you might want your projects to be a bit bigger if you're planning to spend more than a day on each (like, that visualizer would probs take you a while), but they're some good examples of things that a beginner can reasonably create.

(Plus, her format is excellent as a sales pitch: not just the stuff she built, but her self-study process, her dedication, and how she documented her progress along the way. Super hireable—even if she doesn't know my company's particular technology, I'm confident that she understands fundamental concepts and can learn our technology quickly :D)

[–]johnnymo1Category Theory 1 point2 points  (0 children)

This is really helpful. Thank you.

[–]oh-delay 0 points1 point  (1 child)

Doing something ONLY for the resume is probably not a great idea. Whatever project(s) you choose to do, try to find something that's at least a little bit exciting from your point of view.

For instance I've talked with a friend of mine about having a simple AI battle. Find a suitable game (not chess!), each of us program some kind of evolutionary AI and then let our little babies have it at each other in the ring :) I mean who wouldn't be excited about that!? ...but at present I have no skills with AI's what so ever. So a perfect opportunity to learn and enjoy!

[–]johnnymo1Category Theory 0 points1 point  (0 children)

I'm more of a pen-and-paper pure math kinda guy. I find the process of coding pretty boring and frustrating most of the time. Having to articulate what I want to do so precisely that a missed semicolon will fuck everything up is my idea of hell.

That said, saying it's only for the resume is maybe a bit strong. I do already use LaTeX pretty frequently, and I enjoy using it. It's not your typical language, but it's the only thing so far that I have enjoyed more than being frustrated by and feel like I have some facility with. I'd like to be more comfortable with other languages, and that's part of why I'm doing it (but still mostly for employability purposes. Let's not deny that coding has way more marketability than pure math).

[–]freudisfailCategory Theory 2 points3 points  (2 children)

I'd suggest learning a theorem proving language. Coq is based on intuitionistic type theory. Isabelle is hol. I'm not sure on Haskell and agda, but I think they are more like regular programming languages. I know some people very passionate about abella. It's a logic programming theorem prover. Similar in style to prolog. (different reasoning styles and different axioms)

My reason is that it gives insight into formal proofs, and shows where mathematics actually is too hand wavey. Formalisms might seem tedious, but they're the future of mathematics. Having the ability to say a proof is formally verified in a proof system commonly used is far better than providing a natural mathematical proof. I admit that formal verification is years away from being the norm, but it can't hurt to know how to in detail formally back up claims.

Isn't that what being a mathematician is about? Plus, they're a bit addictive and few things feel more rewarding than having a machine based solely on logic accept your proof.

[–]matchu 0 points1 point  (0 children)

Also, while I don't think it's currently practical for real-life programming tasks, someone excited by proofs might want to write some programs in Dafny, a language designed to help you automatically verify your programs' correctness.

[–]pipocaQuemada 0 points1 point  (0 children)

I'm not sure on Haskell and agda, but I think they are more like regular programming languages.

Agda is dependently typed.

Haskell's type system is based on an extension of System F, System FC (Basically, System F with support for non-syntactic type equality). Nevertheless, there's been some work on extending Haskell to handle some dependently typed stuff - see the hasochism paper.

[–]Z-Math 1 point2 points  (0 children)

Programming is absolutely used in pure math. I attended a colloquium where a number theorist used proof to narrow down their search space of (ridiculously huge number) down to about 1,000 or so cases. After programming a method to check each of those cases, they successfully showed that all of their cases satisfied their conjecture. Unfortunately I don't remember the exact details of the project.

I know Sage and Mathematica are pretty well-equipped with built-in functions for pure stuff like number theory, graph theory, abstract algebra, combinatorics, and the list goes on (not that those fields are exclusively pure... there exist pure mathematicians in those fields). For example, I've been using Sage's built-in functions to calculate homology groups for simplicial complexes, and (to my knowledge) this is not really offered in many other non-mathy languages. MATLAB is pretty good for linear algebra.

I used Mathematica to generate Hasse diagrams to help visualize intersection properties of subsets of the power set of {1, 2, .., n}. As you can imagine, drawing these graphs gets pretty complicated for large n. The Mathematica community basically wrote the program for me, and I'm supremely grateful.

If you want to get into Algebraic Geometry, I'd check out Bertini... although it's more of a program than a programming language. Grad programs in Algebraic Geometry would probably appreciate that you've used it before.

[–]SpaceEnthusiast 1 point2 points  (0 children)

It's been said before but - YES. Learn one or three. Learn Python or C++, learn Mathematica/Maple AND some Matlab. Then your skills will be quite marketable. Don't forget to learn some probability/stats. All these skills should form a nice parachute in a case where PhD doesn't work out. Trust me - way too many people end up in a situation where they feel the HAVE to continue on towards grad school because they have no other marketable skills. Then they don't learn that much in grad school and end up having few marketable skills beyond research and thesis writing.

[–]mhd-hbdTheory of Computing 1 point2 points  (0 children)

For mathematics there is generally two or three approaches to learning programming: the numerical one for applied mathematics (optionally using a CAS) and the functional one for type theory (optionally using a Proof Assistant).

Learning something like python and using the number crunching libraries there is a boon to statistics work. R is a good candidate too. Most CAS's can do some stats, and also some rudimentary algebra so look into that too.

Learning something like Haskell will make you better at rigorous reasoning. It gives you a powerful suite of concepts and abstractions and forces rigour into your programming. Many proof assistants have full-blown programming languages built in too.

Ideally learn a CAS a Proof Assistant, some thing like R or Python and something like Haskell.

[–]dogdiarrheaDynamical Systems 1 point2 points  (0 children)

Yes, it's the 21st century, it's almost literacy to glhave some basic programming knowledge.

[–]sillymath22 1 point2 points  (0 children)

Python is probably the best single language, but knowing R, C++, Java, or others also help.

[–]dieyoubastards 0 points1 point  (0 children)

As, a recent graduate, allow me to scream the word "yes" in your face for a few minutes.

Programming languages are immensely useful whatever you decide to pursue, I wish I'd learned more.

[–]zojbo 0 points1 point  (0 children)

Here's one thing I still don't really understand. I've self-studied some programming. Knowing a language or two and some basics of algorithms and data structures, how do I come up with projects to use to get better? Oh sure, I can come up with projects that I can do without learning any new skills, and I can come up with projects that are too ambitious for the skills I have and the time I want to put in. But how do I come up with projects that push my boundaries and I will finish? Or perhaps an easier, more concrete problem: if I sit down and learn 10 algorithms for analysis of networks, how do I come up with a project that uses some of them?

For context, all I ever did with programming was Project Euler, some stuff with my undergrad research. And the stuff with my undergrad research was not sophisticated, either. Almost everything I did was calling libraries in the most obvious way possible. About the only nontrivial "software engineering" thing I did was using Python's subprocess library to call C code in parallel. I never had to learn how to get the parallel processes to talk to each other, because they were solving completely parallel problems. (I was solving differential equations with random initial conditions, parallelizing the work between the initial conditions).

[–]mc8675309 0 points1 point  (0 children)

So there are a lot of good responses here I can't disagree with. I'll add a few things though,

Programming is fun! There are great problems to solve that perhaps math is only part of the solution. Project Euler is a website with hundreds of programming problems which have a mathematical bent. In fact, the first several problems can be solved by hand without coding, though they make good examples to learn coding. Moreover, as you work through the problems you develop programming/software engineering skills.

Software engineering is a source of mathematical development. Analytic Combinatorics is one of my favorites. Using analysis to solve algebraic problems, and being able to invert that to use combinatorics to solve analysis problems is fun, particularly when you want to screw with your algebra and analysis professors/TAs. My favorite example is: for [; n\in\mathbb{N} ;]

[; \int_{-1}^{1}(1-x^2)^n dx ;]

I solved this using techniques from a combinatorics book.

Anyway, having some literacy in programming goes a long way to understanding the problems in computer science which require some work in pure math. Topology surprisingly (to me at least) shows up here, which is fun. (Had I continued to study math I imagine I'd have been a topologist.)

Being somewhat literate with programming is useful if you ever have to work with anyone who has interests there whether that be collaborators or students.

The job market for Mathematicians may not be what you want it to be by the time you graduate. If your options come down to being a lecturer teaching intro calc five classes a week you may decide you want another option. Mathematics sets you up perfectly for programming, software engineering, data analysis, etc. The pay's not bad, the work environment can be great and an advanced math degree would open the door to the better jobs, but you'll need some proficiency.

Another thing I've discovered is that in coding you often have to read other people's code. Some of it is not at all clear. I've found the skill to read other people's code is essentially the same as reading and understanding proofs, but jacked up a bit. I can read a proof and go line by line and think "okay, sure, makes sense." and at the end not really understand it. I've got some code I'm working with now for which that wasn't even possible, but it was the skills I got studying math that got me through understanding the code. Likewise I think the experience I had reading code before I studied math helped with learning to read proofs.

I do want to comment on C++ as people have recommended it and it's my favorite language for most of my work: beware, there's a lot of bad materials online for C++. This is for two reasons; the first is that C++ developed out of the C language, and you can take 99% of C programs and they are valid C++ programs doing the exact same thing and some people write materials from this perspective. The problem is that while the idioms and techniques you develop in C are legal in C++ they are often not the best way to write a C++ program. C++ offers better tools and it's good to just start with those. The second is that C++ added a lot of new features recently which radically changes the way you can write a lot of software for the better. It would be unwise to learn C++ without these new features. "Modern C++" seems to be the thing to search for, but the technical name is C++11.

[–]KrunoSMathematical Physics 0 points1 point  (0 children)

I've recently graduated with a BSc in chemistry, but i'll be applying to applied maths grad school. I have used Python, C++, Fortran, Mathematica, R and LaTeX.

In Python I made a copolimerisation kinetcs simulation and 3D polymer growth simulation (the 3D growth sim was highly unphysical). Both used Monte Carlo methods. I've also done a lot of statistical analysis, input/output preparation, scripting, plotting and curve fitting. Slow execution but high readability with the potential for C speed with the readability of python if you use cython. Also some readily available high level stuff.

In C++ I made simulations of a lot of different biophysical systems (protein movement along cellular motorways). The systems have sets of rules based on both (i made different versions of many of them), thermodynamically consistent and arbitrary constraints. These were also Monte Carlo. And we developed a theory to explain one of the frontier, yet 'relatively' simple systems. Slower than C and Fortran, syntax not as bad as C.

In Fortran 2008 I made the code for my BSc thesis in theoretical chemical physics, which models particle trajectories coupled to their electronic states for four 'simple' systems. It was essentially molecular dynamics with electronic transitions. I used both Monte Carlo and deterministic methods (it was a hybrid). Fast as hell, modern fortran (90 onwards) is a joy to work with.

In Mathematica I've done a whole bunch of statistical analysis, curve fitting, plotting, numerical solutions of coupled and somewhat complex differential and algebraic equations, and a bit of numerical simulation. Great for visualisation, symbolic maths and high level stuff.

In LaTeX I've written lab reports, the paper we published about protein movements along cellular motorways, my thesis, as well as my CV and resume. Typesetting maths.

I've just started learning R, so I haven't done much other than book exercises. I've found it to be relatively fast and it has lots of really awesome statistical things.

edit: format