Friday, 31 October 2014

Scottish Devolution, and Socialism in One Nation

Image courtesy of Stewart Bremner
[This is a submission to the Smith Commission, written mainly by me but on behalf of Radical Independence Dumfries and Galloway. It's separate from (and deals with different issues to) my own submission, which is here. My instructions from Comrade Lucy were 'Just scrawl "full communism now" on rahbackuvvah silver rizla'. I may have written slightly more. Thanks to everyone who contributed.]


Dear Commissioners

It is a truth universally acknowledged that, compared to the United Kingdom as a whole, Scotland tilts a little to the left. How far to the left Scotland tilts is something we don’t yet really know; in the run-up to the Independence Referendum the SNP pursued a disappointingly unradical policy, an almost Labourite technocratic administration distinguished only by its relative competence. But the fact remains that even counting Labour as a right of centre party, there are more left of centre MSPs than right of centre MSPs – there is a majority at Holyrood which is to the left of the Labour left-wingers, at a time when the Scottish Labour Party is itself somewhat to the left of its UK parent.

This was one of the key drivers of the Yes campaign in the referendum. The left in Scotland has lost confidence in the possibility of seeing progressive government in the UK, and consequently sees the prospect of independence as a means by which a more left wing state can be achieved.

How left wing? We don’t know. No-one knows. Given the chance, it will develop. It may become Scandinavian style social democracy. It may become Clause Four socialism. It may become full blown communism. It should be up to the people of Scotland to decide. And, as today’s Ipsos MORI poll shows, the djinni is not back in the bottle. Any devolution settlement which does not permit Scotland to evolve – if it so chooses – Socialism in One Home Nation, is not a devolution settlement that can last.

That means that is is not possible to devolve this tax but not that tax, this benefit and not that benefit. The possibility must be allowed for in which the constituent nations of the United Kingdom raise taxes on bases wholly different from one another. Scotland must have the option of raising taxes principally from wealth, or property, rather than from income or consumption. Scotland must have the option of instituting a Citizens’ Income rather than retaining a complicated and inconsistent mess of means-tested benefits. We’re not saying that there is now an appetite in Scotland for any of these things, but rather that Scotland is on a journey and we don’t yet know where that journey will lead; but if the devolution settlement is not sufficiently open and flexible to accommodate the path that Scotland chooses, then the devolution settlement will fail.

This, inevitably, raises the matter of TTIP. It should not be in the gift of the UK government to offer up, through secret treaties entered into without public consultation, the public services of Scotland to bids from private industry. It is for Scotland to decide whether our health care, our social care, our street cleaning and bin collections, our fields, hills, factories and housing are to be in public hands or private. If Scotland chooses


“to secure for the workers by hand or by brain the full fruits of their industry and the most equitable distribution thereof that may be possible upon the basis of the common ownership of the means of production, distribution and exchange, and the best obtainable system of popular administration and control of each industry or service”

then that is Scotland’s choice, and must prevail.

The same applies to policy on energy. Scotland has different energy resources, and different energy opportunities than the other home nations. It has significantly higher average windspeeds, a much longer coastline exposed to rougher seas and fiercer tides; it has much more fossil hydrocarbon reserves already discovered than it can responsibly afford to bring to the surface and burn. At the same time it also has scandalous levels of fuel poverty.

Scotland should not be forced to pay to subsidise a nuclear power station in Somerset which it categorically does not need. But similarly, Scotland should not be forced to accept fracking on its own soil. Scotland may choose to frack, or not; it may choose to buy expensive baseload power from the French government’s power station in Somerset, or not. Energy policy, like social policy, taxation policy, education policy, transport policy, must be devolved, and for the same reasons.

So the question becomes, what should not be devolved? It is a fact which cannot be denied that there was a referendum on independence, and the Yes side – on which we stood – lost. Because the Yes side lost, the pro-union parties are feeling encouraged in a spirit of triumphalism to row back from the generous offers they made in the closing days of the campaign. They are well advised to be cautious in doing so. The Ipsos MORI poll published by STV today suggests that pro-independence candidates – the SNP – will take 54 of the 59 Scottish Westminster seats at the general election in just six months time. And if that should happen, then the outcome of the referendum is moot: there will be a clear and incontestable mandate for independence. The will of the Scottish people is by no means settled.

The positive case for the Union, in so far as it was made at all by the No side during the referendum campaign, seems to be that the Union allows a Labour government to impose, with Scottish votes, policies on England that the English do not want and the Scots would not themselves tolerate; and it allows Conservative governments to underpin their economic incompetence with the proceeds of North Sea oil. We’re sorry, you cannot have either of those. The West Lothian Question is a paradox at the core of our constitution; it cannot continue. English votes for English laws may be a slogan of the right, but it’s also clearly democratic and just. The English should be allowed to implement policies which the Scots would not choose for themselves, just as mush as we should be allowed to implement policies which the English would not choose for themselves.

In order to prevent that – in order to retain the UK – the pro-union parties must live up to and exceed their pledges. The irreducible minimum that is required for a functioning UK is that Westminster should control Defence, Foreign Policy and Monetary Policy. We acknowledge that if there is to be a Union at all, these things must be retained by the centre. We caution the Unionist parties that little else should be, if they wish the Union to survive a twelvemonth.

And acknowledging that Defence policy should continue to be a reserved matter does not mean that we are content that the United Kingdom should continue to park its weapons of mass destruction on Scotland’s lawn, in Scotland’s landscape and within spitting distance of Scotland’s largest city. On the contrary: the United Kingdom has entered into a solemn commitment under Article IV of the Nuclear Non-Proliferation Treaty to entirely disarm. These weapons are illegal, and in retaining them the United Kingdom is in breach of its obligations. There is no reason that Scotland should be required to shoulder the burden of this ongoing shame.

We wish to endorse the submissions of our members Simon Brooke and Janet Moxley, and those of Dumfries and Galloway Green Party and Eddi Reader

Sincerely

Simon Brooke, for and on behalf of Radical Independence Dumfries and Galloway

Image copyright (c) Stewart Bremner


Saturday, 25 October 2014

Post Scarcity Hardware

A second-generation connection machine in use.
Each light represents one active processor node.
Eight years ago, I wrote an essay which I called Post Scarcity Software. It's a good essay; there's a little I'd change about it now - I'd talk more about the benefits of immutability - but on the whole it's the nearest thing to a technical manifesto I have. I've been thinking about it a lot the last few weeks. The axiom on which that essay stands is that modern computers - modern hardware - are tremendously more advanced than modern software systems, and would support much better software systems than we yet seem to have the ambition to create.

That's still true, of course. In fact it's more true now than it was then, because although the pace of hardware change is slowing, the pace of software change is still glacial. So nothing I'm thinking of in terms of post-scarcity computing actually needs new hardware.

Furthermore, I'm a software geek. I know very little about hardware; but I'm very much aware that as parallelism increases, the problems of topology in hardware design get more and more difficult. I've no idea how physically to design the machines I'm thinking of. But nevertheless I have been thinking more and more, recently, about the design of post-scarcity hardware to support post-scarcity software.

And I've been thinking, particularly, about one issue: process spawning on a new processor, on modern hardware, with modern operating systems, is ridiculously expensive.

A map of the problem

What got me thinking about this was watching the behaviour of the Clojure map function on my eight core desktop machine.

Mapping, in a language with immutable data, in inherently parallelisable. There is no possibility of side effects, so there is no particular reason for the computations to be run serially on the same processor. MicroWorld, being a cellular automaton, inherently involves repeatedly mapping a function across a two dimensional array. I was naively pleased that this could take advantage of  my modern hardware - I thought - in a way in which similarly simple programs written in Java couldn't...

...and then was startled to find it didn't. When running, the automaton would camp on a single core, leaving the other seven happily twiddling their thumbs and doing minor Unixy background stuff.

What?

It turns out that Clojure's default map function simply serialises iterations in a single process. Why? Well, one finds out when one investigates a bit. Clojure provides two different versions of parallel mapping functions, pmap and clojure.core.reducers/map. So what happens when you swap map for pmap? Why, performance improves, and all your available cores get used!

Except...

Performance doesn't actually improve very much. Consider this function, which is the core function of the MicroWorld engine:

(defn map-world
  "Apply this `function` to each cell in this `world` to produce a new world.
   the arguments to the function will be the world, the cell, and any
   `additional-args` supplied. Note that we parallel map over rows but
   just map over cells within a row. That's because it isn't worth starting
   a new thread for each cell, but there may be efficiency gains in 
   running rows in parallel."
  ([world function]
    (map-world world function nil))
  ([world function additional-args]
    (into []
           (pmap (fn [row]
                    (into [] (map
                             #(apply function
                                     (cons world (cons % additional-args)))
                             row)))
                  world))))

