Jul 08 2010

Mex-a-Tron!

Published by Dougal under Films, Food, Reviews

I don’t know if I ever saw it the first time round, but I saw Tron this evening. Now I’m fully prepared for the sequel when it appears.

A few friends came over and we got fajitas from Los Cardos across the road — and despite the utilitarian appearance the food was pretty good. The staff were friendly too. I got a “fajita burrito”, which is kinda what I’d call a fajita if I was making it at home, except they loaded it with rice as well as the usual fried onions, peppers, cheese, salsa and spicy chicken. (There are a number of other fillings available besides chicken, including haggis…) The food was more or less what you’d make yourself, simple but plentiful, and they had big, good quality tortillas which seems to be the hardest part when it comes to make-your-own fajita meals.

The film was weird as all hell. I borrowed the special edition with audio commentary and a separate making-of disc — I wonder what explanation they’ll have for some of the stranger scenes. Some didn’t even seem to connect at all to the rest of the story. It certainly wasn’t what I expected. I knew there was action in light-striped arenas that probably represented some gaming system, but I didn’t realise that most of the protagonists would be computer programs. Needless to say, if you know anything about computers you have to plug your ears at some points or risk bursting into entirely inappropriate laughter. The plot is a bit like The Lord of the Rings (take the magical item into the evil overlord’s domain to free everyone from tyranny).

The sequel — coming out in December I think, so aiming for the family Christmas market I suppose — follows the action twenty five years later in the same inner-computer environment. Hopefully they won’t be relying on the crutch of dazzling graphics and spectacle instead of coherent plot. But that’s probably a foolish hope…

Helen’s out tonight because one of her colleagues is leaving the lab, so she didn’t get to see it. Maybe we’ll watch it tomorrow with extras before I give the DVD back.

3 responses so far

Jun 30 2010

New active lifestyle, available in five exciting colours!

Published by Dougal under Hobbies, Life

Among the many advantages of no longer having a swollen infected toe is the ability to do sports again. I know, it doesn’t seem like me, but I have been known to do it in the past.

At the weekend Helen and I went an epic (miniature epic?) walk up the Water of Leith, from Bonnington to Juniper Green. This map shows the extent of the Water of Leith Walkway but we didn’t cover all of it. We started near the firth outlet, about halfway between Craigleith and the docks I think, and went to Juniper Green which is one of the yellow-marked waypoints. It was probably about 8 or 9 miles in total, uphill but mostly on a very slight incline and broken up by lots of down and flat bits.

We passed by the Water of Leith Visitor Centre (why does a river have a visitor centre? who knows) but it was closed. We saw a couple of herons like in the photo on the visitor centre website. I took my new camera and spent the day playing with different settings in Manual mode, trying to get a feel for how things turn out. I’m not confident but I’m much closer than I was, and I’m enjoying it greatly.

When we got to Juniper Green we had tea at Ristorante Al Borgo, which is owned and run by the parents of one of Helen’s colleagues. After a half day walking in serious heat it was a relief to hop on the bus and get back home again.

But that’s not the extent of the new, exercising, Dougal. Oh no! Near to the flat is the Out of the Blue arts centre, an ex-drill hall that’s been gutted and refurbished to include studio spaces, exhibition areas, a cafe and so on. We go to regular art fairs there and I’ve often seen a poster on the wall advertising their capoeira classes. Last night I popped over to the beginners class organised by the Mão no Chão. They were very friendly and the guest tutor was genial and enthusiastic in equal measure. The class lasted an hour longer than advertised: it should have been 8–9.30 so by the time I got home at 10.40 I was completely wiped out.

It was great fun though. I last did any capoeira about 8 years ago so some of the ideas seemed familiar but it’s not like falling off a bike. It can be forgotten!

6 responses so far

Jun 28 2010

How filtered-accumulate generalises accumulate

Published by Dougal under Maths & Computer Science

I posted a couple of days ago about one of the earlier exercises (ex1.33) in SICP. After some discussion with Brent Yorgey on Facebook I had another look at some of the definitions given in the book. Yes, if in doubt, re-read the question! :-)

The issue that needed clarified was whether I could justify treating the null-value argument as a full-blown identity element. The text says:

a null-value that specifies what base value to use when the terms run out.

(It’s worth noting that the definition of combiner also isn’t specified very well: a “procedure (of two arguments) that specifies how the current term is to be combined with the accumulation of the preceding terms”.)

This isn’t abundantly clear but it suggests that null-value is the last element that can be included in the calculation, so that:

