Archive for the ‘just for fun’ Category

December 23rd, 2015

Some numbers have something to say. Take the following, rather huge number, for example:


This number wants to tell you ‘Happy Holidays’, it just needs a little code to help it out.  In Maple, this code is:

n := 18532529104068264480353131238404133659515101876112780772576330806424607039523076495646885634139967048751461005248758632306757568791464282975763655513845614593843019187655175699232981800640177552230121901623724542589154403221854439086181827152684585874764890938291566599716051702867105827305295569713835061785617174899049034655848488352249531058730460687733248824488684969031964141214711866905054239875930383262767247976845232997188307342087743859641917976242185446451606034726912968063437466250120212904972794971185874579656679344857677824:
modnew := proc (x, y) options operator, arrow; x-y*floor(x/y) end proc:
tupper := piecewise(1/2 < floor(modnew(floor((1/17)*y)*2^(-17*floor(x)-modnew(floor(y), 17)), 2)), 0, 1):
points := [seq([seq(tupper(x, y), y = n+16 .. n, -1)], x = 105 .. 0, -1)]:
plots:-listdensityplot(points, scaling = constrained, view = [0 .. 106, 0 .. 17], style = patchnogrid, size = [800, 800]);

The result is the following plot

Screen Shot 2015-12-23 at 13.03.12

Thanks to Samir for this one!

The mathematics is based on a generalisation of Tupper’s self-referential formula.

There’s more than one way to send a message with an equation, however. Here’s an image of one I discovered a few years ago — The equation that says Hi

December 13th, 2015

Way back in 2008, I wrote a few blog posts about using mathematical software to generate christmas cards:

I’ve started moving the code from these to a github repository. If you’ve never contributed to an open source project before and want some practice using git or github, feel free to write some code for a christmas message along similar lines and submit a Pull Request.

November 23rd, 2015

A recent trend on Facebook is to create a wordcloud of all of your posts using an external service. I chose not to use it because I tend to use Facebook for personal interactions among close friends and I didn’t want to send all of my data to another external company.

Twitter is a different matter, however! All of the data is open and it’s very easy to write a computer program to generate Twitter world clouds without the need for an external service.

I wrote a simple script in R that generates a wordcloud from the most recent 3200 tweets and outputs the top 200 words (get the code on github). The script removes many of the uninteresting words such as the, of, and that would otherwise dominate the cloud. These stopwords come from the Top100Words list of the R package qdap but I also added a few more such as ‘just’ and ‘me’ that I seem to use a lot.

This is the current wordcloud for my twitter account, walkingrandomly. Click on the image to see a bigger version. My main interests are very clear – Python programming, research software, data and anything that’s new!


Once I had seen my wordcloud, I wondered how things would look for other twitter users who I pay a lot of attention to. This is how it looks for Manchester University’s Nick Higham. Clearly he’s big on SIAM, Manchester, and Matrix Analysis!



I then looked at my manager at Sheffield University, Neil Lawrence. Neil finds data and the city of Sheffield very important and also writes about workshops, science, blog posts and machine learning a lot.



The R code that generated these wordclouds is available on github but it won’t work out of the box. You’ll need to register with twitter for app development (It’s free and fairly straightforward) and get various access keys before you can use the code.

June 4th, 2015

The ever-superb John D. Cook recently found this lovely looking curve in a book he’s currently readingmystery_curve


John posted some Python code that reproduced this curve. I stole borrowed his code, put it in a Jupyter notebook and wrapped it in an interactive widget to allow me to play with the parameters and see what other curves I could come up with. The result looks like this.

Screen Shot 2015-06-04 at 15.09.26

If you’d like something where those sliders work, you need to run the notebook I’ve created in Project Jupyter. Here are 2 ways to do that.

Once you have the notebook open, click on Cell->Run All and play with the sliders that pop up.

Other posts about these curves:

March 12th, 2014

A recent Google+ post from Mathemania4u caught my attention on the train to work this morning. I just had to code up something that looked like this and so fired up Mathematica and hacked away. The resulting notebook can be downloaded here. It’s not particularly well thought through so could almost certainly be improved on in many ways.

