A little mathematical game

August 26th, 2008

Given five things:

  • The number 0, denoted 0
  • The ability to find ex for any number x, denoted {x}
  • The ability to find the principle natural logarithm log(x) for any number x, denoted [x]
  • The ability to find the additive inverse -x for any number x, denoted <x>
  • The ability to find the sum x+y for any pair of numbers x and y, denoted (x+y)

What numbers can you make and how long are their denotations? This gives some sort of metric to how "complicated" a number is. Write the length of the smallest possible denotation for number x as L(x). Then:

  • Subtraction: a-b is denoted as (a+<b>) and L(a-b) <= 5+L(a)+L(b)
  • Multiplication: ab is denoted as {([a]+[b])} and L(ab) <= 9+L(a)+L(b)
  • Division: a/b is denoted as {([a]+<[b]>)} and L(a/b) <= 11+L(a)+L(b)
  • Exponentiation: ba is denoted as {{([a]+[[b]])}} and L(ba) <= 13+L(a)+L(b)

Some interesting numbers, with their complexities:

1 {0} 3
e {{0}} 5
-1 <{0}> 5
2 ({0}+{0}) 9
i {{([[<{0}>]]+<[({0}+{0})]>)}} 29
π <{([[<{0}>]]+[{{([[<{0}>]]+<[({0}+{0})]>)}}])}> 47

Some interesting questions:

  • How does the complexity function L grow with its argument?
  • What interesting numbers do not have finite complexity?
  • How could the game be changed to include them?

Related: Fine structure constant update.

rm for the web

August 25th, 2008

My first thought on reading this article was "what would an rm for the web look like?". It seems that many of the commenters on that post had the same thought.

One possible way this could work is to set up a proxy that people can set in their browser. Then if they don't want to see a particular website any more, they can visit the "rm" website, enter the address of the website that they don't want to see any more and then it would be blocked by the proxy. The "rm" website should of course also provide some way to remove a site from the blocked list.

There are a few reasons why such a thing might be useful. There are a few "shock websites" out there which most people would not want to visit knowingly. It could significantly cut down on the number of instances of rickrolling and spyware infections. It could enable organizations to take control of their own web filtering needs rather than relying on some off-the-shelf solution which is bound to block some sites that it shouldn't. Of course it would be easy to circumvent, but that's not the point - the idea isn't to prevent people from seeing stuff they really want to see, it's to keep them honest and keep them from accidentally stumbling onto unsavory areas of the web.

Evidence against God

August 24th, 2008

A commenter recently suggested that if I wanted to believe in God and went looking for the evidence, I would find it. Nope. Tried that. It didn't work. Back at university I engaged in some great debates with theists, and I really wanted to believe in it. But a dispassionate look at the evidence really does favour the atheist point of view.

The first piece of evidence that Christians will point towards is the Bible. "It's a historical record" they will say. Evidence it may be, but it's not good quality evidence - it's all second hand. Stories passed along from person to person, distorted by time and translation and plucked from historical context. Let's contrast this with the evidence for quantum mechanics (which seems similarly ridiculous at first glance). This is real evidence - experiments which you can do to convince yourself even if you think the original experimenters lied about their results. Experiments which have been repeated all over the world and verified many times. That's real evidence. A book (even a very popular one) is not good evidence.

The next thing Christians will try is sheer weight of support - "two billion people can't be wrong" they say. Well, of course they can - there are also two billion people who are Muslims and Hindus, who the Christians will say are wrong. And another two billion people are either not religious or believe something other than "the big 3". So whatever the truth is, at least two thirds of the people are wrong about it. And even the 2 billion Christians can't all agree on which particular sect is the right one. Number of people is not good evidence.

The third thing is "the power of prayer" and religious people have lots of anecdotes about how prayer has helped particular people. Anecdotes are not evidence though - they suffer from selection effects. When theists pray for something and it comes true it is seen as evidence for God but when they pray for something and it doesn't come through it "must not be God's will for this to come about". If you do actual scientific, statistically accurate analysis of the power of prayer it turns out to have little or no effect. Any effect it does have is not proof of God anyway - it could just be a form of placebo effect.

The fourth is "religious experiences" - people who claim to have seen or touched God, or to have had very powerful feelings of being close to a magnificent, benevolent power. I used to find this argument extremely compelling (and was quite jealous that I hadn't experienced it myself) but I have since discovered that similar effects can be induced in the brain with magnetic fields or drugs. Like the power of prayer, this is something else that is "entirely within the mind". Chemical imbalance in the brain seems to be a much more likely explanation for these experiences than God.

These seem to be the main arguments. There are a number of minor ones as well but they mostly seem to have logical flaws like taking their conclusion as an initial assumption.

There are some very compelling arguments against God as well. The main one is Occam's razor - positing the existence of God doesn't actually explain anything (not even the creation of the universe, as God Himself then has the same origin problem). So we can get a theory of the universe that is simpler (and therefore more likely to be correct) by not including God.

Another thing that I found very convincing is the geographic distribution of different religions. People tend to believe the same things as their parents, friends and neighbours. This suggests that religion is passed on from person to person like a meme rather than having any intrinsic truth. Dawkins poses an evolutionary explanation for this strange human behavior - there is an evolutionary advantage to believing what your parents tell you. This behavior started out as a way for advantage-giving wisdom like "don't eat these particular berries" to spread to one's offspring but because historically we had no way of verifying these memes, incorrect but (mostly) harmless memes like "pray to the great invisible being for healthy crops" also sprang up and took advantage of the same mechanism.

A third argument against religion is how contradictory it is. Surely if there was a God and He wanted us all to behave in a particular way, he would have made the bible very coherent and hard to misinterpret. It is none of these things, as we see from the number of people who misinterpret it to forward their own agendas constantly. In fact, religious dogma seems to be particularly effective as a tool for powerful ruling classes to exert control over the general population, which suggests that it evolved to be that way for exactly that purpose.

Atheism vs agnosticism

August 23rd, 2008

I used to describe myself as an agnostic, but now I describe myself as an atheist. What changed was not my faith (or lack of it) but what I understood those words to mean.

I used to think that the meanings were as follows:

Atheism: I believe there is no god.
Agnosticism: I neither believe nor disbelieve in God.

But I know think that the following definitions are more accurate:

Atheism: I do not believe that there is a god.
Agnosticism: I have no opinion about the existence or nonexistence of God.

Specifically, I don't think that there is a god but would rather avoid describing myself as having any sort of "belief" one way or the other, because that word carries some implication of "belief without (or despite) evidence". While it's impossible to ever prove with certainty that there is no god (or indeed to prove with certainty anything other than "I think, therefore I am") I think that there is a great deal of evidence that there is no God. I'll take a look at some of this evidence tomorrow.

Apostasy

August 22nd, 2008

There have been several moments during my life that particularly influenced me towards atheism.

One of these was when I first started learning about science. Scientific explanations seemed to me to be much more satisfying and believable than those of the bible. For a while I thought that this was because the people who originally wrote down the bible were not sophisticated enough to understand the science so it was written down in terms they might be able to understand on some level - that the bible was a simplified version of the truth that we would eventually figure out for ourselves. I had precedents for this concept - I had computer manuals which give strict instructions like "don't remove the floppy disk from the drive while the light is on" but I later discovered that you can remove disks during the time between when the save operation completes and the light goes out (the instruction in the manual was less efficient and less accurate but easier to understand and more difficult to screw up).

The second of these moments was probably when I was told the story of "doubting Thomas". Nobody ever seemed to be able to explain to me exactly why being skeptical was a bad thing (other than the usual "God works in mysterious ways" rubbish that I always found totally unconvincing).

The third was probably when I tried to read the Old Testament. This must have been during secondary school as well. I got as far as the story of the Tower of Babel. In the past when I heard this story it had been presented as a kind of "just so story" about the origins of the different languages. But when I read it for myself I realized that this God was a real dick! Rather than celebrating the great achievements of his creation, he scrambles their language out of fear and jealousy! ("...now nothing will be restrained from them, which they have imagined to do. Go to, let us go down, and there confound their language..."). At that point I was so disgusted I gave up.

The fourth was at university when (while debating a Christian friend) I came across a site called "Who Gives a Fish" (which now longer seems to exist). This linked to some extremely compelling arguments that all of Christianity is bunk. After reading that (and failing to find the refutations to it that I would expect to find if it were false) I no longer had any desire to be infected with this particular meme.

That I ended up an atheist despite my religious upbringing seems to me to be quite damning evidence against God - surely if there were something to it at least the people who started off religious would stay religious.

I never believed in Jesus

August 21st, 2008

I used to think of myself as a Christian, back in primary school and the early part of secondary school. I was brought up in the Church of England. My first primary school was a C of E school, meaning that we had prayers in morning assembly and (one or twice a week) the vicar would come and tell us bible stories. For a while I went to Sunday school every week. I found this very boring and I'm sure I always used to say "It's Sunday - why do I have to go to school?".

In secondary school one day they handed out little red Gideon bibles to everyone in my year. I recall observing with horror when some of my classmates mutilated their copies. I read mine every day for probably the best part of a year. I don't recommend it - the writing style is really rather awful (I eventually gave up because it was so unreadable rather than through lack of faith).

Even amongst all this religious upbringing, I don't think I ever believed that the stories about Jesus and all the other bible stories were ever more than stories. They were just too ridiculous. In fact, I don't think it even occurred to me that there was anyone who ever thought of them as anything other than parables - certainly none of the religious people I knew ever gave me the impression they did. In fact it wasn't until I got to university that it sunk in that there were people who actually believed in the literal truth of the bible! This may seem strange to my American readers as this point of view is quite common here but I suspect it is the exception rather than the rule in England.

The trouble with editors

August 20th, 2008

Since changing jobs I now mostly work with Unix machines rather than Windows ones. Mostly it's a not too unpleasant experience (once things are set up the way I like them) - Unix seems to be much more flexible and configurable than Windows, even if some things don't work quite so well out of the box.

One area I have run into difficulties with is editing text files. When I first started using DOS I used to use edlin, which is horrible. After a while I discovered QEdit on a magazine cover disk and loved it - very quick to load and scroll (even on an 8MHz 8086 machine), easy to use but with powerful macro facilities there when you need them.

I used that up until 2002 when I switched from using Windows 98 to Windows XP and QEdit stopped working so well. I bought TSE (the updated, renamed QEdit) and it was worth every penny - everything that was great about QEdit was the same or better in TSE and I've used it almost every day since for almost every text editing task (though I have been known to use the Visual Studio editor occasionally for its Intellisense goodness). Moving from QEdit to TSE I discovered that the Windows shortcuts for select, copy and paste (shift+navigation to select, Ctrl-X to cut, Ctrl-C to copy and Ctrl-V to paste) were much quicker and easier than the QEdit defaults (which I think originated in WordStar) Ctrl-K B, Ctrl-K K etc.

When I switched to Linux, TSE was one thing that I missed most. It works under Wine but not particularly well (it always defaults to full screen, copy/paste integration doesn't work and scrolling is painfully slow). A Linux version of TSE is in the works but doesn't show any sign of materializing soon.

Joe is the closest thing to TSE that Linux has to offer but it's a bit limited and just different enough to be annoying. It also isn't available on all of the machines that I need to use. The latter requirement basically means I have to make the big choice - vi or emacs?

I gravitated towards vi initially as it seemed to be a bit more lightweight and I had some experience with it from my brief stint using Debian sometime around 1999-2000. I relearnt how to do the basics, put it into syntax highlighting mode and fix the colours (dark blue on black is unreadable to me, and of course comments have to be in green). But it still drives me crazy - I never know which mode I'm so I'm always inserting ":q" into files or (worse) typing text which gets interpreted as random commands and then trying to figure out what I did and how to undo it.

I eventually found out that most people who develop GNU software use Emacs (I saw a lot of people using it at the GCC Summit) and that it has great features for writing C code according to the GNU guidelines. So I decided I had better learn Emacs. I had used it a bit at university (the Physics department gave us a brief tutorial in it as part of the Fortran course). I have also learnt a bit of Lisp in the intervening years and having Lisp as the macro language of an editor seemed to be a rather reasonable thing to do.

One big problem annoyance with all the Unix editors is that none of them support the Windows-style shortcuts I mentioned above (plus Ctrl-Z, Ctrl-Y, Ctrl-A and Ctrl-S for undo, redo, select-all and save) by default. I almost squealed with delight when I discovered the CUA mode in Emacs 22 which brings it significantly closer to being the perfect editor (at least once I figured out how to tweak various terminal settings to actually make it work - this helped. Unfortunately many of the machines at work still use Emacs 21, so there was some more fiddling required to install the CUA package.

Then I need to figure out if I can get the scrolling behavior to work like QEdit's, fix up some behaviors related to tabs and (once again) fix the syntax highlighting colours. "Eventually I'll have everything the way I like it" may be the mantra of a great many Linux users...

Part of the reason this is so difficult is that customizing editors is generally considered an advanced thing to do - you really have to learn the basics first. But if the first thing you want to do with a new editor is make it act like your old one, you first have to learn the default way of doing things, then do the customization, then unlearn the default way of doing things. My natural inclination is to take shortcuts - try to figure out the advanced stuff without really getting the hang of the basics first. This does seem to have a tendency to complicate things.

Square aeroplanes

August 19th, 2008

Almost all aeroplanes have round cross-sections. This doesn't seem to be the best shape for optimal use of the interior space. In particular, it means that there isn't much headroom above the window seats. On my most recent flights I found that could not even stretch my arms above my head.

I don't think the reason for these round cross-sections is an aerodynamic one - if I recall my fluid dynamics correctly, drag is a function of turbulence, which is caused by chaotic vortices being shed from the trailing edge. I don't think that would be affected by a square cross section.

I suspect that the real reason is that with our current materials, it's easier to make planes strong enough if they're round - a square cross section would have weak points at the corner edges and might lead to parallelogramming. I wonder if future advances in materials science might be able to counteract this.

Airport integration

August 18th, 2008

One of the most annoying things about flying is that airports are generally a long way out of town. This means that you have to leave extra early in case of bad traffic on the way to the airport, and it means that upon arriving you still have to get a taxi/bus/shuttle to the place you actually want to go to.

This seems to be an inevitable consequence of aeroplane technology - it's very loud and smelly and requires a lot of space for take off and landing. But if cities and aeroplanes were designed from scratch with each other in mind, one could imagine that this could be different. While take-offs and landings would still have to happen a way out of town, perhaps boarding and deplaning (what a silly word - what's wrong with "disembarking"?) could happen in the middle of the city and then the plane could taxi all the way to the runway. Perhaps pieces of the plane essential for flying but not for passenger comfort (like wings and tails) could be made detachable - they would be attached right before takeoff and detached right after landing. The rest of the plane could then fit into a tunnel for taxiing into the city. Sounds a bit dangerous, perhaps, but I'm sure there's a way it could be done without compromising safety.

Of course, because this would require massive infrastructure investments simultaneously all over the world it's unlikely to happen for a very long time (if ever) - probably not before our current idea of air travel is superceded by something altogether cheaper, faster, more comfortable and more environmentally friendly anyway. So I guess it will remain just another of my more crazy ideas.

String storage

August 17th, 2008

Most applications store strings as a consecutive sequence of characters. Sometimes when the string is copied the characters are copied too. Sometimes strings are reference counted or garbage collected so to minimize this copying, but copies are made when concatenating and performing other "string building" operations (otherwise the characters would no longer be consecutive in memory).

An alternative that might work better (especially for something like a compiler) would be to do the concatenation lazily. Actual character data comes from just a few places (the input files which are kept in memory in their entirety, static character data, and program argument data). There are two subtypes of string - one consists of a pointer to the first character and an integer recording the number of characters in the string. The other subtype consists of a vector of strings which are to be concatenated together. Integers (and maybe also formatting information) could be kept in other subtypes. The resulting tree-like data structure has a lot in common with the one I described in Lispy composable compiler.

I'm not sure if this actually saves much (if anything) in terms of memory space or speed over the usual methods (I suppose it depends on how long the average basic string chunk is), but it does have at least one potential advantage - Vectors (especially if they grow by doubling) will have many fewer possible lengths than strings, so memory fragmentation may be reduced. I think it's also kind of neat (especially if you have such data structures lying around anyway).