5 + 4 + 3 + 2 + 1 + 0

is allowed but

0 + 1 + 2 + 3 + 4 + 5

is not allowed, because I’m starting with my null-value (ie, 0) and adding the remaining values to it. In this case there is no difference in result. So I needed to find a situation where some element work as an identity on the right but not on the left. Wikipedia to the rescue!

The number 1 as an identity element for exponents if it’s the power but not if it’s the base. Using ^ as an infix exponent function, for any x:

x ^ 1 = x

but

1 ^ x = 1

We can create a chain of odd-numbered exponents to test our implementations of filter-accumulate:

(define (odd-exponent-chain a b)
  (filtered-accumulate odd? expt 1 identity a inc b))

An implementation of filtered-accumulate which cleaves as closely as possible to the definitions should implement (odd-exponent-chain 2 6) as (expt 3 (expt 5 1)).

This conclusion that null-value only works as a right-identity has further repercussions — most of the answers published for iterative version of accumulate are wrong. Why?

(define (accumulate combiner null-value term a next b) 
  (define (go acc n) 
    (if (> n b)
        acc
        (go (combiner acc (term a)) (next n)))) 
  (go null-value a))

The iterative versions always start with the null-value in the accumulator and slowly combine each new term until the end. But the definition above clearly states that null-value is to be combined with the results when there are no more terms left.

This is possible but not as elegant as the recursive solution by a long shot. There’s probably a good way of cleaning it up that I haven’t spotted yet.

(define (accumulate-iter combiner null-value term a next b)
  (define (go acc n)
    (if (n > b)
        (combiner acc null-value)
        (go (combiner acc (term n)) (next n))))
  (if (a > b)
      null-value
      (go (term a) (next a))))

Having got this far we realise we can no longer implement filtered-accumulate in terms of accumulate: the first term forms the seed for the accumulator whether it is appropriate or not. In this case we do have to create a new filtered-accumulate which is more powerful than accumulate on its own.

(define (filtered-accumulate-iter filter combiner null-value term a next b)
  (define (go acc n)
    (if (n > b)
        (combiner acc null-value)
        (go (combiner acc (term n)) (next n))))
  (define (start n)
    (cond ((n > b) null-value)
          ((filter n) (go (term n) (next n)))
          (else (start (next n)))))
  (start a))

After all this it seems prudent to ask “who’s being pedantic here?” and whether the mistakes identified are the right ones.

  • The lack of formal specification of parameters like null-value encourages assumptions. Most people doing these exercises assumed that null-value works as an identity element per the examples of (+,0) and (*,1). These examples reinforced rather than highlighted the assumptions.
  • With this assumption it is possible to implement filtered-accumulate in terms of accumulate, contra the question. I haven’t found an instance online where someone spotted this mismatch.
  • The “obvious” ways of writing the iterative and recursive accumulate have different semantics if you don’t pay close attention. (Which is another way of saying one of them is wrong.) Hence the problem with making poor assumptions.
  • The only way that requires a rewrite of filtered-accumulate is one that doesn’t assume a left-identity element.
  • There is an official tutor’s book published but not available online (presumably to prohibit cheating for universities who use this textbook). So we don’t know what the writers had in mind when they wrote that section.

It’s been an interesting few days of thinking! Many thanks to Brent for making me re-examine the text and my assumptions a further time. I think we got to the bottom of it in the end.

2 responses so far

Jun 26 2010

Does filter-accumulate generalise accumulate?

Published by Dougal under Maths & Computer Science

My latest interesting thought while doing the exercises in SICP is a bit confusing because the book is suggesting something which seems wrong. In Exercise 1.33, after creating a function accumulate (a kind of fold without lists where the start and end values are specified) it asks:

You can obtain an even more general version of accumulate by introducing the notion of a filter on the terms to be combined. That is, combine only those terms derived from values in the range that satisfy a specified condition. The resulting filtered-accumulate abstraction takes the same arguments as accumulate, together with an additional predicate of one argument that specifies the filter. Write filtered-accumulate as a procedure.

The tricky bit I see is the “even more general version” instruction. As far as I can tell filtered-accumulate can be written in terms of accumulate. It’s not more general or more powerful than the plain accumulate.

The previously-defined accumulate takes the following arguments:

  • a null-value and a combiner-function (which is to say the binary operator and identity for some monoid)
  • a pair of numbers representing the start and end value in the range we want to accumulate over
  • a function which maps values in this range to values in the monoid described above (and it could be the identity)
  • a function to get to the next value in the range given the current one

