Monday, 11 May 2015

Thrifty Business

In the run-up to the UK General Election 2015, I ended up writing so many similar posts on facebook on why Austerity doesn't work that I thought I'd turn it into a blog entry.

Nobel Prize-winning economist Paul Krugman has written an excellent piece in the Guardian about the Austerity delusion. He covers the historical developments over the past 5 years and provides evidence for a negative correlation between austerity and economic growth.

All I want to do is show why the common-sense argument of the analogy from thrift isn't correct.

 The thrift argument is that, if I'm in debt, I have to cut back on my own spending until everything's under control and I can (and have) paid it off.

[*]And that's the right thing to do, however, it's not the whole story. In reality what happens is that when you cut back to pay off your debt, the people you trade with lose income. In a sense, they're soaking up the imbalance of your finances, but it works, because they're only losing a little bit when you cut back by a lot. The key thing is that your income stays the same while your outgoings shrink (a lot), and their income shrinks (a bit) while their outgoings stay the same - so you're passing on your debt, they take a bit of a hit too.
And therefore, it won't work if everyone is simultaneously in debt. When everyone starts cutting back, everyone's income shrinks and so they become less able to repay their debts. That's what happens when governments enact austerity: the private purse shrinks, internal trade stalls (and this in fact is what happened - banks stopped lending and started calling in debts, which is why businesses failed) and if the government acts along with it by reducing its spending in accordance with its lower tax revenue, it just adds to the problem.

The right thing to do then, if private lenders won't lend, is for the government to provide the cash to keep the economy going - and that means public borrowing during a financial crisis. That's half of Keynesianism, in essence.

Keynesianism, relies on another insight - that cash isn't a substitute for goods as we normally think, instead, cash is a medium for exchange. That is, cash operates as a pipe for transporting goods; the size of the pipe is the amount of cash we have, it determines the rate we can exchange and trade; it's not a representation of what we have.

So, if we go back to [*], we can see that's what's happening in the example. Your original debt is distributed across the entire system. It's the capacity of your input pipes (income+loans), which is the same as your output pipes capacity (spending), which determines the sizes of others' input pipes (income). When you cut back, the whole network capacity shrinks. Which is to say your debt was distributed everywhere all along. It's a really powerful concept to get one's head around, I've barely scratched the surface.

Friday, 20 March 2015

Arctic Attacks

Arctic Sea Ice has reached a new record low maximum. The Guardian covers it quite nicely in this article.

Arctic sea ice extent hits record low for winter maximum

In writing a reply to a comment for the article I ended up listing a number of major reasons why the Arctic is under attack. It turns out there's an awful lot of mechanisms and feedbacks that are making Arctic Sea Ice increasingly vulnerable. Off the top of my head I could think of these:

1. Most of the ice is now easily melted first-year ice, which even when it melts is less likely to refreeze, because it doesn't change salinity of the top layer of water much.

2. The Arctic sea surface temperatures are rising, and will be hit harder again, now we are in an El Nino phase; so melting from below is becoming more of an issue. [This is the primary cause of this years record low Arctic Maximum]

3. The increased amount of open water in the Arctic ocean means that Arctic sea ice is being affected more by storms. In the past the ice itself dampened waves; the effects of currents and could distribute the force of storms across the ice pack. Now there are open waves and the structural integrity can't withstand the currents nor storms. One the effects of this is 'flash melting' where stunning amounts of sea ice can suddenly melt by being submerged during a storm (this was a contributory factor to the summer record in 2012).

4. The increased amount of energy in the atmosphere around the Arctic ocean means that storms are becoming more common and stronger.

