Friday, 30 September 2011

Enfranchize the workforce

In a world that's in the middle (or possibly still near the beginning) of a recession/depression, the pressure is on employers to cut costs by reducing workers' pay and making redundancies and so the people who carry the consequences are those with the least power. To defend themselves, employees are increasingly looking to taking strike action.

Striking has a long history within the labour movement. Here's a proposal for a simple alternative for a workers' action. Instead of striking for pay increases during a recession, why not campaign for greater stakeholder influence? That is, it's understandable if there's no pay increase in a recession or depression, but it's not the worker's fault (nor I would argue is it necessarily the management fault either). But if the management can't maintain wages, is there any reason why they can't provide shares in the company?

Campaigning for shares (i.e. shares for individual members) would have numerous consequences.
  1. It'd mean that the workforce would potentially receive compensation for their loss of earnings, albeit deferred to when dividends would become available.
  2. It'd mean that the workforce would have more of a vested interest in the company's success.
  3. It'd mean that all levels of the workforce would have a stake in the company power base: the company would be taking a step towards being a cooperative.
  4. It'd be much easier for outsiders to sympathize with the aims of the workers: it's hard to justify penalizing your employees and simultaneously keeping them disenfranchised when the entire company's existence depends on them.
Enfranchise the workforce - what's there not to like :-) ?

Ref: Maverick.


Saturday, 3 September 2011

Accessing Ram on an Intel 4004

Hi folks,

I've recently been trying to work out how RAM is accessed on an Intel 4004, 4-bit Microprocessor. The most valuable information I've found is from:

http://e4004.szyc.org/iset.html

Whose website provides a javascript emulator for the 4004.



The 4004 is a seriously primitive device. One of its odd behaviours is that it doesn't really address RAM as such. What it does is provide a means of sending an address to a RAM chip and it expects each RAM chip to contain its own address register, this is done with an SRC ixr instruction, which outputs the contents of one of its 8 * 4-bit register pairs on its multiplexed address bus, selecting RAM if the upper 2 bits are [This bit I don't know] and ROM if the upper 2 bits are [Similarly Unknown].

Ram is organised as follows:

You can have up to 8 RAM bank chips which are selected using DCL nnn instructions which simply output nnn to CM lines 1..3 on the chip. (There's the default Ram Bank 0 which is selected when nnn=0, which activates CM0, and the rest nnn>0 which literally output to CM1..CM3, so you can attach a 3:8 decoder and decode the other 8 - though that doesn't quite make sense).

Next up: The Src instruction outputs a register pair as described above. The top 2 bits are ignored by the RAM chip itself. The bottom 6 bits select one of 64 addresses (4 registers of 16 4-bit 'characters'). You can then transfer between RAM and the Accumulator using RDM (to read from the RAM address), WRM ( to write Acc to the RAM). There's also ADM and SBM to add (with carry) and subtract (with borrow) the addressed RAM nybble to/from the Acc (and store in the Acc).

In addition, each 4004 RAM chip supports 4 'status characters', per register - bonus nybbles, so each register really contains 20 nybbles. You can access these using RD0 to RD3 and WR0 to WR3, so you can't index them via registers. It's all very strange.

But it gets stranger still. I/O is also accessed via the RAM and ROM chips which each provide 4-bits of I/O (RAM is output only) which you can access via RDR (read ROM port), WRR (write ROM port), and WMP (to write to the RAM output port).

Anyway, this blog explains why you can access 5120 bits of RAM: (8 RAM banks selected via DCL * 4 registers * 20 nybbles/register) * 4-bits / nybble = 5120 bits.


Tuesday, 2 August 2011

You can't have it both ways

