Nabla is Not A Blog, Alright? It's just my random online ramblings, and any similarity is obviously some kind of coincidence. Nothing to see here, move along...
Apple's Time Machine
Apple's Time Machine is an interesting piece of technology. The GUI front end is friendly, simplistic, and brittle. I used it to back up my Macbook, but once the disk died, I couldn't use the GUI to access the network back-ups of the lost machine!
I think this is partly as I had to tweak it originally a bit to get it to back-up to something that wasn't a particularly Apple-supported network share, or perhaps it was because the Mac I was trying to access it was used a different version of MacOS.
Anyway, I was now somewhat frustrated - perhaps vexed even, as I couldn't access my back-ups. However, behind the scenes, all it is is a 'sparsebundle' disk image, containing a list of dated directories containing the entire filesystem as of that time. Very straightforward to access once you're in!
It wasn't quite that straightforward in practice - there were random error messages until it got itself into a sensible state, but still... not bad!
The technology that makes this work is rather nice. The collection of directories share as much data as possible with minimal overhead by having hard links on directories! And to decide what needs to be backed up, the filesystem tracks directories modified since the last back-up. The transparency and simplicity of the back-up system, within the constraints of it being efficient, are rather neat. It does feel (to me, at least) that while it pushes the technology forward, it stays true to the Unix approach.
And then they put a glitzy but brittle GUI on top. :)
Permalink. Posted 21:36, Thu, 10 May 2012.
Ignoring non-sensical solutions
Warning: Contains simple puzzle spoilers!
On and off I've been working through Rae's Quantum Mechanics. One of the things that annoys me is the way the solutions to problems are chosen. Take a particle in a potential well: A differential equation is given, solved, physically non-sensical solutions are discarded, and what remains must be the solution.
How on earth can we justify only considering the 'sensible' solution? Can we really claim we have a mathematical model if it involves such judgement calls?
It reminds me of a simple mathematical puzzle. We have a cell, which, every time step, dies with probability 1/3, or otherwise splits into two cells, each of which follow the same rule in future timesteps. The children behave independently. What is the probability it survives forever?
If x is the probability it doesn't survive forever, this is because it either dies in the next step, or both children must die - as they are independent, the probability of this is x^2. So, x = 1/3 + 2/3 x^2. Solving this gives x = 1 or 0.5. Ignoring x = 1, we have the answer x = 0.5. But... why can we ignore the incorrect solution of certain death?
One way to look at it is as a convergence issue. If you plug in numbers around 0.5 into 1/3 + 2/3 x^2, you get a number closer to 0.5. If you plug in a number just under 1, it'll end up further away from 1. This shows that 0.5 is a 'stable' answer, but 1 isn't.
However, this still isn't convincing. What you can do is define x_i as the probability of the colony dying out in i steps, with x_{i+1} = 1/3 + 2/3 x_i^2. We can then say the colony death probability is the limit as i goes to infinity, and show that the limit is 0.5, if x_0 is in the range [0,1), thanks to the above convergence properties, and solving the quadratic is simply a way of finding the converged value for the real solution.
In a similar fashion, I believe the differential equation isn't the real quantum problem. It's an equation that represents possible equilibrium solutions, but misses out how to select the real one from all the possibilities it brings. Somehow, there is a mathematical phrasing for the real problem we're trying to solve, one that eliminates the 'non-sensical' solutions automatically, but I'm not sure what it is.
Permalink. Posted 21:44, Sat, 24 Mar 2012.
On Simplicity
Again and again I see designs that are just... wrong. Given the choice between doing it right and doing it simple, the choice is 'simple'. I'm not the only one to notice this.
Unix is a traditional example. It's as simple as possible. Look at the file API. Let's say that you want to read some data. You can read(2) it. If we're streaming the whole file in, a bit of prefetching would be nice. If we're trying to read regularly-sized records from all over a file, we want different behaviour. The API ignores the notion of record sizes and advance knowledge of access patterns. Any optimisation has to be heuristic.
Perhaps worse is atomic file update. Also known as: Write to new file, hard-link old file to back-up file, move new file over old file. Moreover, there's magic in the semantics of the file system to make this work: the writes to the file should be committed to disk before the move is, so that you don't get a partially-written file in the case of a crash. Ugly hacks to do a conceptually simple operation.
Or look at TCP/IP. The internet's favourite way of distributing video. There's no quality of service built into basic TCP/IP, and a packet-switched network is just the wrong solution for that kind of problem.
Way back, PalmOS was another example (like MacOS before it) - a co-operatively multitasking OS. Simple to design and implement, great for lightweight hardware, able to beat its pre-emptively multitasked competitors, but you know that in the end it'll be running on more powerful hardware doing more complex things, where the original design looks horrendously underpowered.
This is really the key. A complex up-front design will be bad, since you don't understand all the corner cases, people don't want all the infrastructure yet, the current hardware can't really support it, and you'll be trounced in the marketplace by a simple design that works right now.
Real good design is one that can evolve. Unix started off life as an OS for an impressively under-spec'd machine. Amongst other limitations, one thread per process, no real-time guarantees, uniprocessor model, certainly no graphics or networking. Even when Unix had been extended, Linux started as an x86-specific (and uni-processor) monolithic kernel Unix clone. Somehow, the design has extended in a way that has not fundamentally compromised it. Sure, it's warty, but it's somehow scaled. TCP/IP's not dissimilar. Despite its grimness, video over TCP/IP is working out mostly ok.
Sometimes, even ignoring the evolution over time, doing the simple wrong thing is better than the right thing. When I heard about Erlang's error model (basically, 'if something goes wrong, explode, and have a hierarchy of processors that can deal with children exploding rather than attempting to recover), I was horrified. However, it sounds like the right thing, in the end. Error handling is tricky to write, tricky to test, and errors in error handling could make for a nice cascading failure. Playing it dumb may make it more safe and reliable than trying to think hard.
Einstein's maxim to make it as simple as possible, but no simpler, seems to have some relevance. The lesson is, make it simpler than you think 'possible' would be - you might be surprised. On the other hand, make it extensible, so that success and scope-creep doesn't induce long-term failure.
Permalink. Posted 22:19, Mon, 27 Feb 2012.
Differential 1-forms, again
A while ago, I tried to make sense of differential 1-forms by thinking of how they're used in terms of a type system. I got approximately nowhere fast (you can see the post!). I've recently been reading Penrose's Road to Reality which describes them in near-laymans terms, and this seemed a good point to try again...
He defines a vector field as a function which takes another function (from point in the manifold to real value), and then at each point calculates some weighted sum of partial derivatives, effectively taking the derivative in a particular direction. i.e. a vector field E acts on a scalar function P defined over the manifold - E(P). E is of type (Point -> Real) -> (Point -> Real).
He then defines dP = dx dP/dx + dy dP/dy + ... (you'll have to insert your own curly 'd's as appropriate), where the dx and dy and so on are differential 1-forms. Thus, ahem, dP . E = E(P). For some variant on a dot product which is not really explained.
So, one minute E is a function, then it's something you can dot product. This is probably in some vector space of functions, but the whole thing seems pointlessly messy to me.
Instead, I decided to build my own mental model, and assume that whatever the books have is just waffle disguising it.
Taking the derivative of a function is basically identifying the linear transform which it's locally like. In Euclidean space, taking the derivative of an R^n -> R^m gives you the information about a R^n -> R^m linear transform. However, for a manifold, the space you view the derivative in (a vector space) may be rather different from the space you started in (something curvy). This space for derivatives is the tangent space. The tangent space for the reals is the reals, so if you have a manifold M with a tangent space T, taking the derivative goes from M -> R to T -> R.
Thanks to duals, this derivative can also be represented as a member of T. We can then view the dx, dy etc. as basis elements of the tangent space, and dP as an element of the tangent space representing the derivative.
The tangent space allows you to tack directions onto each point. In other words, a vector field can be viewed as supplying an element of T for each point in M. This gives us a way of representing E. Happily enough, dP . E gives us the thing we were after.
Overall, I think I prefer defining dP as a function of type T -> R. That way, the covariant scaling effects are made clearer, and you can probably get away without a dot product (haven't thought hard about that second part). If you change the scaling on your parameterisation of the manifold, when your vector field entries increase in measured length, the derivatives (as a function from the tangent space to reals) also decreases proportionally, so that the final number you get stays the same.
I'm sure I've swept a lot of clever and subtle issues under the carpet here. However, I feel the textbooks' approach does too. Until I can get a handle on an alternative well-typed interpretation of these things, this will do nicely for me.
Update: I underestimated Penrose. In a later chapter he clarifies his handwavey notation. I have been using the dual of the normal convention. The vector field assigns each point an entry in its tangent space. Interpreting this vector space as the space of functions taking derivatives in all directions gives us the 'vector field as differential operator' view of the world. Treating it as a vector space, the dual space of functions from the tangent space to the reals is the differential 1-forms, aka covectors. The 'dot product' we see is really just applying one to the other, and we end up with the contravariance between the two as needed.
Penrose's rather nice geometric intuition of this is that vectors work as you expect - their length is as you understand, but covectors represent density. 'dx' can be thought of as the hyperplane of points perpendicular to the direction x, and represents a density of stuff in that direction. I'm still working through this chapter, but I expect this will fit quite nicely with integration...
Permalink. Posted 21:50, Mon, 13 Feb 2012.
Sony and Abstraction Failure
Being nasty to Sony is a bit like shooting fish in a barrel, but it won't stop me doing it.
I saw a Sony iPod dock in the shops the other day. Gosh, how the mighty have fallen. Sony admitting the existence of another company? I had to check that the dock wasn't only compatible with a special Sony iPod-alike.
The combination of seeing this Sony stuff and having played with my ickle iPhone for a few weeks made me really think about the differences between Sony and Apple. They both produce beautiful looking products. I'm generally a fan of Sony hardware. The firmware is mediocre at best. Their software is awful (Remember when they tried to install rootkits on customers? Pretty par for the course, really). Their networks have been hacked and millions of customers' details lost.
Fundamentally, Sony can't do abstraction - the more high-level something is, the worse it is. The WalkMan worked because it was largely mechanical, and lacked any embedded CPUs. I suggest Sony move into brick-making.
Permalink. Posted 22:43, Thu, 17 Nov 2011.
Good Stuff: Raspberry Pi and the iPhone
Looking at this blog, it seems I mostly complain about stuff. In real life, I'm not that bad (honest), but this is where I end up writing down various frustrations, and it's relatively rare that I actually want to point out good things. I thought I'd make an exception to my normal posting style...
Raspberry Pi is a fantastic project, aimed at getting children back into programming - the '80s BASIC-powered home computer for the new century. While there are a lot of people involved who I really respect and trust (including my PhD supervisor, and an ex-employer), it's really the brainchild of Eben Upton, who is a really great clever guy. I can't really say enough good stuff about it, so I'll give up now, and instead encourage you to go scour the web for more information.
From the very open to the very closed. I have finally bought myself an iPhone 3GS, after years of having the dumbest of phones. In the past, what I wanted was a small phone without all the pointless and expensive extras. Having had years of PDAs, I'd generally found them nice toys, but useless in practice. So, while I could see the use others were getting out of their smartphones, especially in mobile internet, I couldn't be sure it wasn't going to be another pile of wasted electronics.
It's been great. The main thing this gadget has provided, which the others haven't, is mobile internet. It does this well. However, either gadgets have changed, or I have, as I've found the organiser and notepad features very useful! I guess I've got more meetings and to-dos than I ever used to.
Why'd I get the old 3GS? Basically, I enjoy living on the trailing edge of technology. Every upgrade I do has the thrill of discovering the new features, just like everyone else, except the things I upgrade to are bedded down and reliable, and much cheaper than they would have been otherwise!
So, now that I own an iPhone, I can see what Apple are up to. The app store may be horribly closed, but their vision is compelling - they've managed something Microsoft never did, making their customers want a monopoly. Having skipped the painful early stages, I can also see why Apple held off on 'easy' things like multitasking and cut-and-paste for so long. The iPhone was their way of completely redefining the graphical user interface - challenging UI conventions that had basically been standardised on all platforms since Apple introduced them in the mid-'80s.
It's weird to see this 'phone interface', knowing it's also the basis for the iPad and the features are now making their way into OS X in Lion. Rolling out the features incrementally was Apple's way of making the world used to their new plans, and making sure they got it right, without assuming too much of the old ways. The fact that the supplied manual is really one sheet of paper, and the whole design is both so innovative and intuitive is quite amazing.
Permalink. Posted 05:01, Mon, 14 Nov 2011.
Retro-gaming Update: Chimera, AGC and Christminster
A while ago I had some nostalgia for a proper ZX Spectrum isometric game. So, I didn't do anything sensible, like play a classic such as Head Over Heels. No, I got a copy of Chimera, a budget label isometric game I played over 20 years ago. I never got very far with it, but that's probably because I was very young, right? I could beat it now!
As I have limited time nowadays, even with arbitrary save/restore, I felt I didn't have quite the edge to get through it and see how it panned out without a lot of pain, so I found a map and walkthrough. I followed it. It was clear that there would have been a lot of tedious exploration otherwise, creating my own map. It also soon became clear that the game design consisted of traversing a the longest routes the game designer could make, repeatedly. There are no actual moving baddies. Failure at the trial-and-error necessary to work out what does what leads to instant death and the going right back to the start. Fundamentally, the game is a race against the clock, but different events speed up the clock. For example, being in a room with a radiator seems to speed up the water clock something like a hundred-fold, thus totally unbalancing the game. It was so poorly set up that even with the walkthrough and map, and saving and restoring to optimise things, I still somehow managed to end up running out on the timers, and needing to use some pokes to complete the game.
Apparently I hadn't failed to complete the game because I was young. I failed to complete it because it was badly designed and tedious rubbish.
More rewarding have been the text adventures. After playing some commercial titles, I thought I'd try a couple of the more popular amateur efforts. I made my way through the Adventure Consumer's Guide, which was surprisingly fun. You get a sidekick who is vital to many of the problems, but also acts as a subtle hints mechanism. Mostly, however, the hints aren't necessary, since it's a fairly friendly game. As I said, lots of fun, and recommended.
Christminster is a bit of a classic in the 'IF' (interactive fiction) world. I'd tried to get into it a couple of times before, but never really clicked. The start, being a linear and not particularly helpful set of puzzles, had previously blocked me from exploring the game. So, I swallowed my pride and looked at a couple of hints. This allowed me into the main section of the game, and also gave me an insight into the author's mind, useful for solving following puzzles.
While there are plenty of puzzle components, and you're not lead round on rails, there is something of a plot to it, which makes a nice change from wondering around looking for a relatively unmotivated puzzle to solve. I'm now about halfway through (judging by my score), without having used any more hints, although I'm at a bit of an impasse now. Something to plug away at from time to time, I guess.
Permalink. Posted 23:01, Mon, 26 Sep 2011.
Pushchairs and geodesics
Maths abuse alert: All the following is done intuitively, and I've completely failed to formalise it, which is a bit embarassing given I've read a book on differential geometry.
It occurred to me the other day while wheeling the children to Greenwich Park, over the somewhat unever ground, that pushchairs try to follow geodesics. That is, if one of the wheels is taking a longer path, the pushchair will tend to turn away from that side. So, locally, it seeks a shorter path, and in the limit it'll run along geodesics.
Another way of looking it is that the pushchair will run along a path such that each side wheel runs along the same distance. So, along the path the derivative of distance stuff perpendicular to the path is zero, so that said distance stuff is locally maximised or minimised (and I guess we're looking at a minimum).
This in turn helped me understand a Feynmanism. Feynman said that light takes the fastest route between points, but I never really got why this should fit with the other formulations of the behaviour of light. However, I now see this is rather like the case with pushchairs. In refraction, light changes direction as it goes through media with different speeds of light, so that the wavefronts match up across the interfaces (GCSE description of refraction). In other words, it makes the light turn towards the faster medium, and away from the slower medium. And as long as it dos this in the appropriate way (which it does), once again it'll follow a geodesic. Lightbulb appears above my head.
Permalink. Posted 14:04, Sun, 25 Sep 2011.
On the Creation of Sentient Creatures
I watch far too much children's TV nowadays. This is a side effect of having children, I guess. There is a programme called 'Get Squiggling!', feature the character Squiglet, who can draw things and bring them to life, and have adventures with them. This includes drawing people, bringing them to life, and creating new sentient creatures out of nothing with no higher justification required than her own enjoyment. No serious thoughts about the implications, no ethics committee, no nothing.
I mean... I know it's a children's programme, and not meant to be taken deeply, but... surely the philosophical implications are huge?
Could you imagine the real-world consequences of people just being able to create new sentient, conscious beings without any real oversight? What a strange world that'd be...
Then I realised that's precisely the world we live in (and indeed the reason we have children's TV).
Permalink. Posted 13:29, Sun, 11 Sep 2011.
Choosing an Open Source Library
When developing code, you often want to glue in third-party components. If you're writing commercial software, and are pulling in commercial components, it's traditional for the manager deciding to be motivated by Fear or Greed. That is, to either buy from the biggest vendor (No-one Got Fired For Buying IBM), or the one offering the biggest freebies and kickbacks (a nice meal out with the vendors, you say?). Often the two factors point in the same direction, making the choice especially easy. The actual quality of the software can be completely irrelevant - it's basically marketing-driven.
When pulling in open source software, you can be properly objective, right?
So, what do you look at? You download the various alternatives. Read their docs, look at their APIs, build them and prototype with them. Perhaps look at the source to see what the quality's like. If one has a slight technical advantage, you'd probably go with that?
Wrong choice! You actually still want to go for something a little more like the PHB approach. Technical quality and appropriateness is still vital, but so is the community surrounding the software. You could argue that how they deal with bugs and support are parts of the technical quality, but that's missing the point. If you have to choose between two similar packages, don't choose the one with the minor technical edge, choose the one that'll be around in a few years' time!
What determines this? The momentum. Choose the one which is going places, with lots of happy contributing users, ongoing improvements, and fundamentally where the developers understand marketing. You're not using the product because you're a fool who is easily swayed by marketing, but because others are. It's a networking effect, and you want to be using the winning product.
As a clever developer, it's really cool to find an underdog project that's technically better than the obvious choice. It marks you out as part of the cognescenti. This can even be made to work - if it's technically much better, and you can support it yourself if it goes nowhere, or it's an underdog with clear positive momentum, it can be a good choice. Most of the time though, even in open source, the pure technical choice may not be the right one.
Permalink. Posted 12:55, Sun, 11 Sep 2011.
The English Riots: Business as Usual?
I have an amazing ability for waiting until a topic is no longer trendy before actually getting around to writing my thoughts on it. In this case, the riots in the UK. This means that reality turned out to match my thesis, even before I wrote it down; namely, that the riots didn't actually mean anything on a social or political scale. Having started with my conclusions, I shall move back to my reasoning...
I started thinking about how much it really meant when seeing reporting (a lot of it international) about how shocking this rioting was, and how it was revealing something fundamentally rotten in UK society, and should give those running the country pause to think. I even saw some comparisons with events in Egypt etc. (definite high clue quotient there). On the other hand, I'd also seen plenty of people writing it off as mindless thuggery, which is also a bit too convenient and stops any need to try to understand them. What's the actual situation?
First off, I'm ignoring the looting. That's not about the poor or underpriveleged. That's about a group of people where lots of people are clearly breaking the law, getting away with it, and gaining from that. Locally, different social norms start to apply, as following the law puts you at a disadvantage for no 'fair' reason. See, e.g. MPs' (MsP's?) expenses, phone hacking, etc. for other non-disadvantged groups doing similar things.
So, how many people were rioting, ignoring the looting? My opinion would be somewhat more convincing if backed up by real numbers, but it's clearly a tiny fraction of the communities, and looks not entirely dissimilar to the fraction of the population with a propensity to crime and violence anyway. There will also be some people carried along because they're normally only held back by fear of justice, and felt they could get away with it this time.
Put another way, the riots looked to me like people's normal behaviour, only condensed. Indeed, if you look at the amount of crime that was committed, I don't think you need to spread it out over an awfully long period before it blends into the overall crime level. It's certainly lost in the noise on the 30 year scale we seem to have between riots.
In summary, I don't think these riots mean nothing, they just tell us as much about the problems of society as our normal background level of crime and violence. Moreover, it's a real shame to focus on these riots when there have been so many much larger protests motivated by real issues. *sigh*
Permalink. Posted 12:15, Sun, 11 Sep 2011.
Oh, the Horror: Twitter
First, a couple of disclaimers:
- I understand the nature of start-ups. You quickly write rubbish code, because having something running is much more important than anything else. Moreover, the ideas are far more important than the technology details, and if you're successful you'll have plenty of time to rewrite later, right?
- This is Twitter Of Old. I'm pretty certain they've hired some people with actual technological skill and have real scalability now.
So, without further ado, I looked at some old presentations on Twitter's implementation and scalability. MY EYES! THE GOGGLES, THEY DO NOTHING! Let us remember that Twitter is a service so reliable that its most memorable image is the Fail Whale that appears every time it goes down...
So, in a presentation in the late 2000s, post-optimisation, they were handling 600 requests per second on 8 Sun boxes. That's 75 messages per box per second. Er, great. We best not talk about e.g. the performance expected out of IRC servers, a decade earlier.
The real killer for me was this quote:
For us, it's really about scaling horizontally - to that end, Rails and Ruby haven't been stumbling blocks, compared to any other language or framework. The performance boosts associated with language would give us a 10-20% improvement, but thanks to architectural changes that Ruby and Rails happily accommodated, Twitter is 10000% faster than it was in January.
This sounds really cool, until you realise that IN JANUARY, THEY WERE PROCESSING 3 REQUESTS PER SECOND. I've seen shell scripts with better performance, and they're all multi-millionaires now.
Not that I'm bitter. ;)
Permalink. Posted 14:30, Wed, 24 Aug 2011.
Simple Programming Advice: Put Examples in Comments
Just a quick note encapsulating some simple advice I'd only discovered recently: Put examples in your comments. Comments should add something to the code. Explaining what the code should do is good, how is bad, since the code itself should say how.
There's a school of thought that says that comments are dangerous, since they easily get out of sync with the code, becoming dangerous lies. So, don't comment, and make your code readable instead. I certainly have some sympathy with this viewpoint, but I think it's naive. For a sufficiently complicated algorithm, each step may be clear and well-named, but the overall structure and intention may still be mysterious. Very little code is designed to be readable by someone without an awful lot of context, and I think this is a real shame.
So, for comments to add value they should do something other than what the code does. A terse and formal description of what the function should do is well and good, but can sometimes leave the reader confused. By illustrating the same thing in another way, through some examples, you've got a much better chance of having the reader understand what you're up to.
The trendy programmer will point out that you can move the formal description of the function out into a set of pre- and post-conditions, and you can convert your examples into test cases. By doing this, you can ensure that your 'comments' never become out of sync with your code. In theory, yes. In practice, the Test Driven Development book made incredibly heavy weather of developing even the simplest of functionality, and I worry about how it scales up.
One day, maybe. In the meantime, comments explaining 'what' plus examples, please.
Permalink. Posted 12:22, Wed, 24 Aug 2011.
Programming "Experts"
Browsing Amazon's recommendations the other day, I saw "97 Things Every Programmer Should Know: Collective Wisdom from the Experts" by Kevlin Henney. Oooh, I thought, someone's managed to glue together a selection of blog posts (97 tips in one book aren't exactly going to be deep). As Amazon has "Look inside!", I did, and skimmed the table of contents...
I recognised several names. No, it's not a star-studded line-up. They've just contracted at my workplace. This is where the definition of "expert" comes in. They are, indeed, experts at discussing programming. They spend a lot of time at conferences, and networking with each other. They may know some language lawyering tricks. When it came to actual programming (or even design) I saw nothing setting them apart from most other seasoned programmers.
This is unfortunate, as in other domains I've met what I would regard as real experts. People who not only understand a subject backwards, but also have great and incisive ideas. This covers both proper academics and really effective business people. Those guys are a pale shadow of this.
This is not to denigrate the book - I suspect there are plenty of useful, non-controversial pieces of wisdom that deserve to be spread around and some of the contributors may deserve the title "expert". I guess I'm just complaining about my own naivety.
Permalink. Posted 20:01, Sat, 21 May 2011.
On symmetry-breaking, logic, perception and AI
One of the things I was thinking about recently was our perception of symmetries. For example, formal logics tend to have a symmetry between true/false, and/or, etc. Formally true and false aren't particularly distinguished, but they certainly have different meanings to us! This is one of those things that makes me suspicious of using formal logic as an underpinning of AI.
Are there similar isometries for natural languages? Could you switch other important concepts around, and a document remain just as consistent and useful? I don't think there is much of this. Why? Natural language is glued to the real world in a way formal languages aren't. When it comes down to it, language is bolted onto us as animals - there can't be the same symmetries amongst concepts that control life and death. In other words, perhaps a good way of creating an AI is to, say, base it around a program that wants to be happy! :p
Anyway, there are some symmetries in the real world, not just in language, but in our perception of the world itself. For example, I may perceive the colour red to look like what you think of the colour blue, and vice versa. As long as we're used to the colour schemes of the world, and have a consistent naming convention, we'll never know. Moreover, if my left-right perception of the real world were reversed, I'd have no way to tell. This one seems more odd to me, as there is (arguably!) an orientation to the real world, but I can never know if I'm seeing it correctly.
Despite these mappings of the real world to our perceptions being arbitrary, they're so taken for granted that people hardly notice they're there. What is the symmetry-breaking mechanism here? Is it really arbitrary? Are these different mappings truely isomorphic, or do the variations change our perception of the world? I have no idea!
Permalink. Posted 20:52, Tue, 17 May 2011.
Miranda Elizabeth Patricia Frankau
Miranda Elizabeth Patricia Frankau was born on Friday 6 May 2011 at 16:32, weighing 2950g (6 pounds 8 ounces). Mother and daughter are doing well, and the whole family are overjoyed. Yay.
Permalink. Posted 08:48, Tue, 17 May 2011.
Differential geometry, category theory and typing
NB: This entry involves hand-wavey maths-abuse.
I've been reading a book on differential geometry. It's the first maths book I've read (other than an introduction to category theory, which is kinda cheating) that actually has commutivity diagrams. I didn't really see why category theory might have come out of geometry, but it does seem far more understandable, having seen all these maps between different spaces, and mathematical equivalents of 'if you do this in over there, it's just like doing that over here'.
So, geometry's given category theory to computer science. I'd love it if computer science could give really clear types and anonymous functions to geometry. For example, what actually is a differential form? To keep it simple, let's look at a differential 1-form... these are standalone things like 'dx'. A-level maths said that a 'dx' isn't an actual thing, it's just a bit of notational convention in an integral, be careful, etc. At this level, it's made into a thing...
So, what is it? Let's say we have a manifold U. At each point of U we have a tangent space, which is a vector space of all the tangents at a particular point. How do we tie this tangent space to the underlying manifold? We can make it the space of functions which take derivatives in particular directions - i.e. the things normally written 'd/dx', for some direction x. That is, it's a vector space of functions from points to real values to points to real values. In Haskell type terms, this is a space of (Point -> Real) -> (Point -> Real). Given each point in U has its own tangent space, the overall type is Point -> (Point -> Real) -> (Point -> Real). Of course, in the text the parameters and abstractions and all the rest of it are done in implicit mathsy form, which I think makes things a little more obscure for no good reason.
What's a differential 1-form? It's a member of the cotangent spaces - the dual of the tangent spaces. Does this mean it's of type (Point -> (Point -> Real) -> (Point -> Real)) -> Whatever? No, it's actually a function from point to member of the vector space that is the dual of the tangent space at that particular point. In other words, this whole dual business is being done in a lifted world, if you were writing Haskell. The type is Point -> (Point -> (Point -> Real) -> (Point -> Real)) -> Whatever. What is 'Whatever'? Well, it's the scalar type of the vector space we're looking at, so for a fairly dull manifold, it'll be Real: Point -> (Point -> (Point -> Real) -> (Point -> Real)) -> Real. Still pretty impenetrable, but perhaps the start of an explanation.
What is 'dx' supposed to be? It's supposed to be the thing that when given a member of the tangent space projects out the d/dx component of it. How can we do that? Well, I guess we can just make a function which is linearly increasing in the direction of interest, but is otherwise flat, feed it into our derivative-taking function, and then evaluate it at an arbitrary point (the resulting function should be the constant function, for a given tangent space):
diff_1_form point tangent_space =
tangent_space_elt my_fn zero
where
tangent_space_elt = tangent_space point
my_fn = -- Function linearly increasing in our preferred direction
zero = -- Zero element of vector space
Other function could be substituted in, I guess. Is this correct and accurate, or have I missed something? I'm not sure. For all the formal notation, I'm still not sure if I've extracted the true meaning correctly!
Update! More re-reading reveals further details. The smoothly varying tangent space thing is called a vector field, and the point used to select the derivative-taking functor from the tangent space is the same point used to evaluate it. That is, the overall type is, depending on how you look at it, (Point -> Real) -> (Point -> Real), or Point -> (Point -> Real) -> Real - that is, you can look at it as a thing that transforms functions of the form (Point -> Real), or as, for each point in the manifold, a thing that maps functions to real numbers (specifically, the derivative of that function in a particular direction at that point).
Interestingly, the second type means that the tangent space is effectively over certain functions of the type '(Point -> Real) -> Real', which already looks like the dual of some vector space of functions of type 'Point -> Real'. Sticking together the element of the tangent space with the cotangent space is then basically the idea of passing this function to the tangent space functor. Indeed, the definition of the differential operator 'd' is exactly that:
Given a function f : Point -> Real, and a vector field X : (Point -> Real) -> (Point -> Real), d : (Point -> Real) -> ((Point -> Real) -> (Point -> Real)) -> (Point -> Real) is the surprisingly obvious ((d f) . X) x = X(f). (No, I'm still not sure I've got it exactly right!) For things beyond 1-forms it's more complicated.
Permalink. Posted 12:08, Fri, 22 Apr 2011.
The Universe as a Fixed Point
More random silliness. The common model of a the universe at a point of time seems to be based on the prevalent technology. So, in the mechanical past the universe is 'like clockwork'. Nowadays there is a bit more thought of the universe algorithmically - leading to things like Tiplerian nuttiness, The Matrix and Wolfram's New Kind of Science (I think - I've not read that tome).
A more general view is of the universe as the solution of equations. In some ways, this is not entirely dissimilar to the algorithmic view. For example, you can solve a PDE abstractly, or treat it as some kind of grid-based evolution of state. However, the equation solution approach is more powerful.
For example, you can be very silly, and extend the Tipler view. If the universe has infinite computational capability, it can simulate, say, the universe. Moreover, the universe we're in could be the result of some simulation. But we can go further than that, and have the universe simulate itself. That is, have the universe be a simulation running inside itself. This is obviously rubbish, if you treat the universe as a naive algorithm.
Another way of looking at it, though, is as a Y combinator attached to the world. That is, the universe is the fixed point of an equation of 'things that simulate themselves'. It simulates itself into existence. It's turtles all the way down. :p
Permalink. Posted 22:13, Wed, 13 Apr 2011.
Optimal memory reallocation
If anything is to demonstrate why I'm unsuited to blog-writing, it's the fact that I've been planning to write this post for about five years, and haven't done so because it's trivial!
When doing auto-resizing contiguous storage (e.g. C++'s std::vector), the normal growth mechanism is resizing by a multiplicative factor - e.g. doubling the size each time. My boss of 5 years ago pointed out that doubling is probably a bad factor. Imagine you have some kind of zero-overhead allocator, and this is the only allocation going on in your address space. The first allocation takes 1 unit, then 2 units, 4 units, etc. The next allocation takes 2^n units, but the sum of allocations so far take (2^n)-1 units. In other words, the new allocation must be placed in a fresh part of the address space, rather than recycling previously-used-and-now-free space. This can be viewed as rather wasteful (as such previous allocations are unlikely to be returned to the OS).
This got me thinking as to what is the optimal allocation resizing factor, in this rather simplified view of the world? We continue to assume multiplicative scaling. The array first takes 1 unit, the first resizing x units. The next resize can't go into the 1 unit space, so we tack x^2 on the end. However, we may be able to fit the next allocation (x^3) into the freed (1+x). Then we free the x^2, and x^4 goes in its place. x^5 is after that, and again we can hope to put the x^6 into the space previously occupied by (x^3 + x^4).
What x is appropriate? In both cases, the equation boils down to 1 + x = x^3. As I am lazy, I fed this into Wolfram Alpha rather than solve it myself. The solution by radicals looks ugly, so suffice to say the result is around 1.32. This is one of those cases where an approximation to e.g. 4/3 would be pretty pessimal, as the allocation then wouldn't fall into the pattern we're aiming for. Given the overhead of allocation, you're probably better off with a growth factor of 1.3 or maybe even 1.25.
At a scaling factor like that, you're going to be spending a lot of time copying data. The reallocation overhead may be a constant factor compared to getting the array size right in the first place, but that constant will be big.
What about if we're willing to do an extra step before we can start recycling memory? The real root of 1+x+x^2 = x^4 is just over 1.46. That's somewhat better. And if we're willing to do more and more steps, what is the limiting factor if we wish to eventually be able to fit the newly allocated array into some previously allocated memory? Why, the golden ratio, of course! (The limit is not a factor of 2, as it might look naively, since you have to keep the previous allocation until copying is complete)
All of this is somewhat silly and academic - in a real environment a growth factor of 2 is probably pretty reasonable in terms of avoiding unnecessary copying. On the other hand, from this we see that a growth factor of 1.5 might not be an unreasonable trade-off, in terms of reusing existing memory if you've got an appropriate allocator. A fun little toy.
Permalink. Posted 22:28, Tue, 12 Apr 2011.
Toddlers play Text Adventures
One of the odd effects of playing too much adventure games is that you can start to look at the world in odd ways. For example, it now seems to me that toddlers treat the world as a text adventure. David's common approach is to go through a think-do cycle, where the 'do' is generally a simple verb-noun phrase. Moreover, it genuinely does appear to be mostly adventure-game-like: Drop ball. Look. Get book. Examine book. Give book to daddy.
I guess it makes sense. After all, they're wandering around a strange world, where they don't know the rules, trying to make sense of it all. They have a limited interface to the world (a small vocabulary, both literally, and conceptually). As with most text adventures, communications with other characters is difficult.
So, my thesis is that randomly wandering around the house, moving objects about apparently aimlessly and doing wierd things isn't actually babyish at all! If an adult were dumped in a sufficiently alien environment, they could do no better....
Permalink. Posted 23:04, Sat, 12 Feb 2011.
Guild of Thieves
Having played Jinxster, I thought I'd have a go at another Magnetic Scrolls game. I tried to get into The Pawn, their earliest game, but got pretty much nowhere - it's lumpy and uneven. I'll probably complete it with a walkthrough for completeness' sake, but it's amazing how they developed in terms of playability. Guild of Thieves, being between the two in age, has a good pile of very reasonable puzzles, plus some really rough playability edges.
I've played it rather slowly and patchily, getting stuck and unstuck. One ofthe problems is realising when you've reached the endgame section. You have to keep checking if the bank is open now, so I'd been ready to start that section of the game for ages before realising I could! This is not made clear from the scoring system, which is pretty patchy, or the presence of a number of red herrings.
So, I resorted to a walkthrough to see what I'd been missing, only to discover... nothing up to the point I'd reached! Still, I was stuck on the coloured dice problem, and the banker's door, and getting impatient to finish, so I took hints to complete them. Not quite as even-handed as Jinxster, but pretty fair if you overlook a couple of flaws.
What next? A bit of Infocom?
Permalink. Posted 07:54, Sat, 12 Feb 2011.
Debugging is Computer Science
An awful lot of computer science has nothing to do with science - it's rather more like applied discrete maths. Oxford call their undergrad degree 'computation', and I have rather a lot of sympathy with this approach.
There are some parts of the subject which really are more like science, with experiments and stuff. Good systems design, for example, where benchmarks are created and implementations profiled, has a lot in common with setting up a lab experiment. However, this stuff rarely makes it into an undergrad course.
This perhaps explains why so few people seem to be able to debug properly, for debugging is science. Actually, it's worse than that. In science, you build a hypothesis, and then create an experiment that tries to disprove your hypothesis - if you can't, you have more confidence in your hypothesis. In other words, you start off with a consistent view of the world, and try to construct tests to extend your understanding. With debugging, your view of the world ('This should work') doesn't coincide with the reality ('It doesn't'). You have to design experiments to clarify where your view of reality differs from reality.
In short, in science you're testing hypotheses, in debugging you're testing assumptions. Either way, a scientific mindset is vital.
Permalink. Posted 22:08, Fri, 21 Jan 2011.
Happy Birthday David!
I don't tend to a) update this regularly, and b) write too much family-personal stuff. So, I shall belatedly state the obvious: David is now over a year old. Nearer 15 months now, in fact. It's been absolutely fascinating (and rather lovely) to watch him grow and learn. Observing him, it does make me rather suspect that all AI researchers have been barking up the wrong tree, but that's another story....
Permalink. Posted 21:39, Thu, 20 Jan 2011.
Fixing BoingBoing
I used to enjoy reading Boingboing back when it was a 'directory of wonderful things'. Nowadays there's more random pointless opinion pieces, mixed in with the cool things collected off the web. At worst, it's a left-wing new media Daily Mail. It's rather a shame, as they've also collected a couple of interesting new regular columnists.
One of the most tedious garbage-spewers is Douglas Rushkoff, who had an incredibly annoying guest column a while ago. He's back. So, I thought I'd finally work out how to do this GreaseMonkey-style filtering business. I finally managed to hide all articles mentioning him. I then tacked on a few extras. Between AdBlock and this script, and I now have something to remove all the most obvious rubbish from the site.
How's that for the Maker spirit?
Permalink. Posted 22:38, Fri, 01 Oct 2010.
Pseudocleverness
Time for another rant and a word I made up to describe a trait I particularly dislike. In a sense, it's experience/knowledge vs intelligence. Obviously the best kind of hire has both, but if you can only pick one I'd go for intelligence every time. When doing something new, it's intelligence that counts. If you're doing something again, knowledge or experience without proper understanding most likely means doing the same thing as last time, choosing a bad-fitting solution, and not learning from mistakes. So...
Pseudocleverness is what I'm calling the habit of suggesting a clever-sounding solution when the obvious, straightforward solution would do immeasurably better. The clever solution is never an original idea. It's a cool trick that has its place, which is then misapplied by someone who wants to show off, without actually thinking about the problem at hand and its suitability.
For example:
- Don't use stacks for storing your scoped data. Region-based allocators are very cool and efficient. Never mind that stack-based allocation keeps exactly the right amount of data around, has very good locality of reference, can be implemented in a few assembly instructions, and is pretty universally supported. If you're playing with continuations and closures you may want something different, but that wasn't what was under discussion.
- Don't use smart pointers in C++. Good design can control ownership explicitly, and anyway smart pointers can leak with cyclic references. We use smart pointers precisely because they stop the need for very careful design to control ownership. They are simple and straightforward, and pretty much universally used in the area that was under discussion. Those not using smart pointers aren't using them because they haven't started using them, not because they've switched away. In a new library planned for years of evolution where we have const data objects which form a DAG, not using a reference-counted shared pointers to manage the lifetime of these objects is nutty.
- When creating interfaces in C++, don't use abstract base classes. Instead, use complex templates to create tables of function pointers to non-virtual functions, making the interfaces rather more like traits on the objects. Fundamentally, reimplement virtual functions manually. 'nuff said.
Permalink. Posted 23:28, Tue, 28 Sep 2010.
Art in Summer 2010
It's that time of time of year again, so we've been doing our limited art seeing thing. Specifically, we went to the BP portrait competition at the National Portrait Gallery, followed by the Summer Exhibition at the Royal Academy, both of which I tend to enjoy. David came along, and was wonderfully quiet throughout (sleeping through most of the RA!).
The portait competition was happily a bit more varied than last year. Not so much in the way of photo-realism, so there was a bit more opportunity for personality to be expressed. There were a few I didn't care for, but on the whole I really rather enjoyed it.
After brunch at the NPG's rather nice restaurant, we decided we'd attack the Summer Exhibition. We wondered if they'd cope with a push-chair, but it turned out to be fine. Critics have panned it, but I enjoy it pretty much for the same reason as they hate it. I love looking through the higgledy-piggledy of the entries from the hoi polloi in the Weston rooms, and I enjoy looking on in horror at the overpriced rubbish from the more famous artists (special prize here for Tracy Emin's awful, awful tat). Generally, though, I enjoy trying to find those few items I think utterly lovely.
The prices have rather increased this year - what that's doing with a recession, I don't know. So instead of looking at my favourite things that are almost on the edge of affordable (ha!), I thought I'd just ignore price and list my favourites:
- River Flood - Antony Whishaw RA Wonderfully atmospheric abstract painting.
- Personal Creation Myth - Grayson Perry How he produces such beautiful, yet disturbed objects, I have no idea.
- Blue Hold - Elizabeth Magill A moody and desolate picture of some trees, somehow brought to life by bright yellow paint. Much more lovely than it sounds. She won the 'Sunny Dupree Family Award for a woman artist' award, which seems almost offensive to me, since its loveliness seems entirely independent of the gender of the painter...
- Einschuesse - Anselm Kiefer Huge, looming and highly textured oil painting. A huge grey mountain and fields, with sinister red spots. The title appears to be 'bullet hole'.
- Various Fred Cumings Four rather nice landscape paintings.
Permalink. Posted 22:48, Mon, 19 Jul 2010.
Electronics for Newbies: Oscillator practice
Some people might suggest that the theory of crystal oscillator design should perhaps precede constructing such an oscillator. I thought a) I'd have a go by doing, and b) It's easy, anyway, right?
Consulting Horowitz and Hill plus a minimal bit of research on the internet indicated that I wanted a Pierce oscillator, that you need to get capacitors which match the crystal, and that otherwise the series and feedback resistor hardly matter.
So, I got myself a 4MHz crystal and 32kHz crystal, both with their appropriate capacitors. I used a 10k series resistor, and a 10M feedback resistor. I breadboarded up the circuits, attached my 'scope and... nothing. Hurrah. The 4MHz generated nothing, and the 32kHz generated noise.
So, I lightly investigated the theory, to see which tweaks might make the things work. The 4MHz crystal wasn't too difficult to twist into working. Replacing the 10k series resistor with 220 Ohms (!) made it work, at least some of the time. 220 Ohms is about all I have, otherwise, as most of my resistors are either pull-ups, or current limiters for LEDs - That's all I needed for simple logic circuits, I thought. Either way, it worked, as can be seen in my little picture.
The yellow trace is the power supply. Perhaps I should have put more decoupling in? I'll experiment later. My skimming of the internet, trying to find clues as to the problem lead me to a couple of useful application notes - Microchip's AN849 and ST Microelectronics's AN2867. The former seems to concentrate on debugging broken oscillators, while the latter on using maths to design them right! In my current situation, the former was what I approached first. With the small resistor, I was worried about overdriving, so I moved the resistor to the other side of the capacitor and measured either side of it to get the potential across it (using the exciting 'maths' mode of my 'scope).
It looks like it could be just a little overdriven, or it could just be the way I'm measuring. Of course, measuring all this stuff with an oscilloscope probe is rather fun, since the probes have similar capacitance to the caps actually designed into the circuit! The other fun point is that as it's really just a little feedback circuit, with different gains at different frequencies, the oscillation in a badly designed circuit (e.g. mine) can vary on a per-startup basis. Sometimes there might be no oscillation, and at other times a different mode may appear. I have much to learn!
Finally, I tried my hand at getting the 32kHz crystal working, which had been much more uncooperative. With much faffing, I got it to work (unreliably) with 18pF capacitors, 30M of feedback resistance, and 115k of series resistance. As you can see from the screenshot, it's incredibly noisy. Next stop, I'll look up the theory and do some maths to see if I can make it work better!
Permalink. Posted 21:12, Sun, 27 Jun 2010.
Electronics for Newbies: Oh, silly scope
David L. Jones apparently has too much influence on my life, as for my birthday I got one of those lovely Rigol oscilloscopes. It's still not modded to 100MHz, as I'm not playing with those kinds of frequency. Indeed David Frankau's also having a huge influence on my life (unsurprisingly), since I've hardly played with it, and my birthday was more than 2 months ago.
Still, the use I've had out of it has been terribly helpful. Starting off, I can see the bouncing when I flip a switch, or the logic delay propagation through a chip. I've got a photo of the latter, which just happens to show off my new pride and joy.
Really, though, it's been most useful when debugging, of which I've done more than anything else recently. As a demo, I've now got lovely little screenshots of my wallwart power supply's output, before and after smoothing.
It's interesting to see the way the rectified waveform doesn't have a massively sharp bounce, and the top of the waveform isn't super-smooth-and-symmetrical. Once I've added a smoothing cap, all that's left is a little ripple - about half a volt by the looks of it.
Lovely. Then I tried to show the result of regulation with the MCP1826S. Mucho weirdness. The output level was about right, but it was somehow pulling the input voltage way down, too. And this was with a very light load. That's not right, is it? Hmm. It's getting really hot, too. Since I'm using the dual channels of the scope as voltmeters, it frees my actual multimeter up to measure the current. Several hundred milliamps. That's really not good.
It's pretty happy when I run it off an old 9v battery, but this mains supply makes it go nuts. What does this tell me? It tells me to read the data sheet properly! While these regulators are nicely low drop-out, and are capable of driving pretty big currents, they can only take 6V in. That may be useful for driving low-voltage circuitry, but it seems a little lame for what a 5V regulator can handle. Silly me for not reading the datasheet, and after I've stuck 12-13V across them I'm now left with a couple of TO-220-packaged heaters. They certainly don't do a sensible job of regulation any more.
Anyway, now that I have a little more experience with oscilloscopes, I think it's time for me to go off and play with crystal oscillators....
Permalink. Posted 06:40, Sun, 27 Jun 2010.
Bureaucracy and Broken Hinges
From time to time, I try to keep up my text adventure habit. After a period of being stuck in Guild of Thieves I decided to have a go on the Infocom side with Bureaucracy, which has the added advantage of having had Douglas Adams's input into it.
It's a fun enough game. The plot does have Adams's fingerprints on it, and the puzzles are varied and interesting. However, I think I've been spoilt by Magnetic Scrolls! I'm not too worried by the lack of pictures, but Bureaucracy is comparatively... spartan. The descriptions are short, the number of locations limited, and the structure quite linear. To compare, the total points in the game is 21, versus 500 or so for some other adventures. Admittedly, it gives out points one at a time, rather than in lumps of fives or tens, but this is still small.
Difficulty-wise, Bureaucracy is reckonned to be rather difficult. I found it straightforward with lumps of difficult. Of the twenty or so puzzles in the game, I got stuck on three. As I'm annoyingly time-limited nowadays, I resorted to spoilers. Rubbish me! Reading the answers generally made me feel rather silly - I should have got them! On the other hand, they really weren't straighforward. The game's sadistic sense of humour stretches to the puzzles. You might see how to solve a puzzle, but it'll set an obstacle in the way, and another. Oh, and the puzzle may involve an item from way earlier in the game you didn't know you needed. Nice.
Still, it really was a good pile of fun.
In other news, my MacBook Air continues to give hardware problems. I think the warranty-expiration timer must have fired. Closing it, the hinge made a funny noise, and it failed to shut. Further inspection revealed that the little metal bits had, well, kinda got out of sync. A bit of fiddling did get them back. However, the hinge cover ('antenna cover') is plastic, and the dislocated metal was levered into it, weakening the plastic. It's now broken, leaving a little hole in the hinge area. I think it provided a certain amount of pressure on the hinge, so the hinge is now a little weaker, and the screen tends to fall back.
Looking at the internet, I don't appear to be the only one - see here, for example. The replacement parts are hideously expensive, and to fix it involves removing pretty every internal component. I think I'll hold off for a while, after the last fix....
Permalink. Posted 21:32, Sun, 06 Jun 2010.
Return of the Mac
Hurrah! My Macbook Air is finally fixed! And it only took a month... The hard drive died when we went on holiday to Cheltenham (apparently it's still a bad idea to travel with them in suspend mode - I thought things like that were pretty ok, now?). Fortunately, the failure mode was that it eventually succeeded when doing most reads, so I managed to back up most of the stuff I wanted after the event.
Things I have learnt include:
- Back-ups are useful.
- When making disk images, large archives, etc., avoid FAT32, as files only go up to 4G. Useful.
- Apple's disk imaging software is a big girl's blouse in the face of read errors. Log the error, skip the sector and carry on? Ha! Give up immediately? Of course!
- Caroline relies on the internet an awful lot.
- Using a computer connected via the telly is really a lot less convenient than a laptop.
- Official Apple repairs are expensive.
- Even unofficial SSD storage is still eye-watering in price.
- You can buy pretty much anything off e-bay, but it might take some time to arrive if there's a cloud of ash in the sky.
- The innards of Macbook Airs are fiddly...
- But actually straightforward enough to deal with, given instructions off the internet, and a brand-new Philips #00 screwdriver.
Permalink. Posted 14:18, Sat, 08 May 2010.
Electronics for newbies: Voltage regulation
Once I realised my Nokia 'PSU' was outputting a decent number of unregulated volts, I thought it'd be good to get some voltage regulation in the picture. Given I'm living in a world of slightly retro CMOS (Z80s, etc.), I got a few 5V regulators. I bought myself a few Microchip MCP1826S-series linear regulators, and for fun a couple of switchers - National Semi LM2574N-5.0's.
The linear regulators are really straightforward to deal with and, in conjuntion with a decent-sized cap to smooth the supply from the wall wart, worked nicely. I thought that I'd be fine without heatsinks - after all, how much power will they be putting out? - and indeed it has been fine so far, but it does rather seem an omission now. These little regulators get awfully hot, even when supplying small circuits.
When I do the numbers, this does make sense. Powering a decent number of LED segments can put you in the region of a hundred milliamps. If the regulator's starting with a supply around 10V, the regulator's putting out a decent fraction of a watt. This may not seem like a huge power output, but the thermal resistance of one of these regulators without a heatsink is pretty high. The result is a regulator which is, ahem, 'noticably warm' to the touch. Fortunately, I doubt it's anywhere near a failure temperature. Nonetheless, there'll be a few 'sinks in my next parts order.
The switching regulators are much more fascinating devices. Vastly more efficient, they don't need a heatsink, and as you can get them in 8-pin DIPs, the combination of size and efficiency makes them sound perfect for running off a battery. Or so I thought. Enter Exhibit A.
Er, yeah, that's the kind of size of component I want in a portable, battery-powered device. *sigh*. I think I over-specced it slightly, at 470mH, and perhaps I should have checked the dimensions before ordering, but that's not what I had in mind. I've seen inductors before on PCBs, but... nothing like that.
I notice that my EPROM programmer has an MC34063A to step 5V up to VPP, with a super-tiny (comparatively) 100uH inductor on it. The LM2574 datasheet is really quite dummy-safe, and is very explicit about which inductors to buy for it. I'm wondering if there's basically a trade off between idiot-proofing and designs using cheap, small components, and I've landed in the 'idiot' end. Ho hum. In any case, I've yet to actually build a circuit using the switchers, put off as I am by these huge coils....
Permalink. Posted 13:26, Sat, 03 Apr 2010.
To the dark side
I now have an entry on Facebook. Years of resistance have come to naught, and I'm shoving my communications through a commercialised, centralised doodah for the sake of convenience. Go me. On the other hand, it's very convenient.
Permalink. Posted 10:42, Sun, 28 Mar 2010.
Electronics for Newbies 3: Faffing with memories
Skipping the fun of voltage regulation, which I'll come back to, I've been mostly playing with SRAM and EEPROM. I'll need these for my plan of building a simple microcomputer. First up was the SRAM. I built a simple circuit to allow me to load values into the SRAM and then read them back:
The structure's probably not terribly clear, so I've since done a schematic:
The schematic's messy because I'm too lazy to make it look really pretty. I've skipped decoupling caps and the power supply.
One thing I discovered that while building circuits directly is the easy way to go for simple designs, it doesn't stop you making simple mistakes. For example, when setting up a switch as a CMOS input, connect the switch and resistor in series, and then wire the input line from between the two components. Otherwise it doesn't work so well. Duh. Not so easy to spot in a rat's-nest of wires.
The resistors between the switches and the inverting buffers/SRAM side prevents me shorting an SRAM output to ground through a switch while reading its contents, and it seemed to be a source of surprising weird behaviour. Without enabling the SRAM, toggling some of the switches back and forth a bit left the LED glowing, as if the whole thing had got into some kind of metastable state or something.
Take the SRAM away (even thought it's supposed to be Hi-Z), and the problem goes away. Disconnecting a line from the SRAM and measuring its voltage (with a voltage divider attached, to make sure I'm not seeing some Hi-Z rubbish) showed the SRAM driving the line slightly (even though the thing's supposed to be in high impedance), once I've annoyed it enough on the other lines.
Reducing the size of the connecting resistors from 10k to 220 ohms (they are supposed to be simple current-limiters, after all) reduced the problem, but didn't make it go away. Sticking a small cap (0.1uF, IIRC) on one of the data lines made the problem go away completely! Then I could happily write patterns into various addresses and read them back. Woo.
I still have no idea why it was doing this. Given this was supposed to be a really straightforward circuit, and I'm hoping to build something much more complex involving this chip, running at actually reasonably fast speeds, I'm more than a little unnerved. I'm hoping a shedload of bypass caps will do the trick.
Then my EEPROM programmer arrived, from China, no docs at all. Still, it didn't look too dodgy, so I plugged it into my computer, downloaded some approximately-right looking software from the net, and it worked first time. I wired my newly-programmed EEPROM into the world's simplest reader circuit:
It worked. I had a massively-overkill hex digit to seven segment display converter. I am now officially back to first year undergraduate digital electronics level. Woo-hoo!
Permalink. Posted 10:18, Sun, 28 Mar 2010.
E-book Reader Review: The Sony PRS-300
I've been watching the whole eInk thing for a while and finally gave in at the start of the year, going for the entry-level Sony PRS-300. It doesn't have any form of wireless, or any snazzy note-taking features, 'cos all I really want to do is pre-load it with books and read them.
Specifically, I don't want to load it with papers or highly-mathematical books. Novels and maybe some light compsci, yes. The reason for this was the eInk technology - page refreshes are slow (a noticable fraction of a second), and eInk (and indeed most electronic book readers) is really bad for flicking around and browsing, which comes up a lot with the heavier reading where you can't just start at the beginning and read through.
My experience so far has justified this, which is kind of ironic as it's actually a lot better for light novel reading than for the kind of technical text a gadget early-adopter might read. As a novel-reader, this kind of technology is excellent, as it's smaller and lighter than a chunky paperback, let alone a hardback, and it can store a decent number of books. On a commute, you needn't be stuck if you've finished one book and want another.
So, on to the specifics of this device. It's a standard Sony product. So, the hardware feels pretty nice. The firmware is mediocre, and the PC-installed software is dire. Starting with the PC software, it's taken a leaf out of iTunes's book, but copied it very badly. iTunes on Windows imports an Apple look-and-feel... the Sony software on a Mac has a nasty, inferior widget set that e.g. gives really ugly context menus. The software is laggy when it's not downright locking up, and it seems to manage to screw up syncs as often as it can, and have random arbitrary limitations. Yay.
On to the firmware. I've not been using 'proper' ebook formats, since I have little interest in buying DRM rubbish. The formats which look most convenient to me were therefore PDF, RTF and plain text. Most PDF documents render too small to be readable on the 800x600 display in normal portrait mode, but the firmware does fortunately have a landscape mode, viewing a single page in two chunks. If your document has a big margin, it'll happily display this, but fortunately Apple's Preview application allows easy cropping of PDFs, so that it'll take up the entire reader screen. Why is this not built in?
PDF display is not all fun-and-games, though. It can be really very laggy to switch pages. Why not pre-render and cache the adjoining pages, to remove the render lag? Moreover, it's sometimes rather difficult to tell when an operation has started. The eInk is no good at quick updates, but why not have an LED for 'I'm thinking'? There's a charging LED built in already - why not use that? Some buttons require you to hold them down for alternate operations. So, a tap for next page, a press for skip 10 pages. Of course, there's no feedback for when you've reached the 'press' period of time, and it will only start grinding away once you've let the button go, so you've got to guess the minimum hold time that'll get you forward 10 pages as quickly as possible. Argh! So simple features implemented so badly!
Having said that, PDF's been pretty reliable for the docs I've got in that format, although if I had a document in a different format I wouldn't convert it to PDF. I've seen one or two rendering bugs (cheers, Sony), but they've not been killers. So, what's a good format if you have the choice? The software doesn't allow you to specify an author name on a plain text document, and when I briefly looked at it it had some particularly braindead handling of paragraphs, so I quickly dumped it. The RTF support is certainly good enough for novels - 'A Deepness in the Sky' (one of my favourite-est novels, evar) worked very nicely for the 1000+ pages it had. However, I tried converting an RTF with lots of pictures in, and it gave up rendering the text part (but kept the pictures!) after a hundred pages or so. Useless. Oh, and HTML support? I switched to RTF because the HTML support was pretty dire.
Finally, the hardware. It feels very pleasant. The eInk really is very pleasant to read - I've been reading various documents off it for a couple of months now in every morning and evening commute, and it's much more pleasant than the alternatives. The build quality is good. It claims 'up to 7500 page turns', and I can support this claim. Specifically, there's absolutely no chance of it exceeding 7500 turns on one battery charge. I'd be surprised at 2k, and given one paperback can come in at over 1000, I'd strongly recommend taking a charger if you want to take this thing on a holiday. It's surprisingly irritating to be unable to read a book you're carrying because its battery is flat!
All-in-all, it's definitely immature technology. It's too expensive, slow, the particular implementation has Sony's renowned software, and the ebook market is still screwed-up. However, it makes a great novel-reader, and it really does look like the thin end of a very long wedge which will eventually make my lovely bookshelves look as useful as a vinyl collection. I'd give it 15 years.
Permalink. Posted 21:42, Tue, 23 Mar 2010.
Electronics for Newbies: Random catch-up
I've been playing about with a few more electronics bits and pieces, but haven't had the chance to write them up (yay, babies!), so to keep up the momentum I thought I'd put up a few notes:
- As I ultimately want to make a simple 8-bit computer, I need to program EEPROMs. I thought about making my own programmer, but I discovered that the ZIF sockets at Farnell at 10 quid, and a full 'Willem' programmer, off Ebay, with cables and delivery from China can be yours for 21 quid. Gah. No contest, really. The downside is that I don't learn from building and debugging my own, the upside is that I get straight to my goal and get a much more mature design. Ho hum.
- Then... I checked Ebay for ZIF sockets, and you can get similar sockets for a couple of quid. So, I could have built it from scratch quite cheaply. Ho hum. Apparently the rule is that if you're looking for this kind of component, do check Ebay first!
- Add simple safety features! Unlike programs, an error can't always be fixed and the program re-run, as one of the components may now be smoke. For what I've been doing, these features come to power-on LEDs and resistors between most things. Resistors in series with pots stop the resistance going to zero are useful, and any time I'm uncertain as to whether a certain configuration could lead to the same point being driven to different levels, I bung a resistor in.
- Learn to use your multimeter. Ok, that sounds obvious. Learn to use your multimeter effectively. I've got a fairly fancy meter, and i's been increasingly useful as I learn its features. On the other hand, I've found the best way to learn to use it is in practical situations, rather than by just reading the manual.
I've played a bit with voltage regulators, SRAM and EEPROM since writing last, so hopefully I'll manage to write those up soon...
Permalink. Posted 09:39, Sun, 21 Mar 2010.
Electronics for Newbies: The LCM555
Having not played with any electronics for something over a decade, I thought it'd be time to whip out the breadboard again. So, I thought I'd start with the bog-standard newbie construction, a 555-based blinking LED. This time round, for fun, I thought I'd use an LCM555 CMOS-based 555, since it apparently wouldn't do bad things to the power rail, which is nice, as my eventual goal was to use the 555 as a clock for some sequential circuitry while testing. I looked at the reference circuit design, plugged it into a surplus Nokia phone charger (the LCM555's got a nice, wide supply range, so I didn't think too hard here), plugged it all together, and... nothing.
So, yay, electronics debugging time! For the first time in my life, I actually bothered to learn how the 555 works, rather than treat it as a magic incantation for making something blink. It's actually rather straightforward and neat, but I'd never bothered getting the datasheet before. Once I understood how it worked, I realised I'd been choosing resistor values that were basically shorting it. You'd have hoped something might mention not to do this, but noone seems to bother. D'oh.
I fix that up and... nothing. Even a fresh chip doesn't work. I'm now a little frustrated, but at least I understand how it's supposed to work. I now set up a simple test circuit which removes all that faff with capacitors, so that it should basically run in a steady state and show its hysteresis:
I plug this in, and it behaves weirdly. The the lower level switches on, but then it immediately switches off above this level - there's no hysteresis up to the higher level. Why this asymmetry between the levels? Could it be something to do with the adjustment pin ('CV')? Nope. The circuit should be quite static, without a capacitor, so I shouldn't be seeing any glitchy behaviour. However, when I put more bypass caps in, it goes from on/off to on/slight glow. Hmmm.
Argh. Sticking a multimeter in min/max mode voltage on the power supply reveals a rather high max, and a min of zero. Frequency? 100Hz. Yay, we have a fully-rectified but unsmoothed, yet alone regulated power supply. I'd really assumed that thing would be regulated. Apparently not!
The attachment of a 9V battery (they're convenient in that you can attach them using crocodile clips, if you don't have a proper snap), and everything works fine!
So, now I've been learning up on power supply theory. Horowitz and Hill has been sitting on my shelf for years - I tried reading it front-to-back before, and wedged somewhere near the start of Chapter 3, but I've now zipped through the whole of the power supplies chapter. I only needed about 3 pages, but it's fascinating, and each chapter seems to be about as self-contained as it can be, so it's been surprisingly engrossing.
I could just power my future projects off batteries. Not a 9V, since many of the digital chips I'm looking at max out not far over 5V, but maybe a set of rechargeable AAs. However, I now want to play with all the options, so I've ordered a few battery holders, plus the chips, caps etc. for both linear and switching regulators. I think the switching regulators should be overkill, but at least fun to play with.
We'll see how it goes.
Permalink. Posted 08:39, Wed, 03 Mar 2010.
Python is the new BASIC
This is not an original blog post title. Others have said the same thing, followed by a post body saying 'but I don't mean that in a disparaging way'. Let's get one thing clear. I mean this in a disparaging way.
Ok, it is a good beginner's language. And unlike Dijkstra thought about BASIC, you can learn it as your first language, and you won't be scarred forever (just like BASIC). However, you will eventually need to move on from this language and be rehabilitated into society before you can be fixed up. You need to acknowledge that it's not a real language, and so few Python programmers admit this. :p
The problems I have with the language are, basically, that it's a dynamically-typed grab bag of ideas from all over the place. So, its core design isn't particularly coherent. As the ideas were copied without real understanding, they're done wrong, and there are unpleasant bodges. Dynamic typing means there are whole classes of error you can pointlessly leave in, waiting for the appropriate runtime failure. Yeah, you can do insane amounts of testing and run other tools, but... a solid, static type-check from the get go is just so much cleaner and safer. And that matters.
The problems I have with Python programmers is that they think they know something. The language is neither low-level, nor cutting edge. It doesn't show you the hardware, or bring you to neat theory. It just gets the job done, and because it's so pragmatic, it gets the job done badly. So Python programmers, having chosen this particular sub-optimal point in the space of programming languages for themselves, are either ignorant or deluded.
(I'm still programming Haskell for my day job. It's an impractical and basically ludicrous language. However, the right language doesn't exist, and it certainly doesn't have an excellent compiler and set of libraries. In the meantime, I love Haskell.)
Permalink. Posted 23:58, Mon, 21 Dec 2009.
Finding bugs in the GHC runtime
Race conditions are always a pain. We just spent the better part of two days tracking down a race condition which caused our production executables to hang once in every few thousand invocations. Surprisingly, it wasn't the normal DllMain deadlock.
On the other hand, it was a nice excuse to play with WinDbg and binary patches.
See GHC Trac for details.
Permalink. Posted 14:13, Sat, 12 Dec 2009.
Magnetic Scrolls
My Project Euler addiction has been effectively destroyed by taking away my mathemtical ability. A new baby has had that effect on me. But I still have a puzzle urge and time between feeds. So, I've been looking at the old Magnetic Scrolls text adventures. I tried Fish! and Guild of Thieves nearly 20 years ago, but never really got very far, so I was intrigued about having another go. Jinxster looked like a lot of fun, so I had a go...
And generally, it was! As with so many adventure games of the era, it's unforgiving and pedantic. You have to spell things out, and if you make a mistake it'll let you keep playing even though you can't play to completion. Having said that, it's friendly as far as the genre goes. In-game characters sometimes provide subtle hints, and the structure of the game allows progress even if you're stuck on one puzzle.
On the whole, the puzzles are rewarding. Initially, I thought there were a number of evil red herrings in the game, but it looks like a number of puzzles can be solved multiple ways! I'm almost proud of myself. I made it through the whole game except the last puzzle without spoilers. When I read the spoiler for the final puzzle, it basically told me how to do what I was already trying to do. *sigh*
In fact, I found the whole ending section disappointing. The last puzzle was put together slightly shoddily, and the ending might have tried to be a clever twist but... no thanks. It's a shame, really, as I rather enjoyed the game as a whole. I may have to play another.
Permalink. Posted 16:09, Mon, 07 Dec 2009.
David Alexander Frankau
Having now announced this to most of our friends directly, this is now unembargo'd!
Caroline and I are delighted to announce the safe arrival of baby David Alexander Frankau, who was delivered safely at home at 8.04am on Friday 30th October 2009. He weighed 7 pounds 11 ounces at birth and is, in the opinion of his completely unbiased parents, the cutest baby ever!
Permalink. Posted 23:25, Tue, 10 Nov 2009.
Mail me at random.user@arbitrary.name.