Please visit my new campsite listing site ukcampingmap.co.uk


Archive for the ‘Maths’ Category

More pizza squabbles

Saturday, May 2nd, 2009

The other day I ruminated on whether going for the smallest slice of pizza initially will result in your getting more in the long run than going for the biggest first, and concluded that I should try and write a computer model of it, which I have now done (bear in mind the page is a bit slow to load), to a degree.

The graphs below, plotting number of pizza slices vertically (increasing as you go down) and number of people horizontally (increasing to the right), and average over 100 trials per slices/people combination, show that there is a small area, when the number of people is roughly equal to half the number of pizza slices, and the number of people is not too big, where taking the smallest available slice on the first go pays off. But an even better strategy under these circumstances is to take the smallest of the N largest slices, where N is the number of people.

Graphs of pizza slice taking strategies

Graphs of pizza slice taking strategies

There are lots of alterations I’d like to make to the model, as it’s not quite a true reflection of reality.

  1. Add the ability to have people eating at different rates.
  2. At present the sizes of the slices are chosen randomly (and then normalised to make sure the total size is equal to the number of slices). However, the distribution in real life pizza slice sizes is far from random; they will probably have roughly a normal distribution, with very few extra big slices and very few extra small ones. Because the size of one slice is not independent of the sizes of other slices, they are likely to follow a more complex distribution, but it’s probably beyond me to work out what it is.
  3. The colours are nowhere near contrasting enough. I’ve done a bit of a fiddle on the greens to bring them out a bit more, but it’s a bit of a cheat that probably won’t always work. There are regions in the graph where one strategy is consistently slightly better than the other, but it doesn’t show. A high contrast version (below) does show this info (and in fact also showing that most of the time you’re better off wtha smaller slice first strategy if more than two slices per person), but I think it’s important to show the subtleties too.
    pizza-slices-high-contrast
  4. The slow loading is an issue.

For the record, now that I know how OOP works in PHP I used my new skills to write the model, and it was most useful. Much easier to keep track of what values you’ve written to where.

How to get the biggest slice of pizza

Sunday, April 26th, 2009

It’s always a battle trying to eat enough pizza when it’s being shared between friends. It’s believed, in fact, to be the cause of the Crimean war.

But is there an optimal strategy to make sure you get the most pizza you can?

To date I have always followed a “take the biggest piece that’s left” strategy, but ruminating on this has led me to the following conclusion: taking the biggest piece still on the plate isn’t necessarily the best way to maximize the amount of pizza you eat.

Suppose a pizza, P, is sliced into n Slices, s1, …,  sn, ordered such that their areas a1, …, an form a decreasing sequence.  Also assume that the time taken to eat a slice is proportional to its area, i.e. tn = can. Further assume that everyone eats at the same speed and that there is a set polite interval – T – between one person taking a slice and the next person taking theirs.

We will concentrate on the smallest remaining slice and the largest.

Assume you take slice k (the largest remaining). Then the person who took a slice before you (presumably the largest available slice, if they play the traditional pizza game) has time tk + T = cak + T to finish his slice in order to guarantee he finishes before you, and therefore get to pick a bigger slice than you next time. The time it takes them to eat their slice is tk-1 = cak-1. So for him to get a bigger next slice than you:

cak-1 <cak + T
ak-1 -ak < T/c

However, if you take the smallest slice available instead of the largest this changes to

ak-1 -an < T/c

which, if the difference in size between slices is great,  is considerably less likely. Therefore you would be considerably more likely to get to choose before your predecessor next time, and thus securing a bigger slice should you show wish. Now you would have eaten slice an and picked another slice before he’s finished his first.

This strategy won’t always pay off though, and it’s difficult to judge when it would be effective. For instance, say there are very few slices available; If all slices are taken before you finish slice an then you lose out but, on the other hand, if you are the only person quick enough to finish their first slice in time to grab the one remaining slice after the first round, then you win.

It may be worth trying to write a computer model of.

Junior’s a programmer now

Saturday, April 11th, 2009

I didn’t take the traditional route to my present career. After graduating in maths I knew I didn’t want to take the obvious route of becoming an actuary or accountant as maths, contrary to popular belief, is nothing remotely to do with adding up (although, in hindsight I reckon being an actuary might be fairly interesting, but you still have to mix with graduate training scheme types).

So many years later, after leaning web-wards through a series of charities and lower jobs, I find myself a reasonably competent web-developer.

But I still have a lot to learn and the book I’m reading (Deep Simplicity by John Gribbin) is proving to be a great source of ideas to stretch my programming legs. Making websites is all well and good, but the examples of complex systems emerging from simple rules, and the constant talk of computer models, has given me the impetus to stretch my abilities to making convoluted programs to model certain behaviours.

The first one I’ve attempted is the following scenario:

You have N buttons and an unlimited number of threads. You pick up 2 buttons and connect them with a thread, and then do this repeatedly.

So I wrote something to produce a graph of interesting things to keep track of during this process.

It’s also given me the idea for a jQuery plugin

How to spot an obvious idea when you’ve got one

Wednesday, April 1st, 2009

I did say, and I quote:

Now, somebody has probably already done this, but I’ll throw in my twopenneth anyway.

with respect to finding analytical function for the logic gates. But, lo and behold, I’m the top result in Google for it, and no-one else seems to have thought of exploring this before.

So maybe it’s not so obvious as I thought.

Front paged on Google…