The end result was a Manipulate which you’ll be able to play with below, provided you have a compatible Operating System and Web browser. The code for the Manipulate is

   circArray[circrad, theta, pointsize, extent, step, phase, 
 , {{showcirc, True, "Show Circles"}, {True, False}}
 , {{theta, 0, "Dot Angle"}, 0, 2 Pi, Pi/10, Appearance -> "Labeled"}
 , {{pointsize, 0.018, "Dot Size"}, 0, 1, Appearance -> "Labeled"}
 , {{phase, 2, "Phase Diff"}, 0, 2 Pi, Appearance -> "Labeled"}
 , {{step, 0.25, "Circle Separation"}, 0, 1, Appearance -> "Labeled"}
 , {{extent, 2, "Plot Extent"}, 1, 5, Appearance -> "Labeled"}
 , {{circrad, 0.15, "Circle Radius"}, 0.01, 1, Appearance -> "Labeled"}
 , Initialization :>
   dotCirc[{x_, y_, r_, theta_, pointsize_, showcirc_}] := If[showcirc,
     {Circle[{x, y}, r], PointSize[pointsize], 
      Point[{x + r Cos[theta], y + r Sin[theta]}]}
      Point[{x + r Cos[theta], y + r Sin[theta]}]}]
   circArray[r_, theta_, pointsize_, extent_, step_, phase_, 
     showcirc_] := Module[{},
      Flatten[Table[{x, y, r, theta + x*phase + y*phase, pointsize, 
         showcirc}, {x, -extent, extent, step}, {y, -extent, extent, 
         step}]], 6]

If you can use the Manipulate below, I suggest clicking on the + icon to the right of the ‘Dot Angle’ field to expose the player controls and then press the play button to kick off the animation.

I also produced a video – The code used to produce this is in the notebook.

December 11th, 2013

Back in 2008, I featured various mathematical Christmas cards generated from mathematical software.  Here are the original links (including full source code for each ‘card’) along with a few of the images. Contact me if you’d like to add something new.

MATLAB Christmas card

SAGE Christmas greetings

Fern Fractal Christmas card

August 1st, 2013

I am currently in the market for a new thin and light laptop; the things that everyone seems to be calling ultrabooks these days.  Here’s what I’ve considered so far and the major good/bad points from my point of view.

  • 2013 Macbook Air: Good: Fantastic hardware specs including Haswell and Intel HD 5000. I’ll get an educational discount. Bad: No touchscreen, I’m not interested in OS X. No tablet mode.
  • Lenovo Yoga 11sGood: Both a tablet and a laptop but it’s a laptop first and a tablet second.  Bad: Only 3rd generation Intel.  Weird to hold in laptop mode because your fingers are mashing the keyboard.
  • Haswell based Dell XPS 12Good:Haswell. Beautiful mechanism for switching between tablet/laptop. Bad: Only Intel HD 4400 graphics compared to the Air’s Intel HD 5000.  I’ve heard that the connection between computer and screen is unencrypted WiDi. Possibly just FUD but its putting me off right now.
  • Samsung Ativ Book 9 Plus Good: Haswell. Amazing display resolution. Bad: Much higher resolution than the Macbook Air but with weaker GPU (Intel HD 4400)–that surely can’t be a good combination? No tablet mode. Win 8 doesn’t handle such high  resolution screens well but should be fixed in 8.1.
  • Samsung Ativ Q: Good: Haswell. Amazing display resolution. Tablet mode.Win 8+Android.  Bad: No trackpad. Looks horrible in laptop mode–seems to be a tablet first and laptop second.  Like the Book 9 plus, it has a relatively weak GPU (Intel HD 4400) to drive all those pixels.

I think that at the moment, what I want is the form factor and weight of the Dell XPS12 with the resolution of the Samsung and the hardware specs of the Air.  I’m open to suggestions though.

July 30th, 2013

I am extremely short sighted and have a contact lens prescription of the order of -10 dioptres or so.  Recently, I was trying to explain to my wife exactly how I see the world when I am not wearing my contact lenses or glasses and the best I could do was ‘VERY blurry!’

This got me thinking.  Would it be possible to code something up that took an input picture and a distance from my eyes and return an image that would show how it looks to my unaided eyes?

Would anyone like to give this a go?  How hard could it be?

February 15th, 2013

I know it’s a day late but someone just sent me this and I simply had to share so please indulge me.  Solve this inequality to find the love


January 29th, 2013

I am having a friendly argument with a colleague over how you calculate the peak number of floating operations per second (flops) for devices that support Fused Multiply Add (FMA).  The FMA operation is d=a+b*c, an operation that can be done in one cycle on devices that support it.

I say that an FMA operation is two flops, he says it’s one.  So, when I calculate the theoretical peak of a device I get twice the value he does.  So, what do you FMA one flop or two?