Wireframing

10.06.2010 20:12

After seeing the beautiful x0xb0x front panel on Keith's blog I spent some time thinking about the design of the exterior of my new lab power supply.

Power supply front panel wireframe

Compared to your average (computer) graphical user interface there is really not much to it. I want to keep it simple, with knobs and old-fashioned analogue panel meters.

I chose this wide, low case so the power supply will fit under my oscilloscope on the table.

I would love to have that brushed-metal finish. I've seen front panel adhesive films on which you can print with a laser printer. However the case is wider than A4 paper format, which makes it tricky to print on in one piece.

All my previous projects that used the "double-sided-tape + laser print on paper + transparent protective adhesive foil" approach got wrinkly with time. So I'm more than willing to try something new this time.

Posted by Tomaž | Categories: Ideas | Comments »

Camera in a bathroom

07.01.2010 21:53

Hot water in my apartment is supplied by a storage-type electrical boiler. As uneconomical as it is to use electricity for heating in a big city I can't really do much about that. However what I did notice is that the insulation on the boiler is pretty good - the water will remain hot enough to use even if the heater has been turned off for a couple of days. So maybe I could optimize the time the heater is working. Instead of a simple thermostat I could add a timer that would only allow the heater to work at night when electrical energy costs around half as much as during the day.

However, before I start tearing the boiler apart I want to have at least a rough approximation of how much energy the boiler actually uses and how much such a modification would save me per month in lower electricity bills.

Unfortunately I don't have proper equipment at hand to directly measure and record electrical power (plus that would mean more messing with the wiring in the bathroom and that's a can of worms want to open as rarely as possible).

So I used another approach. I took my EeePC, put it on a high shelf across the boiler and trained the camera on the indicator that lights up when the heater is operating. From the recording it will be obvious at what time the heater was on and since I know approximate power I'll be able to calculate the energy consumption and cost.

Of course, the thought has crossed my mind that having a camera operating in a bathroom can be a really bad idea. Even more so if it's connected to a Wi-Fi capable laptop. So I took some extra precautions to prevent anyone ending up on YouTube (i.e. I disabled the wireless adapter).

I used the following GStreamer pipeline to record the video:

gst-launch -v \
v4l2src ! video/x-raw-yuv,width=640,height=480,fps=5 ! ffmpegcolorspace ! \
videocrop bottom=112 left=288 right=288 top=112 ! \
videoscale ! videorate ! video/x-raw-yuv,width=128,height=512,framerate=1/4 ! \
clockoverlay ! \
jpegenc ! avimux ! filesink location=boiler.avi

Everything up to ffmpegcolorspace appears to be necessary for the camera to operate properly. videocrop crops the video so that only the boiler can be seen on the image (makes for a boring video, but that's what I'm aiming for here). videorate drops 19 frames out of 20 to save disk space.

I also added a clock overlay, so that each frame would have the exact time recorded, just in case I couldn't later deduce the time by other, more sophisticated means. I had to scale the video width up by 2 (hence the videoscale element) to make it wide enough for the clock display to fit onto it.

Video is saved in the simple motion-JPEG format. Not really the most efficient encoding out there, but everything else seemed to produce unusable results. I guess the default settings for Theora and friends don't work very well at 0.25 fps.

I left this setup running for a week and it produced around 3.5 MB of video data per hour - no problem for EeePC's somewhat limited storage capabilities.

If ran at a normal 25 frames per second, this video shows a day in 15 minutes, so in case I won't be able to do anything automatically I would still be able to watch it and manually record the time (however I'm confident it won't come to that)

Posted by Tomaž | Categories: Ideas | Comments »

Reverse biased LED

25.11.2009 16:10

Here's an interesting question: If you force current through a LED in the reverse direction (i.e. by causing a breakdown in the junction), will it emit light, and if not, why?

Fear the glowing spheres

Let's start with an experiment. I took an old low-intensity 3 mm yellow LED (I'm guessing GaAsP chemistry) - I want to limit this discussion only to simple P-N junction devices and ignore for the moment complicated new LEDs with quantum wells and such.

