Dynamic Source Maps

I’ve been looking at source maps recently. The reason for this is that I want to be able to pass some code through a pipeline of transformations, but still maintain sourcemaps so that you get the nice debugging behaviour.

The specification for source maps talks about VLQ as if it’s a well known thing, and perhaps it is - apparently it’s part of the MIDI spec and the wikipedia page is entirely focussed on that implementation. I finally found a bit more detail from Peter van der Zee on exactly how it works and was able to create my own decoder.

As part of that, I got into a discussion about whether it was possible to use dynamically generated source maps. The result of my investigation is on github here.

Dancing-links: What Programming Is

Most people have no idea what ‘being a programmer’ is about. A common response when saying what you do is ‘oh, I couldn’t do that, staring at a screen all day’.

In the hope of communicating better, I’ve been trying out a few different responses. One I tried recently is “I solve abstract problems through the manipulation of symbols”. By itself it doesn’t actually help all that much but it does open up a whole realm of possible conversations that would normally be shut down by ‘oh I couldn’t do that, staring at a screen all day’.

What do I mean by abstract problem? Well, the sudoku in the paper on friday is a concrete problem. An abstract problem would be solving every sudoku. Solving the friday sudoku gives you the solution and some limited insight into how you got there. Solving the abstract sudoku problem gives you every solution for any sudoku you come across in the future, and an insight into what kind of thing sudoku actually is, what solutions are, and often what sorts of things are going on in the human brain, and what sorts of things would go on in the human brain if its ability to keep track of things without getting bored wasn’t hopelessly stunted.

Every time you tried to solve a sudoku and found yourself jotting little notes to help you keep track of more information than could reasonably be kept in your head you were reaching for solutions that were beyond what is practical in a normal human brain. If you ever started reading about ‘techniques’ or trying to work out all the different ways you can make progress on a sudoku, you were thinking about the abstract problem.

Solving the problem teaches you the solution. Solving the abstract problem teaches you about yourself and the nature of the world.

What does the solution to the abstract problem look like? The solution to the abstract problem has to be able to generate a solution to any of the concrete problems, so rather than a filled in grid, the solution to the abstract problem is a process that given a puzzle grid will generate the filled in grid. Both the concrete problem and the concrete solution can easily be printed in a newspaper but the abstract solution is a process which could be represented in many different ways none of which look anything like a sudoku grid, just as a recipe for cupcakes doesn’t look anything like an actual cupcake.

cat sleeping when it should be doing sudoku because this *is* the internet after all
A cat is not a good abstract solution to the problem of sudoku.

Still, while the abstract solution may be a process, we need a way to communicate it to other people, so we describe the process in words. As you come up with more and more abstract solutions, you discover that a lot of the parts of the process can be broken down into small steps that are used in all sorts of different abstract solutions. Amazingly, these steps are simple enough that they can all be done by machine, so you can build a machine that takes a description of an abstract solution and makes that process easily repeatable (which is in fact what a computer is).

One of the interesting things that comes out of finding the abstract solutions to problems instead of the concrete solution is that sometimes you find that the exact same abstract solution can be used to solve apparently different problems. Often this involves converting between different representations of the problem. For example, there’s no difference between a sudoku puzzle where the symbols you use are the numbers 1 to 9 or the same puzzle using the letters A to I. You can rotate a sudoku puzzle or flip it upside down, but it’s still essentially the same problem. Once you start thinking like this, you can make surprising discoveries, like the fact that tiling shapes into a chessboard can be solved with exactly the same abstract solution as sudoku.

For a time, it was hoped that perhaps all problems in the universe could ultimately be solved by one single master abstract solution, which would contain the answer to everything. Starting perhaps with logic and maths puzzles, and then ultimately, as we find better descriptions for the universe moving on to problems of physics, chemistry, biology and psychology. The german mathematician David Hilbert in the early nineteen hundreds was particularly associated with the first part of this task. The dream of being able to do this with everything looks pretty unlikely now that Gödel proved that any system that includes simple mathematics can represent problems for which it is unable to represent solutions, but there are many interesting stories in the history of logic puzzles, going back at least to Archimedes who proposed a maths puzzle about the ‘cattle of the sun’ which when solved gives an answer of more cows than could possibly fit in the visible universe.

In computing we call the process that is an abstract solution an algorithm after the Persian mathematician Muḥammad ibn Mūsā al-Khwārizmī from the 9th century House of Wisdom in Baghdad. One of the abstract solutions for solving sudoku (and n-queens, and shape tiling…..) is called Algorithm X, and an efficient way of keeping track of all the moving parts was named ‘dancing links’ by computing legend Donald Knuth (currently working for Google).

For fun, I’ve implemented dancing links here where you can see it solve sudoku and shape tiling (at the bottom of the page). It’s also a project that I created using particular tools and services; javascript, jasmine, node.js, heroku, jsdoc, cloud9, git, github and I will write a more technical blog about my experiences with those soon.

Game In A Day Challenge

Looking through my ‘project ideas’ page, I see that many of them rather ambitious - plans that would really require a minimum of a year of full time effort before seeing anything. They’re all really good ideas, but the chance of me actually doing any of them short of winning large amounts of money in a lottery is fairly slim.

I’ve been reading The Lean Startup recently, and one of the things that struck me is the importance of getting things in front of people quickly. It argues this from the importance of learning and appropriately acting in an uncertain environment, but perhaps even more important is in terms of your own motivation and focus.

So I set myself a challenge. Could I create a game and put it on the android market in less than a day?

You can see the answer here or if you don’t have an android phone here.

It’s designed to be played on a tablet, and you drag your green circle around while at the same time shooting at the yellow circles. It’s pretty simple, but reasonably fun.

I certainly learnt a lot, and one of the best things that came out of it was that it inspired me to spend a week learning and writing other things that came from it. I think that perhaps the biggest benefit setting myself a ’1 day’ challenge is the effect it has on larger projects too.

The centre of the universe – 1665

The other opinion - followed by the Pythagoreans, Aristarchus of Samos and others long before Aristotle or Hipparchus or Ptolemy came into this world and returned to center stage by Nicolas Copernicus some one hundred years ago - is still approved by the most excellent mathematicians. It places the sun at the center of the universe as the soul of the world and governor of the universe, from which the earth and all the planets borrow their light. There they believe it to remain stationary, as we can see in the second figure…

Now it is not our intention here to specify which of these opinions is consistent with truth and best befits the natural order of the world. That is a question we must leave to those versed in the science of celestial matters. And for all that the earth, according to the Copernican hypothesis, moves annually around the sun in a circle whose diameter would be two million leagues from Germany, and that the sphere of the fixed stars would be of so vast an extent as to be utterly incommensurate with that of the sky around the earth, there is, nonetheless, no noticeable difference between this theory and the earlier one (according to which the earth is the center of the universe) in respect of the apparent rising and setting of the celestial bodies, the changing duration of days and nights and the other things that follow from this. But since the hypothesis of a fixed earth seems generally more probable and is, besides, easier to understand, this introduction will adhere to it, without for the present considering the other theories.

- Introduction to Geography, Joan Blaeu, Atlas Maior, 1665

(by the way, two million leagues is about the 1/75th of the true distance).

Milgram

This is distressing. I had thought that there was a reasonable argument to be made that adults in modern society are a lot more individualistic and skeptical of authority than in the early 1960s. Apparently that was just wishful thinking on my part.

Recent notable HARDtalks

Dissident writer Liao Yiwu spent four years in jail after writing an epic poem about the Tiananmen Square massacre. In a rare interview, Liao talks to Stephen Sackur. on iplayer, the interview webpage

When the pictures of torture of Iraqi prisoners by American soldiers at Abu Ghraib prison flashed around the world in April 2004 most people were shocked. But the images were eerily familiar to Professor Philip Zimbardo, as they were very reminiscent of those he himself had taken during the famous Stanford Prison Experiment, which he devised in 1971. Stephen Sackur talks to him about the parallels and the lessons we should learn. on bbc programmes (I have this one recorded, let me know if you want to borrow it).

Res Judicata

John Reynolds stood in the lobby of his office block staring up at the sheets of rain that had just unfolded themselves all over his unremarkable town. He’d just finished an unremarkable day of giving advice to customers of his employer. After a moment, he exchanged nods with the security guard, zipped up his unremarkable coat and stepped out into the downpour.

Stooping along the slick pavement, his head into the wind, he would barely have registered that there was a man in the long dark coat and pulled down hat in his way but for the two words said to him as he moved to go past.

“Mr Reynolds”

Nobody had said those two words to him for more than six years. He stopped short, standing straight, the rain forgotten.

The first thing his brain reached for was the simple lie; “That’s not my name”, but as he became aware again of the rain dripping from his nose and running in rivulets down his coat he realised the futility of denying with his mouth what he had already confirmed with his actions. He felt once more the vague sense of danger he had managed to forget as the years had passed.

“Are you with the police?” he asked.

The man paused, then nodded. “Let’s talk somewhere drier”, he said, and gestured towards a nearby car.

John started to back away. If they knew where he worked, they probably knew where he lived. What was left for him now? “I’m afraid I’m going to have to see some identification” he said.

It was at that point that he stumbled backwards into another man who’d stepped out from behind the car.
“Careful sir”, he said, hand resting firmly on Johns shoulder. With quick efficiency John was guided into the back seat of the car, where he made a dejected puddle in the upholstery.

~~~

An hour later the car pulled up outside a miserable concrete construction. The rain had slowed to a drizzle and John had collected himself enough to realise that he was falling apart. Not just emotionally. Over the years, he had come to believe in the new identity he’d forged; now he was losing that, he wasn’t really sure who he was. What did he have left? He knew he was angry though. And scared too.

The two men in the front of the car hadn’t said much to him the whole journey. He’d been trying to guess who they might be working for, but since the building they’d pulled up to was obviously government owned, he was assuming it was something to do with the witness protection program. That didn’t explain their tactics though.

They bundled him through the door quickly, but he was quick enough to read the lettering in black stencilled onto the reinforced glass. “Department of Decided Matters”.

“You’ll be wanting to talk to your lawyer I suppose”, said the man who’d first approached him.

“Do I need to?”.

“Well, you’re under arrest, and will be deported tonight”

“Deported?”

“You have a court appointed lawyer, upstairs, first door on the right.”

The stairs were narrow, steep and the plastic underfoot felt cheap. John pushed his way into the cluttered office, and sat down in what was obviously the designated clients seat. His court appointed lawyer was nowhere to be seen. He drummed on the desk to pass the time.

It was then he noticed the newspaper. It was sitting on the top of a stack of papers on the desk as if someone had been reading it before he came in. The date was from six years ago, shortly after he’d been put in the witness protection program. He’d blundered innocently into working for an organised crime syndicate, and had gone to the police as soon as he realised. There were still those who wanted him dead.

The newspaper was one he’d read at the time. Shortly into his new life and new identity, he’d read about the horrific murder of Senator Jackson and the trial of John Reynolds, his killer. Was it just coincidence that the man had had the same name as him? He’d looked very familiar in the photos, grainy though they were. He’d assumed that it had been a clever trick by the witness protection agency to make it look as if he was out of the picture while he got on with his life. He hadn’t followed the case that closely, prefering to concentrate on what was new in his life.

Imponderables, partially pondered.

Derek Abbott has a hobby of collecting Imponderables. Interesting or unanswered questions. Many of them require specialized knowledge, or more rigor than I’m prepared to put into them at the moment to attack them properly, but here are a few of my thoughts on some of them.

Information theory: Imagine you are an alien from a totally different world - so different that even the building blocks of life are completely different on your planet. Now say that you land on planet Earth. You find three huge sheets of paper (i) one containing English text (ii) one listing a DNA sequence and (iii) one listing a computer program. You have no idea which is which, but you recognize you are looking at ordered bits of information - three very strange and different languages. The question is, using statistical principles and principles from information theory can you (the alien) detect any fundamental differences between the three sheets of paper so that you can distinguish between a human language, a machine language and a biological coding language? Or is it in fact impossible to distinguish them in principle?

Are we talking C or Haskell? Information theory could tell you the level of structure and redundancy in each. My guess would be that entropy could be measured and would go DNA > English > Computer program. No real idea though.

Convention: Why do clocks go clockwise?

I’ve read that this is because clocks were invented in the northern hemisphere and the hands were intended to bear a similarity to the motion of the sun. Pointing south, they go from east to west.

Ethics and Law: Imagine you have been sentenced to jail for 50 years for murder. But you are really innocent (someone set you up). You serve your sentence and when the 50 years is up, you are so angry that you kill the person who set you up. The question is: should you go to jail for a further 50 years or have you already served your sentence in the last 50 years?

On the one hand society owes you 50 years and if it realizes (you find some way of proving your innocence once freed) it should pay you back that time as best it can, on the other hand, I don’t believe that it is appropriate to be able to serve sentences in advance, otherwise anyone who had suffered oversentencing can hold the rest of society to ransom for the rest of his life. Someone could check themselves into prison for beating their wife, and when they got out, threaten the wife with beatings for the rest of her life. Allowing people to receive sentences for crimes they have not yet done, ignores the fact that the threat of committing a crime at some point in the future can also be a terrible curtailment on societies freedoms. In economics, companies can offset debts that may or may not be called in, society would have to do the same with crimes. The purpose of the 50 years sentence, justified or not was to teach not to murder. If someone comes out and immediately murders, then it was unsuccessful, and another sentence is appropriate.

Philosophy: What is truth?
Philip K Dick: Reality is that which, when you stop believing in it, doesn’t go away.
Truth is an expression of reality. People express reality by speaking or acting, nature expresses its reality by being sensed. Since we are incapable of fully expressing reality, any truth that we encounter will necessarily be partial. There is also the danger that any expression will reduce the ability of the mind that receives it to comprehend truth beyond the boundaries of that expression, or around it’s edges. I believe that’s why many mystics find it safer to define the things that are not true rather than run the risk of actually describing truth.

Law and Sociology: It could be argued that when we lock someone in jail for a crime, we cut them off from society and inevitably interfere with any possibility of normal social development of that person, and therefore perpetuate their condition. If the person is a danger to society, is there an alternative?
Although the argument might be accurate, the premise is wrong. Their normal social development so far (they were previously not cut off from society), led them to crime. Since their normal social development was harmful to society (and probably to them), it is sensible to argue that the kind of development most beneficial to them (and society) in future would be different to their “normal”. It’s the exact opposite of perpetuating their condition that is the intention. Is there an alternative to removing someone who is a danger to society from society? Yes, society can simply accept the cost of the crime and absorb it. I think this is a good idea in only a few situations (cycle of vengeance type problems). This doesn’t mean that jail is the best way of changing what is normal for their social development though. Perhaps a loving family environment may be better, assuming that that is not the environment that led to their current social development.

Philosophy: If there were no evil in the world, would good cease to have meaning?
Good would not cease to exist, but if there were nothing to distinguish it from, the word itself would lose meaning.

Law: Many paradoxes in law arise because law is black & white and real life is a continuum of grey. Law takes continuous variables and sets a threshold or boundary. Either side of the boundary is 1 or 0, ie. right or wrong. Is this for convenience because we have no better way or is there a deeper reason? If it is a matter of convenience, can we someday use technology to evaluate all the main variables and produce continuum based laws? Could we trust machines? Would it be fairer than binary laws?
Law is not binary. We already have continuum laws. Every law is required to be applied by a person to situations. Whether or not to apply any punishment in a given situation is at the discretion of a person, and how much punishment is also at the discretion of the judge. Since there are innumerable kinds of situations, situations can arise that were not forseen when the law was created, only a machine capable of understanding the intent of the law and the new, unforseen situation should be trusted (reduces to the Strong AI problem). A fundamental principle of fair laws is that those they apply to should be easily able to understand them.

Game theory: If a country has the capability to fire a nuclear missile at New York city, then conventional game theory seems to tell us that New York should point a nuclear missile at the other country. This creates a stalemate, so that no actions are taken and we are all safe. However, straight game theory needs to be expanded to include error analysis. The question is what if a nuclear missile was fired at New York and was said to be by mistake? What is the best strategy for New York now? From a game theory point of view, should New York still strike back? Also there are two possibilities to consider: the declared mistake could have been genuine or a bluff. Also another related question is that if the missile is intercepted whilst in the air, will the resulting explosion create more deaths and than if the bomb was allowed to hit the ground?
Perhaps the residents of New York should estimate the likelihood that their enemy will trigger the bomb by mistake, and ensure that their bomb has an equal margin of error. This gives the aggressor an encouragement to decrease the error for their bomb (because New York assures them that it will match any demonstrable improvement).

Extra: Irresistible force meets immovable object
Forces cannot be resisted by objects, only by other forces. So an irresistible force is simply any force not balanced by another force. The only immovable objects that can exist are frames of reference, or objects defined to be at the center of a frame of reference - a perceptor. An unbalanced force meeting an immovable object happens every time I drive a car, and what happens is that from the forces point of view, the immovable object moves (it must, unbalanced forces are defined to accelerate), and from the immovable objects point of view (my frame of reference), the rest of the universe moves.