5. The increased humidity above the arctic has numerous effects. (a) Water vapour is a greenhouse gas and therefore it acts as a positive feedback on melt. (b) Increased cloud cover reduces direct levels of radiation acting as a negative feedback (though it's understood less than (a)). (c) Regular air temperatures above 0ºC means that rain is increasingly likely and rain is a much more effective thermal conductor than air (because water has a much higher specific heat capacity).

6. Arctic melting is starting to reach the coasts of the Greenland and Canadian Archipelago. This means that the multi-year ice is no longer held fast to the land and is therefore more easily transported.

7. Increased outflow and calving from Arctic glaciers, particularly in Greenland adds to the destabilisation of land-fast Arctic sea ice.

8. The opening of the North East Passage and in particular open water from the North Sea to the Bering Strait (separating Alaska and Russia) means that for some of the year actual ocean currents can flow all the way across the Arctic. This, again, increases transport.

9. The increased rate of arctic temperature rises compared with more southerly latitudes means that the northern Jetstream is breaking down (this is different to the Gulf stream of course). The effect is to make  the Jetstream more wavy which allows warmer air to be transported to the Arctic (often raising temperatures by >20ºC) as well as transporting cooler air further south causing major climatic problems in Canada and North America (the Polar Vortex).

So, in short - there's whole set of depressing indicators and feedbacks as the Arctic Sea Ice melts, which is why as a whole it's accelerating.

Thursday, 30 October 2014

Climate Faith For Beginners

There's a recent Guardian article about combating apathy about climate change.

Reports show the biggest threat to progress on climate change is cynicism. That’s why 10:10’s #itshappening project showcases positive action happening around the world now

I get this a lot on facebook - I have a high number of friends there, but it's rare that I see any of them post anything about raising awareness about climate change, and just as rare for them to like, share or comment on my frequent climate change posts. If cute kittens were the face of global warming activism we'd be in renewable utopia right now.

One of my biggest concerns about climate change is the serious possibility that in practice or in theory it's already too late. We know we're pretty close to exceeding the maximum amount of CO2 we can actually emit, but we also know that thanks to political efforts by the fossil fuel industry, we're still on track for the worst-case scenario for emissions.

The question is, assume that's the case, what happens then? I think, if I was an atheist (or possibly if I was pagan), then I'd either give up and just try to have as much fun as I could, while I could; or I might end up thinking that resolving global warming issues by violence would become my raging response to this slow inexorable crisis.

But I'm not, I'm a Christian who believes that we have a responsibility to take care of the planet. There's a school of theology that argues that Jesus won't return until the world is wrecked (and God plans to complete the destruction). In my post God Loves Green, you can read why I think that theology is misplaced so I won't cover it further here.

I think that a Christian perspective offers hope in a changing climate that I wouldn't have if I had other beliefs. And it centres on the message about Jesus. The message is this: everything we've fouled up, and everything people have damaged in us, was personally dumped on Jesus on the cross. The whole lot, as if he was to blame. He died, beyond any hope of coming back to life, and yet that's exactly what happened: Jesus was raised from the dead. It means that he overcame the lot and buying into him means you buy into that life, forever, from this moment.

This informs my perspective on climate change in three major ways.

Firstly: I'm already a winner; if I die tomorrow, I've already won. It means I can afford to lose in this world, I am not number 1. A practical example of this is the question of how I use my earnings. Almost a decade ago I was in a position to be able to buy a house of my own, instead I decided to invest in wind turbines and rent in shared accommodation. It put me at a disadvantage in a number of ways (e.g. my status amongst my peers who were buying houses), but I can afford to lose.

Secondly, because of the relationship between me (or us) and Jesus there really is a responsibility to act faithfully w.r.t God's creation. It does matter whether we de-carbonize or not, we can't just pray it away (though prayer, being the catalyst for God in action, is integral to everything we do and integral to the changes we see in others).

Thirdly, if we act faithfully, God will do the rest - he can do the impossible.

Put together, for me, my faith is the biggest hope I have for combatting climate change: it gives me a basis for being active even if the odds are against me. It means that I have a big, green light from God to act faithfully and it means I have hope even if I lose, because I've already won.

Tuesday, 16 September 2014

TUKES (The United Kingdom Except Scotland) Isn't Good Company.

I'm not very patriotic, to me that means I think the UK and Scotland will be worse off if The UK Excludes Scotland (TUKES). My lack of patriotism means I'm pro-union. Here's two personal reasons why:

  • Thanks to Scotland being in the UK it's easier for me to invest in Scotland. Case in point: I've invested thousands of pounds in the Boyndie Windfarm Cooperative; which means I effectively supply carbon-free energy to a number of houses in Scotland. With TUKES it would have been much harder for me to invest in Scottish wind farms and by that token harder for me to invest in English wind farms either.
  • My largest sales for FIGnition have been thanks to Strathclyde University, a Scottish University; through their investment with me RS Components decided to take the risk and place an order with me too. It would have been much harder for them to do that if Scotland wasn't part of the UK.
So far who's winning? On balance, Scotland. The amount of money I've made out of Scotland is less than the amount Scotland's made out of me in this respect. And what if Scotland leaves the UK? Then I'll make more money from Scotland than it's likely to invest in me simply because trade won't be quite so open and my current investments have a long-term payback.

To my mind, being part of the UK is in one sense an unpatriotic and therefore good thing to do, because it means considering the interests of the community outside the country. To my mind the whole Nationalist cause, whether it's the Front Nationale in France; the UKIP or the Scottish SNP are all expressions of the same trend when faced with the economic challenges post-2008: an inevitable trend to blame the issues on outsiders (the EU, immigrants or London) combined with hubristic jingoism. It doesn't follow. It's far more likely that the loss of Scotland would lead to greater economic hardship for both TUKES and Scotland.

For example, here's one scenario. If Scotland leaves the UK then it is likely that TUKES would shift in a more right-wing: England, Wales and N.I would become more nationalistic, UKIP (or TUKESIP as perhaps it should be called) would gain power, not least because there would be a loss of confidence in David Cameron, but also because the same trends that would have pushed Scotland into independence have been pushing the whole of the UK towards Nationalism.

This would raise the prospect of TUKES leaving the EU sooner, which would mean that Scotland (though newly independent) would also be at least temporarily leaving the EU. So, Scotland's independence will make it more likely the whole of the UK would leave the EU and the loss of the TUKES from the EU would help destabilise the EU itself (which isn't exactly looking solid right now).