As you see, this maps across a two dimensional array, mapping over each of the rows of the array, and, within each row, mapping over each cell in the row. As you can see, in this current version, I parallel map over the rows but serial map over the cells within a row.

Here's why:

Hybrid parallel/non-parallel version

This is the current default version. It runs at about 650% processor loading - i.e. it maxes out six cores and does some work on a seventh. The eighth core is doing all the Unix housekeeping.

(time (def x1 (utils/map-world
        (utils/map-world w heightmap/tag-altitude (list hm))
        heightmap/tag-gradient)))
"Elapsed time: 24592.327364 msecs"
#'mw-explore.optimise/x1

Pure parallel version

Runs at about 690% processor loading - almost fully using seven cores. But, as you can see, fully one third slower.

(time (def x2 (utils/map-world-p-p
       (utils/map-world-p-p w heightmap/tag-altitude (list hm))
        heightmap/tag-gradient)))
"Elapsed time: 36762.382725 msecs"
#'mw-explore.optimise/x2

(For completeness, the clojure.core.reducers/map is even slower, so is not discussed in any further detail)


Non parallel version

Maxes out one single core, takes about 3.6 times as long as the hybrid version. But, in terms of processor cycles, that's a considerable win - because 6.5 cores for 24 seconds is 156 seconds, so there's a 73% overhead in running threads across multiple cores.

(time (def x2 (utils/map-world-n-n
       (utils/map-world-n-n w heightmap/tag-altitude (list hm))
        heightmap/tag-gradient)))
"Elapsed time: 88412.883849 msecs"
#'mw-explore.optimise/x2

Now, I need to say a little more about this. It's obvious that there's a considerable set-up/tear-down cost for threads. The reason I'm using pmap for the outer mapping but serial map for the inner mapping rather than the other way round is to do more work in each thread.

However, I'm still simple-mindedly parallelising the whole of one map operation and serialising the whole of the other. This particular array is 2048 cells square - so over four million cells in total. But, by parallelising the outer map operation, I'm actually asking the operating system for 2048 threads - far more than there are cores. I have tried to write a version of map using Runtime.getRuntime().availableProcessors() to find the number of processors I have available, and then partitioned the outer array into that number of partitions and ran the parallel map function over that partitioning:

(defn adaptive-map 
  "An implementation of `map` which takes note of the number of available cores."
  [fn list]
  (let [cores (.availableProcessors (. Runtime getRuntime ))
        parts (partition-all (/ (count list) cores) list)]
    (apply concat (pmap #(map fn %) parts))))

Sadly, as A A Milne wrote, 'It's a good sort of brake But it hasn't worked yet.'

But that's not what I came to talk about.

We are reaching the physical limits of the speed of switching a single processor. That's why our processors now have multiple cores. And they're soon going to have many more cores. Both Oracle (SPARC)  and ARM are demoing chips with 32 cores, each 64 bits wide, on a single die. Intel and MIPS are talking about 48 core, 64 bit wide, chips. A company called Adapteva is shipping a 64 core by 64 bit chip, although I don't know what instruction set family it belongs to. Very soon we will have more; and, even if we don't have more cores on a physical die, we will have motherboards with multiple dies, scaling up the number of processors even further.

The Challenge


The challenge for software designers - and, specifically, for runtime designers - is to write software which can use these chips reasonably efficiently. But the challenge, it seems to me, for hardware designers, is to design hardware which makes it easy to write software which can use it efficiently.

Looking for the future in the past, part one


Thinking about this, I have been thinking about the Connection Machine. I've never really used a Connection Machine, but there was once one in a lab which also contained a Xerox Dandelion I was working on, so I know a little bit about them. A Connection Machine was a massively parallel computer having a very large number - up to 65,536 - of very simple processors (each processor had a register width of one bit). Each processor node had a single LED lamp; when in use, actively computing something, this lamp would be illuminated. So you could see visually how efficient your program was at exploiting the computing resource available.

[Incidentally while reading up on the Connection Machine I came across this delightful essay on Richard Feynman's involvement in the project - it's of no relevance to my argument here, but nevertheless I commend it to you]

The machine was programmed in a pure-functional variant of Common Lisp. Unfortunately, I don't know the details of how this worked. As I understand it each processor had its own local memory but there was also a pool of other memory known as 'main RAM'; I'm guessing that each processor's memory was preloaded with a memory image of the complete program to run, so that every processor had local access to all functions; but I don't know this to be true. I don't know how access to main memory was managed, and in particular how contention on access to main memory was managed.

What I do know from reading is that each processor was connected to twenty other processors in a fixed topology known as a hypercube. What I remember from my own observation was that a computation would start with just one or a small number of nodes lit, and flash across the machine as deeply recursive functions exploded from node to node. What I surmise from what I saw is that passing a computation to an unoccupied adjacent node was extremely cheap.

A possibly related machine from the same period which may also be worth studying but about which I know less was the Meiko Computing Surface. The Computing Surface was based on the Transputer T4 processor, a 32 bit processor designed specifically for parallel processing. Each transputer node had its own local store, and very high speed serial links to its four nearest neighbours. As far as I know there was no shared store. The Computing Surface was designed to be programmed in a special purpose language, Occam. Although I know that Edinburgh University had at one time a Computing Surface with a significant number of nodes, I don't know how many 'a significant number' is. It may have been hundreds of nodes but I'm fairly sure it wasn't thousands. However, each node was of course significantly more powerful than the Connection Machine's one bit nodes.

A caveat


One of the lessons we learned in those high, far off, arrogant days was that special purpose hardware that could do marvellous things but was expensive lost out to much less capable but cheaper general purpose hardware. There's no point in designing fancy machines unless there's some prospect that they can be mass produced and widely used, because otherwise they will be too expensive to be practical; which presumes not only that they have the potential to be widely used, but also that you (or someone else related to the project) is able to communicate that potential to people with enough money to back the project.


Hardware for Post Scarcity software


Before going forward with this argument, lets go back. Let's go back to the idea of the Clojure map function. In fact, let's go back to the idea of a function.

If a processor is computing a function, and that function has an argument, then before the function can be computed the value of the argument must be computed; and, as the function cannot be computed until the value of the argument has been computed, there is no point in handing off the processing of the argument to another processor, because the first processor will then necessarily be idle until the value is returned. So it may just as well recurse up the stack itself.

However, if a function has two arguments and values of both must be computed, then if the first processor can hand off processing of one of them to another, similar, processor, potentially the two can be processed in the time in which the original processor could process just one. Provided, that is, that the cost of handing off processing to another processor is substantially less than the cost of evaluating the argument - which is to say, as a general thing, the closer one can get the cost of handing off to another processor to the cost of allocating a stack frame on the current processor, the better. And this is where current-generation hardware is losing out: that cost of handing off is just way too high.

Suppose, then, that our processor is a compute node in a Connection-Machine-like hypercube, able to communicate directly at high speed with twenty close neighbours (I'll come back to this point in detail later). Suppose also that each neighbour-connection has a 'busy' line, which the neighbour raises when it is itself busy. So our processor can see immediately without any need for doing a round-robin which of its neighbours are available to do new work.

Our processor receives a function call with seven arguments, each of which is a further function call. It hands six of these off to idle neighbours, pushes one onto its own local stack, computes it, and recurses back to the original stack frame, waits for the last of the other six to report back a value, and then carries on with its processing.

The fly in the ointment here is memory access. I assume all the processors have significant read-only cache (they don't need read-write cache, we're dealing with immutable data; and they only need a very small amount of scratchpad memory). If all six of the other processors find the data they need (for these purposes the executable function definition is also data) in local cache, all is good, and this will be very fast. But what if all have cache misses, and have to request the data from main memory?

This comes down to topology. I'm not at all clear how you even manage to have twenty separate data channels from a single node. To have a data channel from each node, separately, to main memory simply isn't possible - not if you're dealing with very large numbers of compute nodes. So the data bus has to be literally a bus, available to all nodes simultaneously. Which means, each node that wants some data from main memory must ask for it, and then sit watching the bus, waiting for it to be delivered. Which also means that as data is sent out on the bus, it needs to be tagged with what data it is.

Looking for the future in the past, part two


In talking about the Connection Machine which lurked in the basement of Logica's central London offices, I mentioned that it lurked in a lab where one of the Xerox 1108 Dandelions I was employed to work on was also located. The Dandelion was an interesting machine in itself. In typical computers - typical modern computers, but also typical computers of thirty years ago - the microcode has virtually the status of hardware. While it may technically be software, it is encoded immutably into the chip when the chip is made, and can never be changed.

The Dandelion and its related machines weren't like that. Physically, the Dandelion was identical to the Star workstations which Xerox then sold for very high end word processing. But it ran different microcode. You could load the microcode; you could even, if you were very daring, write your own microcode. In its Interlisp guise, it had all the core Lisp functions as single opcodes. It had object oriented message passing - with full multiple inheritance and dynamic selector-method resolution - as a single opcode. But it also had another very interesting instruction: BITBLT, or 'Bit Block Transfer'.

This opcode derived from yet another set, that developed for an earlier version of the same processor on which Smalltalk was first implemented. It copied an arbitrary sized block of bits from one location in memory to another location in memory, without having to do any tedious and time consuming messing about with incrementing counters (yes, of course counters were being incremented underneath, but they were in registers only accessible to the the microcode and which ran, I think, significantly faster than the 'main' registers). This highly optimised block transfer routine allowed a rich and responsive WIMP interface on a large bitmapped display on what weren't, underneath it all, actually terribly powerful machines.

BITBLT for the modern age


Why is BITBLT interesting to us? Well, if we can transfer the contents of only one memory location over the bus in a message, and every message also needs a start-of-message marker and an object reference, then clearly the bus is going to run quite slowly. But if we can say, OK, here's an object which comprises this number of words, coming sequentially after this header, then the amount of overhead to queuing messages on the bus is significantly reduced. But, we need not limit ourselves to outputting as single messages on the bus, data which was contiguous in main memory.

Most of the things which will be requested will be either vectors (yes, Java fans, an object is a vector) or lists. Vectors will normally point to other objects which will be needed at the same time as the vector itself is needed; list structures will almost always do so. Vectors will of course normally be contiguous in memory but the things they point to won't be contiguous with them; lists are from this point of view like structures of linked vectors such that each vector has only two cells.

So we can envisage a bus transfer language which is in itself like a very simple lisp, except decorated with object references. So we might send the list '(1000 (2000) 3000) over the bus as notionally

[ #00001 1000 [ #00002 2000 ] 3000 ]

where '[' represents start-of-object, '#00001' is an object reference, '1000' is a numeric value, and ']' is end-of-object. How exactly is this represented on the bus? I'll come back to that; it isn't the main problem just now.

Requesting and listening


Each processor can put requests onto the 'address bus'. Because the address bus is available to every processing node, every processing node can listen to it. And consequently every processing node does listen to it, noting every request that passes over the bus in a local request cache, and removing the note when it sees the response come back over the data bus.

When a processing node wants a piece of data, it first checks its local memory to see whether it already has a copy. If it does, fine, it can immediately process it. If not, it checks to see whether the piece of data has already been requested. If it has not, it requests it. Then it waits for it to come up the bus, copies it off into local store and processes it.

That all sounds rather elaborate, doesn't it? An extremely expensive way of accessing shared storage?

Well, actually, no. I think it's not. Let's go back to where we began: to map.

Mapping is a very fundamental computing operation; it's done all the time. Apply this same identical function to these closely related arguments, and return the results.

So, first processor gets the map, and passes a reference to the function and arguments, together with indices indicating which arguments to work on, to each of its unemployed neighbours. One of the neighbours then makes a request for the function and the list of arguments. Each other processor sees the request has been made, so just waits for the results. While waiting, each in this second tier of processors may sub-partition its work block and farm out work to unemployed third tier neighbours, and so on. As the results come back up the bus, each processor takes its local copy and gets on with its partition, finally passing the results back to the neighbour who originally invoked it.

The memory manager


All this implies that somewhere in the centre of this web, like a fat spider, there must be a single agent which is listening on the address bus for requests for memory objects, and fulfilling those requests by writing the objects out to the data bus. That agent is the memory manager; it could be software running on a dedicated processor, or it could be hardware. It really doesn't matter. It's operating a simple fundamental algorithm, maintaining a garbage collected heap of memory items and responding to requests. It shouldn't be running any 'userspace' code.

Obviously, there has to be some way for processor nodes to signal to the memory manager that they want to store new persistent objects; there needs to be some way of propagating back which objects are still referenced from code which is in play, and which objects are no longer referenced and may be garbage collected. I know I haven't worked out all the details yet. Furthermore, of course, I know that I know virtually nothing about hardware, and have neither the money nor the skills to build this thing, so like my enormous game engine which I really know I'll never finish, it's really more an intellectual exercise than a project.

But... I do think that somewhere in these ideas there are features which would enable us to build higher performance computers which we could actually program, with existing technology. I wouldn't be surprised to see systems fairly like what I'm describing here becoming commonplace within twenty years.

[Note to self: when I come to rework this essay it would be good to reference Steele and Sussman, Design of LISP-based Processors.]

Sunday, 5 October 2014

Submission to the Smith Commission

Dear Commissioners

First let me say I wish you well in your immensely difficult task. While separating Scotland out of the Union might have been hard, keeping Scotland in the Union under present circumstances looks a great deal harder. Your commission was set up in the immediate aftermath of the recent referendum. Germane to the establishment of your commission were

  1. 'The Vow', signed by all the leaders of the major UK parties, whose terms as written are so woolly as to be virtually meaningless, but which was represented to the Scottish electorate as being a promise of DevoMax
  2. A series of extraordinary interventions by Gordon Brown MP, in which he promised - on the basis of what authority it is not clear - a solution '...as close to federalism as we can go in a country where one nation accounts for 80% of the population.'1

While the Command Paper which, as I understand it, will set out your full remit is not due to be published until the end of this month, your own statement of your terms of reference states that your recommendations '...will deliver more financial, welfare and taxation powers, strengthening the Scottish Parliament within the United Kingdom.'2


England does not seek subdivision


In his comments as quoted above, Gordon Brown lays his finger on a core issue which, in my view, your commission cannot duck. England does account for more than 80% of the population of the entire union, and there seems little appetite in England for any significant devolution to smaller units. There is no campaign to recreate Wessex, Mercia or Northumbria as states of the union in their own right. Rather, it seems clear that England, in so far as it wants anything at all from this process, wishes to remain England. It does not seem to me that it would be either desirable or in the medium term sustainable to seek to impose division on England in order to facilitate devolution in Scotland.

Political opinion is not homogeneous across the union


While some commentators rightly point out that the degree of difference between the political centre ground of the Scottish, Welsh, Northern Irish and English polities can be over-emphasised, it remains broadly the case that Wales and Scotland choose more left-leaning politicians and parties, while England chooses more right leaning. The situation in Northern Ireland is confused by factors which do not apply in the remainder of the Union. While none of these things are set in stone, the broad picture of a more right-leaning polity closer to the centre of power in Westminster and more left leaning polities further from Westminster has remained apparent consistently over the past 75 years. Furthermore, in recent elections this division has accelerated3. It is true that the line of division between the more rightward leaning and more leftward leaning territories of the Union does not necessarily accord with national subdivisions.

The West Lothian question and after


On 19th July 2004, Sir Thomas Dalyell Loch, the Eton and Cambridge educated 11th Baronet of the Binns, voted at Westminster to raise the university tuition fee cap to £3,000 per year - for university students in England, only.

Sir Thomas sat then for the constituency of Linlithgow, in West Lothian, in Scotland; his constituents' education was - then as now - governed by the Scottish Parliament at Holyrood. And thus he answered his own West Lothian Question, which has dogged the British constitutional settlement ever since it was first asked, and which has an added frisson in the aftermath of Scotland's failed butterfly rebellion.

Clearly, it is unjust and inappropriate - intolerable to fair minded citizens of any of the nations of the Union - that Members of Parliament representing constituencies in the peripheral nations can vote, as Sir Thomas did, on matters which uniquely affect England. The anomaly which Sir Thomas identified must be addressed.

However, what is being proposed now by Conservative voices is a parliament - the Westminster parliament - which will continue to debate both bills affecting the whole United Kingdom and also bills affecting England only; but with the quirk that Welsh, Northern Irish and Scots MPs will be unable to vote on the English-only bills. This looks, on the face of it, sensible. It will not work.

An English Parliament is inevitable

If Labour wins the next Westminster election, but without a majority of English seats, who then is the English Secretary of State for Health? For Education? For the Environment? for Transport? for Rural Affairs? Fully half of the current UK cabinet have portfolios which cover only England4. If Labour wins a majority in the UK but not in England, Miliband will find himself on the horns of a dilemma.

Either he appoints Labour members to head the English departments, in which case they will none of them have a majority in the chamber to pass any legislation; or else he appoints Tories to his cabinet, in which case fully half of his cabinet are from the opposition. In either scenario, England is quite ungovernable.

The broad consequence of this is that the Union parliament and the English parliament cannot be the same institution. An administration which commands the confidence of the union may not command the confidence of England, and vice versa. It is not coherent to have two separate administrations within the same parliament. Consequently, a new, English parliament is a necessity of any settlement - whether the English want it or not.

The House of Lords cannot continue to be a union institution


This merely adds to the anomalous position of the house in which your chairman sits. No democracy in the world could tolerate a situation in which more than half of its parliamentarians are unelected; the United Kingdom cannot pretend to be a democracy precisely because more than half of its parliamentarians are unelected. Members of the House of Lords represent no constituency - indeed, a significant number of its members hold their seats precisely because they have been roundly defeated in democratic elections. Others hold their seats in consequence of financial donations to political parties - a practice we would condemn as rankly corrupt in any other country.

Although people appointed to the House of Lords take territorial designations in their titles, they in no way represent the views of the people of those territories. Whatever their place of birth, most are by the time they are appointed simply members of the metropolitan elite. So it is not the case that the membership of the House of Lords can conveniently be divided into 'English', 'Welsh', 'Scots' and 'Northern Irish' members. Furthermore, whatever may be the views of the people of England, I cannot see Scots willingly accepting a rag-bag of failed politicians and the undeserving rich as an 'Upper House' for the Scottish Parliament.

The House of Lords has been a serious and scandalous anomaly in the United Kingdom constitution for two centuries now; it simply cannot continue in the new circumstances.

The Union parliament cannot be elected on a population-share basis


The primary reason for the political dissatisfaction which led up to and gave rise to the recent referendum has been that, whoever Scotland votes for, we are always and automatically outvoted in parliament by England. The same, of course, is equally true for Wales and Northern Ireland. It is not possible to have a federal system in which one federate can always, in all votes, outvote all the others put together.

The United States constitution, and the European Parliament, both provide potential solutions to this. In the US, each state, regardless of its population, elects precisely two Senators to Congress5, whether it is Wyoming with 582,658 people or California with thirty-eight million, sixty-five times as many. In the European Parliament6, smaller states elect members from much smaller constituencies, so that one Maltese MEP represents 74,000 electors, whereas each German MEP represents 833,000 - eleven times as many. In the United Kingdom, it is probably not politically feasible to propose that England, Scotland, Wales and Northern Ireland each elect ten members to the Union parliament; but it does not seem to me impossible to suggest that Northern Ireland and Wales might each elect six, Scotland ten, and England fifteen.

These relatively small numbers are based on the notion of a system as Gordon Brown proposed, '...as close to federalism as we can go...' Few responsibilities would remain for the Union parliament to administer; each of the devolved administrations would collect tax and pay a subvention to the Union administration; and consequently with little to do, the Union parliament would not have to be large. If the degree of devolution is less radical, then these numbers might be increased ten fold; but the general principle that England should not be able to outvote the other nations combined must not be lost.

Taxation cannot easily be split


Scotland has subsidised the rest of the UK for every one of the last 35 years7. At the same time, Scotland has suffered areas of great deprivation and especially of shockingly poor health outcomes. This injustice has been partially reflected in the Barnett Formula, but Barnett recognises only the additional social need in Scotland, not the additional tax take. This historical imbalance raises many difficult issues. While there is some merit in the argument that richer areas should pay more to the common weal than poorer area and that Scotland is a richer area, nevertheless there is historical injustice, consequent historical lack of capital spending, and a legacy of anger and mistrust to take into account.

To add any sort of adjustment of taxation into this mix will be fraught.

Currently Scotland has powers to vary income tax, but has not, under either Labour/Liberal Democrat or  SNP administrations, used them. Given the continuing commitment of all the Westminster parties to austerity, a cut in the rate of income tax is fiscally impossible - public services are already stretched to breaking point. But a raise has been seen by all parties as too politically risky; and because the current power only extends to the basic rate of tax, any rise would be regressive, which would run counter to the social policy of any political party which could conceivably be electable in Scotland in the medium term.

However, the 'offers' made by the UK political parties are each in their own way predicated on naked partisan self-interest. None is in Scotland's interest. Income tax alone will not fund the Scottish government's current expenditure, let alone the increased expenditure that must necessarily be a consequence of increased powers. So the Conservative proposals are aimed squarely at undermining the Scottish government's ability to spend, and consequently at undermining its popularity. Labour's bizarre proposals of tinkerings at the margins are aimed at preserving the ability of Scots MPs - of whom Labour optimistically assumes it will continue to have the preponderance - to vote on the Union's, and consequently England's, income tax rates.

The only solutions which will work on taxation are

  1. Devolve no tax-raising powers, and continue with an enhanced Barnett Formula. It will be very hard to get a political consensus on this, and it is against Scotland's interests since the long-term drift of Union policy is towards ever more austerity and ever deeper cuts to social and health provision, leading to lower Barnett Formula payments to Scotland; or
  2. Devolve all tax raising powers completely, and have Scotland pay a subvention to the Union. Again, this will not be easy to build a political consensus around, and the formula for the subvention will be particularly contentious; but it is clearly the only solution which will work in the medium term.

And so I end as I began: by wishing you well in a task which I know will prove thankless, suspect will prove fruitless, and believe will prove pointless. I think that, notwithstanding the verdict of electors in the recent referendum, the slow dissolution of the United Kingdom is already past the point of no return.

Sincerely

Simon Brooke


  1. https://www.pressandjournal.co.uk/fp/news/politics/316983/brown-interdependence-is-the-future/
  2. http://www.smith-commission.scot/news/lord-smith-of-kelvin-announces-details-of-his-commission-at-the-scottish-parliament/
  3. http://www.theguardian.com/news/datablog/2010/may/08/general-election-2010-results-maps
  4. https://www.gov.uk/government/ministers
  5. http://en.wikipedia.org/wiki/United_States_Senate
  6. http://en.wikipedia.org/wiki/European_Parliament
  7. http://bellacaledonia.org.uk/2014/10/08/smith-and-the-subsidy-myth-makers/

Sunday, 28 September 2014

More on modelling rivers

I've been writing a lot about politics recently - and with reason. But now it's time to be getting back to writing about software, and, specifically, about river flows again.

Computed river map. Ignore the vegetation, it's run only a few generations and does not yet show natural patterns.
I wrote almost a year ago that I had had the first glimmer of success with modelling river flows. Well, some success was right, but not enough success. I didn't have a software framework in which I could model other things I wanted to model in my world, nor one with which I could play flexibly. I also - because I was working with maps of my fictional world, and not the real world - couldn't assess how well my algorithms were working, particularly as I had persistent diagonal artefacts.

So I decided to restart working in Clojure, using a cellular automaton, and with maps of Britain - maps I'm familiar with. I've written about that, too. From the point of view of modelling settlement, it's working well enough to be promising. So now I'm back to river flows, and once again I'm having 'the first glimmerings of success', and once again, frustrations. The picture above shows where I'm up to.

As you can see, I'm still using the 8Km granularity map. I can now actually compute water flows on the 1Km granularity map, but I haven't yet even tried to render them - it's a massive amount of data. But the 8Km map shows both that my algorithm partly works, and that it really does not work anything like well enough.

What works and what doesn't

What works? You can see the River Clyde from about Biggar down to the Falls of Clyde - but there, it disappears. Bits of the mouth of the Clyde are there, but not joined up. The lower Ayr is not only there, but identified as navigable. All of that is promising. I am getting some bits of some rivers showing up, and in the right place.

What doesn't work? Well, 8Km is a horribly wrong scale for doing this sort of thing. Even 1Km granularity is much too coarse, but attempting to map rivers on an 8Km scale... very few of our rivers have enough flow of water to show up. But worse, I haven't implemented 'laking' (as I did in the earlier, Java implementation). When a river arrives at a local low spot, it cannot flow up hill, so it just vanishes. At this coarse a granularity such local low spots are bound to exist. Actually, they will at any granularity - landscapes are fractal. So I need to rewrite my algorithm to deal with local lowspots - fill them up with water until it spills over and follows the rest of the valley down.
Visualisation of the problem. Numbers represent altitude, intensity of blue represents water flow.

This explains why my map of Britain shows so few rivers. The Spey is clearly visible from Aberlour down to Fochabers; the Tweed is a feature in Peebleshire; the Cree and the Esk are visible and recognised as potentially navigable. In England, the Tyne is entirely missing but the Tees is present and marked as navigable; a bit of the Ribble is recognisable as is a bit of the Mersey; tiny bits of the Thames show up around Oxford; and there's a river running north-south, west of London, that might be the Chess or the Misbourne. The Exe and the Tamar are also present. But several of the major rivers of Britain are not present at all, and many of those that are, are, like the Clyde, present only for parts of their course.

The Algorithm

So what is my algorithm? I had hoped, by this time, to publish all my source code so that you can see it. Unfortunately, when I went through the polite step of running this past my present employers, I hit a snag. Although this is - quite obviously - of no relevance to their business and of no interest to them, they claim that it is their secret, proprietary code. Which means that I and my present employers will part; but in the meantime (and possibly afterwards) I cannot publish this code.

I'm damned if I see why I should not publish a description of the algorithm, though.

Firstly, rainfall. I'm not (yet) trying to model the variability of rainfall. I could; last autumn's algorithm recognised that in middle latitudes the wind is primarily a coriolis wind, from the west. It carries damp air from the ocean to the west, and precipitates that rain as it cools - which it does as it rises over higher ground. So west facing slopes recieve more of the potential rainfall than east facing, highlands than low lands, western areas than eastern. We can verify those statements by looking at actual rainfall maps, and they're fairly easy to model. I have not done that yet; my present code just dumps one unit of rain on every cell of the map.

Then, from each cell, I compute the amount of rain which flows through that cell recursively by summing the flows through each of its neighbours which have a greater altitude. This is the simple-minded observation that water flows down hill. And, of course, it does. Obviously, again, the flow value at which I decide a river exists is arbitrary; for this map, I've shown a river where the flow through the cell is thirty units or above - which is to say, where the cell has collected the rainfall from at least thirty upstream cells.

There are two problems with this algorithm as it exists at present. When water in the real world hits a low point then - disregarding the amount lost to evaporation, which in Britain we can do, although in my fictional world I can't entirely - it builds up in a lake until it overflows the lip of the local hollow and continues. I had hoped that river valleys would show up sufficiently strongly that I could get away without laking, but sadly they don't. At the point the Tweed peters out on my map, the altitude of the last cell in which it is visible is 49 (arbitrary units - a monochrome heightmap gives me only 256 gradations of altitude, and sea level is 10). The altitude of the next cell down valley is 50. Given these are average elevations over an 8Km square, it's not in the least impossible that that's correct, but it stops the flow.

Worse still, the last recognised cell of the Ribble is at elevation 28. The next cell down valley - to which the river should flow - is also 28. The Clyde peters out at elevation 35, and the next cell down valley is also 35. It's inevitably the case that long rivers have sections in which they don't fall 5 metres in 8 kilometres, even disregarding the coarse granularity of my elevation data. But again, my present algorithm doesn't cope.

Parallelism and mutable data

There's a second problem, though. This one is not a modelling problem, it's a software framework problem. I'm working, now, in Clojure, and on the whole I find that extremely comfortable; it's a lovely language in which to write exploratory code. And I've been working with a framework which allows me to map a function across a two dimensional array, passing the function two arguments: the whole array, and the cell on which it's to operate. It returns a new copy of that cell, and the mapping operation constructs a new array from all the new cells. This has served me very well during my exploration of modelling environmental change and human settlement, because this process inherently allows great parallelism. On my eight core desktop machine, I can see 5 cores simultaneously maxed out processing a map.

But, the parallelism works because in Clojure data is immutable. In order to process the flow for each cell, I have to process, recursively, the flow in each cell upstream of it. But because the map is immutable, I can't cache those results on the map, so I can only return the one cell I was considering; all those partial results upstream are lost and must be recomputed when those cells are themselves considered. That's obviously wasteful, wasting all, and more, of the time I saved by paralellism. I haven't yet, however, worked out a practical way to pass those partial results round so that they don't need to be recomputed. That's an issue; it's part of the tradeoff of using immutable data, and also, possibly, part of the matter of learning better to use functional languages. But it isn't a blocker. While running this on a one kilometre resolution map is costly in time, it does run.

Laking

'Laking' can't easily be hacked onto my present algorithm. If you allow the algorithm to peak over hilltops as it works upstream, you have a halting problem. What is needed is a second pass which finds low spots where there is a flow of greater-than-river-flow value, and reworks from there.

One possible algorithm which I shall explore would then find the lowest adjoining cell and propagate the flow to that cell and so downstream. That isn't strictly laking, that's a  minimal-uphill algorithm; but it would, I believe, more or less accurately model the river flows.

A slight variation on the minimal-uphill algorithm would be to lower the lowest adjoining cell until it is lower than the cell in which the flow has stopped; that's a slightly more natural solution, with a possible risk of creating gorges where there are no gorges. Again, that's something to explore.

The final workaround is true laking. Let the water level rise - in all cells with the same altitude - until a way out is found. What I worry about laking on my relatively coarse models is that I will construct enormous lakes in unlikely places. It's also likely to turn the whole of East Anglia and Lincolnshire into essentially one lake - but if one interprets these large areas of water on flat land as fen rather than lake, that's more or less right..

Progress is being - very slowly - made.

Mind you, if it takes me two years to work out how to map rivers, this huge game world - which I really know I'll never finish in my lifetime - looks even further out of reach.

Saturday, 20 September 2014

Parliamentary Questions

On 19th July 2004, Sir Thomas Dalyell Loch, the Eton and Cambridge educated 11th Baronet of the Binns, voted at Westminster to raise the university tuition fee cap to £3,000 per year - for university students in England, only.

Sir Thomas sat then for the constituency of Linlithgow, in West Lothian, in Scotland; his constituents' education was - then as now - governed by the Scottish Parliament at Holyrood. And thus he answered his own West Lothian Question, which has dogged the British constitutional settlement ever since it was first asked, and which has an added frisson in the aftermath of Scotland's failed velvet revolution.

What is being proposed now by David Cameron, is a parliament - the Westminster parliament - which will continue to debate both bills affecting the whole United Kingdom and also bills affecting England only; but with the quirk that Welsh, Northern Irish and Scots MPs will be unable to vote on the English-only bills. This looks, on the face of it, sensible.

It will not work.

Suppose - just suppose - Ed Miliband wins the next Westminster election, but without a majority of English seats. Who then is the English Secretary of State for Health? For Education? For the Environment? for Transport? for Rural Affairs? Fully half of the current UK cabinet have portfolios which cover only England. If Miliband wins a majority in the UK but not in England, he will find himself on the horns of a dilemma.

Either he appoints Labour members to head the English departments, in which case they will none of them have a majority in the chamber to pass any legislation; or else he appoints Tories to his cabinet, in which case fully half of his cabinet are from the opposition. In either scenario, England is quite ungovernable.

You think that's bad? It gets worse.

Baron Smith of Kelvin, Knight of the Most Ancient and Most Noble Order of the Thistle - no, seriously, if I was trying to make this up I would write something less unbelievable - is the unelected grandee parachuted in by Cameron to oversee an enhancement of democracy in Scotland. He's a Lord, you might have guessed from the title. As such he's a member of the Westminster parliament - like most members of the Westminster parliament, wholly unelected by any constituency.

Up until now, of course, that hasn't mattered. But, is he a Scots Lord or an English one? He was born in Glasgow, and his titular demesne is Kelvin. He even owns a Scottish island - Inchmarnock, off Bute. On this basis, you may say he's Scots. But like many other lads o' pairts, he's spent a great deal of his career furth of Scotland. As such, he's one of very many who have debatable peerages.

Should he be able to vote on English-only bills?

Well, should he?

It will not work, will it?

If only English unelected members should be able to vote on English-only legislation, should Scots unelected members be able to vote on Scots legislation?

Aye, right! The other one has bells on it.

Or should unelected members not vote on any national legislation, but only on union legislation? That too would stick in Scotland's democratic, presbyterian craw. A man is, after all, a man for aa that - even if some prince has made him a beltit knight, a marquis, duke or aa that. We are all Jock Tamson's bairns.

The union parliament cannot be the same institution as the English parliament, for the reasons I've given above. The English parliament must be a separate institution. Whether it's still elected by the unsatisfactory first-past-the-post system, whether it should include an unelected upper house - those are questions for the English. It's not something we Scots should intrude on. Whether the English parliament or the union parliament should inhabit Pugin's gothic extravagance on the bank of the Thames is a decision we can all put off until 2020, since the building is going to be closed for renovation anyway.

But that still leaves two uncomfortable, unanswered questions.

First: are we, in the twenty-first century, still going to tolerate unelected members in the union parliament?

Think about it.


  • They're there because some distant ancestor was a ruthless mercenary; or
  • They're there because they had once been elected, but the electorate had kicked them out; or
  • They're there because they hold office in the English state superstition; or
  • They're there because they paid some political party an awful lot of money.


Is that tolerable in today's world?

But second: how do you make a confederation work when one confederate has five times the size and five times the votes of all the others put together?

Of course, this has always been the problem with the United Kingdom, since its inception. Scotland, Wales and Northern Ireland will always - on every vote - be outvoted.  This isn't like the EU or the USA, where smaller states can form coalitions of common interest against the larger ones. England's interests will always prevail. We might just as well not bother to turn up.

Is that tolerable in today's world?

Well, is it?



[Some parts of this essay previously appeared in my essay The West Lothian Question, take two]

Friday, 19 September 2014

Jock Tamson's Bairns


So, we lost.

The important thing to remember is that we all lost, every one of us in Scotland. All Jock Tamsons's bairns, those who voted 'no' just as much as we who voted 'yes'. All of our futures are dimmed, all of our hopes of comfort and prosperity diminished, all of our security eroded. And we are luckier than they. Not for us the slow dawning realisation of how dreadfully, how catastrophically they have erred.

When the value of their homes collapses and they are in negative equity, they will know - for they knew that the United Kingdom government was promoting yet another unsustainable housing bubble - they will know they voted for that.

When they cannot afford to pay for their child's cancer treatment, they will know - for they knew that the United Kingdom government was determined to privatise healthcare - they will know that they brought that, too, upon their heads.

When their salaries will no longer pay for adequate food and the shelves at Maryhill are empty, they will know - for they knew the United Kingdom was building a low wage, low skill economy - they will know that that was their choice.

When the terrorist's bomb rips through their train, they will know - for they knew the United Kingdom has made itself, justly, the second most hated nation on Earth - they will know that they chose to step aside from the path of peace.

When there are no jobs in Scotland and their children emigrate in search of work, they will know - for they knew the United Kingdom concentrated all investment within the circle of the M25 - they will know that their action last night made it inevitable.

And when the security state arrests them and holds them without charge, they will know - because they knew the United Kingdom was progressively tearing up human rights - they will know that they have been architects of their own misfortune.

These things will come. The sky to windward is dark.

So we must swallow our anger. Master our grief. Cast away resentment and schadenfreude.

When these things happen - and they will - we must all stand together in solidarity, 'yes' voters with 'no' voters, hope with fear, the brave with the cautious. For we are all - still all, all of us together - Jock Tamson's bairns.

Father, forgive them, for they know not what they do.

A Bill anent Wrongfully Enclosed Common Lands

Right, we've lost the referendum, we won't get independence. It's time to move on. 

As Lesley Riddoch pointed out before this whole campaign began, we can do a great deal to change Scotland for the better with the powers we already have. Up until now, the SNP government have been adopting bland and uncontroversial policies in order not to scare the horses in advance of the vote. I grudgingly accepted that was a reasonable policy - then.

It won't wash now. It's time to make maximal, radical use of our powers, to change Scotland, to redistribute power and wealth from the elite to the people. There are plenty of things we can do, but here is, it seems to me, one particularly low hanging fruit: wrongfully enclosed common lands. And so I present a draft bill. Feel free to improve upon it.

1: Wrongfully Enclosed Common Land

(i) A great deal of land in Scotland which was, historically, held as common, is now held as though it were private property.

(ii) Land is wrongfully enclosed common land if
(a) at some time in the past it was held as common;
(b) rights of common were extinguished without fully and adequately compensating all persons who had rights of common over that land.

(iii) Where it cannot be proven one way or the other whether all persons with rights of common were fully and adequately compensated, it shall be presumed that they were not.

2: Managing agent of Common Lands

(i) Where no other historical arrangements exist for the management of common lands, the managing agent of the common lands shall be
(a) The community council(s) in whose area(s) the lands occur, or
(b) where a community council does not exist, or declares itself unable, for whatever cause, to manage common lands, those lands shall be managed by a common lands factor appointed by the Scottish Government who shall take a management fee of at most [percentage] out of the proceeds and use the remainder for the common good of the people of that area.

(ii) Management of common lands shall be subject to the limitations that
(a) The managing agent may not sell any common land;
(b) The managing agent may not lease out any common land for a term exceeding [period: 20 years?];
(c) The managing agent  may not lease out any common land for a rental less than the fair rental determined by the District Valuer.

(iii) Rental, wayleaves, and other monies levied for use of common land shall be payable to the managing agent and be used by the managing agent for the common good of the people of the area.

3: Voluntary restoration of Common Lands

Where common land has been wrongfully enclosed, but that land has been restored as common land with management passed to the community council(s) in whose area(s) it occurs not later than the date on which this act comes into force, the provisions of sections 4 and 5 of this act shall not apply.

4: Arrangements for smaller holdings

Where greater than 10% of a holding of fewer than 250 hectares in extent is found to be wrongfully enclosed common land,

(i) if no beneficial holder(s) being natural persons can be identified - for example if the land is held by an offshore trust or by a company one or more of whose beneficial shareholders is such a trust - then that part of the holding found to be wrongfully enclosed common land shall be restored as common land, managed as set out in section 2 of this act,
(a) when this act comes into force, or
(b) immediately the land is found to be wrongfully enclosed common land
whichever is the later.
(ii) otherwise, a rent free lease of the wrongfully enclosed common land shall be granted to the natural persons who are beneficial holders
(a) when this act comes into force, or
(b) immediately the land is found to be wrongfully enclosed common land
whichever is the later.
for the period of their lifetimes, after which management shall pass to the managers set out in section 2 of this act.

5: General arrangements

(i) For areas of wrongfully enclosed common lands not covered by sections 3 or 4 of this act, a rental shall be levied at compound interest for the entire period during which such common lands have been wrongfully enclosed.
(ii) The rate of interest shall be 5%.
(iii) The district valuer shall assess a fair rent for the unimproved lands
(a) at the time of the wrongful enclosure and
(b) at twenty-five year intervals thereafter.
(iv) Of this rental
(a) 2.5% shall be payable to the district valuer to cover costs;
(b) 5% shall be payable to the person or agency bringing forward evidence that the lands have been wrongfully enclosed;
(c) The remainder shall be payable to the managing agent for the lands as defined in section 2 of this act.
(iv) This rental shall be payable by the current holder of the lands.
(iv) Management of the lands shall pass to the managing agent for the lands as defined in section 2 of this act
(a) when this act comes into force, or
(b) immediately the land is found to be wrongfully enclosed common land
whichever is the later.

Tuesday, 9 September 2014

Is a currency union with fUK worth £126 Billion?

Bear with me folks, I'm just thinking aloud. Address it as such.

UK debt is £1.4Tn; the cost of servicing that is £50Bn per year.

Scotland's population share of the debt - if we do the deal that seems to be proposed, of a population share of debt in return for a population share of assets, with the pound Sterling explicitly counted as an asset - is £126Bn. So if we got the same interest rate as the UK gets now, our servicing cost would be £4.5Bn per year, but we'd probably get less good terms so it would be a bit higher - say £5Bn.

Suppose we don't do the deal. Suppose we walk away from the debt. Everyone says we can't do that because the international banks wouldn't lend to us. But, actually, do we need them to?

Scotland's share of the deficit is quoted as £8Bn. Less debt servicing - which we wouldn't have to do because we wouldn't have debt - it's £3Bn. Less the cost of Trident (our share is £2Bn per year), it's £1Bn. Less the cost of overseas military adventures... I don't think Scotland would actually have much of a deficit at all.

So: suppose Scotland actually has no deficit, we don't need to borrow anything from the international banks, so what interest rate they would charge us is purely academic. And suppose in twenty-five years we did need to borrow, by that time we'd have a reasonably good credit rating.

But suppose Scotland does still have a small deficit - say £2Bn a year. Suppose also that the banks charge us four times as much as they currently charge the UK. Then it would take us until 2031 before our deficit hit the £8Bn, which, if we did have an agreement, it would be from day one. And in that time we'd have saved £75Bn.

Suppose we'd made no useful investments, received no interest payments on that saved money, and nothing else had changed, and everything continued as before, it would be 2039 before that £75Bn cushion was exhausted. And if we'd serviced a debt successfully for twenty-three years, we would, inevitably, have earned a reasonable credit rating - perhaps not AAA, but not none. So our interest payments would slacken off.

I'm not saying we should do this. But I honestly don't see that exchanging a currency union for a population share of debt is a good deal for Scotland. Sooner or later we will need a new currency anyway, firstly because Sterling will collapse when the fUK leaves the EU, and secondly because our economy is systematically different from the fUK economy - we are net exporters of food, power and hydrocarbons, they are net importers of all three - so a currency managed for their benefit isn't going to suit us for long. Sooner or later, we need out own currency. And in the short term, no-one denies that Sterlingisation will work.

So I think that we should be robust in our negotiations with fUK, because actually I believe that walking away from the debt is not such a big deal as it's being presented.

Remember: the debt is not Scotland's debt, Scotland is not the nation that contracted it and the nation that did contract it will still exist. If we have clearly and publicly volunteered to take on a fair share of that debt in return for a fair share of assets (including the currency, which is an asset), and that share of assets has been refused, walking away from the debt is not defaulting. The banks may be a bit sniffy about it; we may get our credit rating marked down a bit. But we won't be junk status.

Tuesday, 26 August 2014

Modelling settlement with a cellular automaton

I've written about modelling settlement patterns before; several times, actually:


I had hoped to have the algorithm for Populating a Game World written by now, but I've been ill most of this summer and it hasn't happened. Instead, I've revived a rule-driven cellular automaton which I first wrote back in the 1980s; I've reimplemented it in Clojure, and used it to experiment with settlement. The results have been mixed.

What works

Irish Sea basin after 84 generations
Firstly, it's remarkable how simple it is to model a landscape on a coarse granularity with very few rules. Establishing a basic biosphere with birch/oak succession woodland on lower ground, growing to climax forest in more favoured areas, and fading to birch scrub and then to heath in uplands, takes just sixteen rules.  Adding human settlement, up to the point of establishing permanent markets and urban centres, takes just thirty more. And when you run this on a map of Britain, unsurprisingly urban centres end up in just the sort of place you'd expect to see them - for example, in the map shown, there's an urban centre near Lancaster and another at Derry, with settlement around Belfact Lough, Dublin, and in Wigtownshire - all places where we know, historically, there were important early towns.

Lancaster was an urban settlement from Roman times. Rerigonium, in west Wigtownshire, was one of the only British towns important enough to make it onto Ptolemey's pre-Roman map. Derry was the site of a monastery in the 6th century, and probably an urban centre earlier. There's a settlement on Ptolemy's map called Eblana which may possibly be Dublin, but is at least close to it. Belfast has the oldest claim - it has a five thousand year old henge (although there's also a neolithic monument complex at Dunragit, one of the possible sites of Rerigonium).

So this very simple model of settlement patterns works quite well - at a coarse scale.

What doesn't work

While the results are reasonably good, the cellular automaton isn't fast. The scale shown in the picture uses cells about five miles (eight kilometres) square. At this scale, generating a map of Britain and Ireland on my (very powerful) desktop PC takes about a minute per generation, although optimisation is certainly possible. Settlement patterns don't really start to emerge until after one hundred generations, and I'd really like to run for at least two hundred and fifty to get the patterns stable. But five-mile granularity is nothing like good enough to model settlement. I think what I need is hectare granularity. It's obvious that (optimisation aside), for a given ruleset the time to compute a map scales with the area of the map.

I have a map of Great Britain and Ireland at about one kilometer granularity, but I haven't yet even tried to run the ruleset on it yet. It's sixty-four times the area of the map I'm currently using, and one would anticipate it would take about one hour per generation to compute. But, as I've said, even kilometer granularity doesn't seem enough, and a hectare granularity map would take six thousand four hundred times as long to compute (assuming the memory requirement could be handled, which I believe it could), so about four days per generation or about one hundred generations per year of continuous computation.

Now, that isn't in itself impossible. If one sees this as a one-off pre-computation of the settlement pattern of a game-world, it's a not unreasonable investment. But this mechanism doesn't really support ongoing evolution of settlement patterns while the game is in progress.

Also, the rules I have so far are unsophisticated. I don't have a rule which represents the strategic value of a port, or the strategic value of a river crossing. And to produce rules which would model the development of a hierarchical system of territorial aristocracy - a feudal system - would require much more computationally expensive rules than I have now.

Finally, this map is a grid, and as a grid it inevitably will have visual artefacts in the world. That can be mitigated by the rendering algorithm, but it's bound to show. So I don't think this is an avenue which in its pure form I'll pursue much further; but it is a promising start. A hybrid system based partly on a cellular automaton, partly based on actors (as in Populating a game world) is probably the line I shall follow next.

Addendum: the rules

I hope to be able to publish the full source code for the cellular automaton shortly, but it depends on authorisation from my employers - at present all code I produce, even in my spare time, is their copyright. In the meantime, however, here's a high-level statement of the rules used to model settlement.

# Human settlement

;; This rule set attempts to model human settlement in a landscape. It models
;; western European pre-history moderately well. Settlement first occurs as
;; nomadic camps on coastal promentaries (cells with four or more neighbours
;; that are water). This represents 'kitchen-midden' mesolithic settlement.
;;
;; As grassland becomes available near camps, pastoralists appear, and will
;; follow their herds inland. When pastoralists have available fertile land,
;; they will till the soil and plant crops, and in doing so will establish
;; permanent settlements; this is approximately a neolithic stage.
;;
;; Where soil is fertile, settlements will cluster, and markets will appear.
;; where there is sufficient settlement, the markets become permanent, and you
;; have the appearance of towns. This takes us roughly into the bronze age.
;;
;; This is quite a complex ruleset, and runs quite slowly. However, it does
;; model some significant things. Soil gains in fertility under woodland; deep
;; loams and podzols build up over substantial time. Agriculture depletes
;; fertility. So if forest has become well established before human settlement
;; begins, a higher population (more crops) will eventually be sustainable,
;; whereas if human population starts early the deep fertile soils will not
;; establish and you will have more pastoralism, supporting fewer permanent
;; settlements.

;; hack to speed up processing on the 'great britain and ireland' map
if state is water then state should be water

;; nomads make their first significant camp near water because of fish and
;; shellfish (kitchen-midden people)
if state is in grassland or heath and more than 3 neighbours are water and generation is more than 20 then state should be camp

;; sooner or later nomads learn to keep flocks
if state is in grassland or heath and some neighbours are camp then 1 chance in 2 state should be pasture

;; and more herds support more people
if state is in grassland or heath and more than 2 neighbours are pasture then 1 chance in 3 state should be camp
if state is pasture and more than 3 neighbours are pasture and fewer than 1 neighbours are camp and fewer than 1 neighbours within 2 are house then state should be camp

;; the idea of agriculture spreads
if state is in grassland or heath and some neighbours within 2 are house then state should be pasture

;; nomads don't move on while the have crops growing. That would be silly!
if state is camp and some neighbours are ploughland then state should be camp

;; Impoverished pasture can't be grazed permanently
if state is pasture and fertility is less than 2 then 1 chance in 3 state should be heath

;; nomads move on
if state is camp then 1 chance in 5 state should be waste

;; pasture that's too far from a house or camp will be abandoned
if state is pasture and fewer than 1 neighbours within 3 are house and fewer than 1 neighbours within 2 are camp then state should be heath

;; markets spring up near settlements
if state is in grassland or pasture and more than 1 neighbours are house then 1 chance in 10 state should be market

;; good fertile pasture close to settlement will be ploughed for crops
if state is pasture and fertility is more than 10 and altitude is less than 100 and some neighbours are camp or some neighbours are house then state should be ploughland

if state is ploughland then state should be crop

;; after the crop is harvested, the land is allowed to lie fallow. But cropping
;; depletes fertility.
if state is crop then state should be grassland and fertility should be fertility - 1

;; if there's reliable food available, nomads build permanent settlements
if state is in camp or abandoned and some neighbours are crop then state should be house
if state is abandoned and some neighbours are pasture then state should be house
;; people camp near to markets
if state is in waste or grassland and some neighbours are market then state should be camp

;; a market in a settlement survives
if state is market and some neighbours are inn then state should be market
if state is market then state should be grassland

;; a house near a market in a settlement will become an inn
if state is house and some neighbours are market and more than 1 neighbours are house then 1 chance in 5 state should be inn
;; but it will need some local custom to survive
if state is inn and fewer than 3 neighbours are house then state should be house

;; if there aren't enough resources houses should be abandoned
;; resources from fishing
if state is house and more than 2 neighbours are water then state should be house
;; from farming
if state is house and some neighbours are pasture then state should be house
if state is house and some neighbours are ploughland then state should be house
if state is house and some neighbours are crop then state should be house
;; from the market
if state is house and some neighbours are market then state should be house
if state is house then 1 chance in 2 state should be abandoned
if state is abandoned then 1 chance in 5 state should be waste 


## Vegetation rules
;; rules which populate the world with plants

;; Occasionally, passing birds plant tree seeds into grassland

if state is grassland then 1 chance in 10 state should be heath

;; heath below the treeline grows gradually into forest

if state is heath and altitude is less than 120 then state should be scrub
if state is scrub then 1 chance in 5 state should be forest

;; Forest on fertile land grows to climax

if state is forest and fertility is more than 5 and altitude is less than 70 then state should be climax  
   
;; Climax forest occasionally catches fire (e.g. lightning strikes)

if state is climax then 1 chance in 500 state should be fire

;; Forest neighbouring fires is likely to catch fire. So are buildings.
if state is in forest or climax or camp or house or inn and some neighbours are fire then 1 chance in 3 state should be fire

;; Climax forest near to settlement may be cleared for timber
if state is in climax and more than 3 neighbours within 2 are house then state should be scrub

;; After fire we get waste

if state is fire then state should be waste

;; waste near settlement that is fertile becomes ploughland
if state is waste and fertility is more than 10 and some neighbours are house or some neighbours are camp then state should be ploughland

;; And after waste we get pioneer species; if there's a woodland seed
;; source, it's going to be heath, otherwise grassland.

if state is waste and some neighbours are scrub then state should be heath
if state is waste and some neighbours are forest then state should be heath
if state is waste and some neighbours are climax then state should be heath
if state is waste then state should be grassland


## Potential blockers

;; Forest increases soil fertility.
if state is in forest or climax then fertility should be fertility + 1

## Initialisation rules

;; Rules which deal with state 'new' will waste less time if they're near the
;; end of the file

;; below the waterline we have water.

if state is new and altitude is less than 10 then state should be water

;; above the snowline we have snow.
if state is new and altitude is more than 200 then state should be snow

;; otherwise, we have grassland.
if state is new then state should be grassland

Creative Commons Licence
The fool on the hill by Simon Brooke is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License