My cousin (and president of Birmingham Uni's Atheist society) Benjamin reposted a YouTube video which argues that Christians don't have the objective morality they can often claim to have, they have a subjective morality like everyone else.

OK, so here's a bit of a response, as per these debates I'd be very surprised if it got anywhere, but here goes!

The real problem with the argument is that it fails to distinguish between a command and a moral principle, so for example when the antagonist says: "Today's the sabbath, they're supposed to be put to death if they worked (Exodus 31:15)" the Bible verse is talking about a command, not a moral principle.

The underlying command: that of having a day of rest is still valid (Ex 20:10). Similarly, Lev 20:10 the underlying principle of not committing adultery is still valid. Similarly, Deut 21:18-21 and Prov 20:20, honouring your parents is still a moral principle. So it turns out that all the moral points the verses refer to are still valid, and so the argument here against objective morality doesn't stand.

In which case the Christian's argument is valid insofar that the New Testament maintains that the O.T morality is correct, though the way our failure to maintain it isn't: that's what the New Covenant in Jesus is about.

What's not quite right is the Christian's statement: "The old laws were made in the context of a very different culture and time period." What's happening here is that DarkMatter2525 is injecting the antagonist's definition of subjective morality here as an explanation for the difference between the Old and New Covenant.

In reality, the difference with the New Covenant has nothing to do with a change in the culture and time period. It's to do with the fact that (a) the Old Testament demonstrates that Israel couldn't keep the morality embodied by the law by their own efforts (and neither can we), Rom 3:2-21 (b) Jesus did keep it and because we can be 'in him', God's agreement with Israel is shared with us: Rom 8:3-4.

The key thing here in Rom 8, goes to the heart of what morality is about, since the natural question to ask is why the command in Ex 31:15 is not the same as the principle in Ex 20:10 when both appear as commands. That I'll leave for another time.

-cheers from julz

For reference, here's the transcript:

(Calm expression) "Morality is subjective, the perception of Morality depends greatly on the on context of the culture and the time period. As such it can be uniquely defined and subject to change."

(Angry) "NO, morality is objective, morality comes from God and God doesn't change. A sin is a sin no matter when or where. What's wrong today was wrong yesterday and what's wrong here is wrong everywhere."

(Calm)"Did any of your friends or family do any work today?"

"Yeah."

"Today's the sabbath, they're supposed to be put to death if they worked (Exodus 31:15). And according to the Bible you should condone the killing of adulterers and witches, disobedient children.. (more Bible verses: Lev 20:10, Deut 21:18-21, Prov 20:20, Lev 20:9, Ex 21:15)"

(Shock)"Oh my God! What's That?" (points right, antagonist follows)

"What - What?" ( Christian steals the "Subjective" heading from his antagonist and replaces his old "Objective" heading with it)

"Uh, I guess it was nothing. Anyway, that was the Old Testament, there's a new covenant with Jesus Christ. The old laws were made in the context of a very different culture and time period."

"Hey, you just stole my word."

"I don't appreciate these accusations, why the Hell would I..."

"Hey, Look out!"

"Yeah, right, like I'm gonna faaeeuugghh." (gets eaten by Alien).

Tuesday, 19 July 2011

FIGnition oxo game! (noughts and crosses/ tic-tac-toe)

After my doom and gloom blog about the arctic, I thought I'd write a bit of a journal on how to write a simple noughts and crosses game. So, this'll be technical, and fairly involved as it'll include code, but at the same time will give a bit of insight into FIGnition, Forth and simple strategy games.

FIGnition is a real 80s-style computer. It's got enough memory (8Kb) to write simple programs and enough built-in storage to develop them in. The keyboard's somewhat awkward, but I'm getting used to it (I designed it).

The Computer History Museum is running an event called Hacker's delight, and as I'm exhibiting, they've asked me to produce a version of noughts and crosses to be demoed there. Demoing the development is as important as playing the game.

I started by looking at a few versions of tic-tac-toe. It's possible to write a recursive min-max algorithm, but I took my original cue from an online version of Not Only 30 Programs for the Sinclair ZX81. There are some insights into playing the game here.

Firstly, how to number the board. The board is numbered not in the order:


1|2|3
-+-+-
4|5|6
-+-+-
7|8|9


But

1|2|3
-+-+-
8|0|4
-+-+-
7|6|5


And it's done this way to make it easier to analyse the board. Opposite corners have a difference of 4 and subsequent diagonals have a difference of 2. In fact it's best to represent the board like this, because it reflects the real structure of a oxo board: if you rotate it by 90ยบ it's still the same.

So let's first convert the ZX81 game. The ZX81 version simplifies the game by making the computer go first, by placing an 'X' in the centre. It then follows the following strategy:

  • In the first move (A=1), the computer plays the opponents move+1 (so, if the user played to middle, the computer plays to the next corner and if the user plays to the corner, the computer plays to the next middle).
  • In all other moves, if the user fails to block, then the computer plays opposite of the previous move and wins (i.e. because the user failed to block).
  • Otherwise, for the computer's third move if the user had played to the middle of a row in its first move then we step 1 back from our previous move and win. (That's our other winning case). That's because the computer's second move always creates a dual two-in-a-row where the previous location is its other winning choice.
  • Otherwise for the fourth move then we backwards by 2 and it's a draw.
