tobilehman.com: a blog on computing, structure and math

How Contract Law Could Become a Form of Computing

Since 2012, when I first heard about Bitcoin, I’ve thought it was a very cool application of cryptography and peer-to-peer networks that solves the problem of double spending and runaway inflation. Other than that, I didn’t really think it was revolutionary, but a recent article by @ThoughtInfected has changed my mind.

The most thought-provoking quotes where:

It is just such a huge game changer that a program could hold wealth in a way that is inaccessible to anyone, and then distribute said wealth based on defined and agreed mathematical rules.

and

The twin technologies of cryptocurrencies and cryptocontracts are going to turn contract law into a programming language.

The bitcoin protocol includes a non-Turing complete interpreted language that can be used to create more complex transactions, and it can be used as a basis for so called ‘Smart Property’ and self-enforcing contracts.

This idea of turning contract law into a form of computing is similar to what I’ve been wanting for a while, I’d like to see laws themselves be in a computable form, then interpretation of law would be replaced with a program that might resemble a SQL query. What bitcoin smart contracts give is a way to enforce contractual obligations without paying lawyers and police, and they take out the need for trust, since people will be incapable of breaking the terms of the contract.

A beneficial side effect of having computable laws is the ability to cross check them all for logical consistency, my ideal government would find all inconsistencies and eliminate them by vote, any pair of laws that cannot be consistently resolved would be deleted, and the territory covered by those laws would be unspecified.

An example of this is the current inconsistency between Federal and State Law regarding the recreational use of cannabis, it is illegal at the Federal Level, but legal in some states, such as Colorado and Washington. If these laws were being checked like some continuous integration server running software tests, it would fail upon seeing this contradiction, it would generate a ballot and put it to a vote. If the vote does not resolve the inconsistency, the conflicting laws are deleted. Then legislators would be forced to start anew, applying principles that are consistent with the current body of law.

But back to contract law, this not only eliminates the need for lawyers and courts in contracts, it also solves the problem that DRM attempted to solve. Musicians could create contracts that ensured people paid for the song they were listening to, and it would be enforced by the mathematical rules built into the bitcoin network, not the arbitrary whim of a company like Sony. Or ebooks could be sold by the authors themselves, and people could only pay for what they read, this would obviate the need for a middleman like Amazon. Removing middlemen would give artists a larger cut, and could reduce the prices for the consumer as well.

Cryptocontracts such as those built on Bitcoin could really be revolutionary, since they sidestep the often expensive dealings with the legal system, don’t require trust, and solve the problem of property in an age when infomation is copied freely.

Switching Away From MathJax

I am switching away from MathJax for my math blogging for a few reasons, first one being that RSS readers won’t see rendered formulas, and second one being that rendering complex formulae such as tables of aligned equations can be very slow.

Instead, I’ve decided to use this Jekyll plugin to pre-render the formulae and insert images into the generated markup.

Counting Bits in Integers

While working on the code to count the number of fifteens I had in a hand in cribbage, I found it would be useful to count the number of bits in an integer. The comment below explains why it is useful.

Since subsets and the bit representations of integers are in one-to-one correspondence, I can enumerate all subsets of an n-set by simply counting from 0 to 2n-1, then I can use the bits in the loop variable to determine which element of the set is in the subset. From the example in the comment above, you can see that the bits of the row number line up with the elements in the subsets.

In order to finish this code, I wanted a way to count the number of bits in an integer. I looked around for an existing algorithm to do it, and I found this, from K&R:

I had no idea how it worked, so I tried to figure it out. The parts that I do understand are the roles of v and c, the former is the number for which we are counting bits, and the latter is the actual number of bits.

Why does v & (v-1) clear the least significant bit?

To figure this out, I considered a general n-bit integer, represented in base 2, I thought about it as

If v is odd, then vn = 1, so v-1 simply clears the least significant bit, and since the first n-1 bits are the same, the bitwise AND of v and v-1 is just v-1, which v with the least significant bit set to zero (cleared).

Otherwise, v is even, which means vn = 0. What is v-1 in this case?

If v = 32 = 1000002 (base 2), then v-1 = 0111112, so v&v-1 = 0000002, which is v with it’s least significant bit set to zero.

So far, so good, but that is only one example, we need to prove it for a general even n-bit integer, not just 32.

Let v be an n-bit even integer, and vk=1 is the least significant bit. Then vn=0, and k < n.

We can then write v in the following way:

Then, the number vkvk-1…vn = 2n-k

We can find v-1 by considering the subproblem of vkvk+1…vn - 1 = 2n-k-1.

Now, we can see that v and v-1 have the same first k-1 bits, with the last n-k+1 bits opposite, so that the bitwise AND clears the last n-k+1 bits. Since v has the last n-k bits equal to 0 and the k-th bit equal to one, it follows that v&(v-1) clears the least significant bit. This completes the proof.

Now, looking at the code again:

This will clear the least significant bit, increment c, then if v is nonzero, repeat. Now this makes sense.

Political Parties Are More Like Tribes Than Consistent Philosophies

Much of political opinion is rationalized groupthink, this article argues this by using a list of 5 political proposals written from a liberal viewpoint, and then re-written from a conservative viewpoint, the results are telling.

No substantive policy change occurred, but many liberals supported the liberal-flavored list, while many conservatives rejected it. When the conservative-flavored version was written (same exact policies), that divide was inverted.

The response suggests that most people judged it based on how it was framed, and in particular, whether it was their group or the other group endorsed the idea. This is a good reason that political parties should be abolished, or at least worked around.

This could be solved by sterilizing ballots. Instead of seeing a candidate’s name, party, or see who endorsed what policy, several equivalent voting ballots could be written by different people. This would require that the candidate’s name is replaced with some other unique identifier, say a CIN (Candidate Identification Number). The CIN could be paired with a list of policies, each of which have been re-written by neutral parties (perhaps a machine compiled them from some computer model). Then, people would answer a questionairre about which policies they supported the most, along with a weight, assigned by the voter. Then, a program could calculate the closest match, and that would be the person’s vote.

One obvious problem with my proposal is that if the software that calculated the closest match was closed source, it would be very easy for software developers to rig it one way or another. Two solutions come to mind:

• Make the voting software open source and submit it to a peer-review
• Give the voter instructions on how to calculate the closest match, so that they can do it themselves, manually.

The options of using software or going manual are not mutually exclusive either. This is how people in the United States do their taxes, some delegate the calculations to software like TaxHawk or TurboTax, and some do it themselves with a calculator.

This proposal would solve the problem of tribal thinking in politics, and make voting a more logical activity that really did reflect the needs of the public.

Making people register with parties and then vote only exacerbates this, because they’ve made a commitment to a tribe before they’ve made a decision.

Country Code TLDs Using GeoJSON on Github

There are more country code top-level domains (ccTLDs) than there are countries, that is because territories such as Wallis and Futuna has the ccTLD .wf, even though it’s a French territory, not a country.

There are so many that I have a hard time remembering them, and given one it’s hard to tell what country it belongs to, since ISO 3166 specifies that ccTLDs should be two characters long, that makes a maximum of 676 (26 squared) ccTLDs that could ever exist.

To solve the ccTLD→(Country/Territory) problem, there is this great decoding table here at iso.org.

For the other problem, (Country/Territory)→ccTLD, I made the following map using GeoJSON