The outgoing President of the European Council, Herman Van Rompuy, said a few years ago that "a rising tide of nationalism is the EU's biggest enemy... In every member state there are people who believe their country can survive alone in the globalised world. It's a lie... the time of the homogenous nation state is over."

The mistake is to think that independence means escaping from domination, but in reality the UK is interdependent and so the process is one of de-interdependence. That's what's really being voted on. It's the same issue as independence from the EU - though the ties are less strong and France/Germany have been the dominant partners, it will be bad for all concerned if we leave.

The mistake with Nationalism is to undervalue the level of interdependence. That's the problem with London, because it has an implicitly built-in Regionalism which under-values the interdependence of the rest of the UK. So, a vote for Nationalism validates London's attitude because it says "Hey, you got it right, we'll take it a step further." The rest of the UK feels the Regionalism and doesn't like it, but the solution isn't to go it alone and to form a break-away Northumbria (though with 15 million people* they'd have nearly 3 times the clobber of Scotland).

The solution is to make London more accountable, to redistribute power across the Kingdom rather than validate the Regionalism. It means bringing in laws that cause concentrations of power within the UK to look further afield and that can only be done by increasing the level of interdependence.

And another reason why I don't want to lose Scotland? Because I really like Scottish people, and so in my mind, The United Kingdom Except Scotland just Isn't Good Company.

(This is the first blog of two on why I think Scottish Independence isn't a good thing, the next blog is coming soon!).

*Comprising of the North West, the North East and Yorkshire & Humber = 14.9million.

Saturday, 5 July 2014

BootJacker: The Amazing AVR Bootloader Hack!

There's an old adage that says if you don't know it's impossible you could end up achieving it. BootJacker is that kind of hack: a way for ordinary firmware on an AVR to reprogram its bootloader. It's something Atmel's manual for AVR microcontrollers with Bootloaders says is impossible (Note the italics):

27.3.1 Application Section.
The Application section is the section of the Flash that is used for storing the application code. The protection level for the Application section can be selected by the application Boot Lock bits (Boot Lock bits 0), see Table 27-2 on page 284. The Application section can never store any Boot Loader code since the SPM instruction is disabled when executed from the Application section.

Here's the background: I'm the designer of FIGnition, the definitive DIY 8-bit computer. It's not cobbled together from hackware from around the web, instead three years of sweat and bare-metal development has gone into this tiny 8-bitter. I've been working on firmware version 1.0.0 for a few months; the culmination of claiming that I'll put audio data transfer on the machine (along with a fast, tiny Floating point library about 60% of the size of the AVR libc one).

Firmware 1.0.0 uses the space previously occupied by its 2Kb USB bootloader and so, needs its own migration firmware image to copy the V1.0.0 firmware to external flash. The last stage is to reprogram the bootloader with a tiny 128b bootloader which reads the new image from external flash. Just as I got to the last stage I came across section 27.3.1, which let me know in no uncertain terms that I was wasting my time.

I sat around dumbstruck for a while ("How could I have not read that?") before wondering whether[1], crazies of crazy, imagining that a solution to the impossible might actually lead me there. And it turns out it does.

The solution is actually conceptually fairly simple. A bootloader, by its very nature is designed to download new firmware to the device. Therefore it will contain at least one spm instruction. Because the spm configuration register must be written no more than 4 cycles before the spm instruction it means there are very few sequences that practically occur: just sts, spm or out, spm sequences. So, all you need to is find the sequence in the bootloader section; set up the right registers and call it.

However, it turned out there was a major problem with that too. The V-USB self-programming bootloader's spm instructions aren't a neat little routine, but are inlined into the main code; so calling it would just cause the AVR to crash as it tried to execute the rest of the V-USB bootloader.

Nasty, but again there's a solution. By using a timer clocked at the CPU frequency (which is easy on an AVR), you can create a routine in assembler which sets up the registers for the Bootloader's out, spm sequence; calls it and just at the moment when it's executed the first cycle of the spm itself, the timer interrupt goes off and the AVR should jump to your interrupt routine (in Application space). The interrupt routine pops the bootloader address and then returns to the previous code - which is the routine that sets up the outspm sequence. This should work, because when you apply spm instructions to the bootloader section the CPU is halted until it's complete.

Here's the key part of BootJacker:

The code uses the Bootloader's spm to first write a page of flash which also contains a usable outspm sequence and then uses that routine to write the rest (because of course you might end up overwriting the bootloader with your own new bootloader!)

BootJacker involves cycle counting, I used a test routine to figure out the actual number of instructions executed after you set the timer for x cycles in the future (it's x-2). In addition I found there was one other oddity: erase and writes always have a 1 cycle latency after the SPM in a bootloader. I fixed this with a nop instruction in my mini bootloader.

This algorithm, I think is pretty amazing. It means that most bootloaders can in fact be overwritten using application firmware containing a version of BootJacker!

[1] As a Christian, I also have to fess' up that I prayed about it too. Not some kind of desperation thing, but some pretty calm prayer, trusting it'll get sorted out :-) 

Saturday, 31 May 2014

Gini Sim

The Gini Index is a measure of wealth distribution.

GiniSim is a simple Javascript program which demonstrates, in simple terms, flaws in free market economics, by showing that trading freely will lead to gross inequality. Copy the program into a .html file; save it and then open it in a browser: you can stop it by pressing the Stop button. Alternatively, you can download and run a simple Java version, GiniSim.jar from here.

Each bar is the wealth of a person, and the simulation starts with everyone having $10 (or £10, or 10€).

Each step simulates a free trade transaction, two monetary notes are picked at random and the person the first one belongs to pays the person the second one belongs to. Intuitively, you’d think this would average out: sometimes some people win and sometimes others would.

In reality what happens is that whenever a person accumulates wealth, it makes it more likely that someone poorer will give money to them. This is due to the fact that as a person accumulates wealth it increases the chances of them effectively paying themselves for a transaction, but a poor person is unlikely to do a trade with themselves. Consider the trivial example below.

How does this correspond to an idealism of the free market? It corresponds, because exchanges take place on the basis of being indifferent towards cash. Therefore when people gain wealth, their wealth acts as a bigger wealth footprint and people (who want to buy things) notice the cash more. If you’re poorer, that doesn’t happen, you’re not noticed, because your visible presence is the cash you hold - you literally disappear.

The important thing to note is that GiniSim demonstrates inequality without the agents involved behaving maliciously. All it does is play fairly towards cash (rather than people). It's a demonstration of a power law.

How does GiniSim1 not correspond to classical economics? GiniSim1 correspond to free trade under mercantilism, which is a zero-sum economic theory.

Here’s GiniSim, copy everything in yellow:

<!DOCTYPE html>
<button onclick="clearInterval(timer)">Stop</button>
<canvas id="myCanvas" width="800" height="600" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.

  var c=document.getElementById("myCanvas");
  var ctx=c.getContext("2d");
  var timer;
  var rects=0;
  var cash=[0],people=[0];
  var kStartCash=10;
  var kNumPeople=100;
  function initGini() {
    var ix,iy;
    for(ix=0;ix<kNumPeople;ix++) {
      people[ix]=kStartCash; // everyone starts with $10.
      for(iy=0;iy<kStartCash;iy++) {
        cash[ix*kStartCash+iy]=ix; // each $1 is owned by a person.
  function incomeSwap(from,too) {
    var ix;
    for(ix=0;ix<kNumPeople*kStartCash;ix++) {
      else if(cash[ix]==too)
  function exchange() {
    var aNote=Math.floor(Math.random()*kStartCash*kNumPeople);
    var aOwner=cash[aNote];
    var aNewNote=Math.floor(Math.random()*kStartCash*kNumPeople);
    var aNewOwner=cash[aNewNote];
    if(people[aOwner]>0 ) {
      // can't take cash from people who have nothing.
      while(aOwner>0 && people[aOwner]<people[aOwner-1]) {
      while(aNewOwner<kNumPeople-1 && people[aNewOwner]>people[aNewOwner+1]) {
  function drawImage() {
    var ix;
    for(ix=0;ix<kNumPeople;ix++) {

[Edit: Added link to GiniSim.jar on 20150321.]

Tuesday, 1 April 2014

The Royal Fracking Society

This blog takes a slightly more provocative title to raise questions about the role of the UKs Royal Society with respect to hydraulic fracturing approvals.

It is estimated that there are 11,000Km3 of extractable methane gas reserves in the United Kingdom. In view of increasing questions about energy security worldwide, and the reported economic boom for shale gas/oil in the United States,  the British government is keen to exploit these reserves as much as possible.

This gas will be extracted using a technique called Hydraulic Fracturing - or Fracking - which is proving controversial not least because of concerns about water supplies being contaminated by fracking chemicals, but health related issues, questionable economics and geological issues such as induced earthquakes. As as result there have been widespread protests around the world, notably in the USA and more recently in Europe and here in the United Kingdom.

Large-scale Fracking the UK is in its early stages and activists have been able to draw attention to the cause by protesting at the first few sites, most notably in Balcome in West Sussex and Barton Moss in Manchester. However, the government has already approved of over 600 Fracking permits and it will not be possible to protest at anything more than a small fraction of them.

Protests work, really by massing public conscience against (or in favour of) a cause rather than by physically forcing organisations to comply. The key thing is being able to raise a person's conscience enough to act. It is therefore politically important for the government to argue the case for Fracking: positively, by citing potential economic and employment benefits; energy security, cost and safety regulations as well as negatively by portraying protestors as being disruptive or irrelevant etc. At the moment there is little consensus on fracking amongst the British public.

Today I came across this report on Fracking approvals at Barton Moss in Manchester and one paragraph particularly caught my attention:

This 3-D seismic will also fulfil UKOOG Shale Gas guidelines, the recommendations of the Royal Society and Royal Academy of Engineers and is a requirement of the Department of Energy and Climate Change consent process prior to any shale gas hydraulic fracturing and flow testing operations being undertaken.

It looks to me that Fracking consent can only be granted following the recommendations of the Royal Society (amongst other organisations). Now my thinking is that the Royal Society's brief is that they are only allowed to object to a fracking operation on scientific grounds and the grounds they'd be asked to review would be its viability and potential safety.

However, because it is a scientific body, its responsibility is broader than a narrow remit given by the government; it can (and in fact has a duty to) object on any scientific ground if the scientific consensus warrants it. And, given that the consensus amongst (albeit climate) scientists is around 97% or more that the continued use of fossil fuels will be globally catastrophic, it seems to me that there are good grounds to make the case to the Royal Society itself and get them to act on the basis of their scientific conscience. Here it's important to state that the extra-remit grounds for objection would be on the basis of carbon emissions, not health, economic or geological concerns. The objective basis is that we cannot burn more than a tiny fraction of fossil fuel reserves without causing dangerous, essentially irreversable climate change.

Because, without their approval the DECC can't currently give consent and there's already a high degree of consensus. I imagine that if they were persuaded to publicly object, it would mean that the government would change the law so as not to require the Royal Society's recommendations, but this would have potentially severe negative consequences for British public opinion and also actual safety issues. This would be a major step forward for eliminating Fracking in the UK.

[Note: additional links and labels to be added in a later update]