It's a really simple strategy, which if you note, doesn't involve responding directly to the user's moves, except to record whether they first played on an odd or even square or whether they last blocked the computer's move.

In Forth we can simplify it by representing the moves as a table, one set for when the person played to an even-numbered square and the other set for when the person played to an odd-numbered square:



cdata compMoves 1 c, 2 c, 7 c, 0 c, 1 c, 2 c, 3 c, 6 c,

And then the algorithm simplifies to:
  • If the user didn't block or we haven't played yet, then pick the next move from the table adding it to our current position and if the move was '7' we win, else if it was a '6' we draw.
  • Otherwise we move to the opposite side of the board to our last move and win.
In Forth this is:


: compPlay ( movnum comp h -- m c f )
dup opp + brdRange = ( m c h h+4=c )
>r over = r> or if
over compMoves + c@ dup >r + r>;
7 =
else
opp + 1
then
;


An entire oxo game in approximately 9 lines of code! The entire game is listed on the FIGnition website and also here. It takes up approximately 5 screens and 554 bytes.

( Simple oxo )
: 2drop drop drop ;

: .brdLine
cr ." -+-+-" cr ;

: . Board
." 1|2|3" .brdLine
." 8|X|4" .brdLine
." 7|6|5" ;

4 const opp
64 15 + const (o)
64 24 + const (x)

: cdata <build does> ;

0 var board

cdata posConv
0 c, 0 c, 1 c, 2 c,
5 c, 8 c, 7 c, 6 c,
3 c,

: pos2xy posConv + c@
3 /mod 1 << swap 1 << swap ;

: place ( pos ch -- f )
over 1 swap << board @ swap over or 2dup =
if ( pc old nu )
2drop 2drop 0
else
swap drop board !
swap pos2xy at emit 1
then ;

: range? (val lo hi -- val | 0 )
rot swap over <
>r swap over > r>
or if drop 0 then ;

: humPlay
0 begin drop
begin
key 49 57 range?
dup until
48 - dup (o) place
until
;

: brdRange 1 - 7 and 1+ ;

cdata compMoves
1 c, 2 c, 7 c, 0 c,
1 c, 2 c, 3 c, 6 c,

: compPlay ( mv c h ..)
2dup opp + brdRange =
>r over = r> or if
over compMoves +
c@ dup >r + brdRange
r> 7 =
else
opp + 1
then
over (x) place drop
; ( .. -- mv c f )

: init 0 board ! cls .brd
;

: win? 5 0 at
?dup if
." I WIN!" key drop 1
else
over compMoves + c@ 6 =
?dup if
." DRAW!" key drop 1
else 0 then then ;

: oxo
init humPlay dup 1 and
4 * swap dup
begin
compPlay win?
0= while
swap 1+ swap humPlay
repeat
2drop ;


In a future post I'll look into a more sophisticated (2Kb!) version of noughts and crosses: where the person can start first, where I use real UDGs for a full-screen display and where the computer can LOSE ;-) !

Monday, 18 July 2011

Arctic Smashed


I've been doing some simple analysis of the arctic sea ice extent data in order to generate my own prediction of the summer low. I'm now almost entirely convinced that the 2011 record will be smashed in 2011.

I've based it on the Jaxa arctic data from 2002 to 2011, which I imported into a gnumeric spreadsheet. You can see from the initial image that the SIE for 2011 is below the record-breaking year 2007 and has been
every day since mid-May. In itself, this should be cause for alarm, but let's go back to 2007 to see why it's even worse than you might think.

2007 was a record-breaking year, but it didn't look that way until it lurched into free-fall in the last 10 days of June, due to a 'perfect-storm' of (AGW-induced) weather conditions, which set the scene for a record loss in late September. So the fact that 2011 has been lower since May isn't conclusive.

So, what I did was take the Jaxa data an import it into a spreadsheet. My first estimates were based simply on the ice loss from previous years after July 16 bolted on to July 16, 2011. There I discovered that the SIE minimum for this year would be about 4.16million KM2 - a new record, but not by much, a mere 80,000Km2. What's scary though is that simply bolting on the curves means that we'd get a record for 7/9 of the previous 9 years.












































July 16: 20117347656
Year:201020092008200720062005200420032002
Minimum: 481359452498444707813425453157817195315156578468860320315646875
July 16 802500083429698423438759250080798448401094902937588582818832969
Simple Prediction: 409312541992193549219391187450248444174218405890644264064077187
Average:4168333


