Archive for October, 2008

New technologies from new physics

Sunday, October 19th, 2008

Almost every fundamental new discovery in physics so far has yielded great advances in technology. The exception seems to be general relativity - probably because gravity is such a weak force, it's difficult to make consumer items out of it.

I like to wonder what new technologies we could hope (in our wildest dreams) to obtain with a complete theory of physics. It might take a while, because we don't even know of any practical way of even getting experimental evidence for a grand unified theory so far, let alone make technology from those experimental results.

One possibility is new particles. Many promising theories predict various new particles. Unfortunately most particles other than the ones that make us up tend to be very short-lived and therefore don't yield any new materials. But if we do find a new long lived particle (and it doesn't cause a phase transition that swallows us all up) there is a possibility of new materials heavier, lighter, stronger or with better information storage abilities than the ones we have.

Another possibility is gravitational engineering. Particularly if we can find a way to violate the weak energy condition, we might be able to build stable, traversable wormholes, time machines and other such time/space abominations.

Even more far-fetched (but also possible) would be more ways to manipulate matter and energy, as in The Trigger and Ed stories.

You can't learn something until you already almost know it

Saturday, October 18th, 2008

This is one of those ideas that seem completely obvious when you first hear of it, but once you've been made aware of it you keep noticing it again and again.

When learning something, you have to have a frame of reference in which to place the new piece of knowledge, or you can't understand it. This is why trying to teach can sometimes be a very frustrating experience - you might think that something is completely obvious and can't understand why your student cannot understand it, but that's because your student doesn't yet have the scaffolding required to hold up that understanding, scaffolding that you're taking for granted. Whenever you are frustrated by someone's lack of understanding, try to imagine what their scaffolding looks like and give them the next piece from the set of pieces that are missing.

This also sometimes sets the pace about how quickly you can learn something completely new and unfamiliar - there are lots of pieces of scaffolding missing and you need to take each one and internalize it before you can understand the next. Since it isn't always obvious what the "next" piece should be, sometimes you have to read the whole textbook to get each piece. The problem isn't memorizing lots of facts (though that helps) it's slotting each piece into the framework.

If you've read the information about the next piece but haven't yet internalized it, sleeping on it can help. When you dream your mind is playing a kind of tetris, sorting things out and slotting things into gaps so that it all fits together.

This theory also explains why young children want to have the same books read to them over and over again - they start off knowing nothing (not even how to learn) so they seek out familiar patterns. In the context of that repetition, a new piece of scaffolding will occasionally drop into place. When that happens, there is a satisfying "Ah ha!" feeling associated with it. We have somehow evolved a mechanism to recognize this event and derive pleasure from it in order to give us a drive for learning.

Dual time

Friday, October 17th, 2008

The way we measure time is very complicated and difficult to get right, with all those time zones each with different daylight savings time rules. Perhaps we should rethink the whole thing.

The root of the problem is that there are two contradictory things we use time for - one is coordinating between people and the other is telling us when it will be dark. Timezones worked fine until we started collaborating globally, across time-zones. And daylight savings time is a hack to avoid sunrise being too early or too late in the day.

Perhaps instead all our clocks should show two times, "global time" (i.e. UTC) and "local time" (i.e. the time such that the sun will rise at 6am in place where the clock is). GPS could be used to make the local time clock adjust itself so that this was always true. One could also get something like our current timezones by having "standard time points" on the Earth's surface - one would tell one's clock to pretend it was at one of these points in order that all the clocks in a particular region agree (useful for things like television broadcasts).

"Global time" would be used for things like coordinating international teleconferences and "Local time" would be used to tell the farmer when to get up and milk the cows.

I think having days that were a couple of minutes shorter in the spring and a couple of minutes longer in the autumn would not be particularly confusing (we probably wouldn't even notice apart from the fact that the difference between global time and local time goes up and down with the passing of the seasons).

Marginal cost of a vote

Thursday, October 16th, 2008

Suppose you are in charge of a large political campaign (like, say, the ones for Obama and McCain that are going on the moment here in the US). You have a certain amount of money to spend and want to spend that money in a way that will make as many people vote for your candidate as possible. As always with such things, there are bound to be more things that you can conceive of doing than there is available money, so you have to choose only the things that meet a certain "expected number of voters swung per dollar" threshold. I wonder what that threshold is? I.e. if you give $100 to a political campaign, how many extra votes does that buy?

This isn't the same as the total number of votes cast for a candidate divided by the total amount that campaign spent, because some of those voters would have voted for that candidate anyway without the campaign spending any money. I'm interested in the marginal cost of a vote.

I'm sure the figure varies from day to day (if the other candidate makes a big gaffe, you can probably exploit that to swing a lot of voters relatively cheaply) and from state to state (votes in swing states are more valuable than votes in safe states, so it's worth spending more to swing them). I expect it also varies depending on how much the other campaign spends (since it costs money to undo their work). I'm sure the political campaigns do calculations to figure this stuff out - it would be interesting to see their statistics.

Algorithm for finding "hot" records in a database

Wednesday, October 15th, 2008

Suppose you have a database, and (as often happens with databases) records change from time to time. Suppose also that you'd like to maintain a list of the "hottest" records, that is the ones which have been changing a lot lately.

The first thing you have to determine is whether you want to put the emphasis more on "a lot" or "lately" - i.e. you need to have a characteristic time tc such that n changes tc ago are equivalent to n times e changes now. This time determines how quickly changes "decay" into irrelevance. Depending on your application, this might be a day or so.

The next thing you might try is to keep a table of all the changes made, along with a time for each. Then you can just weight the change times according to how long ago they are and add them up. That's going to be a big table and an expensive operation, though.

A clever trick is to use a running average and "last changed" timestamp in each row of the original table. The running average starts off at 0. Each time the row is modified, calculate the number of characteristic times since the last change N = (tnow-tlast)/tc, update the average by multiplying it by e-N and adding 1 and then update the old "last changed" timestamp to tnow for the next change.

To show that this works, suppose the running average was a=1+e-N1+e-N1-N2+e-N1-N2-N3+... (one term for each change, weighted by how long ago they happened). When we update the running average it becomes 1+e-N(1+e-N1+e-N1-N2+e-N1-N2-N3+...) = 1+e-N+e-N-N1+e-N-N1-N2+... which is just what we want.

That isn't quite the end of the story though because the running averages in the table are not directly comparable to each other - if a record had a burst of activity a long time ago but then hasn't been touched since, it will have a similar activity to a record which had a similar burst of activity which has only just ended. To compute the "current" value of the running average we need to multiply a by the e-N corresponding to the time since it was last updated (without adding one this time, since we haven't added another unit of activity). This requires looking at all the records in the table though, which will be faster than the table of changes approach but might still be rather slow for a big database.

If we only care about the top (10, say) "hottest" records, we can speed it up by caching the results in a small table, and noting that scaling all the activity values by the same factor doesn't affect the ordering of the list. Suppose we have a singleton value tupdate which is the time we last updated the small table and a10 which is the activity of the 10th hottest record the last time it was changed. Whenever we change a record, take the new activity value a, multiply it by eN (note no minus sign here) where N=(tnow-tupdate)/tc and compare it to a10. If it's larger the new record should be inserted into the "top ten" table and the old 10th hottest record shuffled out (if the new record wasn't already in the table) - think of a high score table for a game. When this happens, set tupdate=tnow, multiply all the activity values in the small table by e-N and update a10 with the new value. Then when you need to display the hottest records just display this table.

There is one more complication which comes about from deleting records. If you delete a record it probably shouldn't appear in the "hottest" records list, even it was updated quite recently. But if you delete a record from the small table when it is deleted from the big table, you will only have 9 records in the small table and you'd have to go searching through the entire big table to find the new 10th record.

If records don't get deleted from your database too often, a simple workaround to this problem is to keep maybe 20 records instead of 10 in the small table so that there are plenty of "substitutes" around, and only display the top 10 of them.

The algorithms used by Digg, Reddit, StackOverflow etc. are a little more complicated than this because the records of those sites also have a "rating" which is factored in (higher rated records are considered "hotter") but which can change with time. There might be a way to deal with this by scaling the running average according to the rating and updating the hot records table when the rating changes.

Gödel's incompleteness theorem

Tuesday, October 14th, 2008

Gödel's incompleteness theorem is an interesting little piece of mathematics but probably gets talked about more than it really deserves to be. I'm going to add to the problem here by talking about it.

It's a pretty simple idea really - if you have a formal system of mathematics F sufficiently rich to do anything interesting, you can write down a statement G that says, essentially, "statement G cannot be proved in formal system F". G must be true since if it was false it would be provable and therefore true, which is a contradiction. So given any formal system you can either use it to prove a contradiction (in which case it can be used to be prove anything, and is therefore useless) or you can find a true statement that cannot be proved within the formal system. Mathematics (being a non-contradictory formal system) can therefore never be used to prove all the statements that are true. "But hang on a minute," I hear you say, "that proof that G is true looked an awful lot like mathematics to me." Really all this means is that the kind of things we think about as being mathematical proofs can't be enumerated into some nice tidy finite set, since whatever you put in that set you can use to find another element that needs to be added.

There is an analogy here with Cantor's diagonal proof that the real numbers form a greater class of infinity than the integers. While they're both interesting proofs there is a fundamental "infinite-ness" and "strange loop-iness" about both of them. Infinite things are strange and non-intuitive, and also useless for describing the real universe (since we can never measure anything with infinite precision).

JavaScript vs PHP

Monday, October 13th, 2008

In order to implement Tet4 I learnt two new languages - JavaScript (or JScript, or ECMAScript - the language has a bit of an identity crisis) and PHP. Why PHP? It's installed on my web hosting server and seems to have a huge community of people writing code in it and pre-written scripts. It may not be the ideal language for writing web server apps, but it does seem to be the most well-supported.

JavaScript seems to be a very clean, pretty language. The whole closure thing seemed a bit weird at first but once I understood that "class" is spelled "function" and "public" is spelled "this." I got to rather liking it. I especially like how each scope has access
to the variables from all the outer scopes - that saves a lot of messing about. It's very well integrated with the browser - manipulating the DOM feels very natural and not tacked on.

PHP on the other hand is a bit of a mess. It is as if its designers had a little spinner with markings "C, C++, Perl" which they spun each day to decide what languages features to copy that day. If JavaScript was sent by God, surely PHP was sent by the devil.

W3Schools has been an excellent reference for learning all this.

I have to say though that automatically promoting integers to double-precision floating point numbers on overflow is weird. On IE7, computing the value of 1111111111*1111111111 gives 1234567900987654400 (you can easily see this is wrong because it's even). This caused a rather hard-to-debug problem with my random number generator (which assumed that when multiplying two 32-bit integers together, at least the low 32 bits of the result should be correct). If you're going to automatically promote numbers, at least have the decency to use a multiple-precision integer library - there are lots around.

Mornington Crescent data mining

Sunday, October 12th, 2008

Over on alt.games.mornington.cresent, a game has been running for a very long time. Many years ago (so the legend goes) the newgroup received a spam with the subject line "10,000 celebrity CDs". People started replying to the thread, decrementing the number and adding (vaguely) related text each time. Here is an example:

>> >>>> >>>>>>> 4840 Film scores that include 'Suspicious minds'
>> >>>> >>>>>>4839 Jukeboxes playing 'Suspicion'
>> >>>> >>>>> 4838 Suspicious boxes leading to evacuated buildings
>> >>>> >>>>4837 Other excuses for time of work
>> >>>> >>> 4836 hours to retirement
>> >>>> >>4835 hours to many
>> >>>> > 4834 second rate customer services
>> >>>> 4833 Vodaphone helpdeskers
>> >>>4832 Desk Tidies (A real help)
>> >> 4831 Deck reshuffles
>> >4830 Aces up my sleeve
>> 4829 dead rabbits
>4828 1.5v cells
4827 years before Red got his redemption

At some point, the subject line got changed to celerity and it stuck (or maybe it was misspelled in the original spam, I'm not sure).

I first learnt of this at university, some 10 years ago. I check back on this thread every once in a while to see where it's got to. It seems to have slowed down a bit in recent years - I think when I looked at it a few years ago I calculated that it should be over by now.

It would be an interesting task (maybe for a Googler?) to run a program over the history of this thread and plot a scattergraph showing how the number has changed over time. This would show the various rival threads as they fork off, skip ahead (or backwards) and sometimes die, and show how interest in the thread has waxed and waned over time.

Touch typing is irrelevant for programmers

Saturday, October 11th, 2008

Steve Yegge argues that touch typing is a fundamental skill that all programmers should have.

I disagree. Being able to type at a reasonable speed is important, but touch typing isn't. I never learnt to do "proper" touch typing, but I type pretty fast and I don't look at the keyboard when I type. I also don't always use the same finger for each key - I use the finger which happens to be nearest to the key I want to press. I'm not overly terse when writing comments, emails and documentation. Improving my typing speed wouldn't make me more productive - the bottleneck is my brain, not my fingers.

Touch typing was invented for typing dictated text on mechanical typewriters which required a lot more force to operate than a computer keyboard. Programming is very different. Working on code there is much more punctuation, much more moving around the document and much more reading. Keeping hands in the touch typing position means that they are not in good places for punctuation and cursor movement, which is slower and leads to RSI.

Touch typists also dislike laptop keyboards. I prefer laptop keyboards to full-size keyboards - the keys are closer together and travel less far, which makes typing faster.

Manifesto

Friday, October 10th, 2008

I seem to have developed opinions about a lot of political things over the past few years. Here is a rundown of some of them. This is rather US-centric but much of it applies anywhere. In alphabetical order:

Copyright & patents

  • Put the copyright term back to 14 years with an option for another 14.
  • Eliminate work for hire - copyright remains with creators. For a large project like a movie, this won't make much difference since it would be difficult for someone else to come along and obtain licences from all the people involved. Recording studios will work for musicians, not the other way around.
  • Only work which is available to the general public in the preferred form for making modifications to it is considered to be copyrighted.
  • Introduce compulsory licensing - copyright should not give you a say about how your work is used, just that you get reimbursed for it. Yes, this would break the GPL but I think these reforms would also make it unnecessary.
  • Abolish software patents.
  • Disband the RIAA, MPAA and BSA for racketeering.

Defense & foreign policy

  • Reduce military spending. Investigate abusive recruitment tactics - allow people to opt out of being contacted by military recruiters.
  • Get out of Iraq as soon as possible - civil war seems to be inevitable there anyway. Get out of Afghanistan. Stop picking sides in conflicts between other countries. Stop supporting regimes with abusive human rights records. Adopt a general policy of non-interference with foreign governments except by UN resolution. Promote mediation between conflicting parties rather than invasion and occuption as a way to reduce conflict.

Drugs

  • Reduce the drinking age to 18.
  • Make all currently illegal drugs legal for people 18 and over. Tax them. Stop interfering with drug-producing countries. Ensure anybody who is addicted to drugs and does not which to be has access to rehabilitation facilities. Make rehabilitation mandatory for convicted criminals before their prison sentence can start.
  • Pardon anyone convicted for non-violent drug crimes not involving under-18s (i.e. anyone who would have done nothing wrong under these new rules).

Education

  • Empower teachers to give students the guidance they need. Education is critical for avoiding hereditary poverty and making the society work - you can't have real democracy without an informed electorate, or a working free market without informed consumers. Education is also critical for a country to be competitive in the global market, and for progressing science and technology as rapidly as possible.
  • Teenagers must be taught how various contraceptives work and how to use them, what STDs are and how to avoid them, how the human reproductive system works and that they should never feel obliged to have sex with anyone that they don't want to have sex with. Parents should not get to opt their children out of this, but are welcome to tell children that abstinence is best outside of school.
  • Certain other life skills like how to do household budgeting and how to raise children should also be taught in school.

Healthcare

  • There is a big problem with ever having someone that is uninsured - if they become ill while uninsured, they can't get insurance "because you don't insure a house that's on fire". Nobody should ever get bankrupted as a result of illness or injury. To fix this, ensure everyone has free-at-point-of-use access to a basic level of healthcare including preventative care and life-saving care.
  • Keep abortion legal up to a certain gestational point as it is today, but do what we can to make it as rare as possible. Provide free contraception. Provide more help for mothers who choose not to abort. Promote adoption as an alternative, including removing roadblocks preventing gay couples adopting. These things will reduce abortion more than banning it.
  • Ban circumcising children. This might be rather controversial, especially in the US but there is no medical reason for it. People might object on religious grounds, but we don't allow mutilation of girls for religious reasons - why should boys be any different? Adults can still be circumcised if they want to be.

Homeland Security & Immigration

  • Get rid of US-VISIT. Expand the visa waiver program. Stop mandating RFIDs in passports. Be more welcoming to tourists.
  • Make it quicker and easier for people to become permanent residents and citizens.
  • Scrap security theater in favor of actual security. Affirm the right of people to take photographs in public places (even of police officers, infrastructure and government buildings).
  • Scrap the no fly list - it's racist and ineffective. If anyone on it is actually too dangerous to be let onto an aeroplane, prosecute them.
  • Shut down Guantanamo Bay.

Justice & crime

  • Repeal the death penalty - it has no place in a civilized society.
  • Start a program to allow early parole of some prisoners into the military for rehabilitation purposes.
  • Nationalize the prisons - they never should have been privatized in the first place.
  • Get rid of the PATRIOT act. No searches, taps or seizures without a warrant.
  • Any seized property that is legal to possess must be returned within a week (enough time to copy the hard disks of seized computers).
  • Investigate unconstitutional restrictions on freedom of speech and assembly (e.g. at the GOP convention in 2008). Put safeguards in place to stop such abuses happening again.
  • Make it easier to impeach government officials for condoning torture or suspension of Habeas Corpus.
  • Many injustices seem to be caused by pleading guilty in exchange for a reduced sentence. This practice should be prohibited - the purpose of the court system is to find the truth, not to make it easy for prosecutors to find somebody to blame.
  • I don't think it's practical to ban guns in the US, but close loopholes allowing people to obtain guns without licences and background checks. Investigate introducing technologies that prevent guns from being fired by people other than their legal owners, and eventually phase out guns that don't have such a mechanism.
  • Decouple police funding from traffic fines so that speeding tickets etc. are handed out to improve safety rather than raise money.

Religion & culture

  • Repeal the tax exemption for religious entities. If churches want to do charitable work they can fork off a charitable arm which must not promote religious beliefs, and donate money to these organizations tax-free as corporations can do.
  • Allow creationism/intelligent design to be taught in schools but not in science lessons - schools should have religious education lessons which teach what people believe, why they believe it, what they practice etc. This should include a discussion about what creationism/ID is and why it exists.
  • Provide help for people who want to leave a church or cult but who fear retribution.
  • The Archbishop of Canterbury was involved in some controversy a while back for saying something to the effect that aspects of Sharia law in the UK were unavoidable. If you read what he says, it's actually quite sensible - if Muslims (or any other group) wish to have their own courts for dispute resolution they should be welcome to do so (but can fall back to the state courts if they do not wish to abide by the private court's findings.)
  • Ensure homosexuals have the same civil rights as heterosexuals. Don't care whether you call it civil unions vs marriages or marriages vs church marriages or get rid of all marriage-based civil rights altogether - that's just semantics. But make it fair. Churches should not be forced to perform or recognize any unions they don't like (not that anybody is suggesting that they should as far as I can tell.

Tax & economics

  • Tax as little as possible, but recognize that some taxation is necessary to ensure a decent standard of living for the most vulnerable members of society.
  • Taxes should generally be fair, progressive and cheap to collect. Simplify the tax code. Allow everyone to file taxes online for free.
  • Taxation policy can be used to encourage behavior that benefits society. Taxing luxuries (especially unhealthy ones like tobacco, alcohol and recreational drugs) is a good idea, as are tax breaks for entrepreneurial enterprises.
  • Eliminate the deficit and put safeguards in place to prevent future deficits.
  • Most things can be handled by the market with some regulation to ensure the market is diverse and well-informed - the recent financial crisis was caused by deregulation.
  • Companies that get "too big to fail" should be broken up into smaller companies before they fail rather than get bailed out at taxpayer expense when they inevitably do.
  • Unsecured loans are a bad idea - discourage them by making bankruptcy easier. Ultimately it would be great if this would lead to the demise of the credit reporting agencies.
  • Overhaul zoning laws to make it easier for people to run businesses from their homes and to make cities more livable/walkable by mixing commercial/residential areas more.

Science, technology & the environment

  • Progress is good. Promote cheap bandwidth.
  • Much research can be done in the private sector, but there is a place for government funding research whose payoff is too small financially or too far off in the future for the private sector to be concerned about it.
  • Environments are good. We should have one. Sign the Kyoto protocol. Amory Lovins has some good ideas about how to reduce and ultimately eliminate use of fossil fuels.
  • Public transport is good. So is investment in infrastructure.

Unemployment & poverty

  • Provide training and job-seeking help for the employed in return for unemployment benefits. Help families escape the cycle of poverty by giving them the resources they need to raise children to become successful and productive adults.

Voting & politics

  • Everyone over the age of majority should be allowed to vote, even prison inmates. Disenfranchising people is wrong.
  • Only a vote on a paper ballot is a true vote (though machines can be used to fill out the ballots and generate exit polls). Wanting the results on election day is not a good excuse for making voting easy to tamper with.
  • Severly limit campaign spending and lobbyist influence. Reduce the amount of money in politics.
  • Switch to approval voting or similar to improve the diversity of views in government beyond the two party system.