I applied a high reverse bias through a large resistor (1 MΩ, to limit power dissipation) and visually checked for any light. The diode started conducting a significant current at 185 V (which, by the way, is surprisingly high as all datasheets I've seen rate such LEDs at maximum 5 V reverse bias). At that reverse voltage I let 0.1 mA of current through it (which gave total power of something around the rated 20 mW). I couldn't see any light coming from the LED.

As a control I then reversed the polarity and let 0.1 mA flow in the forward direction. In that case I could clearly see the LED lit up in a darkened room. So, the LED wasn't destroyed in the experiment and 0.1 mA was enough to produce a visible effect.


So, the experiment confirms that a LED will not light up when the current flows in the reverse direction. But what is the theory behind it?

Visible photons emitted by the LED are generated by electron-hole recombinations in the semiconductor. The material has just the right energy gap that an electron in the conducting band can give away it's excess energy to a visible photon when it fills a hole in the valence band. In forward operation most of these recombinations happen after charge carriers travel through the depletion region and are diffusing into N or P material as minority carriers.

When the junction is in breakdown, a similar thing happens (from the high reverse voltage I measured I'm guessing the avalanche mode of breakdown). However this time carriers don't diffuse through the junction but are generated there through impact ionization. But because the voltage is reversed, electrons enter the N material as majority carriers (same goes for holes in the P material). So gone are the recombinations near the depletion region and no significant number of photons is produced.

Interesting though, carriers from an avalanche breakdown have significantly more energy than thermal ones in forward operation. And they do in fact emit light after they pass through the junction (i.e. through bremsstrahlung and hot carrier recombinations). However the light's wavelength is no longer defined by the material's band gap and its spectrum is completely different to that of forward operation. So the LED might have as well lit up in my experiment, but with intensity and wavelengths that were invisible to an unaided eye.

Posted by Tomaž | Categories: Ideas | Comments »

Google Translate idea

03.08.2009 18:40

Google Translate is currently pretty useless for any serious translation (regardless of what translators of user manuals for consumer electronics think).

However, I sometimes find myself searching for, say, a Slovene equivalent to a specific English technical term or phrase. I'm fluent in both languages, it's just that the term may be too far out of my expertise to know the correct translation - although I can usually spot the correct one when I see it in context.

Scientific terminology is usually very strict, with one specific name for a phenomenon. And if you want the translation to appear correct in the eyes of someone knowledgeable in that field, a simple by-the-dictionary translation of that name may make you a popular target of in-jokes (take note, authors of subtitles on Slovenian television networks).

So, if I don't have someone fluent in that terminology at hand, what I usually do is first check for equivalent pages in different languages of Wikipedia. More often than not, that approach fails miserably. Then I'm off to Google, where I search for the term I want to translate (in quotes) plus some terms in the targete language that I estimate must appear nearby in the translation.

However, that's not really a good task for a general search engine - translations may for example appear on different web pages (pages often have an English and an Slovenian section separated on different pages). On the other hand my search will only return results when a single page contains both English and Slovene texts, so a lot of potentially useful results would be missed.

Here's my idea: machine translation tools like Google Translate already recognize pairs of texts on the web that are direct translations of each other. That's the input for their machine learning algorithms, where they learn how to (badly) translate free text.

Wouldn't it be nice if you could enter just an English phrase and select a language, and get back a list of English texts containing that phrase, plus the matching texts in Slovene? It's not even necessary to point out where exactly in the text the equivalent phrases are - A paragraph-level of precision would be more than enough. I can find the exact spot myself while reading the context (which I must, to make sure I'm using the correct translation).

So in effect you would be using the infrastructure that most likely already exists, but for human instead of machine learning. I'm sure that would be a most useful tool for people translating technical texts. At least until machine translation becomes a little more accurate.

Posted by Tomaž | Categories: Ideas | Comments »

Entering PIN without confirmation, part 2

20.06.2009 19:44

In my last post I was trying to figure out an optimal strategy for guessing a combination for a lock that only checks the last m symbols entered.

It turned out my venture into the graph theory was a bit of a dead end. As Luka Rahne pointed out to me (on Facebook, no less), there's a different branch of mathematics that offers a much better approach to this problem and even has a connection to my home field of electronics.

Linear feedback shift registers are actually direct solutions to such a problem, albeit only if you limit yourself to two characters (n = 2). These are digital circuits that will generate all 2m-1 different sequences of length m in a shift register (i.e. for each step they insert a single digit at the beginning of the register and drop one at the end). Exception is the state that contains all zeroes, but that is easy to correct with a special case.

It turns out that there exists a generalization of the LFSR for n states. Basically you replace the XOR operations in the feedback loops with arithmetic multiplication and addition modulo n. There is quite a bit of theory behind, of course, but I had trouble finding a higher-level description of it on the internet. A great deal also appears to be patented judging by the ratio of patents that came up in the search.

Just like with ordinary LFSRs, where you need to find the correct locations of the feedback taps, you need to find the correct set of m+1 multiplicative constants in order to get the maximum length sequence (or M-sequence) out of it. This is not really straightforward, as it involves finding a primitive polynomial for the finite (Galois) field GF(nm). Luka posted his Mathematica code to calculate the polynomial's coefficients, but I found it easier to use COS.

Diagram of a non-binary Galois LFSR

Here Si are memory cells holding register states and aj are coefficients of the polynomial:

a_4 x^4 + a_3 x^3 + a_2 x^2 + a_1 x + a_0

My knowledge of this field is a bit superficial and I don't completely understand the connection between this polynomial and the fact that its coefficients will produce the M-sequence. I admit I only skimmed the most interesting parts of an introductory book yesterday. Even my curiosity has limits.

There was only one obstacle left: a finite field only exists for prime characterics n, which means that you can't get a M-sequence for, say, 10 symbols directly. The answer is to factor n and produce a M-sequence for each prime factor (2 and 5 for 10 symbols). You then run two sequences in parallel and assign a symbol to each unique ordered pair you get in this way. So for ordered pairs where the first element can have one of 2 different values and the second element can have one of 5, you get 10 different pairs.

It's easy to show that two sequences ran in parallel with periods

n_1^m \qquad \mathrm{and} \qquad n_2^m

have a composite period of

(n_1 n_2)^m

if n1 and n2 are prime.


So, the final result, a sequence of 10003 keypresses that checks all 4-digit combinations, is below. C code that calculated it and checked for its correctness is here if anyone wants to play with it.

00007559254372858084599981873643682873396507388560205737258390890406577109057085
84407755656998452440953103431203840871976305548700449533810790452084777529615001
28865995256970698666717343853647244639134769304182425975616718038220171921697881
22883937678958816840159505057807206235198963108968447113618950692228573181015663
86685937212772232024957943835883460493374181748586283133070574410206513727615467
46423377876136810868191927035025480677350167368920043177812754478240711183257227
86425153254550496826957587659209644291712969724740441319298114038042533189239285
44227331436116270606531581499603224811334367500940227153898374812000175583453629
48085599890972652682973387417289460215736349380980407577018156094844177547479885
42441953012530212840971967215449600459532901780542085777438714010288759943479607
88667717252952656244739125679205082435974707708128221171830796890228939367699489
06841159414156816206335189873009868457112709940782229573090114672866959363037623
22025957852934892460593365091649486293132161564500207513636714476464333769671269
00869191836134034480777341077269820053176903744568241711092356236864351523455405
86827957496758218644391703879625640451318389104128043533098338294442373305271063
60607531490598612224911325277401840237152989364902001175492552638480955989819627
42683973296516298460315727259281880417576109146184845177456578894424519521035203
02841971876314458600559523811681442095776529704100289759852578616886777163439427
46245739034778214082535965617609028231170921786980229939276798498068511585051469
06207335098972018868557103619841682239572181104762867959272136632220359569439249
82461593274190658486393123071465400217512727704566465333678770278008791909271241
24481777250176278820153167813645468251710183346326865351432554414868379565877483
08645391612978634640551309299005028053532189328384443373214370072606175305815887
02225911234376410840337143899265802011174583542728481955898918636426939723875063
88461315636358290880517567019047084855176547568984425519430134212028519709673045
48601559432910690442195767439605000299758943568706887777072538436462557381257683
04083535874716618028331161831687880239938367788588069511494150478062173341899621
08869557012718850682339563091005662877958363126722221359478538258824715923651807
48487393032170474400317503637605466475332769760368009791818370250244917763411663
68821153076912654468351701093247226875350523544504869379474976492086553907039687
24641551218398014028153523099229284453372305360162607175214914896022359103253665
00841337052998274802111165493443628491954989908726427939632974072884713147273483
80881517476118056084955167457469884435518521124302029519618772054486115585239007
80443195676538614000399749853469606897776163528526463557290356692040935349657067
08029331070930696880339929277689488079510585140568063173250998630088795561037089
40683339472190014662977949273027622231358569528348825715832750816484973921231605
64401317412736614466575323679661268019790909360340245917672510672688311521679027
44469351610192256226975341433445404879378565966582087553816138696246515503093881
04029153432198238284553363215261062617174305904986023359012352674008513361439883
64803111074592452628591945899809626437938723964162885713056372492808915165671081
46085955076556478884535509431025202039518709762144487115494338016804531947675287
04001399658952478606997767073429426473556381346782041935258756076080393301619207
86881339838376698488179501495041468073172341988720089795470136098406933385631801
04663977858372036622331349479429248835714923740906485973830330614644113165037267
04467575232778670268119781819261240255916763500762689311430778036444793507011823
46227975250532454404979369475867482097552907128786247515412192890040391525231883
28285553272314270062717165215805886033358103342764009513270538892648131101655825
42629591854998818626537929633865062895712147362582809915074770090460959541675465
68885535418530034202139509619663044497114585328106805531856774296040113987499425
68607997676172438426573547291247682051934349746166081393210718216868913389293667
88489179410594050468173163251889620099794561126188407933294730810046739769493621
26623331258578438248935705833641806495972921320704645113074136276044775743237687
60269119690918270240355907673401662699310521768126445793416110832462379743415225
44405979278574876482197543817029686257514503182980041391434330892282955523633043
60063717074314814886133349013243664019512361528982649131010754834426395909459889
08627537838732874062995703057263482819914165760180461959450774474688955345095201
24203139418718672044597105495229006815530947764386041113896598434686179967671625
28427573456390256682151925259647066091392301708306869913298392676884991785015841
40469173072350898620199785471027088417932385720900047739678592630266333303495685
28249935614932650806595963831221604655112165126366045775652336696602791187819083
60241355816772410662799301431669026455792507100922463379652514234444159783695649
66483197452916038686357505413083880051390525320982283955432732052600737161653049
04887133258112252664119503271429882659130101744924427395818558898086375369297229
64063995612156272482919905075661080471958541764564689955254194210242131385097087
62045597014594238006915521857665286051112987588524687179876770634284375725473803
46683151834358656066191383211609206879912389382766885991694114850404791721633409
88621199694570036088517923295621800057738769582720267333212594694282599347059227
40807595872930230604755103075027266055774743326786603791096918092602513549077625
00663799210530678026555783417001822473378743504324445159692794658664931965439061
28687357414512092880151381435221882293954523722142601737070752058048971323491023
42665119412370438882759121011645824437394909548988087375278396238640739947031463
62483919814174670080571949451665464699954345184300243131294196096620555961055843
28007915430956674286151103897489424697178967760724285375634572812466931509253487
46067191292310618206979903299283666895990785104940405791630732418886311987855601
26089517832394630800157729679483620277332303584784283599256158236408175949639203
20605755012174036266155765653227686613790187908182603513458176634006737983015207
68027555692516010822573369653405224455158783784748665931874538070286973565055021
82881151290534230882393945433623042611736161742148049971232590032426751185033605
28883759030110654824537385819449888097374369386328641739856130472624939189051647
60081571858550674464799945255085200253130385186186621555870154852280179145219467
64287151012996498424797169877661624295374725562902467931418352496460771903833007
08207979812398292666995981695005840415790721722508887311896954610260995169233847
20801157638778492620377323213485684293598347148326409175858738212206157541031641
26267155674752236686713781097809082613512549166724007737892114216680375547835061
00823573278752414224555149693685648675930965528160287973474154030828911503815243
20883393854532632042711727071643048059970323580122427751094132614288937581211007
44825537294918458888197365279287228651738947120562625939098150656600915709495407
64465799854354094200353121295087086631554961144942281179054318476642971501039865
88425797078976670624395365635463802477930509342586461771812932016082179789033883
82667995890794014840515781631623408897310987944700261995078332856208111567297685
82621377232312494684393589257049226419174949728302207157450130650262771547657423
26687713690196818082713503459067624017736983104306681375456934070008335723697425
04225555058792694648775921875429060297972565144120829911412914252208933929455227
22043711636170652048159961233481022437750185122704289937490310016448355363859085
48889197274378296228751729857021462635938189140746601915618594416644757989453441
84201353030394096086731545871045842291178145308566643971410138874884357961699667
60625395274734472802577921419243486471770903922106083179698132892826779949817841
04841515690730632408997301897845600271994169322946209111476396694826313763233025
84685393498356058226519165859629202217156541120740263771456756432266977127811869
08083713412558076624117727893005206691374547924160009335632796434042355541497827
84649775830974438060397963475045020839910503904342209933838554236220537107271607
42049159870332490022537741095023604299936581300106449355272958094488991963653683
86229751638956030462735929099041646611914709584506645757898552450842113521213841
86087731454970054842391169055209466653970501128964885357870798676606353943657245
62803577830518252486571761813823006093178789122982827779858916850048515147817207
22409997210996854600371985079223846219110567386784827313672332034846953925893461
48227519074958638202317147451021640273770547746522267977036910878080937125035481
66625117636992014206791365457825060019334723786524043355450596836846597749219645
28061397872574054020939901413805242219932929544326221537016370616420591589613225
80023537650194032604399927491201006459354363948184489991872752692862397507299461
20463735838198050646711905619485406655756989542540843113430312850860977305459601
44843391078154218466753961411029864895356961788766607353852756254628135769215083
42487571670912832006193169699023882837778949906940049515056916216224199963019869
44601371894178232846319101477287684837312763322124847953834992470482375181659487
28203317056550030640373761457647422277976127900968081937034134490666351167279821
04207791274556834060119325633687424053354541586926847597658318654280713969635641
44021939810512814242319923839445226231536107360706421591498712234800335367411841
22605399836590210006559345273849084499990963742782863397416398470204737349291881
40647711814718494406755747899443440853112521302940861977214558610448533901691443
08467753870510038864995347871689666617352943746344629135678314092424975707619029
22007193078798032882937769859807840059514147906306225199872118878446113709851683
22847319010576296684937303673223024857952925982560483375090758496282133161475401
20641373670556656422377967037801868091936125124580667351076378830042177903655469
24061119234732696424153345451487826857596749308744281713878734650440319389015029
04243319832938454226331527017261606431590589702324801335276510850226153989275803
000

In conclusion, it turned out that there is quite a lot more than one way optimal way to guess the combination (as each finite field has multiple primitive polynomials and each polynomial yields an unique M-sequence). Still, you won't hack into a beer store anytime soon with this, as any practical implementation surely locks you out after some number of tries or adds an delay.

Posted by Tomaž | Categories: Ideas | Comments »

Entering PIN without confirmation

16.06.2009 19:52

A brand of electronic locks marketed by a certain security company in Slovenia has a peculiar way of recognizing the correct code.

To unlock it, you need to enter a four digit PIN. However, instead of the usual way where you have to press a confirm key after entering four digits this one unlocks as soon as you enter the correct sequence.

So basically, if the correct code is 1-2-3-4, it will unlock after pressing 9-8-1-2-3-4, or whatever sequence of digits comes before the 1-2-3-4.

It's certain that such a design reduces the time needed to guess the right combination. In theory you can check a new combination for every keypress where a normal lock would require four plus one for confirmation. For example, entering 9-8-1-2-3-4 checks 9-8-1-2, 8-1-2-3 and 1-2-3-4 with 6 presses while a normal lock would require 15 presses).

I'm wondering. What is the optimum strategy for guessing the combination? Is the theoretical one combination per key possible? Or is there necessarily some overlap between sequences entered in this way?

In the general case of n digits and m places I'm picturing this as a directed graph with nm vertices, one for each possible combination, where each vertex has n outgoing edges (corresponding to n possible keys you can press next). So the problem translates to finding a Hamiltonian path in such a graph (which is a NP-complete problem in the general case).

Hamiltonian path for n=5 m=2

Path for n=5 m=2

Hamiltonian path for n=2 m=3

Path for n=2 m=3

I have been able to find nicely symmetrical paths for simple case of m = 2. At least from those examples it seems that you can construct the path incrementally, by first exhausting all combinations with n digits before moving to n + 1

It appears possible that an analogue way exists for more places, but I'm having problems drawing three and four-dimensional grids on paper.

Posted by Tomaž | Categories: Ideas | Comments »

Angels, Demons and antimatter

18.05.2009 21:17

On Saturday I went to see Angels & demons. It was entertaining to watch, although it was apparent at times that whoever wrote the script was more at home in medieval myths than physics. I guess I got used to weird things characters tend to say in Hollywood movies whenever the topic of conversation shifts to science.

One thing that did made me curious is a scene towards the end when they had to get rid of an anti-matter explosive device in the middle of Rome with 5 minutes to spare. So a guy jumps into a helicopter and flies straight up. When the time is up, the helicopter is high enough that the explosion only causes a spectacular fireworks display and shatters some frescoes.

At the first thought, that seemed like a really bad idea to me. They say that the explosion had an equivalent yield of 5 kT of TNT, which is comparable to a small nuclear bomb. This kind of devices do the greatest damage when they're exploded at some height above the target, so is it really feasible to save a city in the way shown in the movie?

First question is how high can you get in an average helicopter in 5 minutes? After sampling some random technical specs on Wikipedia it appears that the rate of climb of a helicopter varies from 6 m/s in civilian to 13 m/s in military craft. In the movie they use a police or a medical helicopter. It's also empty, so take an average, say 8 m/s, to get a nice rounded figure of 500 m/min.

Second question: How dangerous is a 5 kT explosion at 2500 m if you're standing right below it (like the crowds does in the movie)?

Unfortunately the Strangelove Slide Rule doesn't provide this kind of calculation. I did some more searching and found a couple of old DOS programs from the US Defense Nuclear Agency that answer exactly this kind of questions (they're complete with warnings to reset the computer after entering classified data - I guess they haven't yet come to shredding hard disks at that stage).

Angels and demons blast effects

The result shows that 5 kT explosion will cause a shock-wave with 10 kPa of maximum pressure on the ground zero directly below. That's a little under 1.5 PSI, which is, according to the previously mentioned slide rule, not so bad for any by-standers. Such a shock will shatter windows, but won't knock down houses or even damage most people's hearing.

Surprisingly, that's exactly what you see in the movie. So this may be one case where they actually got it right.

Posted by Tomaž | Categories: Ideas | Comments »

Having given both a whirl

29.04.2009 20:02

I'm fluent in both Perl and Python. I've been writing Perl scripts of various sizes since I began using Linux and more recently I've also worked on larger projects using Perl (from G-Tablix to Wikiprep). On the other hand my work at Zemanta has largely been about writing software in Python. Large amounts of complicated, production critical software in fact.

There's this very obvious philosophical difference between these two languages: Perl is all about there is more than one way to do it, while in Python there is (preferably) only One.

Recently I've rewritten software for this blog in Perl. My colleagues were surprised when I mentioned this. Why didn't I do it in Python, when I had plenty of examples at work of how easy it is to set up a web page with Django for example?

Perl and Python

In my experience with both languages the fundamental difference in design philosophy shows in an interesting way: Writing software in Perl is fun by itself. The multiplicity of solutions to a single problem that Perl offers gives you the opportunity to express yourself. You can stop for a moment to contemplate the most elegant way of doing something. It's about writing software in your own, distinct style. To match your thought patterns. Not surprisingly, Perl is often compared to poetry.

Writing Python on the other hand is dull. If you already know in advance the algorithm you are about to write, writing code in Python is pure drudgery. You only have this limited number of valid expressions. You are forced to do indentation just right. Chances are that you'll write exactly the same code as the other guy if he was given the same specification. It's boring because it's simple and straightforward.

You better be discovering something new on the algorithmic level when using Python, or it won't be very enjoyable. On the other hand writing Perl code itself is fun.

Python is for experiments on a logical level. Perl is for experiments on the syntax level.


Then there's the different approach to errors: In majority of cases Perl will do what you want (unless what you want is consistency, as perlfunc(1) author remarks), maybe giving you a warning that you can later research and fix if you're a perfectionist. But in most cases if an undef gets into the stream it's an one-in-a-thousand occurrence that you can safely ignore.

Python on the other will usually throw exceptions in the most unexpected places and a single uncaught exception will kill your program (which was probably 5 minutes away from completing that 100 hour task).

It's the bugs in the code where the situation turns around. Fixing bugs in Python is fun. You get a descriptive back trace by default on all errors, code is easy to read even when it's not yours and it's satisfying to follow that stray None value as it traversed half a dozen modules until it got to some function that actually tried to do arithmetic on it.

On the other hand when something does go seriously wrong in Perl you better be the author of the code you are looking at and be familiar with interpreter's guts. Since functions will silently pass around invalid values and wrongly encoded strings, the root cause of the error you're hunting may be thousands of lines separated from its effects.


Now it's probably clear why I wrote my blogging software in Perl. It's an application that will most likely never be used, maintained or extended by anyone else by me. I was reinventing the wheel. There is no opportunity to be creative with software design of a yet another blog. It's a straightforward job of telling the computer what you want. So at least I was able to get some satisfaction from the act of expressing my wishes by jotting them down in Perl.

Having said that, I still firmly believe Python is way better language for any kind of cooperative work when compared with Perl. Most of software is at one point worked on by more than one person, so on average Python is probably a better bet when starting a project from scratch.

On another thought, even going through your own code a few years later may be considered working together with your younger self. So far I hadn't had any problems understanding my oldest Perl scripts. Then again maybe they're just not old enough.

Posted by Tomaž | Categories: Ideas | Comments »

Get Satisfaction suggestion

18.04.2009 0:52

It's not my duty to read and reply to complaints that get posted to Zemanta's corner of Get Satisfaction public support forums. However I do get notified about them and usually read a few that look like they may have something to do with my department.

Surprisingly many of them rank pretty high on the level of politeness and usefulness in regard to solving the problem. However, there are some that make you wonder which evolutionary step the writer of that particular post missed. For those gems, I propose a minor change to the usual I'm feeling happy/sad/whatever cuteness, which would at least Give Satisfaction to the replier, since the original poster is obviously incapable of getting any.

Get Satisfaction UI proposal

* Not his real name. No offense meant to the chimpanzees.

Posted by Tomaž | Categories: Ideas | Comments »

Reversible computing

10.04.2009 19:35

I've stumbled upon a Wikipedia page about reversible computing recently. It's a concept I haven't seen before.

The idea is that there's a theoretical limit to the efficiency of computation. For every irreversible bit operation (for example AND, OR, but not XOR or NOT), it is thought that two new microscopic states are added to the thermodynamical system that's doing the computation, increasing its entropy by:

\Delta S = k\ln{2}

If the temperature T of the computer remains constant, an amount of heat must be released to the environment:

\Delta Q = kT\ln{2}

That's called the von Neumann-Landauer limit, and it comes to 33 picowatts at 10 GHz clock and 75°C

As it's name suggests, reversible computing is exploring possibilities of doing computations with only reversible operations, that is logic gates that have a 1 to 1 mapping between input and output states. In contrast to irreversible operations there is no known lower limit to the amount of work that has to be done by such a gate.

Such computers would be very different from what we have today. For example, a mere variable assignment in procedural languages is irreversible, since the previous content of the variable is lost. On the other hand, you could run a program backwards starting with the result and ending with the input parameters. That would be an interesting feature for a debugger.

As I see it, this kind of the research fits in the same box as Dyson spheres and warp drives. These kinds of limits won't be reached any time soon in practice (they may bug Universal AC eventually). But it is still fascinating to see just how far you can push some concept before the most basic physics starts to interfere with you.

Posted by Tomaž | Categories: Ideas | Comments »

Three rollers and a ruler

25.12.2008 11:04

I've seen a lot of discussion recently (e.g. BoingBoing, xkcd) on the Internet about the possibility of a vehicle moving directly downwind faster than the wind. I don't want to go into that debate, but what did caught my attention was the following cute video that demonstrates the behavior of a cart constructed out of three rollers under a moving ruler:

Theatrical skills of the author aside, what I found interesting is that very few people had any doubts about the validity of the experiment and the explanation given in this video. When I watched it for the first time, I was pretty sure the little plush monkey got it right. And after some back-of-the-envelope calculations I still thought he was tricked. The cart shouldn't be able to move at all.

So I did an experiment of my own and it just confirmed my thoughts. The experiment is easily duplicated and I encourage you to try it yourself.

However, just before posting my notes I realized there is one minor, but important difference between the geometry of the cart I analyzed and the geometry used in the video. I'm now confident that the video is genuine and I'll be posting the corrected calculations after I get back from Berlin.

Meanwhile, below is my original analytical solution followed by a video recording of my version of the same experiment (minus the furry spectators). Mind that it's still correct, it just provides an answer to a slightly different question (see if you can spot the difference).


Let's start with a simpler case of a single roller on a flat surface:

Single roller

Here vc is the velocity of the center of the roller relative to the ground, while vr1 and vr2 are the velocities relative to the center at different locations along the roller's surface. Remember, the magnitude of vr is constant around the circumference while it's direction changes around the circumference and is always tangential to the surface.

Obviously, the velocity of the roller's surface at the point where it touches the ground must be 0 relative to the ground or the roller would be slipping. So for that point the following equation is true (subtracting magnitudes, since vectors are parallel and pointed in opposite directions):

v_r - v_c = 0
v_r = v_c

Now that we know vr, we can calculate the velocity of the top point of the roller (adding magnitudes, since vectors are again parallel, but pointed in the same direction):

v_t = v_r + v_c = 2 \cdot v_c
Single roller with a ruler

So, in this case the top point is moving in the same direction as the center and at twice its speed relative to the ground. And this is of course also the speed of any non-slipping ruler that rests on the top of the roller.

This result is expected: if you're moving a large rock by rolling it on tree trunks, you put trunks in front of the rock and pick them up behind it.

Ok, so let's now go on to the cart. The situation is very similar to the previous example. The centers of all rollers are moving with the same velocity, vc. At the points where the top roller touches the bottom two rollers surfaces must have identical velocities as there is no slipping. From here it follows that the magnitude of vr is equal for all rollers.

Cart with a ruler

Again, we can write equations for the points where the cart touches to top and the bottom surfaces:

v_r + v_c = v_t
v_r + v_c = 0

And therefore:

v_t = 0

So the ruler at the top can not move relative to the ground as long as it is not slipping. The crucial difference here was that the second roller rotates in the opposite direction to the top one. This changed the sign in the second equation, since vectors vc and vr were now pointed in the same direction at the bottom.

As you can see, the radii of the rollers don't even come into play in this calculation. So the final result is identical with arbitrary roller dimensions.

The conclusion therefore is that the ruler is either stationary in respect to the ground or two surfaces are slipping somewhere. It's impossible to move the cart by applying a horizontal force only to the ruler since the bottom rollers will apply exactly the same torque to the top roller, but in the opposite direction.

I've made a series of simple experiments that confirm the theory above. You can see them on video below (or on YouTube, if you can't see the embedded player):

You can see that moving the ruler in the 4th experiment didn't move the cart - it only caused the ruler to slip along the top wheel.

The only way to move the cart is to apply the force to it directly as in the 3rd experiment, or as the last experiment in the video shows, by resting the ruler on the cart at an angle, so that the force of the ruler is no longer parallel to the force of the ground. The force and torque diagram in that case is left as an exercise for the reader.

Again, you don't have to believe everything I said, but do try it yourself if you have any doubts. Experiments are fun and this one really just takes some cardboard and a couple of minutes (or seconds if you have Legos handy).

Posted by Tomaž | Categories: Ideas | Comments »

Alpha-Centaurians get a free movie

13.12.2008 0:54

NewScientist reports that a Hollywood studio has arranged for their latest movie to be transmitted towards Alpha Centauri.

I'm sure any modestly intelligent life out there is already bored full of Hollywood and their recycled ideas. What's interesting though is that the people doing the transmission had to assure the movie makers that their precious intellectual property could not be intercepted by any resident of Earth. Funny, because as I understand the whole idea of this exercise is to provide the video for free to anyone listening on the other end. Which either means that studios don't believe that planets around our neighboring star are inhabited or that they've already shipped a rocket full of DRM encumbered receivers to them.

The report also says that the transmission will be done by Deep Space Communications Network, a company with a cheesy web site that sends any message to the stars for a price. Not surprisingly, they don't provide any technical details of the broadcast, but they do seem to have their own interesting idea of the prime directive. They say that they will only send NTSC or PAL signal (for which you must prove copyright ownership, of course). I guess any aliens with SECAM sets are out of luck then. Oh, and forget about telling those Klingon p'taks to beat it, because they will not send any offensive materials either.

Finally, note that they aren't NASA's DSN. Those guys have more serious things to do than provide marketing campaigns for movie producers.

Posted by Tomaž | Categories: Ideas | Comments »

Computers want to learn too

28.11.2008 21:01

Wikipedia is a wonderful learning resource. It provides a wealth of easily browsable articles on just about every topic. An article on English Wikipedia is a great starting point when you're either merely curious about a specific topic or you're just beginning a more serious study of a subject. Indeed, the ease of access to that much knowledge even poses a problem for some.

XKCD: The problem with Wikipedia

Image by Randall Munroe CC BY-NC 2.5

This is all the realization of dreams the original creators had of Wikipedia becoming a mainstream freely accessible and editable encyclopedia. However what they probably didn't envisage is that their site will also become an invaluable resource for computers to learn about the world. English Wikipedia as one of the largest freely accessible corpora has also become an important resource in machine learning science. A lot of research in natural language processing, search algorithms, text classification and similar fields is based on data gathered from Wikipedia. Results of this research are now being used by a number of companies and non-profit projects - some directly like Wikia, Powerset, Tagaroo, FreeBase, DBPedia and last but not least Zemanta. Many more are using them indirectly, maybe even unknowingly, by employing methods and algorithms that have been developed from research that was based or was evaluated on data from Wikipedia.

What makes Wikipedia inviting for research is that it's the best real-life approximation of a very large repository of structured information. Why is this structure important? After all the promises in the past decades artificial intelligence research has failed to come up with a system that could understand natural language to a degree comparable with an average human. With the hopes that a computer could ever learn directly from plain text trashed it was realized that in order to make computer systems smarter people must help them understand important pieces text. This means that concepts in the text must be clearly marked as having some specific meaning. Only then can the current state-of-the-art algorithms start learning from it, giving rise to intelligent systems that know how to suggest what book you might want to read next, or can directly answer your questions, not just point you to a semi-relevant webpage, leaving the tough part of extracting the information from its text to you.

While Wikipedia isn't properly semantically tagged, it is a good approximation. What makes this possible is its use of templates - an editing tool originally designed to ease input of data and standardize layout of specific classes of topics. Since text is entered into templates through a standardized set of parameters, the template gives structure to that text that can be used for more that just page layout. For example text that is entered for the parameter birthdate in the Infobox People template suddenly becomes a piece of information with a certain meaning: person described by the article was born on the date, described by that piece of text. Even the presence of Infobox People on a page itself classifies that page as biographical page.

DBpedia links between databases

Image by DBpedia

However not all templates are created equal. Wikipedia as a collaboratively edited project has a curious property that some technical feature (like templates) will only be used properly when the misuse of the feature will be blatantly obvious to ordinary (human) visitors of Wikipedia.

Take for example the category hierarchy. MediaWiki software that powers Wikipedia supports assigning articles to a hierarchy of categories. By themselves these categories seem like a more natural way of classifying articles than checking which page uses which Infobox template. A closer look however reveals that the category system is wonderfully abused: a lot of pages are put in completely wrong categories, hierarchy is full of circles and nonsensical relationships. The reason is that only a minority of Wikipedia visitors know that a category system exists. Even less actually use it to find pages. On the other hand a Botanical Infobox on a biographical page is so striking to most users that sooner or later somebody will replace it with a more fitting Infobox.

Interlocking by Paul Goyette

Image by Paul Goyette CC BY-SA 2.0

Recently a movement in the Wikipedia community seems to have arisen that is against adding more specific fields to Infobox templates, voting instead for smaller, more specialized templates dispersed throughout the page. Take for example the decision to move external links to IMDB out of the Infobox Film and into smaller templates, specialized to make links to IMDB. Or refusal to add official home page fields to several other templates.

While in theory smaller templates give as much structure to text as larger Infoboxes they are in practice much more easily abused. An IMDB field in the Infobox can only be used to point to the Internet Movie Database entry for the movie that is the subject of the article the Infobox appears on. If it's not, it will be very noticeable for anyone that follows that link and there are good chances that it will be fixed soon. On the other hand, smaller templates can (and are) used to link to IMDB entries that have only some weak relationship with the subject - for example a page about an actor can have a multiple smaller templates providing links to movies she has acted in. It will not be obvious to the average user that a template that should only point to an IMDB entry, equivalent to the Wikipedia page it appears on, has been misused. Since a computer can not understand the text surrounding the links like a human reader does, it will learn that the concept of the actor is equivalent to the concepts of her movies. Suddenly, a pretty reliable way to link Wikipedia entries to another large database has been made a lot more noisy.

I understand there are (some) good reasons these decisions have been made in the Wikipedia community. Pages with large Infoboxes do become less convenient for human readers and can be time-consuming to keep up-to-date. However Wikipedia editors should acknowledge that Wikipedia has also become an important resource outside their original human audience.

Both goals, an easily readable and editable encyclopedia and a good quality machine learning resource are not necessarily incompatible. There are many minor changes that could be made to enhance Wikipedia for machine learners without sacrificing human usability. If some piece of information really can not be put inside an Infobox, then at least the specialized templates should be made in a way that makes them hard to abuse. For example the current recommended way to link to an IMDB entry is a template that looks like this to a visitor of a page:

TITLE at the Internet Movie Database

Where TITLE is a movie title, chosen by the editor that inserted that template. A better, more robust way to make that template would be for example to make TITLE always say the name of the current page. This approach, which is well within MediaWiki current capabilities, would make it immediately obvious that a template has been misused.

This is a pretty minor change, but it would probably go a long way to make Wikipedia easier to reliably connect to other databases. If not sooner, this is a problem Wikipedia will have to face itself when they will make the transition to semantic MediaWiki, as distant as that seems right now. It's clear that such a change to the IMDB template is no longer possible now that thousands of pages use it, however I do hope that more thought will be given to this problem when interfaces of new templates are debated.

Posted by Tomaž | Categories: Ideas | Comments »

The sound of hot tea

23.11.2008 16:25

One thing that I was wondering about for some time is why when I pour boiling water from a kettle into a cup, the bubbling sound it makes seems different than when I fill it with cold water. I found it curious, but I never gave it much thought. I always guessed it that if I wasn't just imagining this difference it was more likely the effect of the container from which I was pouring water, not the temperature of the water itself. I never tried filling a cup with cold water from a kettle to check this assumption.

Teakettle by Mr. T in DC

Photo by Mr. T in DC CC BY-ND 2.0

That is until the coffee machine in the office broke down. That forced me to use the office water cooler to make tea. You see, this particular water cooler has two identical faucets: one for chilled and one for hot water. And this time it occurred to me that the sound is still different, even when the two faucets are identical in shape. So I went on and made an experiment in controlled circumstances to come to the bottom of this.

I made a simple replica of the important parts of the water cooler: a funnel with an empty ceramic cup below it, so that when the funnel was quickly filled up, the water trickled down into the cup over the period of around 20 seconds (diameter of the opening was 3 mm, volume of water was 200 ml). I recorded the sound with a microphone placed over the top of the cup. The funnel was high enough that the flow became turbulent.

I did 10 measurements, 5 with water at room temperature and 5 with freshly boiled water just below 100°C. For each measurement I cut out a 10 s long part 3 s into the recording to ignore any transient effects of filling the funnel. On those cut-outs I made a discrete Fourier transform.

Sound spectrum of a cup being filled with water

This figure shows all 10 measured spectra superimposed. Measurements with hot water are red, while those with cold water are blue.

The most obvious difference is the nicely defined peak at 3000 Hz: it raises in frequency for almost 500 Hz with hot water. Also noticeable is that hot water spectra are on average weaker than cold water between 6000 to 12000 Hz.

So it looks like there is a noticeable difference. The question remains what mechanism causes it.

One factor that contributes to the sound is the ringing of the ceramic cup, excited by the falling water. To get the resonant frequencies of an empty cup I did an impulse response test without any water in it (i. e. I hit the cup and recorded the spectrum of the 'ding' sound):

Impulse response spectrum of a ceramic cup

As you can see this particular cup design resonates strongest at around 2500 Hz, so I'm confident that the similar peak in the spectra in the previous figure is connected with the same cause - the resonant frequency is probably higher when the cup is partly filled with water. I'm not sure why the peak moves with temperature though. Mechanical resonant frequencies of solid objects do change with temperature, but the rate observed here seems a bit excessive. It's also possible that difference in water viscosity caused the hot cups to fill up faster and so resonate at higher frequencies during the measurement interval I used. Some more measurements of responses of an empty cup at different temperatures may clear this up.

The change in higher frequencies is a bit trickier to explain. After a bit of browsing it turned out that I'm not the only one asking such silly questions. For example, the change can be attributed to tiny water droplets of condensed steam in the air according to this post at Yahoo Answers. It seems a plausible explanation to me, although I can't think of a simple way to test it.

Posted by Tomaž | Categories: Ideas | Comments »

Best photoshoped pilot ever

13.11.2008 17:13

Recently a video has begun circulating of an airplane that loses a wing during a snap roll. Despite this problem the pilot miraculously manages to save himself and what is left of the airplane. Even a major Slovenian news site picked up the story, attributing the maneuver to James Andresson.

As many have noted, the video is undoubtedly fake. While the basic aerodynamics of the flying appear to be correct, there are glitches: like the direction of the initial uncontrolled spin of the aircraft and the unrealistically hard landing that does not even bend the landing gear. A more careful look at the video itself also reveals lots of other clues that support the theory that it has been constructed from several different sources.

my father's x-free

However, if you forget for a minute that it's fake, the video actually shows a really good trick. I have some experience piloting model aircraft and I know that aerobatic airplanes are capable of flying with wings in the vertical position ("knife edge" flight). In this position the body of the airplane provides the lift instead of the wings. So, in theory a controlled flight with a missing wing is possible, provided you manage to pull out of the initial spin.

Now there are always people wanting to show off their skills at RC meetings and competitions. Why doesn't somebody try to replicate this, Mythbuster style? The wing could be constructed so that one half would come off in mid-flight by remote control. And the model airplane can be one of those modern, lightweight Depron foam types so that it would survive more than one failed attempt.

It would take on hell of a pilot to do it, but I'm sure that with a trick like this you would be the star of the event. Anyone up for the challenge?

Posted by Tomaž | Categories: Ideas | Comments »