“Hello World!”

As anyone who has been following the discussion of EDP will be aware, I am interested in programming, but have until very recently favoured an extremely high-level language called BLOG. The principle of this language is that you describe in English in a blog post or comment what you want an algorithm to do, after which a probabilistic process operates. At the end of this process, if you are lucky, your description gets translated into a language that a computer can understand and the algorithm is implemented. The amazing thing is that one often is lucky. I believe that BLOG is closely related to a language called GRADSTUDENT that various mathematicians have used in the past. (My attention was drawn to the latter language on some blog or other, possibly even this one, but I can no longer find the reference.) [It has now been supplied to me.]

However, BLOG and GRADSTUDENT have certain disadvantages. One is that one does not have complete control over what one is doing. Another is that one feels slightly guilty using it. I have recently decided that it is high time I learnt to program in a more traditional language, and last week I went to a short course put on by the Cambridge computer science faculty called “C for absolute beginners”.

I’m sure a significant percentage of people reading that last sentence will react by thinking that C was not the right language to choose, so let me defend the choice. One reason for it was that that happened to be the course that I could get to. Another is that C is a very standard language. And yet another is that I am not necessarily looking at this stage for the perfect language for my needs. In fact, I don’t even know quite what my needs are. Rather, I just want to learn some language, after which it should be easy to adapt to another one (though I have heard the view expressed that if you learn C then it gets you into bad habits that you have to get out of if you want to get good at an object-oriented language such as C++).

It’s not quite true to say that I am an absolute beginner, because about thirty years ago I used to be able to write simple programs in BASIC. In a funny way, that experience has made it harder to get to grips with C and similar languages, because in BASIC you didn’t have to do weird things at the beginning of a program such as writing #include <stdio.h> at the beginning of a program, or defining a function called “main” that had nothing to do with what you were trying to do. (OK, you could argue that main is precisely what you are trying to do, but the fact remains that in BASIC you can just get down to the program without these preliminaries.) I finally lost my fear of the #include <stdio.h> line when the course instructor said that the “h” stands for “header”. I then thought to myself of how I don’t understand the beginnings of the LaTeX files I write (because at some stage in the past I copied them from someone else) and it doesn’t matter. So now I think of that first line as putting some useful stuff at the beginning of the file that I don’t actually have to think about. And from what I understand, that is the right way to think of it, at least for a beginner.

In a way, what I most wanted to do was learn how to write, compile and run any program at all. It seemed to be a big barrier to get the computer to do anything. And the main thing I’ve got out of the course is to lose my fear of that barrier. (Needless to say, it doesn’t seem quite such a barrier now that I’m the other side of it.) I got back to my office and as a quick test I wrote, without referring to the booklet we were given, a program to input two numbers and output their sum. And it worked!

Annoyingly, I can’t seem to get C to work on my laptop (a Mac). From the internet I worked out that I needed to download something called Xcode, which I did, but then it wouldn’t instal because I have OS 5 point something rather than OS 6 point something. But surely one doesn’t need the most up-to-date Mac operating system just to run C. (Incidentally, before that I tried just tying the commands cc and gcc into a unix terminal, but they were not recognised.) Another problem I have on a Mac is that it doesn’t like me creating files with the extension .c. None of this is a problem in my office, where I have Linux installed in a straightforward way. (I know I’ve got Linux on my Mac too, but as I say, it doesn’t seem to come with C as standard.)

I should perhaps add that I’ve attempted to understand C and C++ in the past, and although I didn’t manage, it was a big help this time round that I had seen at least some of it before. Here’s another example of something that seems weirdly complicated to someone brought up on BASIC. In BASIC, I seem to remember there was a command called “input”. If you were writing a program to add two numbers, it would be something like this (but I can’t remember exactly what it would be): print “What is X?”; input X; print “What is Y?”; input Y; Z := X+Y; print “The sum is”; print Z. But with C and scanf it feels more complicated somehow. Perhaps it’s just the declaration of all the variables and their types that feels complicated, though I think I could get to like heavily typed languages.

I don’t know where this is going to lead. It already felt pretty complicated when we learnt about file handling (things like processing the data from one file and copying it into another), and we didn’t get on to how one might plot graphs — so I probably can’t yet do anything useful for EDP. But it’s a little start, and something I should have done years ago.