But it's not a realistic estimate - it's likely to be an underestimation. That's because SIE curves tend to have some continuity between the current state (and conditions) and the future state. So I constructed a slightly better estimation. In this one, I calculated the slope of the ice loss from July 1 to July 16 and compared the ratio with the eventual ice-loss at the minimum SIE for every year.












































July 1 to July 16:1715157
Year:201020092008200720062005200420032002
July 1-July 16: 78156313798441221562169640611587501214375103125011087501210937
Ratio to min SIE5.113.244.042.972.983.544.153.553.63
July 1-16 Extrapolated:3.002E+053.503E+062.131E+063.973E+063.946E+062.989E+061.951E+062.976E+062.835E+06
Average:2.734E+06


With this, the best-case projection (i.e. maximum minimum SIE) will be 3.95million Km2 and the worst case will be 300,000Km2 (average 2.7million Km2). That's - stunning, and stunning doesn't even cover it: a 50% ice loss from 2007 in the
best case, a 93% ice loss in the worst case, 33% ice loss in the average case.

The question is then how reliable these estimates are. Well, I'd be the first to say, "not very". My projections can be skewed easily by a steep anomaly in early July 2011 which would project a much lower summer minimum than would be likely.

The irony is that 2011 has had a smoothly falling curve between May and mid-July and it was 2007 which had the sudden acceleration over July. So 2007 makes my 2011 estimate look higher than it's likely to be. So, I'll stick my neck out at this point and say I figure the arctic record will be smashed this year, it's likely to be around 20% lower than 2007, probably in the range of 3.5million Km2
, almost certainly lower than 4.0million Km2 and perhaps even as low as 3.0million Km2.

Friday, 1 July 2011

Flashy FIGnition!



I'm the designer and developer of the
FIGnition DIY 8-bit computer from nichemachines and I'd like to share a major milestone in its development with you.

FIGnition contains 512KB or 1Mb of raw Amic Flash storage. I've been working for quite a while on making the chips work like a proper disk, like USB memory sticks do and at last it appears to work and this is a momentous achievement!

Making Flash work like a proper disk is hard, because Flash memory is a development of an old technology called EPROM, which could only be written once and then required sitting under a UV light for 20 minutes to re-initialise it all (losing all the previous data). The only difference with Flash is that you can erase it electronically. Using Flash memory is like trying to write a book with an old mechanical typewriter and without tippex, but with a portable recycling unit. Every time you make a mistake on a page or need to change it you need to pick up a new clean page. Moreover, you're not allowed to change the orders of pages so you'd end up with all the page numbers in the wrong order. It's one redeeming feature is that you can take 16 or 32 consecutively edited pages and stick them through the recycling unit to give you new clean pages.

If everyone had to type like that I figure no-one would have ever bothered.

But that's how Flash is. On the (easier-to-use) Amic chips you can write a block of up to 256b at a time ( a page ), but you can't rewrite it; and you can recycle 16 pages at a time.

This FIGnition firmware is therefore so amazing it needs a blog of its own. As far as I know it's the smallest virtual flash disk software around at only 1.5Kb of compiled 'C' code (on an AVR Microcontroller). The firmware abstracts the Flash memory so that you can read and write 512b blocks to your hearts content; it remaps them to physical flash pages on the fly and recycles all the modified pages. The algorithm is so short you could port it to the internal Flash memory of a Microcontroller and use it as a proper disk and could be converted to work with as little as 4 original 28F010 devices (128Kb drive) (or 1 AMD 29F010 device (80Kb drive)).

To give you an idea of how good this is, it's worth comparing with existing uses of Flash chips. Most standard introductions to the embedded use of Flash memory tell you to create the memory image on the host and simply write it to the target. AmForth, for example uses internal Flash memory to store programs, but if you make a mistake you have to erase the lot again: you can't Forget definitions. Butterfly basic (for the MSP430) is similar, you can write and edit over individual lines of code, but once the Flash is all used up (even if there are reclaimable areas of flash) you have to erase the lot. UCLinux (a fairly complex embedded OS) can either use the rather large MTD flash driver or be restricted to the write-once blkmem driver. The original Psion SSDs on both the Organiser II and Psion 3 systems (both far more complex than FIGnition) used sequential, variable-length records and you had to copy the entire SSD to another one when it ran out.

