An introduction to an introduction to Mathematica

This is the first post in a series on Mathematica. The series is meant to complement and supplement a five-day course in basic Mathematica that I shall be giving at Cambridge in June 2016. I will post after each lesson if I feel that there is something that needs to be clarified, or if some example code will be useful, but these might not be complete course notes.

About this course

I plan to begin with a basic introduction, where I will give an overview of some of the mathematical features that Mathematica offers. In particular, we will cover random number generation, Fourier transforms and NDSolve. We will also use Plot, ListPlot and related functions.

We will introduce Import, which is used for importing data and including code from source files.

I will also introduce the basic concepts of functional programming. Mathematica is a functional programming language; while it provides control structures such as If, For and While, there are often much neater ways of doing things using the likes of Map (or /@), Select and Nest. In fact, If, For and While are themselves treated as functions. We will learn about anonymous functions and the /. and // operators.

My aim will be to focus on concepts and style, not fluency: Mathematica functions tend to have a complicated and difficult-to-remember syntax, but the inbuilt help is very useful for looking up the details.

An introduction to an introduction to C

This is the first post in a series on C. The series is meant to complement and supplement a five-day course in basic C that I shall be giving at Cambridge in June 2016. I will post after each lesson if I feel that there is something that needs to be clarified, or if some example code will be useful, but these might not be complete course notes.

About this course

The course is intended for people with some prior experience of programming in an imperative language, although I shall assume no experience with C. I will not dwell on details of the language but will try to move quickly into applications in maths, particularly in numerical computing.

Here is the provisional course structure:

  • Language features. Hello world. Compiling and linking. Declarations and definitions. The types int and double. Functions and return values. The if and else, for, while and switch structures. The break and continue keywords.
  • Memory, pointers and arrays. The concept of memory and why variables must be declared. Declaration and definition of arrays. Declaration of pointers and the use of malloc and free. Arrays as pointers. Passing arrays to functions. Functions with multiple or array outputs.
  • (*) Input and output. The char type. Strings as char arrays, the string.h library. The printf and snprintf functions. Working with files.
  • Mathematics. Variations on the int type. Floating-point calculations. The math.h header. Random number generation with rand.
  • Applications. Euler’s explicit method. A Monte-Carlo integrator and pi calculator. A heat equation solver (Crank-Nicholson).
  • (*) Structures. Application: A simple three-body problem solver.
  • The GNU scientific library. Brief overview of features. Fourier transforms. (*) A KdV solver (split-step pseudospectral).

Before starting

You will need to have a building system set up on your computer. Most Linux distributions come with such a system. If you are on OS X, then two good options are clang and gcc. If you are on Windows, then Microsoft Visual Studio Express is probably the easiest to set up, although clang and gcc are also available.

GNU Make may be useful if you are using clang or gcc. GNU Make is a system for automating the building process, and is widely used, not just in C.

About this website

This is the first post on this website. At the moment, it consists of just a few pages describing me and my work. Occasionally, I will post things about maths, science, computing, Chinese history, or anything else that interests me.

I am starting this blog as part of a migration away from Facebook. There are several reasons for this, many of which are privacy-related. Richard Stallman and the Free Software Foundation has a more detailed list of Facebook’s transgressions. Below I explain some of the main points.


When people talk about ‘privacy’ on a social network such as Facebook, they often think about controls that keep co-workers, bosses or students from seeing posts that they make in their personal lives. This is an important aspect of privacy, and while Facebook does not offer complete protection, it has made improvements, and a savvy user can achieve these controls quite easily.

But the true danger to privacy that Facebook presents is that Facebook themselves may read posts or things said in supposedly private conversations between users. The danger is not that Mark Zuckerberg will personally read your conversations and use it for blackmailing or shaming you. Rather, it is your usage patterns, writing style or unconscious behaviour which give away the most interesting information about you. Facebook is also capable of tracking your browsing habits on other sites. Logging out doesn’t protect you from this tracking.

The upshot: Even if you never write a message or post a status explicitly stating anything, and even if you give a false name, age or gender, it is easy to build a detailed profile of you, by linking together all of the information that is collected.

Targeted advertising is not a huge worry for me; I never pay attention to adverts anyway. I am most concerned by the prospect of medical information being collected or deduced: an insurance company could use this to set my premiums, or a prospective employer could discriminate against me based on my medical conditions. (The latter may be illegal, but that wouldn’t necessarily stop them.) This is not an unfounded concern: one of my friends noted that she was getting adverts targeted towards one of her conditions.

Ownership, openness and censorship

Centralised, proprietary systems such as Facebook, but also other networks such as Tumblr or, are not a sensible medium for storing or publishing media such as articles or photos. The danger comes from (a) the possibility that the service could be terminated with little or no warning, causing your media to be lost, and (b) the possibility of the host censoring your media.

I don’t know anything about copyright law or fair use, but the prospect of Facebook using my photos as their own (perhaps selling them off as stock photos, for example) is actually a fairly minor concern for me.

Facebook can censor posts arbitrarily. In 2014, it removed a photo of breastfeeding. In practice, its censorship seems to be motivated not by its own morality, but its desire to keep itself unblocked in countries such as Russia and Turkey. It does this by censoring pages of dissent, essentially to appease the Russian and Turkish governments.

Although there is no evidence of doing the same, one has no guarantee against it.

This website is hosted independently server in Cambridge (but independent of the University Computing Service), and is far less vulnerable to this sort of censorship. If I posted something illegal, libellous or extremely controversial, then the service provider may order the shutting down of this site or the government may order my arrest, but these powers are subject to public oversight, and are harder to abuse.

(Note that refers to the blog hosting service; this website is powered by the software WordPress but is hosted independently.)

Facebook as a walled garden

While Facebook can be useful for sharing things amongst immediate friends, the audience of such posts is in most cases ultimately limited to other users of Facebook. Hence Facebook is not really such a public platform. (Contrast that against this post, for example, which can be read by anybody on the Internet.)

Student unions often use Facebook to make announcements, rather than university email. This means that announcements, including important announcements such as upcoming committee elections, never reach students who are not on Facebook or not connected to the rest of the student body. This is undemocratic, and particularly affects mainland Chinese students.


Writing this has taken much longer than I had expected, and I need to go and do some work now, but hopefully it will be useful for persuading some other people to leave, perhaps reverting to email (or even face-to-face contact!) for communication.