84 Responses to ““Hello World!””

  1. Robert Says:


    My PhD advisor was a computer scientist. But even though his research involved algorithms, he was amusingly incapable of programming in any language besides GRADSTUDENT (his research interests were mostly theoretical).

    He could never tell if a program I wrote took 2 hours or 2 weeks … so sometimes it was awfully easy to impress him.

  2. Américo Tavares Says:

    I am trying to learn Python. So far I wrote only two programs: the first computes the date of Easter Sunday and the second displays a list of prime numbers based on a script by Alec Edgington in this comment


    in reply to a comment of yours


    I modified the Python script by Alec Edgington in order to display only the primes.

  3. Blair Says:

    C is nice if you want to write very fast programs but otherwise I would suggest you start off with something much easier and more useful like Python.


    One very nice library/tool you can interface with Python is Sage Math. It is very programmable and is the free opensource equivalent of Mathematica/Maple. It can output nice Latex for you too.


  4. H Says:

    Haskell is a lazy functional programming language. There is a very nice post http://blog.sigfpe.com/2006/01/eleven-reasons-to-use-haskell-as.html on some of the ways Haskell appeals to mathematicians.

  5. Sakura-Chan Says:

    Hi Tim. Welcome to the programming world. There’s nothing wrong with using C/C++ to do experimental mathematics. Depending on your needs though, you might get more bang for your buck learning Mathematica or Matlab scripts first, then transitioning to C++.

  6. Stephen Says:

    I too have used (and been used as) GRADSTUDENT which was an unsatisfactory hands-off experience. On http://www.dpmms.cam.ac.uk/Computing/mathematics.html there is a list of “maths” languages available to you locally. Casting my eye down the list I see Mathematica which is a one-stop shop for all your technical computing needs. With Mathematica I find that I can do everything I need to very quickly. Optionally, you can link Mathematica to code written in C, but I would do that only if I happened to have the C code already written, or in extremis if there was a clever code optimisation that I could do only in a language like C.

  7. Rune Says:

    I also started with BASIC, but over the years I’ve learnt C++, Java, Pascal, etc. I can say, without a doubt, that BASIC is still my favourite programming language. It’s not powerful or fast, but it’s fun and easy. But if you want to do serious number crunching for projects like EDP, I guess C is a good choice due to its great speed and availability of libraries.

    I’d also like to second the comment which said you get more bang for the buck learning MATLAB or Mathematica. Vectors and matrices are so enjoyable in MATLAB, as opposed to C, where it’s a nightmare.

  8. Boris Says:

    You may have seen the graduate student joke here: http://mathoverflow.net/questions/11084/what-programming-languages-do-mathematicians-use/11135#11135

  9. porton Says:

    Gowers, you want a programming language for your needs but you don’t know what’s your needs?

    I think, your needs is to write high-speed mathematical algorithms (for lower speed algs you’d use Mathematica, MatLab, or some their free analog).

    At my opinion, the best language for writing high-speed mathematical algorithms is Ada 95. In simple words, it features debug (slow) mode and production mode (practically as fast as C/C++). Ada 95 is an object oriented language and have all features expected for a modern programming language.

    Well, Ada 95 is not a simple language to learn (however C++ is even harder). But if you want to become a programmer it is definitely worth to learn Ada.

    • porton Says:

      Read an Ada tutorial. After this you may (optionally) read Ada 95 Reference Manual for deeper acquaintance with Ada.

      If you need speed, chose Ada (that is better than C or C++). Otherwise Python (or maybe Ruby which I don’t know) are comparatively good choice. Python is simpler to learn than Ada.

    • porton Says:

      Another reason to use Ada: Ada provides features for the computer to catch some kinds of typical human errors.

      It is specifically important for mathematical programming as in this field we are sometimes unable to check an algorithm by testing it but instead need to prove its correctness mathematically (just like as we check correctness of a paper and pen calculations manually).

      This and some other features makes Ada superior for mathematical programming.

  10. Kevin Reid Says:

    C is a very low-level language, which is nice when you want to write algorithmic code and know exactly what you’re paying for, but the IO operations are often more clunky than you’d like. Of course libraries can provide higher-level operations. C++ has slightly more abstract input by default; you can write “int x; cin >> x;” and you’ve read an integer.

    (though I have heard the view expressed that if you learn C then it gets you into bad habits that you have to get out of if you want to get good at an object-oriented language such as C++).” I would consider C and C++ to be essentially the same thing from a larger perspective. I would not recommend any beginning programmer learning C++; it has too much unnecessary complexity (above and beyond C). If you want to learn more than one language (a good idea; it will help you program better even in your original language), I recommend much more distinct languages, such as Python, Java-or-C#, and Haskell.

    I highly recommend learning Haskell, but I don’t know what it would be like starting from from a mathematical-and-some-programming rather than a programming-and-some-mathematical background as I did.

    I know C better than I know LaTeX, but I’d say that #include is pretty much the same thing as \usepackage.

    Almost all “scripting” languages (a term which is the subject of much debate which I won’t get into here) allow you to just write a program with no prelude and without defining a main() first.

    Think of main() as existing because, at the top level of the program, you’re writing a bunch of declarations, not a procedure. The advantage of this perspective, for some purposes, is that the existence of other functions is a static fact about the program; whereas in the other style, the procedure says “create a function named fib(n) which does this; THEN call fib(10) and print it” — which is less amenable to some useful manipulations because the collection of declarations is not obviously constant without more elaborate analysis of the program.

    But surely one doesn’t need the most up-to-date Mac operating system just to run C.” Well, no, but the big Xcode Tools bundle is OS-version-dependent; you need to install the older version to match your OS. If you’re running the major OS version your Mac came with, then there is a compatible version of Xcode on your system install DVDs.

    Another problem I have on a Mac is that it doesn’t like me creating files with the extension .c.” This is a problem with your text editor. If you’re using TextEdit you can turn off “If no extension is provided, use .txt” in the save dialog; but once you have Xcode Tools installed you can edit .c files with Xcode (even outside of an Xcode project) and get benefits such as syntax highlighting. There are many other editors you could use, too.

    I think I’m done rambling. Feel free to contact me if you’d like more info on any of this or my own perspective on programming or how to get started on a Mac or …

  11. Michael Nielsen Says:

    python is a nice language that’s intermediate between GRADSTUDENT and C in ease of use. Some afficianados claim that with practice it can become much easier than GRADSTUDENT. It’s certainly much easier than C (and easier than BASIC, too).

    Heaps depends on what you’re aiming to do, of course. There are specific problems for which I’d prefer to use C (which I’d need first to learn properly) or ruby or some other language. But as an all-round programming language python seems to hit a pretty sweet spot. With the scipy extension, it makes a lot of scientific programming (including making graphs) very easy. There’s a great free introduction to python online, “Dive Into Python”, by Mark Pilgrim.

    All that said, choice of programming language is a never-ending religious war. Picking something and learning it reasonably well seems like a good strategy.

    • Américo Tavares Says:

      I agree with your view that Python is easier than C.

      Here you find an almost bilingual post in Portuguese and English with a very simple program in Python and it is my opinion that if you compare it with this C version by Renan it is easier to read (at least for those who don’t know very much of C, but do know Basic and Fortran, for instance.)

    • Anonymous Says:

      I agree with : “Picking something and learning it reasonably well seems like a good strategy”

      You can invest a lot of time learning a language and there is always a feeling that maybe your efforts could have been directed toward more positive ends.

      If you choose to learn C, there probably isn’t a better book than Kernigan and Ritchie’s “the C programming language” – a very clean and concise description of the language which doesn’t take very long to read.

      As others have pointed out, there is a wealth of highly optimised numerics code written in C (diagonalization of matrices, etc.) that is freely available from the gnu software project (along with bound volumes of the documentation for a small charge).

      A working knowledge of C also makes it easier to learn C++ which is a far more flexible language.
      However, C++ is also a much larger investment in time. For myself, it took me a few years before I started to get my head around the language (where I didn’t always wonder if there might be some far better way to write my particular bit of code).

      To learn C++, there are two excellent books written by the creator of C++ (B. Stroustrup). The books are thick but don’t be put off by this – the author devotes quite a lot of space to explaining how the language works, and provides you with many different examples of how to write the same piece of code (which you will appreciate later).

      Finally, you may hear somewhere down the road that C++ is an inherently ‘slower’ language than C or Fortran. I don’t think this has been borne out over time, and if I had to learn C++ all over again, I would have liked it if someone had suggested to me the eye opening little book by Bulka and Mayhew (“Efficient C++: performance programming techniques”).

      As far as graphics go, a lot of people seem to be using the ace graphics program (I think it’s called ‘xmgrace’) which is also free, and practically self explanatory (I have the mac version). The gnu project distributes a simpler graphics program called gnuplot.

    • conformal Says:

      Showdown; identical algorithm, C versus C++: The 3% difference in C++’s favour was a surprise – it was a consistent, although small win over all the runs. http://unthought.net/c++/c_vs_c++.html

  12. Juliette Culver Says:

    I first heard about the programming language GRADSTUDENT in the late 90s in the context of Bryan Birch claiming it was his favourite programming language, if I recall correctly.

    C does sound like a strange starting language choice to me as it has a much steeper learning curve than many other languages (including getting it up and running on your computer!) and is much slower to program in generally if you don’t need the performance benefits. Python is the language I recommend for relative beginners these days, but I don’t do mathematically-related programming these days so there may be better languages suited for that.

  13. Stephen Says:

    It is often claimed that Mathematica is slow, but I find that if you use the style of programming that suits it best (i.e. functional, not procedural like C) then it runs fast. I last checked this speed issue for numerical matrix-vector type computations about 6-7 years ago (Mathematica 5), and Mathematica was about a factor of 3 slower than C back then. A factor of 3 is not too bad, and I assume it has gotten better since then (version 7 now). On the other hand, if you program Mathematica in the style of C (e.g. “for” loops, etc) then it will run very slowly.

  14. mobathome Says:

    If you know and use LaTeX, you already program and compile.

    In the 70s and 80s, BASIC was assembler without all the features.

    One question is: interpreter or compiler? Maple gives me both. There are interpreters for C, such as “Interactive C” at http://www.botball.org/ic.

    Remember to learn at last Fortran 90 or APL.

    Some languages allow non-deterministic programs.

  15. Chris Johnson Says:

    Some links here http://www.mac-forums.com/forums/os-x-darwin-development/165766-xcode-leopard.html for downloading the most recent version of XCode that runs on Mac OS 10.5. Annoyingly, gcc isn’t installed by default on Macs – it’s packaged up with XCode, so will only work in the Mac terminal once that is installed.

    Installing gcc on the linux side of your laptop should be simple and quick if you have root access (e.g. “sudo apt-get install gcc build-essential” will install it on the Ubuntu distribution).

  16. Lior Says:

    Regarding “input” commands:

    Since C++ includes C, any a valid C program is also a valid C++ program. So you can just run g++ instead of gcc to compile even if there are no C++ features in your code. Also, you can add C++ constructs to your C program even if you aren’t using any of the object-oriented parts.

    Specifically, if you want a more intuitive input function, add the following incantation to the top of your file:


    After than, you can do output (x,y are variables, endl is a builtin giving you a newline):

    cout << "The value of x is:";
    cout << x;
    cout << newline;
    cout << "The value of y is:" << y <> “Please input x:”;
    cin << x;

  17. Lior Says:

    It seems that wordpress ate my angled brackets. Let’s try again:

    #include <iostream>

  18. Thomas Sauvaget Says:

    Tim, in the course of EDP I had written a little tutorial on how to install Xcode, including the version your laptop requires. But since you couldn’t, perhaps the tutorial wasn’t clear enough (or you didn’t notice it)? Please feel free to ask questions I’ll do my best to resolves issues, I was really hoping it would be useful to you in particular (by sheer luck I’m able to access a mac today, until tomorrow morning, so would be able to investigate things).

    • gowers Says:

      The truth is that at the time I didn’t need it. Now that I do, thanks for reminding me and I’ll go back and see how I get on with the tutorial.

    • gowers Says:

      Right, I’ve now got C installed, thanks to your tutorial, and I am much closer than I’ve ever been to getting it to work. However, I haven’t got there. I tried once again writing a program to add two numbers (integers) together. I wrote it into a folder called Documents/programs. It compiled with no problem. I then ran it. As it was supposed to, it said “First number is “. I typed in the first number, feeling pretty good by this point. And then it said “Bus error”. Wikipedia gives me a vague idea of what a bus error is, but with a program this simple I haven’t the slightest idea what could have caused it. Perhaps it would help if I said what the program was.

      #include <stdio.h>

      int main() {

      int first = 0;
      int second = 0;
      int sum;

      printf(“First number is “);
      scanf(“%d”, first);

      Ah, that was useful. I now realize there should have been an ampersand before “first” in that last line. (But my understanding of why is still rather hazy. Something to do with pointing to a location — the kind of thing I never had to worry about with BASIC.)

      Right — got it to work. Many thanks Thomas.

    • Thomas Sauvaget Says:

      You’re welcome. Now as others have said, Python & Sage is much better suited to your needs, it does a lot off-the -box including graphics and numerics, and it has great tutorials. I strongly recommend learning that too since serious numerics in C/C++ is quite off-putting.

      That said a tiny knowledge of C, and obtaining GCC on your mac as you just did, is worthwile anyway: (1) you’ll be able later on to compile and run useful non-Sage stand-alone applications written in C by other people, which is quite common; (2) and importantly be able to create, modify and compile source code of specific numerically-intensive functions (written by you or other folks) in C or C++, again something quite common, so as to get a fast binary that can then either be run on a terminal or be called within Sage, rather than do a much slower Python loop within Sage.

    • Fredrik Says:

      There are a couple of general guidelines which will catch bugs of this kind at compile time.

      * Turn on warnings. I haven’t used Xcode myself, so I don’t know how to do it in that particular environment. But for gcc you should use the -Wall flag when you compile your code.

      * Read the output from the compiler and learn how to interpret it.

      * Make sure that your code compiles without warnings. This one is quite important because if your code normally compiles without warnings and you suddenly get a warning, then you know that something suspicious is going on.

      In short: make sure that your compiler emits useful warnings and take time to read the output from the compiler.

      When I compile your program on my machine I get:

      $ gcc -Wall add.c
      add.c: In function ‘main’:
      add.c:9: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’

      (I actually don’t need the -Wall flag for this example, I get the warning without it as well. But -Wall turns on some additional warnings which are nice to have.)

      The “add.c:9: warning: …” line may be a bit cryptic at first, but it at least tells you that there probably is some problem with the code. In this case, as you have already found out, you need to use the address-of operator “&” to pass the address of the variable “first” to scanf. (Instead of the value of “first”, which was what you passed to scanf in your original code.)

      As many others, I also recommend Python as a very good general purpose high-level language.

    • Peter Lund Says:

      Fredrik, actually it’s recommended to both ask for all warnings and warnings 😉

      (No, there’s no missing word in that sentence.)

      Take these command lines:
      1) gcc -W ….
      2) gcc -Wall …
      3) gcc -W -Wall …

      One would think that #1 turned on warnings and that would be that. As it turns out, there are many, many warnings in the gcc compiler and lots of macho programmers didn’t like to be told that their code was bad, so -W only turns on some of them (those with the lowest false negative rate, roughly).

      #2 then turns on all the warnings, right? No. Some of them pissed some people off too much so it only turns most of them on.

      #3 turns all of them on (as far as I know).

      For anal retentive reasons, the gcc programmers are slowly deprecating -W in #3 in favour of -Wextra but the rest of the world pretty much ignores that.

      Summary: always use ‘-W -Wall’ with gcc unless you have a really good reason not to. And Python is a really good language (if a bit slow for certain things). Highly recommended. And there’s work under way to make it faster (Unladen Swallow, PyPy) so it’ll probably be faster in a couple of years.

  19. Matt Leifer Says:

    Regarding your problem with installing Xcode, you need to install the version that corresponds to the version of OSX running on your mac. I think that Apple only offers the most recent version for download, which would be 10.6, but it sounds like you are running 10.5 Leopard. If so, you need to track down a 10.5 install disk (your IT people should have one if you don’t) and install Xcode from the disk.

    Although Xcode is probably the easiest solution, there are also other ways to get a development environment up and running on your Mac. For example, you could install fink or another package manager and then install the necessary packages (gcc, etc.). In fact, using this method you could set up a full GNOME environment on your Mac and then use the exact same tools that you are using on Linux.

    Finally, I would like to add my recommendation to learn Python. I think it is very intuitive to learn for mathematicians because the syntax for the ubiquitous list comprehension is so similar to the notation that mathematicians use to define a set. This vastly reduces the number of “for” loops that you have to write and you are better off going straight to this set-theory-like way of doing things rather than learning C’s “loopy” way of doing things and then having to unlearn it again. The main advantage of learning C/C++, FORTRAN or similar for scientific computing is that they are fast. This is still important for very heavy simulations that stretch the limits of the available computing power and is the main reason why I had to suffer through several C/C++ courses and projects. However, for the vast majority of academic/scientific uses the speed difference is not noticeable and is vastly outweighed by the difference in development time. The only other reason for preferring them to more modern languages like Python, Ruby, (or even Java if you must) is that you really enjoy getting severe headaches.

  20. Ross Snider Says:

    The funny thing is that I don’t expect compilers to be much different from BLOG or GRADSTUDENT after we figure this hard AI problem out.

    C is a good language to learn. You’ll get everything that programmers find difficult out of the way immediately and you’ll learn the most popular programming syntax in the works. You’ll have some habits to break moving over to C++, but really it isn’t all that difficult.

  21. Américo Tavares Says:

    Just to quote from the Wikipedia:

    “Python (programming language)

    Python is a general-purpose high-level programming language [2] whose design philosophy emphasizes code readability.[3] Python aims to “[combine] remarkable power with very clear syntax”,[4] and its standard library is large and comprehensive. Its use of indentation for block delimiters is unusual among popular programming languages.”


  22. Scott Morrison Says:

    Installing command-line tools on your mac via MacPorts (my preference) or Fink is a really good idea. You’ll find that for many things, including compiling simple programs, you can use the same toolchain on OS X or a linux.

    I’m actually working on the opposite transition at the moment. I’m a mathematica guru (no, really, I’ve reimplemented most of the mathematica kernel from scratch, I know its quirks!) and use java when I need to be slightly closer to the metal, but I’ve just started learning GRADSTUDENT. There are some excellent implementations around here (Berkeley)!

    • Matt Leifer Says:

      He can’t install stuff via MacPorts because you need to have Xcode installed to use that and installing Xcode is the problem. The issue is that MacPorts always compiles from source, so you need gcc and a few other things already installed to use it. Fink will work without Xcode because it allows you to install precompiled binaries.

      Personally, I prefer to avoid both Fink and MacPorts and use native Mac apps wherever possible. This is because each package manager sets up its own alternative directory structure. This often leads to multiple versions of the same software being installed on your machine. It can be difficult to work out which version is the default and it can break programs that make wrong assumptions about where software is stored on your Mac. It is especially annoying when packages installed via the Mac native .pkg and .dmg routes also install the same software in yet another location because they don’t detect the fink and MacPorts versions. It usually ends up infuriating me so much that I just nuke the whole fink/MacPorts tree and start over. Someone needs to write a package manager for the Mac that integrates better with the native environment.

      By the way, a similar issue is the only thing that really bugs me about python. How ever much effort you put into setting up your system, you always end up with dozens of versions of python installed in different places.

    • Matt Leifer Says:

      Update: It seems that I need to try Homebrew http://mxcl.github.com/homebrew/

  23. Mio Says:

    Perhaps it’s good that you’re getting over the ugliest and messiest part, which is input/output handling, first. Compared to that, the rest will be poetry and elegance. If you want some problems to practice on after you get past the basics, http://projecteuler.net might be right up your alley.

  24. scot shinderman Says:

    Every mac comes with python, ready to go out of the box. Start up a terminal (Applications->Utiliities->Terminal) and type python.
    Starting with c/c++ is a huge investment in time and, possibly frustration. One of the benefits of a language like python is that the edit/compile/run cycle has the middle part removed. You can explore and design rapidly — there are some quirks to the language but it’s powerful enough to write and abstract just about anything.

  25. Dan Hagon Says:

    I would echo what many people have already said here and recommend python as a good all-round language with a mature set of libraries such as Sage. In comparison to C it can be used interactively, which is particularly important when you’re first getting into a language because you get immediate feedback rather than lines and lines of crytic compiler messages.

    The other thing I’d say is that, like in mathematics, programmers only get better at programming by solving problems with their code so I’d recommend trying some of the programming problems available from sites like http://projecteuler.net/ to test your understanding of language syntax and features. Also working through problems with people who are also learning the language at the same time as you can be a huge boost to how quickly you learn.

    The final suggestion I’d make is to perhaps try a functional language like ML (the programming style and syntax is very similar to Haskell which was mentioned above). First year CompSci students in Cambridge are fed on a diet of ML and Java so you might find it helpful to attend some of those lectures – or failing that it’s sufficient to get a copy of Lawrence Paulson’s “ML for the Working Programmer” and copy of Poly/ML and just try it out. ML has such a strong mathematical foundation in comparison to other non-functional programming languages that I’m sure it will payoff in spades when you progress from ‘toy’ problems to real world problems and need the right tool for those jobs.

  26. Emmanuel Kowalski Says:

    Although my sentimental favorite is Lisp, I agree with the many comments that emphasize that, for a working mathematician interested in using a programming language as a tool, the best choice at the moment is the combination of Python and Sage (in particular, Sage has excellent visualization facilities, since you mentioned that you would be interested in graphing thins; it’s clear that trying to re-invent a good plotting framework in C will not really be an option, and although it can be great fun to write custom PostScript code to reproduce geometric constructions, that’s also a waste of time for most people).

    Where C and similar languages are mostly superior is in providing a good way to deliver self-contained binary programs to other users. But, again, this is a very specific purpose that is unlikely to be what most mathematicians really want, and Python also makes it possible (see, e.g., SnapPy, for a special-purpose mathematical tool now distributed in Python, as described here.)

    • Radu Grigore Says:

      C is good at controlling what the computer does in detail. That’s good: (1) you can tell the computer exactly what to do and (2) you understand better how the computer works. It’s also bad: sometimes you have to specify details you really don’t care about.

      Binaries aren’t that portable, so I wouldn’t say that’s an advantage of C.

  27. Américo Tavares Says:

    Although PARI/GP (developed by Henri Cohen and his co-workers, Université Bordeaux I, France) is a computer algebra system “designed for fast computations in number theory” it does have programming & user functions too.

    URL: http://pari.math.u-bordeaux.fr/

    Programming & User Functions (see PARI-GP Reference Card)

    Control Statements

    for(X = a, b, seq), fordiv(n,X, seq), forprime(X = a, b, seq), forstep(X = a, b, s, seq), forvec(X = v, seq), if(a, {seq1}, {seq2}), until(a, seq), while(a, seq), break({n}), next({n}), return(x) (…)


    printp(), printp1() (…)

    Example from the Tutorial:

    ” (…) Now for fun, let us compute in a very naive way the first complex zero of zeta. We know that it is of the form 1/2 + i t with t between 14 and 15. Thus, we can use the following series of instructions. But instead of typing them directly, write them into a file, say zeta.gp, then type \r zeta.gp under gp to read it in:
    t1 = 1/2 + 14*I;
    t2 = 1/2 + 15*I; eps = 1E-50;
    z1 = zeta(t1);
    until (norm(z2) < eps,
    z2 = zeta(t2);
    if (norm(z2) < norm(z1),
    t3 = t1; t1 = t2; t2 = t3; z1 = z2
    t2 = (t1+t2) / 2.;
    print(t1 ": " z1)
    (The original is displayed with identations)

  28. Alec Edgington Says:

    Tim, now that you’ve got some momentum in C there’s no reason not to continue with it — it is good for producing fast, efficient programs — but I’d add my voice to the many who recommend Python, as being easy to learn, use and debug. Most of the computations I’ve done for EDP have at least begun as simple Python programs; only once I’ve tested the algorithm, and only for heavy computations where speed is important, have I then converted the program to C, because there is (for me) significant overhead in getting a C program of any complexity to do what I want it to do.

    With an application such as IPython (freely downloadable), you can use Python as an all-singing-all-dancing calculator, typing in one-line (or multiple-line) commands and getting an immediate response; you can also invoke Python programs written to a file and immediately see and play with the output. Personally I find this quite a fast and productive way to experiment in mathematics, with the help of the Scipy and Pylab packages, which include a lot of mathematical and plotting functions.

  29. Darf Ferrara Says:

    I agree with every one that recommended python and sage. To do mathematics by computer it really helps to have a community with lots of math “out of the box”. If you have time though, I would look into watching the lectures on Structure and Interpretation of Computer Programming (SICP) using the scheme programming language. It is almost the opposite of C. Where C is essentially glorified assembly language (which is important for implementation), scheme shows good ways to think about solving problems with a computer.

  30. Kristal Cantwell Says:

    I also agree with those recommending Sage and Python. There are some lectures on Sage at MSRI that were interesting to me. Here is the URL:http://www.msri.org/calendar/workshops/WorkshopInfo/502/show_workshop

  31. timur Says:

    If you want to practice your programming/algorithmic skills please check out the following sites.



  32. Andrea Says:

    I join the mass recommending Python and Sage

  33. carter schonwald Says:

    hey, i was actually helping a friend with xcode who had the exact same problem

    here’s the bitly version of that link http://bit.ly/amkvoR
    for Xcode 3.1.4 (the kind that should work). note that you may first want to navigate a browser window to http://developer.apple.com and login using your itunes account (which is your apple ID) before clicking on the bitly link.

    that should work. If not, when you’re at the apple developer website, scroll to the bottom of the screen, click on mac dev center, on that page there will prominently be a developer downloads link in the middle on the left, then a new window where you should again click on developer tools, then scroll down until you see the mention of xcode 3.1.4, with a link to the download that i’ve linked to above that should work.

    once thats installed, enjoy!
    (and try haskell too http://hackage.haskell.org/platform/)

  34. Carter Schonwald Says:

    hrm, my previous comment didn’t come through for some reason!
    well, I suggest clicking on http://bit.ly/amkvoR (which is the short version of a download link for the version of xcode you need) after logging into the mac developer website developer.apple.com using your apple id (what you’d use for your itunes account)

    that should link should start the down load for the version of xcode you actually want!

  35. Carter Schonwald Says:

    hrm… the bitly link gets you most of the way there, you need to then click on developer tools and scroll down a bit to get to the the most recent xcode 3.1.whatever bundle, but then you’re done!

  36. Emmanuel Kowalski Says:

    Like one of the previous messages, I recommend having a look at S.I.C.P (available online here. It is eye-opening to see a programming course where local variable assignments are introduced so late (e.g., long after programming a general-purpose Newton-method equation solver). At the beginning, eveything is done cleanly through composition of functions and recursive defintions. Also this is done in Scheme (a variant of Lisp), I think Python has the necessary facilities (such as using functions as first-class data) to do exactly the same things.

    In fact this page (which I didn’t know about…) collects links to (sometimes partial) “translations” of the examples in SICP in many other programming languages.

  37. Matt Leifer Says:

    Whilst we are recommending links to courses and other resources, I have to mention http://software-carpentry.org/ which is python-based and very good (apart from the outdated choice of using SVN rather than a DVCS).

  38. gowers Says:

    If I follow the wisdom of crowds (which I’m inclined to do in this instance) then once I’ve reached some very basic level of competence in C I’ll try to do the same with Python. I’ve now got my Mac set up so that I can run C programs — many thanks for the useful tips for doing that — and have just written a brute-force algorithm that tests for primality and prints out all the factors of a number if it is composite. I was quite surprised and impressed to see how fast it worked even for numbers around 30 million. For 10^8 it takes about a second. To give you an idea of how crude it is, when I input n I test for every single m less than n whether m goes into n.

    I think my next step will be to do some programming exercises, of which I now know of various sources. If I can get through a few of those in C, then maybe I’ll be ready to move on.

    • gowers Says:

      Actually, I couldn’t resist a little look at Python and have just found out how good it is for simple arithmetic via its interactive mode. I’ve also successfully created a file containing the traditional Hello World program and, after a couple of false starts, got it to run. To an experienced programmer, this will sound like a laughably small step, but as I said in my main post, I seriously believe that getting the computer to do anything at all is for me the big hurdle, and after that all I have to do is build up the complexity of what I can program.

    • Carter Schonwald Says:

      if you subsequently would like to get a taste of how interesting/useful some seemingly eclectic features in certain programming languages can get, an excellent resource would be http://okmij.org/ftp/ (a fellow who I believe is professionally involved in weather forecasting, but in his free time cooks up cool programming tricks/theorems that floor folks involved in programming languages research)

    • antoniocangiano Says:

      Prof. Gowers, whether you decide to continue your journey with C or (better) Python, I would highly suggest that you check out Project Euler (http://projecteuler.net).

      Most of the initial problems can be resolved with rudimentary knowledge of any programming language. I personally love how some of the problems cannot be resolved with a naive, brute force algorithm, but require a certain degree of mathematical insight. As a mathematician, you will no doubt love this site and its exercises.

      Another interesting programming language for you to learn at a later stage would be Haskell. You’ll probably love the language for the same reason why mathematically challenged programmers hate it.

      For example, consider the following line of Haskell code:

      [n | n <- [1..], n `mod` 3 /= 0]

      You can probably guess what this does, considering that it's so close to mathematical notation. The line above represents an infinite list of natural numbers that are not multiples of 3. Thanks to lazy evaluation, we can play with data structures that represents countably infinite sets.

      For example, in Haskell I could write:

      take 5 [x | x <- [1..], x `mod` 3 /= 0]

      And I would obtain the first 5 natural numbers that are not multiples of 3:


      This is a simple example, but it should give you a taste of the nice stuff that is possible in Haskell. For the time being, I'd suggest focusing on the essentials though. C or Python will definitely help you build a solid foundation on how to instruct the computer to do the calculations you require it to.

      Finally, should you have any programming questions, feel free to drop me a line by email any time, and I will be more than happy to help.

  39. porton Says:

    You say that Python is good for simple arithmetic.

    Personally I use bc for simple arithmetic. It has flow-control statements and so is a programming language but I use it only as a simple calculator.

    Notably, bc supports arbitrary precision and arbitrarily big numbers. It can be used e.g. to calculate 10000th digit of pi.

    One little note, I have in ~/.bc_init the definition of pi:

    pi = 4*a(1)

  40. Primos em Python/A Python script for computing primes « problemas | teoremas Says:

    […] como explico aqui. Divulgado por Blogs de Ciência Blogs de Ciência Problema do mês (pdf) Problem of The […]

  41. Pradeep Says:

    Learn C on the Mac http://apress.com/book/view/1430218096 is a good resource for getting started programming with C on the Mac.

    As an aside, just finished reading your “Mathematics (A Brief Insight)”. I think it’s a republication of “Mathematics: A Very Short Introduction” but I thoroughly enjoyed it. Thank you.

  42. Peter Boothe Says:

    To find out why a C program is crashing is a bit of a black art, but there are tools which can be of great help. First, when compiling your programs with gcc, get into the habit of always using the flags -Wall and -g. The -Wall flag turns on warnings when you do things which are legal-but-strange and -g makes it so that a debugger can refer you back to line numbers in your source code. To compile a program in a.c you would then do:

    gcc -Wall -g a.c

    Many of my students have had good luck, when they have a confusing C++ crash, with using the valgrind tool. It may be a bit tricky to install on a mac, but on Linux you should be able to install it using your package manager. Then, to run your program a.out, you simply type

    valgrind a.out

    and then you will get all sorts of helpful messages if you ever step outside of your memory bounds (many C errors are memory errors, particularly in beginning programs). C is a very low-level language, and there are lots of tricky things associated with that (integer overflow, pointers, etc). For mathematical programming, I recommend a higher level language. Math grad students of my acquaintance have reported good luck with SAGE ( http://www.sagemath.org/ ), which uses Python to bring together a variety of mathematical programming environments.

    Good luck!

  43. Jonathan Feinberg Says:

    C is a bad choice of first language, for many reasons. It is rife with what you might call “accidental complexity”, wherein the expression of otherwise straightforward algorithms is littered with memory management and abstruse i/o machinations. C’s “types” are not really what computer science thinks of as types (let alone a mathematician), but are, instead, instructions to the compiler about how much space to reserve for variables.

    I humbly join the chorus of folks encouraging you to use Python as a first language. It is pragmatic, and it has very little accidental complexity. It is neither “laughable” nor immaterial that you were able to “hello world” without much fuss, using Python.

    If you find yourself interested in programming per se, as a beautiful and interesting discipline in its own right, then you’d be well served by SICP, as other commenters have suggested.

  44. Mio Says:

    I agree that C is a bad choice for a first language, assembly would have been better:) If one wants to get a wrong model in his head of what goes on in the underlying hardware that will be hard to unlearn, if one wants to remain clueless about the resource consumption of his code, one should stay away from C.

    C is small and beautiful, much more so than the scripting languages. Yes, you’re forced to mind the stuff a scripting language will take care of for you (although often not in a way you’d want it to), but all of those troubles make one appreciate what’s going on in a machine, not to mention the control you get over the resources that you just don’t get otherwise. There’s nothing accidental about memory management, it’s a vital and precious resource and it is often crucial to manage it well.

    For tight and beautiful C code I recommend Sedgewick’s “Algorithms in C”.

    I have nothing against Python at all, I just think that learning C as early as possible is a good idea and a great investment.

  45. Uwe Stroinski Says:

    From my experience with your recent Polymath project I would recomment to consider a Computer Algebra system.

    You can reproduce most of the results (obviously not the Alec/Klas length 1124 result and their current project run on a 2048 core cluster) with a handful of mathematica lines on a laptop.

  46. Toby Gee Says:

    I’m certainly in no position to make recommendations (I’m in a similar position to you), but Python/SAGE does seem like the “obvious” answer, for the reasons mentioned above.

    That said, the only programming I’ve done in the last 20 years or so was to work through (almost) all of this book (SICP):


    which I really can’t recommend enough. It is genuinely one of the best books of any kind that I’ve ever read, and I think that all mathematicians would enjoy it enormously.

  47. Steve Witham Says:

    Aside from being great, Python is BASIC-like in the ways you mention:

    > print 2010 – 1987, “skidoo”
    23 skidoo

    Read Guido’s tutorial: http://docs.python.org/tutorial/
    As language tutorials go, it’s really clear, and quick if you skim the parts you don’t currently care about (e.g. don’t worry about your PATH, just type python).

    On the Mac, the easiest way to get gcc, emacs, make, man pages, and all the stuff Unix people are used to is to install XCode and then ignore XCode,

    But the Apple emacs only runs black and white in your Terminal window with no mouse cursor; I recommend Aquamacs, http://aquamacs.org/
    Put it in your dock and you can drop files on it to edit them, with the right settings they come up in tabs. Did you know Firefox uses emacs key bindings?

    Two stupid but essential Mac command line tricks:

    1) in Terminal, type: open . (period meaning current directory)
    The current directory opens as a Finder window.

    2) with both a Terminal window and a Finder window open,
    Type cd in the terminal,
    drag the little icon from the top of the finder window over to the terminal,
    it pastes in the path of that folder,
    hit return, you’re there.

  48. Hans Lundmark Says:

    I’d say start with Python, since it’s convenient, popular and relatively simple. As you already seem to have noticed, you will be able to get started very quickly with Python.

    Later on, you might want to have a look at Haskell. I recently spent quite a lot of time getting acquainted with it, which I certainly don’t regret. I think it’s not an exaggeration to say that learning Haskell will change the way you think about programming.
    It encourages a way of thinking which should appeal to most mathematicians: a very high level of abstraction, strong emphasis on functions in the mathematical sense (with clearly defined domain and codomain and no side effects), higher-order functions that take other functions as arguments, building new functions by composing old ones without necessarily naming the arguments (like saying f=g \circ h instead of f(x)=g(h(x))), and so on. Like Python, Haskell can be run in interactive mode, so that you can experiment at the command line.

  49. Radu Grigore Says:

    You should get a CS grad student to help with things like figuring out how to do input/output and what stdio.h means. It is much quicker and, since the main barrier is to find the right information, I think you don’t gain much doing it alone. (I think it’s better if you do it yourself, using GRADSTUDENT as a very effective search engine.) I’m sure there must be at least one grad student around who would be happy to help. (I’d be, but I’m not close.)

    My opinion about the programming language to learn: One at a time, and don’t stop. 🙂 It gets quite fast to grok a new language after a time. The slow part is fitting all the available libraries into your head, which you need to do only for the language you prefer and use most often.

    SICP was already mentioned. It’s probably good if you decide to learn some LISP variety. HTDP has a similar style and it’s also using Scheme (a LISP variety). The content is quite simple and every working programmer should be familiar with those concepts.

    Having read your brief intro to math, I suspect you’ll like Knuth’s TAoCP. For example, Section 1.2.2 describes logarithms in a very similar way you do. One exercise for that section asks for an algorithm that computes b^x for 0≤x<1 that uses only shifting, addition, and subtraction. The main benefit for you would probably be finding (more) connections between what you know (math) and (low-level) programming. TAoCP, however, is not a good place to learn a programming language. So it doesn’t directly address your goal. I just couldn’t resist mentioning it. 🙂

    I agree with timur that solving (preferably easy) problems on TopCoder is a great way to learn C/C++, Java, or C#, especially because you can view countless solutions written by others. The best way to try it to make an account, install the Kawigi plugin for the Arena, and go to practice rooms. (Setting this up is an example of a situation in which a (CS) grad student would be useful.)

  50. Radu Grigore Says:

    Last year I taught a C course for beginner programmers. I wrote then some advice to students. Most of it doesn’t apply to you, but there are bits that might be useful to you. I copy-pasted them below. This is my third comment in a day on this post so I feel like spamming. I promise it’s the last one. 🙂

    Start by setting up a work environment. It should at the very least allow you to easily compile, run, and test your program. If these three tasks are hard then you do not have a proper working environment.

    Your program must compile at all times. If the compiler reports an error, never fix it by randomly changing code in the vicinity of the error. Fixing the code without understanding what was wrong in the first place is worse than not fixing it at all: You missed an opportunity to learn. If you have a big pile of code with <10 errors then it’s like trying to learn how to swim by asking someone to drop you off in the middle of the Atlantic. You won’t learn to swim. Most likely you’ll just die. So don’t do it. Write your program incrementally. Keep it compiling. Run it from time to time and check that it does what you expect. This means that you should think about what you expect before running the program. Any mismatch between what you expected to happen and what happened is an opportunity to learn. Don’t miss it. Try to understand what is happening.

    Whenever you have an issue you can’t explain it helps to try to reproduce it on the simplest example. If the issue is a compilation error, then make a copy of your program and then systematically trim down the code in a way that preserves the error. Do this until you get to the smallest possible program that still exhibits the error. That is, there’s nothing more you can trim without making the error go away. By the time you get to this step you probably know what was wrong, you can fix the problem in the small example, test, and then repeat the fix in your big program. If the example is tiny and you still don’t know what’s wrong then ask in the forum (or a demonstrator if you are in the lab).

    You should test your program as it grows by running it. Once it approaches what you think is close to a final solution your testing must become more thorough. Do not just run the program, type in the input, and look at the output on the screen. Write all your tests (inputs and outputs) in files so that you can retest easily after you change the program. [The point here was that it should be easy to re-run the tests. There are fancier ways of doing it than just putting the input/output in paired files.]

    What to do if the program does not do what you expect? First, do the easy thing: Run the compiler with all warnings turned on (-W -Wall -pedantic) and check if any causes the problem. In any case, get rid of them. Then run your program with valgrind to make sure it’s not the fault of nasal demons. If it is, then try to isolate the problem in the same way as you isolate a compiler error: Trim down a copy of your program.

    There are two basic debugging strategies: (1) read the program carefully and (2) trace your program for particular runs. The latter is easier but as you become more experienced you’ll see that the former is much faster for simple bugs. Anyway, how do you trace a particular run of you program? Read the program having in mind a particular input. At each step think what are the values of the variables. If you feel lazy (and that’s often a good thing when you are a programmer; we are after all in the business of automating stuff), then put printf statements that print the values of variables at intermediate points and check when their values diverge from what you expect. Another option is to use a tool like gdb that lets you go step by step thru the program.

  51. jonathanfine Says:

    The best language for a task often depend on what resources are already available to solve the problem at hand.

    I had a recent project: compute the flag vectors of all the full dimensional 01-polytopes in dimension 5. Fortunately, a list of such polytopes (there are over a million of them) has already been computed.

    I modifed the C-program that accesses this list (it is binary data) to produce the list in the form I needed.

    I used a little bit of Perl so I could use polymake (which can be scripted with Perl) to compute the flage vectors and print out the results.

    I used Python (and in particular numpy) so that I could do some calculations on these flag vectors. I also used Python to glue everything together.

    Next, I want to determine the rank of certain quite large sets of flag vectors, but numpy doesn’t provide this. Nor does it provide arbitrary precision integers. So I might find myself using pari/gp for that bit.

    So, in part, my advice would be to use the language that already has a community doing calculations similar to the ones you want to do.

    By the way, it took about 15 Ghz days to compute the flag vectors. I enjoyed the GRADSTUDENT joke. Even the best use it sometimes.

    From Knuth’s ‘Digital Typography’, p505 “I was time to revise the draft of 13 May [1978] so that research assistants [grad students] Michael Plass and Frank Liang could prepare a prototype implementation [of TeX] while he [Knuth] was away [on a month-long trip].”

  52. Dima Says:

     in 2010 there is very little need to even touch C or C++ for doing scientific computations (unless one does something very special, demanding fast low-level access to (almost) bare-bones computer, like fast arbitrary precision arithmetic).

    They take perhaps 5 times more time to write and debug an average complexity code, say, something like an algorithm for finding a maximal weight matching in a bipartite graph, resulting in a code that is perhaps 2 to 5 times faster than the one written in, say, Python. OK, so you have to wait for answers a little longer, but you would say much more time in coding/debugging. And there are easy ways to call these special-purpose packages written in C/C++ from Python, should you need one.

  53. Carl Smotricz Says:

    I’m late to the party but I’d like to contribute anyway.

    For a mathematician who isn’t really interested in the ugliness of #include etc., I’d recommend J. It’s an interpreted language and even more terse than mathematical formulaic language. I never cease to be amazed at the breathtakingly short solutions to Project Euler problems that are done in J. Of the first 30 problems or so, many involving stuff like palindromic primes, most had J solutions no more than 2 lines long. One reason why mathematicians like J is that J handles matrices like vectors like scalars with no extra effort, like handcrafted loops.

    Yes, the J language complete with development environment is free and available for the Mac.

  54. Functional Composer Says:

    Mr. Gowers, You should be learning Haskell! It is a beautiful language and once you see what you can do with elegant compositions you will never want to use a C family language again.


    And if you have any questions, let us help: http://www.reddit.com/r/haskell

  55. Example Says:

    The very basic things, like reading and writing stuff to the screen BASIC style are easier in C++ then in C. I learned C++ in the 90’s and C just seemed like an annoying headache. The OOP stuff in C++ can be hard for some people to grok right away (like the difference between objects and classes) but that shouldn’t be hard for a mathematician.

    Java is like a simplified version of C++.

    And Python is supposedly what most people say is the easiest programming language these days.

  56. Stephane Says:

    Silly question maybe but I’ve tried to google BLOG and GRADSTUDENT but couldn’t find a site where I could learn about those languages or download a compiler… Can anyone help ?

  57. John Armstrong Says:

    Stephane is an adept user of SUBTLE. In case I’m wrong, I’ve whipped up a quick subroutine in FACEPALM.

  58. obryant Says:

    @Stephane: The compiler for GRADSTUDENT is only distributed to people with a Ph.D. I think you need a Fields Medal (or equivalent) before you can get the compiler for BLOG; at least, I don’t have it.

  59. Jason T. Miller Says:

    “A language that doesn’t affect the way you think about programming, is not worth knowing.”
    — Alan Perlis (ref: http://norvig.com/21-days.html)

    While I more or less agree, as with all aphorisms, counterexamples are legion. In this case, the usual suspects are “environmental factors”:
    – Lack of library support and the like: the so-called “Turing tar-pit”: While Mathematica can solve systems of polynomial equations “out of the box,” Gröbner basis algorithms could also be implemented in, say, Brainf**k. These alternatives are only equivalent in theory. Contrarily, it’d probably be easier to implement the Risch algorithm in ARM assembler than it would be to convince Wolfram to port Mathematica to some random embedded platform.
    – Communication overhead: No code is an island. It might be easier to learn C# than to code up a translator in GRADSTUDENT.
    – Politics: rightly or wrongly, there exist “powers that be” that, on occasion, demand a particular implementation language. Even in the “wrongly” case, the shortest distance between two points is often through compliance.

    And so on. But your comment that you “just want to learn some language, after which it should be easy to adapt to another one” is perceptive and correct; the risk you might pick up some “bad habits” along the way is, in my experience (IT and CS, mostly), overestimated. The reason why you can’t teach an old dog new tricks is not that he is incapable, but that he doesn’t care to learn. When it comes down to it, “bad habits” are simply “the devil you know,” and a sort of skeptical conservatism is not only understandable, but commendable in such a marketing-driven field as information technology. A more elegant proof does not invalidate a messy proof; that a “better way” exists does not make all others senseless folly.

    The most important thing, I’d say, is that you’ll be “getting your hands dirty,” one way or another. By way of analogy, consider this: recently, I was in a so-called “advanced calculus” course, moving a bit more slowly than anticipated by the professor and the syllabus; one of the students was clearly frustrated because he “really wanted to learn differential forms.” The syllabus and textbook ended with Stokes’ Theorem; everything was in R^n, so we’re really just talking about translating what he “already knows” into “another language,” and maybe kicking it up a dimension or n because we can. Assuming he met the prerequisites for the course, viz., linear algebra and multivariable calculus, I never quite figured out why he was waiting for what he was waiting for. If he didn’t know the FTC or Fubini’s Theorem, he wouldn’t have been there; the algebra is easy (d^2 = 0, f*dx = df*x = d(x o f)?), and partitions of unity are just a matter of working through a few simple proofs. “A little thought,” Thoreau once wrote, “is sexton to all the world.” In this case, the necessary thought is trivial: whatever integrals he needs to get the hang of things; whatever proofs he needs to understand why they work out? But he didn’t know this, as he never bothered to try. “Not everyone things as you do,” I’m told, and that I overestimate people. But if he wants to learn forms, and he’s capable of undergraduate calculus and algebra, what, exactly, am I overestimating? I’m not expecting he’ll _invent_ the bloody things, or work out their applications to cohomology or mathematical physics while he’s folding laundry. And I’m not that bright — as I’m constitutionally incapable of memorization, I doubt I’d have been able to pass undergraduate calculus if I _hadn’t_ known forms.

    To abuse the analogy a bit, an equivalent “bad habit” might be using the Hodge dual to work out the curl of a vector field in spherical coordinates in order to apply the classical Stokes’ Theorem in R^3 in terms of forms. Pointless, perhaps, though educational in more ways than one. And, from a strictly practical perspective, whatever works, no? But this is hardly a reason to avoid learning calculus in the first place. After all, where would Cartan have been had Newton refused his education on account of a potential “better way?”

    • Lars Hellström Says:

      Perceptive remarks, but regarding differential forms, I would say that these really are one of the things where one benefits greatly from having them explained by a living lecturer. The difficulty often lies in the context, in matters such as “how one should think about them”, “why one should do X”, and “how things fit together”, rather than in details of proof formalia. The difficulty is in learning to apply the right perspective.

      Categories can be like that too. As can C compilers.

  60. anon Says:

    Well the GRADSTUDENT joke is not so funny, I find. A little bit condescending …
    I hope it doesn’t stick around very long.

  61. I’m not dead yet! « Blog in a Vat Says:

    […] fear of publicly declaring idiotic things is a healthy one to have, but let me illustrate with an example: I have recently decided that it is high time I learnt to program in a more traditional language, […]

  62. six youtube please Says:

    I savour, lead to I discovered just what I used to be taking a look for. You’ve ended my four day lengthy hunt! God Bless you man. Have a great day. Bye|

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: