Author Archives: david

Collaborative coin flipping

This post is based on an answer from Paul Crowley to a question I asked on Twitter. I’m writing it up mostly for my notes and because I had a follow up question about it I wanted to answer.

You and I want to decide something by coin toss. But there’s a problem. You see, I don’t trust your coin and you don’t trust my coin.

How do we resolve this issue?

Simple: We each flip our coins. If the results come up the same, call that heads. If the results come up different, call that tails.

Theorem: If at least one of us is using a fair coin, the result is fair.

Proof:

Without loss of generality, suppose I have a fair coin.

P(Heads) = P(Heads|You flip tails) * P(you flip tails) + P(Heads|You flip heads) * P(you flip heads)

But each of these conditional probabilities is \(\frac{1}{2}\) because they’re just the probability that I flip tails and heads respectively. So

P(Heads) = \(\frac{1}{2}\)(P(you flip tails) + P(you flip heads)) = \(\frac{1}{2}\) as desired.

QED

Simple enough.

The follow up question I wanted to ask though: What happens if we both cheat?

Suppose I’m flipping heads with probability \(p\) and you’re flipping heads with probability \(q\). Then \(P(Heads) = pq + (1 – p)(1 – q)\).

Supposing I want to maximize the probability of getting a heads. Let \(f(p) = pq + (1 – p)(1 – q) = 1 – q + (2q – 1)p \). If I don’t know the value of \(q\) (or at least which side of \(\frac{1}{2}\) it’s on) there’s not much I can do here: Any choice of \(p\) I make might hurt my odds rather than help them. If I do know whether \(q > \frac{1}{2}\) or not then I can choose \(p \in \{0,1\}\) to get \(P(\mathrm{Heads}\) = \mathrm{max}(q, 1-q)\). It’s unclear to me exactly what the game theory here is, but it does suggest that if you think that I am able to predict your value of \(q\) then your best choice is to use a fair coin.

This entry was posted in Numbers are hard on by .

An amusing financial instrument for creating a common currency

After my manifesto, I started thinking about the relationship between the new hippy socialist utopia, the EU, and exchange rates.

This got me thinking:

  1. I like common currencies as a way of creating common economic zones, shared trade, etc. They’re not essential but they’re nice
  2. But individual countries and governments need their fiat currencies, otherwise they’re kinda fucked. Witness, recent history
  3. The ideal scenario is that you would be able to use either the local or the common currency in each country. Or at least that certain classes of things would accept either
  4. But how can you create a shared common currency without linking it to governments?

After some (read: 5 minutes) pondering I came up with what I think is a neat solution. You can create a common currency which is naturally linked to the local currencies and has an effectively unlimited supply as a sort of financial instrument. Further, you can do this without requiring a central organisation to administer the currency (although you will probably want to have recognised organisations who are allowed to print paper versions of it).

Suppose we have some collection of countries who want to define a common currency. They each have their own local currencies. We can define a shared unit of currency, which we will call a Credit, as a promise to play a game.

How does this game work? Simple. You pay me one credit. I now pick a country from this set uniformly at random (according to some prescribed and verifiable randomization mechanism). I pay you one unit of that country’s local currency.

A credit is simply a commitment to this contract. Anyone can issue one, and it is subject to local contract law.

However I do not expect that in practice many people would play that game. In reality, the credit has a unique exchange rate defined for it: The worth of one credit in a given currency is the average value of the worth of one unit of currency in each of the countries in the union. If the original set of exchange rates is arbitrage free then so is this new set.

Edit: I’ve just noticed that a much more sensible way to do this is to not have the randomization at all and simply to commit to paying this exchange rate in some subset of the currencies. It’s simpler to just have the contract to be a commitment to pay that average exchange rate for any currency in the union.

Edit 2: On second thoughts, I’ve flip flopped. I think the randomization serves a useful goal after all, because it decouples the contract from the foreign exchange market, which although it roughly follows the simplified model of having a set of consistent exchange rates, that’s not how it really works and pretending that it is ties you to a central exchange. I think in practice you will rarely find you want to employ the randomization, but I think it serves an important theoretical benefit.

It might open interesting options for time based arbitrage – I’m not sure – but I don’t think so. In general you would expect the credit to be more stable than its constituent currencies because the rate of change is averaged, which damps out small fluctuations.

How do you deal with changes to the union?

Well you can do it in two ways. The first is that you can just let it revalue the currency. If your union is large enough this can’t go too badly wrong – e.g. at the 27 member states of the EU, the worst case scenario for adding a new member is that they contribute a 0 value currency, at which point your currency drops 3.6%. Much larger fluctuations in exchange rate are common.

Another solution is that you can version the credit. So rather than committing to a credit for the entire union, you commit to a credit for the union as it was at this date and time. Issuers of physical currency will then have to make sure they create a new distinct currency look for each change to the union and encourage people to sell them old versions of the currency at the exchange rate with the new one. This is not a terrible solution over all.

Note that although it lacks a paper currency, you can use this right now. You might want to get a lawyer to draft up the contracts, but it’s completely workable on a contract basis. Also if you can’t design on a set of countries, just use all of them! Instant global currency.

What would the effects of widespread use of such an instrument based currency be? I don’t know. I like how stable the exchange rate is, and it certainly seems like a more sensible choice than bit coin.

This entry was posted in rambling nonsense, World domination on by .

A manifesto

I have been requested to put together an up to date manifesto for what I will do when I take over the world. This is perhaps a bit too large in scope, particularly as I don’t really believe in world government, so instead I’m putting together a reduced manifesto for what would happen if the queen wakes up one morning, has a moment of clarity and is basically all “Fuck it. I’m going to dissolve parliament and put David in charge” (yes I know she can’t actually do that).

Note: I have previously written some more expansive and less structured notes on how I would structure a government: Part 1 and part 2. These are a bit more far reaching and less focused than this manifesto, and I’ve since refined my political beliefs somewhat, but I largely still stand by them I think.

This is probably the more extreme version of what I would do. I imagine if I somehow actually found myself in this position I’d be slightly more measured. Slightly.

So, that disclaimer aside, here is my manifesto:

A precommitment to democratic oversight

I do not know what the best way to run a government is, but I’m pretty sure it’s a) not what we currently have and b) not a dictatorship. It’s pretty clear that even if putting me in charge turns out to be the best decision ever, it’s incredibly hard to guarantee the same about my successor.

I think in order to ensure it does not all go horribly wrong, democratic oversight is important. As such I precommit that I will reign unchecked for no more than 20 years. After that point, at any time a petition with at least 10k signatures will trigger a referendum on my continued rule. Such referendums may occur no more often than annually, but may continue until I am deposed or step down voluntarily.

I additionally commit to having some form of democratic government in place by the 10 year mark. I will retain complete veto rights over their decisions, but the intent is to let them do most of the running of the country and only step in when I feel necessary.

Short term plans

In no particular order, I plan to get all of the following up and running as quickly as is feasible. Certainly within the first year:

Raise taxes

Income taxes will probably not go up much at the lower end of the income range. They will certainly go up at the upper end of the range – probably to something around the 60% mark. More importantly, I will crack down severely on tax avoidance and corporation tax issues. This country is not going to be a tax haven.

Universal Basic Income

That’s right. Free money for everyone!

Getting this fine tuned is going to be tricky. My initial plan is to give every single person over the age of 10 who requests it £500/month tax free. for those tracking along at home, this is about half a living wage for the country at large, and consequently a bit further under for London. As such it might need adjusting upwards, but I feel like starting a little low is probably a more sensible option. Additionally because it’s not in any way linked to what you’re otherwise earning, it should be comparatively easy for people to top it up to a living wage (a little over half the year working 40 hour weeks at minimum wage + the UBI should give you a living wage)

The existing benefits infrastructure will remain in place, but the new UBI will be counted as income. I expect a great deal of the benefits system to become unnecessary under the UBI, and the next couple years will consist of slowly dismantling the bits that are unneeded and refining the bits that still are, but I’m not touching it until the dust has settled.

As a minor note, this income will come out of your tax-free personal allowance.

Strict financial regulation

You know all those laws which the bankers insist will cause finance to leave England and go elsewhere?

Go on then.

No doubt having closed all the corporation tax loop-holes and raised income tax for rich people, they’ll already be hurting. Good.

My initial proposal is simply a variety of financial transaction taxes. Especially designed to clamp down on high frequency trading, but others as well. I’d also impose a cap on bonuses to be no larger than your current salary, but it looks like the EU might beat me to that one. I will also roll back much of the deregulation of financial markets.

Other than that I’d hire a team of economists to come up with a more comprehensive plan than I am knowledgeable to create. Their two guiding principles will be:

  1. Stability is more important than growth
  2. Money is supposed to represent value. If you can make dramatic amounts of money without adding value, this is a bug in the system and should be patched

Medical infrastructure

I don’t believe in private healthcare. Nor does any country under my rule. All private health care assets will be immediately and irrevocably seized, including drug and medical suppliers. For the moment they will continue to be run exactly as they currently are, but with all profits being directly channeled to the NHS. Over time my intent is to more thoroughly integrate them into the NHS, with the long term plan being to have a system which retains the property that you can pay money for health care but levels the playing field rather more.

While I’m in the area, immediately and painfully clamp down on all homeopathy. It’s not something I consider high priority so much as a convenient low hanging fruit. Look menacingly at other forms of “alternative medicine”, but don’t do anything about it right now.

Justice system

My immediate plans for reform of the justice system mostly include reforming the #1 source of injustice in it: Drug policy.

All drug possession for personal use is immediately decriminalized. Anyone in jail for such an offence is immediately pardoned.

Drugs will be reclassified in severity by actually listening to the advice of people who are experts on this subject instead of asking them for their advice and then ignoring it when it doesn’t fit. Anyone imprisoned for dealing a drug whose classification has been reduced will be retried.

I do not have concrete plans for an over-all justice system reform, but intend to form a body responsible for designing one, with the eventual goal of nearly completely phasing out the prison system (I acknowledge that some prisons will probably remain necessary, but regard anyone in long term incarceration as a symptom of the system failing. Prisons are a failure at rehabilitation and massively disproportionate as a retributive measure).

Be warned that my ideal justice system is probably a mix of rehabilitative and retributive that will satisfy neither side of the political spectrum. I am however prepared and able to listen to evidence and expertise on this subject, so you might find it turns out OK anyway.

Medium term plans

My initial main medium term plan is “Deal with all the fall out of the short term plans”. By now I’ve pissed off all my neighbours (a bunch of the assets I seized will have been foreign owned) and my economy is in free fall.

I don’t really have any more specific plans than “deal with it”. I think the economy will prove to be a non-problem. I am the controller of a fiat currency, and I can basically print money until the numbers balance. I don’t think that will take very long – I’ve basically just dumped a giant stimulus package on the economy. Sure people up top are hurting, but people at bottom are spending.

The ruffled feathers amongst neighbours might be more of an issue. I expect I’ll have to pay compensation in some manner, but I intend to make a long and drawn out process of negotiating that.

More concrete medium term plans:

Renationalization

You know all those things we privatized? Bit shit, isn’t it?

We’ll start by nationalizing the railways and the phone lines and see how things go from there.

Education

Education needs to be affordable. Given the UBI, it doesn’t necessarily need to be free, but it should be possible for someone with no means of support other than the UBI to put themselves through university. I have no concrete plans except “throw money at the problem in the form of subsidies and grants”, but let’s do that.

I would also like a wider range of vocational schools to be available for people who are less interested in going into academic study and more interested in learning to do something useful. I will delegate the exact details of this plan to someone more versed in the issues.

Non-university education is a more pressing issue. I have a very simple plan for solving this problem.

What is that simple plan? Step 1: Find a country that has a working system. I’m going to go with Finland here, but could be persuaded to do otherwise.

Now take the Finnish education system and copy it. Keep on copying it. Bring in actual Finns to tell us what we’re doing wrong. Listen to them. Keep listening to them. Once we have hit parity with them in terms of educational results (at which point I will probably be out of power, because it’ll take a full generation of school children to tell if we have), we can think about doing something more complicated, but until then take something we know that works and copy the fuck out of it.

Energy policy

We’re going to build nuclear reactors, we’re going to build a lot of them, and you’re going to like it god dammit.

Don’t get me wrong. We’re going to build renewables too, but in case you haven’t noticed we don’t get a lot of sunlight here. We’re going to build wind farms (and you’re going to like it goddammit) and wave farms, and we’re going to invest in large energy storage mechanisms to smooth out the load, but it’s simply the case that we need more power than these are going to provide.

How are we going to get our nuclear program off the ground quickly enough?

Simple. We’re going to bring in the French. They have this working right. We’re going to get them to design and build reactors for us.

The long-term goal here is that all energy in the UK should be nuclear or renewable. I don’t expect to hit this goal in my life-time, let alone my reign, but I want to make a damn good try at it.

Long term strategy and general notes

Now that I’ve got the building blocks for my hippy socialist utopia, what’s next?

I don’t know. There’s a list of things to address that would fill a book. Here are a few things that come to mind.

Firstly, I need to actually start building in the democracy part of it before all this power goes to my head and I do something really out there…

There’s still a lot to do around poverty and class inequality. I’ve thrown money at the problem, and a commitment to addressing education should help a lot there, but I expect there is more to fix and deeper problems to root out.

How do I feel about immigration? I’m totally pro it. Lets have more immigrants. They’re not going to take our jobs, they’re an opportunity to make more jobs.

London is something we need to sort out. Or rather, not-London is. Currently the UK seems to be starkly divided into London and the rest of the place. The axing of the finance industry should help with this, but I think fundamentally the problem is that London begets London: So much is here, and so many people are here, that there is essentially a black hole effect creating a strong social pressure to move here. I have plans to solve this, but they’re speculative enough I wouldn’t want to make this a manifesto item.

An important thing that is going to need careful watching is business. I want it. Sure, I’ve created a socialist utopia in which it’s inconveniently hard to exploit people, but I’d still like them to be able to buy stuff on Amazon. Careful attention is needed to make sure business doesn’t abandon the UK entirely. I think it won’t, because I think we’ll end up with a large number of well off people with money to spend (and not just the pound, which naysayers might suggest will be devalued by all my economic shenanigans. If you’ve got 60 million well-fed, well-educated people you really are going to get international money coming in one way or another). Care needs to be taken to make sure that it doesn’t get out of hand, but I definitely want to actively encourage both foreign and domestic business within my domain.

A lot of work needs to be done on becoming more socially liberal.

I touched on the fact that I’d have a much more relaxed drug policy. I’d also legalize sex work. I’d probably stop short of actually forming the ministry of dancing, getting high and fucking but I’m not opposed to plans in that general direction.

On a less hedonic and more human rights note, I plan to drop some of the more absurd moralizing and outdated aspects of our laws. Legal recognition for non-binary genders, absolutely. Legal recognition of whatever-the-hell-you-like-sex marriage? Totally. And not this half-assed same-sex marriage bill where it explicitly permits same as well as different sex marriage. We’ll just erase all the gendered language from the marriage legislations. While we’re at it, we’ll also legalise poly marriage. In general I’d probably like to move away from marriage as a legal concept, but that needs to be a gradual transition and in the mean-time that’s no excuse for not just getting it right.

Other than that, I plan to experiment. There’s a lot we don’t know about how to run a society and, while I’m in general delighted to shamelessly steal from other countries who I think have got it right, I think it’s also important to try our own things. Hello, my little guinea pigs.

This entry was posted in World domination on by .

A crude voting simulation

I decided to perform a fairly crude voting simulation to compare different ranked methods.

The simulation was performed as follows: An individual was a point on the unit sphere in N-dimensional Euclidean space (I chose N = 3). The agreement of two individuals is their dot product. A number of candidates (I chose 6) were drawn uniformly at random on this sphere. 500 more individuals were then drawn, again uniformly at random, and vote for candidates in order of how much they agree with them.

My question was this: With what frequency would various voting systems produce the same answer?

Systems I implemented were First Past The Post, Alternative Vote, Random Ballot (Pick a random voter, use their top choice), Random Ranked Pair (pick two random candidates, pick the one the majority of voters preferred), and random Condorcet (pick a random generalized Condorcet winner)

I ran 2000 simulations of this. Here are the agreement stats:

AV FPTP RandomBallot RandomCondorcet RandomRankedPair
AV 100.00% 44.80% 22.50% 41.30% 24.60%
FPTP 44.80% 100.00% 25.50% 29.60% 18.35%
RandomBallot 22.50% 25.50% 100.00% 19.05% 17.05%
RandomCondorcet 41.30% 29.60% 19.05% 100.00% 27.70%
RandomRankedPair 24.60% 18.35% 17.05% 27.70% 100.00%

Here is the same simulation run with the number of dimensions increased to 6:

AV FPTP RandomBallot RandomCondorcet RandomRankedPair
AV 100.00% 43.75% 20.95% 42.10% 24.00%
FPTP 43.75% 100.00% 23.75% 29.60% 19.90%
RandomBallot 20.95% 23.75% 100.00% 19.45% 17.05%
RandomCondorcet 42.10% 29.60% 19.45% 100.00% 25.50%
RandomRankedPair 24.00% 19.90% 17.05% 25.50% 100.00%

And here it is decreased to 2:

AV FPTP RandomBallot RandomCondorcet RandomRankedPair
AV 100.00% 46.80% 25.60% 47.10% 20.90%
FPTP 46.80% 100.00% 29.50% 33.25% 17.55%
RandomBallot 25.60% 29.50% 100.00% 20.45% 16.10%
RandomCondorcet 47.10% 33.25% 20.45% 100.00% 26.00%
RandomRankedPair 20.90% 17.55% 16.10% 26.00% 100.00%

I don’t really have anything interesting to say about these results other than “Huh. Different voting systems sure do produce different results, don’t they?”. It’s perhaps mildly interesting that AV is about as close to random condorcet as it is to FPTP, but I’m not sure that’s really significant. I’m mostly just posting this because I believe in publishing null results.

Here’s the code if you want to have a play with it. Advance warning: A work of finely crafted engineering it ain’t.

Update: One slightly interesting result from this. I modified it to add my condorcet variant on AV into the mix to see how it would do. It agrees with stock AV about 48% of the time and with “random condorcet winner” about 71% of the time. This suggests that most of the time we’ve got a unique condorcet winner here and AV isn’t picking it. To test this I decided to look at the distribution of the number of condorcet winners:

Number of condorcet winners Number of runs
1 1299
2 50
3 79
4 101
5 149
6 322

Which is about right. About 65% of the time there’s a unique Condorcet winner, and Condorcet-AV agrees with a random Condorcet winner some fraction of the rest of the time.

This entry was posted in Uncategorized on by .

Chesterton’s patch

I encountered the notion of “Chesterton’s Fence” this morning via Ozy Frantz.

In the matter of reforming things, as distinct from deforming them, there is one plain and simple principle; a principle which will probably be called a paradox. There exists in such a case a certain institution or law; let us say, for the sake of simplicity, a fence or gate erected across a road. The more modern type of reformer goes gaily up to it and says, “I don’t see the use of this; let us clear it away.” To which the more intelligent type of reformer will do well to answer: “If you don’t see the use of it, I certainly won’t let you clear it away. Go away and think. Then, when you can come back and tell me that you do see the use of it, I may allow you to destroy it.”

This paradox rests on the most elementary common sense. The gate or fence did not grow there. It was not set up by somnambulists who built it in their sleep. It is highly improbable that it was put there by escaped lunatics who were for some reason loose in the street. Some person had some reason for thinking it would be a good thing for somebody. And until we know what the reason was, we really cannot judge whether the reason was reasonable. It is extremely probable that we have overlooked some whole aspect of the question, if something set up by human beings like ourselves seems to be entirely meaningless and mysterious.

There are reformers who get over this difficulty by assuming that all their fathers were fools; but if that be so, we can only say that folly appears to be a hereditary disease. But the truth is that nobody has any business to destroy a social institution until he has really seen it as an historical institution. If he knows how it arose, and what purposes it was supposed to serve, he may really be able to say that they were bad purposes, or that they have since become bad purposes, or that they are purposes which are no longer served. But if he simply stares at the thing as a senseless monstrosity that has somehow sprung up in his path, it is he and not the traditionalist who is suffering from an illusion.

I would tend to agree with the quote in its original social context as a dampener on progressive change. I think most fences we’ve put up are probably silly, but I think it’s worth investigating which ones those actually are before we tear them down (and then, pass me the err. whatever tool it is you use to dismantle a fence. Lets go with “hammer”).

But reading it I recognised a very different scenario in it: What happens pretty much the vast majority of time when a programmer encounters new code. The code inevitably has special cases in it which accrued over time to handle a variety of situations. As a result the code may be quite ugly in places. The temptation is of course to rip it out, and replace it with something clean and pure and much more easily comprehensible to you, without all this cruft and special cases.

But perhaps you should first ask why is it there in the first place? And what was it intended to keep out?

This entry was posted in programming on by .