Monday, March 30th, 2009

for “Where’s the maths”

Haha

Also somebody got here, probably on a serious search, looking for an analytical function for xor gate.

Finally, this is an unrelated rant, but I just found out from a guy I was hoping to sublet from has had to turn me down as the girls he lives with wanted another girl. This despite the fact that they hadn’t met me, and he told me the only girl to view the room seemed a bit weird, and he would recommend the girls plump for me.

Well screw them* – I hope they get a bunny-boiler.

* I’ve been watching rather a lot of South Park lately. For free. online. legitimately. What nice people.

Logic 2.1.1

Tuesday, March 24th, 2009

Further discussion on the logic functions with my good friend Matt, specifically regarding what they could mean, has landed on the idea that a value of, say, 2 or 3 for the truth of a statement X could equate to “X is sooooo true”.

Bearing this in mind, Matt wasn’t happy with the shape of the graph of =>, and further thought has led to the following necessary conditions for a function =>(x,y) (I’ll call it f from now on for ease of typing) which works well with the notion that something can be soooo true:

  • f(x,1) –> 0.5 as x –> infinityx (so if something very true implies something else is true to a normal level, this means the implication is less a preserver of truth: more a diluter (though I set the asymptote as 0.5 as we thought it shouldn’t get closer to falsity than to truth)
  • f(x,0) < 0 for all x > 1 (if x gets more true but y is still not true, then teh implication is, again, less of a truth preserver, though this is debatable. Maybe eqality with zero would be more appropriate.)
  • f(1,y) –> infinity as y –> infinty (similar to the case where x varies and y = 1,  if 1 is immensely true despite x only being a little bit true then the implication is very strongly true)
  • f(0,y) = 1/y for all y > 1 (the thinking here being that if y contiinues to get more and more true, despite no change in x, then the link between y and x should accordingly be weakened)

logic 2.1

Monday, March 23rd, 2009

I have, as promised, found a better form for XOR:

  • XOR(x,y) = x + y -2xy

As I sit here chomping on a chicken wing, I can’t help but feel a touch of disappointment alongside the inevitable satisfaction at completing my mission. The previous solution – XOR(x.y) = (1-xy)(x + y) – was, I feel, more elegabt; the fact we were dealing with x/y symmetry, and that x and y could take only the values 1 and 0, seemed to almost leap out.

Talking of symmetry – I’ve just realised that I didn’t cover x => y, the only asymmetric elemental* logical operator.

So here, deduced by trial and error is the formula:

  • =>(x,y) = xy + 1 – x

I lied though. Because, of course, => is not as elemental as one would hope, so:

x => y <–> NOT (x AND NOT(y)) = NOT(x AND (1-y)) = NOT(x(1-y)) = 1-(x-xy) = xy +1 -x

Thus demonstrating the usefulness of being able to represent logical operators analytically.

Logic 2.0

Saturday, March 21st, 2009

Now, somebody has probably already done this, but I’ll throw in my twopenneth anyway.

Yesterday morning I woke feeling strangely alert, so decided to do some maths. Namely, finding analytical functions of the real numbers taht agree with the logical operators NOT, AND, OR and XOR on the values of 0 and 1, and here they are:

  • NOT(x) = 1-x
  • AND(x,y) = xy
  • OR(x,y) = 1-(x-1)(y-1)
  • XOR(x,y) = (1-xy)(x+y)

Now, the above begs a few questions

  1. Are they any use? Well, I think so. They can be combined and recombined to form an polynomial function LP: {1,0}^n —> {1,0} to represent any logical proposition, where n is the number of elementary propositions. So given the truth or falsity of all these propositions the truth or falsity of the compound statement can easily be deduced
  2. Are these the simplest analytical functions that agree with the logical operators on 1 and 0? Probably NOT, OR and AND are; they’re all quadratic or less. But XOR is a cubic expression, which is unexpected. I can’t help thinking a hyberbolic parabola – quadratic – with the relevant constants shoudl work. Will have a think. *edit – success!
  3. Can they be extended over the reals? Well, yes – they’re analytical! But a good question is ‘What is the real world interpretation of a function like this?’ Extending the factorial function over the reals has proved useful, but would extending logic to things being doubly true, trebly true, negatively true, make any sense? Search me. The functions above could withstand the insertion of a few square/cube roots here and there, thus making the graphs more linear, and maybe they would be more likely to lend themselves to a real world interpretation. But the shapes of the graphs for the non-rooted functions (and probably ones with roots taken) (see below) defy interpretation I think.
  4. What do these functions look like?

Something I finally understand

Wednesday, December 31st, 2008

I’ve heard of the question about the probabililty of a second child being a boy before – it’s a standard mathematical puzzle to get you to think about conditional probabilities (similar to the Monty Hall problem)

Finally I think I understand it. I always knew there were two candidate answers – 50/50 or 2/3 – but despit eknowing 2/3 was right (or so I thought) was never completely comfortable with it. So here goes:

It’s either 50/50 or 2/3 depending on whether the parent picked the child they told you the sex of randomly or not.

If they picked it randomly and then said “hey look – it’s a girl” then the probability of a boy being left is 50-50, as the picking of the first child was independent of the sex of the second child.

However, if they deliberately picked a girl to tell you the sex of, then they are skewing the probabilities in favour of leaving a boy behind (as they have removed the possibility of picking a boy from the probability space), hence increasing the probability to 2/3.