VDsk FIGnition's VDsk flash system is also a bit of a 19 year personal dream. In the early 1990s I was working at a embedded company called Micro control systems where we developed solid-state storage systems using the then brand-new Intel 28F010 Flash memory chips and a bit later, the early PCMCIA flash cards. They were MS-DOS based systems and you could prepare MS-DOS formatted disks in a sort of write-once procedure. I spent quite a bit of time working on a truly general purpose flash disk system, which could have appeared at the same time as the first San-Disk Flash disks. But it was never in the company's commercial interest, so it could never be justified.

Later still, I worked at Teleca.com where we base-ported Symbian OS (Nokia and SonyErricon's Smartphone platform in the early 00's) to new phone hardware. The Flash drivers were good, but formidably complex! Inbetween I toyed with variants of simple Flash filing, either targetted at an old Apple IIc or ficticious embedded systems.

But now it's done - a simple, purging, embedded Flash Disk system which supports wear-levelling and is reasonably robust in the face of sudden power failures. It's been tested for over 60,000 block re-writes (30K on 2 different device types) with no errors. Enjoy.

Wednesday, 8 June 2011

It's Good To Ask Questions

On facebook my cousin Benjamin shared a reference to an article in an Irish newspaper about her deconversion to Atheism and asked "I'd like to see a theist's take on this article."

So, I thought I'd take him up on it. Hope the response isn't too dry! First it'd be a good idea if you read her article - it's well written and gets to the point.

“Atheism Is the True Embrace of Reality”

Paula's article consists of two major points.

Firstly: she explores the variety of Christian beliefs and finds them completely inconsistent. Therefore you can't know anything about the truth of the existence of the Christian God.

Secondly: Atheism isn't a belief, but a rejection of beliefs not based on evidence.

The first point is essentially an argument from subjectivity. I.e. a subjective experience can't tell us anything about the existence of God. And that's kind of correct, a subjective experience isn't a basis for even determining God's existence, never mind his/her/its properties or character. And that's primarily because from an external viewpoint (which is what the observer has), the subject is simply another item within the reality we live in: a heap of well-organised DNA, generating sound waves.

The problem therefore with the argument is that it's the wrong way round. God, if he/she/it existed determines us and our reality, in a roughly analogous way to the way mathematical axioms determine valid mathematical theorems, or (going another step back) a mathematician determines the set of axioms, which then determine mathematical theorems. It's not possible to determine God's existence from subjectivity in the same way it's not possible to determine the historical existence of Euclid from the existence of parallel lines, not even if the parallel lines could say "I wouldn't be where I was today without Euclid!" ;-)

So, the problem remains, if subjectivity isn't a valid basis for believing in God's existence then what would the basis be?

So, onto the second point: "Atheism isn't a belief, but a rejection of beliefs not based on evidence". So, the questions I would raise are firstly: What is precisely meant by 'evidence' here? Secondly: Is evidence a sufficient basis for beliefs?

I suspect that what she means is scientifically attested evidence supported by a consistent rationale (although she doesn't really mention anything at all about the need for reason in connection with evidence in her article). What she doesn't mean is subjective evidence, i.e. "I went on a milkshake diet last week and lost 2Kg", even if the person could prove that they did go on a milkshake diet last week and lose 2Kg.

The issue in her part of the argument is that all her qualifying terms, such as: 'valid' (as in "a deity for which no valid evidence…") or "reality" (as in "one you have faced up to the reality that there is no evidence") end up being circular. What is 'valid' means (I presume): "scientifically attested" (i.e. attested, because repeated experiments have provided consistent evidence). What "reality" means is: the reality one can infer from valid evidence and reason, etc.

With her second point the problem again is that "evidence" can't be a sufficient basis for beliefs. Let's consider one of her statements: "there is no evidence to suggest there is another life after this one, it becomes all the more important to live this finite life to the full, learning and growing, and caring for others, because this is their only life, too.."

But this doesn't follow. If there's no life following this one, then why not just stomp on everyone else to get your own way? We're both going to die after all. Or putting it slightly differently: there's no life after this one, so why not just try and make as much money as possible? There's no life after this one so why not just party? There's no life after this one so why bother getting up in the morning? All these things, I think, follow just as well don't they?

Conversely, what if the evidence proves unpalatable ideas - should we change our beliefs? What if objective evidence in the end justifies genocide - that is that unless we bump off the weaker members of our society (e.g. religious people) then humanity is doomed. What comes first in that case?

So, as I see it, the nub of the problem is the question of what counts as a sufficient basis for anyone's beliefs on any kind. Subjective claims aren't a sufficient basis for knowing truth, but 'evidence' is a badly defined term and a complete minefield as a basis for constructing beliefs about how to live.

But it's good to ask questions isn't it?