My (recursive) accumulate looks like this:

(define (accumulate combiner null-value term a next b)
  (if (> a b)
    null-value
    (combiner (term a) (accumulate combiner null-value term (next a) next b))))

Exercise 1.33 wants you to pre-filter values so that they don’t all get added together. Only those a which pass some predicate get combined into the result. But since the combining function comes specified with a null value it’s not necessary to skip over undesired results. All we need to do is convert any values which fail the test into the null value.

Put it this way: given a list of numbers between one and ten, you could find the sum of primes by either removing all the non-primes, or converting them into zeroes, because adding zero doesn’t affect the result. Similarly if you want the product of odd numbers between 14 and 103 you can filter out all the even numbers or turn them into 1s, because multiplying by 1 doesn’t affect the end result.

And it just so happens that there is already a way in accumulate to convert numbers before they are combined together, the term argument. This is used to square input values or apply some other function. The key argument is that this function can check if the input meets some criterion and then either process it further or replace it with null-value.

(define (filtered-accumulate filter combiner null-value term a next b)
  (define (filterterm n) (if (filter n) (term n) null-value))
  (accumulate combiner null-value filterterm a next b))

All the solutions to this exercise that I have seen online basically re-implement the rest of accumulate with extra filtering. This doesn’t seem to be necessary. My implementation above works for the following two exercises (sum of squares of primes, and product of all relatively prime integers).

But the exercise plainly says that filter-accumulate is “an even more general version of accumulate”, which to my mind means that filter-accumulate should be able to produce answers which standard accumulate cannot. (And that filter-accumulate cannot be implemented in terms of accumulate.) What is the counter-example that I’m missing, or is the book wrong?

Note: I’ve starting putting my solutions for the SICP exercises online, at http://www.dougalstanton.net/code/sicp/.

One response so far

Jun 22 2010

A simple lab book

Published by Dougal under Computing

At work I keep all my different tasks in separate screen sessions. Each session has a friendly name which makes sense to me, but also has a variable which captures the bug ID. There are various command line tools I interact with that require the ID so it’s easier if I set it once and don’t need to copy-paste it in each time.

After seeing this post on keeping a “lab book” I realised I could make extra use of this environment variable that I already used.

I save this file in ~/bin/note and I can write quick scribbles to myself in whichever window I’m using and it will go to the correct “book”:

#!/bin/bash
 
LOGDIR=$HOME/labbook
 
if [ "" == "$BUGID" ]
then LOGFILE=$LOGDIR/GENERAL.log
else LOGFILE=$LOGDIR/$BUGID.log
fi
 
if [ "" == "$*" ]
then
    echo "No log written: message empty"
else
    DATE=$( date +%Y%m%d-%H:%M )
    mkdir -p $LOGDIR
    echo $DATE $* >> $LOGFILE
fi

It’s not complex but I think it will do wonders for how much I remember to document about my work from day to day.


Update: I learned today the delight of this one-liner which prints everything I’ve done today in order. It’s quite pleasing.

$ grep -h `date +%Y%m%d` labbook/* | sort

No responses yet

Jun 19 2010

Initial thoughts on SICP study group

A few weeks ago I mentioned the idea of a study group at work, for the purpose of reading through some programming-relevant texts and discussing them. We’ve been working on Structure and Interpretation of Computer Programs (SICP) for a few weeks now. I’m enjoying it more than I expected. The exercises are mostly within grasp and I’m happy to note that I’m not being left behind intellectually. There are a few mathematical proof exercises I’ve been skipping and some of the more boring “run this computation by hand” are not worth taking to completion once you’ve seen the basic point. But mostly we’re following the exercises as planned.

Scheme is not so interesting so far. The parentheses still bug me and we haven’t got to the stage where dynamic typing has proven useful so I’m smarting from the lack of a decent type system. From what I remember when I skimmed the book in the past most of Scheme development involves creating ad hoc type systems in the runtime. :-) Many people insist that dynamic languages are good for something so hopefully this something will become apparent.

I have enjoyed several of the exercises which require rewriting recursive algorithms in an iterative style. Seeing the contrast and thinking up different routes to the end product is fun, and I’m glad we’ve got a unit test framework (SchemeUnit) to help in that regard. I tried to track down a Scheme version of QuickCheck but while one used to exist it’s disappeared off the net.

No responses yet

Jun 12 2010

Four book medley

Published by Dougal under Books, Reviews

I’ve managed to get a lot of reading done in the past few weeks, so maybe it’s time to mention a few. Most of these came from the book swap group.

  • Measuring the Universe by Kitty Ferguson

    A kind of history of geometry and cosmology, to answer the question, “how do we measure things that we can’t hold a yardstick against?”. It covers the history of the ancient Hellenic philosophers who calculated the diameter of the Earth, the distance to the Moon, and so on, right up to the discovery of the size and shape of the Milky Way and the distance to the furthest reaches of the Universe. It was interesting to see how much we currently know is very modern knowledge. Before the 1920s we didn’t know there were other galaxies! I also liked learning about the contributions made by people who I’m familiar with through their namesakes — the Cassinis, the Hubbles, the Oorts.

  • The Steel Remains by Richard Morgan

    Richard Morgan is more known for his hard-edged post-cyberpunk science fiction. This is his first foray into “high fantasy”, the realm of dragons, gods and barbarian adventurers with big swords. This book had most of the above, including what I believe to be the first gay sword-wielding hero — a move so obvious in hindsight it is hard to believe it’s taken this long. I enjoyed the book a lot but felt the point of the villains eluded me, and the ending lacked satisfaction. More than enough sex and blood-letting to count as a Richard Morgan book though.

  • Wicked by Gregory Maguire

    This one took me by surprise. I suppose it’s not totally odd that book with the tagline “inspired the hit musical and sold two million copies” would be worth trying but I was still very pleased by everything that it delivered. It’s the life story of Elphaba, the Wicked Witch of the West from L Frank Baum’s The Wonderful Wizard of Oz. She is an outcast from the start, being born green and allergic to water, in a little rural town in Munchkinland. I felt quite caught up in the events of her life and as the events of The Wonderful Wizard of Oz began to overlap with Wicked it was quite painful, knowing that she would soon die from a bucket of water, her dreams unfulfilled and her friends tormented by the despotic Wizard. I’ve added the two sequels to my wishlist.

  • Dark Entries by Ian Rankin and Werther Dell’Edera

    The one book on this list which didn’t come from the book group, this is a graphic novel written by the same Ian Rankin who writes the Rebus novels. It’s a very short (I read it in an evening) John Constantine novel about a Big Brother-style reality show whose contestants are having horrifying visions. Constantine is brought in to exorcise the house or otherwise get to the bottom of the problem, though things don’t go according to plan. The drawing was strangely out-of-kilter with the story — the London graffiti with American spelling, the dialogue describing Highland Park as a whiskey-with-an-e alongside a picture of the bottle showing whisky-without-an-e. It all just seemed badly put together, and the failure to decide whether the story was darkly comic or properly horrific didn’t help. Maybe not bother.

2 responses so far

May 17 2010

More freezer pain

Published by Dougal under Home

I’ve just had to defrost the freezer again — just three months since the last defrost — and it’s currently humming away trying to get back down to temperature. This time it was dual-hairdryer action! We discovered the fridge compartment warm and the milk sour this morning. See the story in the previous post to learn why the fridge dies when the freezer is choked with ice.

I think the time between defrosts is so short now because the inside of the freezer, and in particular the refrigerator element, were still quite wet when I connected everything back up. In order to get everything properly dry it really needs to sit for 24 hours. But we don’t really have that luxury when there’s a freezer full of frozen food sitting on the floor wrapped only in towels.

So within the next month or so we’ll try to run the freezer down and, if necessary, have some kind of defrost party to use up random things which we can’t eat on our own.

One response so far

May 11 2010

The fake yo-yo-er also doesn’t juggle at children’s parties

Published by Dougal under Humour, Society

Would it be “ludicrous to think of hiring a juggler without first seeing him perform”? Raganwald has made this point in the past, with reference to professional interviews. But if someone comes to you claiming to be a yo-yo champion it would be rude to challenge them on this point.

One response so far

May 10 2010

Reading at work

Published by Dougal under Computing, Work

At work there’s a tentative conversation about a book group, to read and discuss (and presumably work through) books like SICP. I’m tempted to join in but I wonder if I’d actually get anything done. I haven’t been to the Science and Society Reading Group for several sessions because I just haven’t had time to read the books in question.

(This is why our other book group is better because reading books is optional and finishing books is not necessary.)

But the combination of SICP and discussion with some of the engaged programmers at work might be really useful. I will put my name down and see what happens. The starting book suggested was the aforementioned SICP but after that they’re going to look at something Agile/XP related which is generally an area I know nothing about except by hyped reputation. I’d also be interested in reading research papers so I might suggest that too.

No responses yet

« Prev - Next »