Thursday, September 5, 2013


I've moved my posts to a new site, a self-hosted WordPress site.

Any further updates will appear there, at

Saturday, February 4, 2012

Hamlet, insanity, and English essays

This is going to be a bit off-topic, at least in the context of my previous posts.
I was watching a production of Ambroise Thomas' opera, Hamlet, recently.  It called to mind the first essay I was assigned to write after starting CEGEP.  I was taking a class on Shakespearean tragedies, and we were asked to take and defend a position on the question, "was Hamlet insane?"
I recall being a bit perplexed by the question itself, but I did write something.  I don't recall now what position I took, that isn't really the point of this posting.  However, when I ponder the question itself, now, many years later, I really don't think I'd be able to write on this topic without a lot of research.  If I were posed this question now, it would be a much more involved assignment, and would take a lot longer to answer.  I might, in fact, have to answer with the substance of this posting, rather than taking a position on the question of Hamlet's sanity.
Before continuing, I'll say that phrasing a question so broadly is a bit awkward.  What, precisely, does one mean by "insane"?  Are we talking about a specific psychiatric diagnosis, or something less well-defined?  In what follows I will assume that we have settled on a particular meaning for the word as used in the question posed by my professor.
So, why is this question difficult for me to answer now, when I was able, as a teenager, to produce several pages of arguments?  No doubt my outlook on the world has changed, it's been a long time, and people change.  I'll describe the way I look at this problem now, as a no-longer-teenager.
First of all, I do enjoy works of fiction.  Books, movies, television shows, they keep my attention, and I focus on them while watching/reading.  However, I do always know that such things are fiction.  One or more writers sat in a room and created the story out of whole cloth.  I am more likely to be affected by the sight of somebody's cut finger in the real world than a traumatic injury in a fictional television show, because I know that the latter is not a real event, an actor is portraying the injury with the help of a special effects team, and at the end of the day that actor will return home having suffered no harm.  In that respect, I somewhat sympathize with the position of the character Chandler on the show "Friends", who said, somewhat indignantly, that Bambi's mother didn't die, they simply stopped drawing her.
So, with that introduction, we come to the issue that I think was perplexing my younger self, but which I couldn't really pin down in words at the time.  The character of Hamlet is a fictional creation, whose actions and behaviours were imposed by William Shakespeare.  The actions of the characters in the play are not those of sentient creatures, but are driven by the dictates of the plot and the historical setting that Shakespeare is trying to present in the play.
Every year or two there will be a newspaper story about some group of researchers who declare that a certain historical figure, dead a thousand years or more, suffered from this or that undiagnosed malady, and they offer as evidence some small set of collected descriptions or writings that they assert proves their claim.  While one may find issue with specific instances of these announcements, the researchers are writing about real people, who interacted with other people in the world, and left traces.  There are objective facts about these people, from which one might be able to draw conclusions.
Fictional characters, such as those in the play "Hamlet", don't have those interactions with reality.  When they are not on stage, they don't exist, except as required by the logical continuity of the plot in which they find themselves.  If nothing in the story hinges on what Polonius had for breakfast a week before the opening scene, then one cannot reasonably expect to "discover" what he had for breakfast, because the character is in a sort of limbo, existing only as dictated by the logic of the story.  We know that, years earlier, he had a daughter, because she exists in the play, but we don't know about things that are not explicitly derived from the text of the play.
So, we come to the question of Hamlet's sanity.  There are three possible positions one can take.  He was sane, he was not sane, or his sanity is unknowable.  The answer lies, first and last, in the mind of William Shakespeare.  When he was writing the story, he knew the answer to that question.  He could then choose to write the story to communicate the idea that Hamlet was sane or insane, or he could choose to make the story deliberately ambiguous on that point, allowing the audience to ponder the question but not supplying enough information to allow a definite determination.  Think of the end of the Arnold Schwarzenegger version of "Total Recall".  There was chatter on the SF Usenet groups discussing the question of whether or not the entire story was an implanted memory, where the character in the story never went to Mars, and in fact never got out of the fancy chair.  My position on this question is that the filmmakers deliberately left it an open question.  There's no way to determine which is the "actual" answer, because there is nothing outside of the screenplay, and the writers want the answer to be "I don't know".
To my thinking, then, the question of "was Hamlet insane?" comes down to asking to know the mind of the author.  We have to read the text, and take our cues not from the actions of the characters but in the way the author chose to depict them.  Don't think "why did Ophelia say that?", she didn't.  Think, instead, "why did Shakespeare choose to have Ophelia say that?"  The play underwent several revisions, we can assume that the rewrites would at least have allowed Shakespeare to communicate the most important points of the story to his satisfaction, and the question of the sanity of Hamlet certainly would be one of those important points, as it is raised several times by characters within the play.  If characters are wandering around asking each other if Hamlet is insane, one hopes that the playwright pondered the issue himself, and that the text of the play communicated, to his satisfaction, the answer that he wanted to convey to the audience.
Fine, so how does one go about knowing the mind of the author, as he is currently unavailable for interviews?  This is where this stops being a CEGEP homework assignment and becomes something more like an English major's university project.
We have a playwright, and we have his contemporary audience.  Shakespeare was not writing for the modern audience, of course, so the way he wrote was to communicate his thoughts to those living in the same time.  Shakespeare's depiction has to be examined in the culture of the time.  To begin, the play is based on a story, already hundreds of years old by Shakespeare's time, of "Amleth".  How much did the Elizabethan theatre-going audience know about that story?  Was the title character in there famously known to be insane?  If so, Shakespeare need do little more than demonstrate questionable behaviour by Hamlet, and the audience would fill in that yes, the character of Hamlet was insane.  But if that was not the popular understanding of the time, then it does little to illuminate the question.  There may be other cultural cues that I haven't thought of, but I'm a physicist and not an English major, and I haven't done this research, I merely point out where I think the research has to go in order properly to address the question.
After looking at the cultural context, we go on to the play itself.  The characters were written around the end of the 16th century, but one imagines they might have behaved anachronistically, saying things or behaving in ways that were not appropriate for Denmark of hundreds of years earlier.  The story was written for the Elizabethan audience, the members of which had their own cultural cues defining eccentricity and insanity as they would have experienced it and talked of it in England of the time.  Certain phrases, gestures, or reactions of the character might have communicated sanity or insanity quite unambiguously to the audience of the time, but a modern reader, not steeped in the culture, might miss those cues entirely, introducing ambiguity where none was intended.  To address this question, one would have to perform a quite lengthy examination of the popular perception of insanity at the time, both in reality, the pub gossip of the time, and in popular fiction of the era, to look for any literary shorthand that might have commonly been used to convey the concept of insanity.  After this research was performed (I hesitate to say "completed" because this sounds like a project that one could never truly decide was finished), the play would be re-examined in the context of this new understanding, to see if there were any unambiguous markers in the play.
Having examined the play, our journey into the mind of William Shakespeare would now go to his other works.  We would examine characters throughout his plays, ones in which insanity is unambiguously manifest, starting with Ophelia but not restricting ourselves just to the one play.  We would learn how Shakespeare developed his insane characters in his works, and how he depicted them as progressing.  We could then look at the character of Hamlet once again, and say that Shakespeare's writing style strongly suggests that he was sane, or insane, or maybe progressing toward insanity, or, once again, we might decide that it was ambiguous, that Shakespeare has not given us a clear answer to the question.
There's at least one more avenue of research that I believe ought to be followed.  One would have to research the reviews and discussions of the play Hamlet as it was being performed, while it was still susceptible to being edited by Shakespeare.  What did the reviewers say about the character of Hamlet?  What did people say about it at the pub?  Were there letters to the local newspapers that touched on the topic of Hamlet's sanity?  Basically, what can we learn about what the contemporary audiences got out of the story?  If it was ambiguous to them, at a time when William Shakespeare would have known their reactions and been able to edit the play to better communicate his position, then I think we can say with some confidence that he deliberately wanted the character's mental health to be ambiguous, and anything we might say, as modern teenagers in a CEGEP English class, has very little weight compared to that.
So, there we are.  If a professor asked me that question today, I don't think I could submit any response I'd be happy to hand in without doing a lot of tedious research with dusty books in old libraries.  It's not something I would throw together on a typewriter in the week before it was due.

Friday, October 28, 2011

Converting DVDs for viewing on a tablet, while inlining captions

Previously, I  described how to convert HDTV videos for my EEE Pad Transformer.  Now, I'll go over something a bit more difficult.

My wife and I have some DVDs of Bollywood films that we enjoy watching.  Aaja Nachle, Om Shanti Om, 3 Idiots, Billu, among others.  These films are mostly in Hindi, but there are English subtitles available.  As we don't understand Hindi, we watch the movies with the subtitles.  The Android media viewer that comes with the tablet doesn't have a way to select subtitles from an alternate video stream.

Now, I wanted to make files of these movies that I could watch on the Android tablet.  As noted in the previous article, the resulting files have to be H.264 Baseline profile, and under 2GB in size.

Here's how I did this.  Note that this procedure required no less than 70 GB of free disk space to hold a large intermediate file, as I wanted to avoid artefacts introduced by running through multiple codecs, so I used a lossless intermediate state.

First of all, I used the MythTV option to rip a perfect copy of the DVD.  That gave me a file, say 3IDIOTS.vob.

Next, I used mencoder to inline the captions directly into the video stream:

mencoder -ovc lavc -lavcopts vcodec=ljpeg:aspect=16/9 \
    -vobsubid 0 -oac lavc -lavcopts acodec=flac \
    -o 3idiots 3IDIOTS.vob

The output file, 3idiots, was, as noted, huge.  It consisted of a lossless jpeg video stream, with the subtitle 0 track overlaid on the video stream itself.

Next, the file had to be converted to H.264 Baseline.  In this case, I decided, rather than setting a qmax, that I would set a bitrate.  That way I could be certain ahead of time what the final size of the file would be, though at the cost of increased trancoding time.  To get a fixed bitrate, it is necessary to run ffmpeg in two passes, once to collect statistics, and the second time to generate the file itself.  Here's how this is run:

ffmpeg -pass 1 -i 3idiots -vcodec libx264 -vpre fast \
    -vpre baseline -b 1400 -acodec libfaac -ab 64k \
    -ac 2 -ar 44100 -threads 3 \
    -deinterlace -y junkfile.mp4

ffmpeg -pass 2 -i 3idiots -vcodec libx264 -vpre fast \
    -vpre baseline -b 1400k -acodec libfaac -ab 64k \
    -ac 2 -ar 44100 -threads 3 \
    -deinterlace 3idiots.mp4 

The "junkfile.mp4" file can be deleted.  The H.264 file, 3idiots.mp4, came in at 1.8 GB, and was of quite acceptable quality to view on the tablet.

Converting HDTV videos for viewing on a tablet

I have an Android-based tablet computer, the EEE Pad Transformer.  My MythTV computer can record digital over-the-air broadcasts in high definition now that I have put an HDHomerun on my network.  So, it would be nice to be able to transfer some HDTV programs to the Android computer to watch them there while traveling.  The HDTV shows are 1080i, encoded as mpeg2 video, at a bitrate of close to 16000 kbits/sec.

So, what are our constraints?  The Android computer is not powerful enough to play videos without hardware assist, and that hardware assist is only available when viewing H.264 videos encoded with the baseline profile.  It doesn't work on main profile H.264 videos.  Also, the Micro-SD card that I plug into the tablet must be formatted as VFAT, it isn't recognized when I reformat it to any more modern Linux filesystems, so our files are going to have to be under 2GB in size.  Also, the Android screen is only 1280x800, so there's no point copying a 2560x1080 file there, the machine will have to reduce the resolution, we might as well do it before we copy it to the card.

So, a 1 hour show, recorded on the MythTV box, is about 8 GB and in the wrong format.  We convert it in two steps.  First, cut out any commercials and transcode it at high quality.  For network broadcast television that chops off about 25% of the file size, and you probably didn't want to watch the commercials while sitting on the train/airplane anyway.

Next, it has to be transcoded to H.264 Basline.  This can be done with ffmpeg:

ffmpeg -i PROGRAM.mpg -vcodec libx264 -vpre fast \
     -vpre baseline -s hd720 -qmax 30 -acodec libfaac \
     -ab 128k -ac 2 -threads 4 -ar 44100 -deinterlace \

This takes the HDTV .mpg file from mythtv, "PROGRAM.mpg", and converts it.  We use the libx264 video codec, fast settings, baseline profile, formatted for a high definition 720 line screen.  "qmax" sets a limit on quality loss, I usually use a value between 25 and 30.  We use the FAAC audio codec at 128kbits/sec, deinterlace the result, and write it to "PROGRAM.mp4".

The resulting file, about 45 minutes of air time, is about 600 MB in size.

Friday, September 18, 2009

Getting GSM + Internet while visiting Taiwan

I have a Palm Centro phone, not SIM-locked, so I can obtain local phone numbers when I travel. Of course, it doesn't make sense to try to sign up for a contract if you're only in the country for two weeks, so a pre-paid phone card is really the best choice.

I recently made one of my frequent trips to Taiwan to visit family there. While there, I wanted a local phone number so people could reach me, and I also wanted to be able to use my phone's web browser and Google Earth, meaning I needed Internet access.

This may not be the only way to do that, and may not be the cheapest, it just happens to be the way I did it. I went to a few cell-phone company shop fronts. FarEasTone had not yet opened for the day, so I went to Aurora. The Aurora staff told me they could give me a pre-paid account, but not with Internet access. So the third stop in my quest was Chunghwa Telecom (中華電信). It's one of the larger companies. Here, I was able to get everything that I was looking for.

You will need:
  1. An unlocked GSM (or G3) cell phone.
  2. Two pieces of photo ID. I used my Canadian passport and my Ontario driver's license.
  3. A local address in Taiwan. A hotel address is fine.
  4. The ability to communicate with the staff.
I can speak Mandarin, and could carry out the transaction in that language. Don't assume that the employees can speak English - if you cannot carry on conversations in Mandarin you should bring somebody to interpret for you.

I signed up for a pre-paid G3 card. While my phone is GSM, the G3 cards are backward compatible to the older format. I paid NT$300 (about C$10) up front, and got the full amount in credit on my account, there are no setting-up fees, all the money goes toward pre-paid airtime minutes. The transaction took only a few minutes, and I was able to make test calls from my phone before getting up from my chair. The SIM card comes with a 4-digit unlock code, you have to enter this every time you turn on the cell phone. You can set up voice mail, but I didn't bother.

I was actually a bit surprised that I could set up a new phone number for only C$10. I would have expected that the administration costs would make it impractical to offer such a low-price entry. In the end, I used only about C$23 in air time charges in the almost three weeks I was there.

Calls are billed by the second. After each outgoing call, a text message is sent to your phone telling you the number you called, the time spent on the call, the amount charged against your account for the call, and the expiry date of your account. The account expiration timer is 180 days, reset every time you add funds to your account. To add funds to your account, you simply walk into any 7-11 and tell them you want to buy a recharge for your Chunghwa Telecom (zhong1 hua2 dian4 xin4) phone. Recharges cost NT$300, and again, all of the money you pay goes into pre-paid airtime minutes, without anything held back for "access fees" etc. To use the recharge, follow the directions printed on the card. Basically, you call 928, go through a couple of menu options, then type in the PIN revealed by scratching the back of the recharge.

The employee who set up my account warned me that Internet use was expensive, but I didn't find it so. Of course, I wasn't watching television shows on my cell phone, just visiting a few websites in the morning to read the news from home. The price quoted for GPRS is NT$0.005 per "packet". A GPRS packet is about 1 kB, so that would make the price about NT$5 per megabyte.

You should probably ask that your service be set for English. If you don't do it at the counter, you can change your language preference at any time by calling the number 928. While I can read Chinese, my phone, bought in North America, doesn't have Chinese fonts, so the text messages sent after every outgoing call are unreadable unless you've set your language preference to English.

EDIT: returning to Taiwan this year, the same SIM card in the same cell phone couldn't log onto the Internet.  After a bit of discussion between their customer service staff and their IT support, it was determined that we had to edit the network settings on my cell phone, specifically assigning an APN string of "emome".

Saturday, July 4, 2009

Musings on the "Impact" miniseries

I watched that 4-hour television miniseries, "Impact", yesterday. I'm now going to set down some of my observations, from a physics and astronomy viewpoint. Even a broadcast like that can teach you something, if it is used as a starting point to explain the things the writers got wrong. And there is a lot of teaching available here, even in the first ten minutes.

OK, we start off with people observing this "biggest meteor shower in 50000 years". It is seen starting up, so we know the observations were simultaneous. There were groups in New Mexico, the East coast of the US, and in Germany, all watching the meteor shower begin. Sunset times between those locations are as much as 9 hours apart, and in the summer time (when this movie appears to have been set) there aren't 9 hours of full darkness. This is a common mistake, movies and television shows will often show two participants in a phone call sitting half a world apart, both in full daylight.

Then, that meteor shower was a disappointment. There are recent records of much more intense meteor showers. The Leonid showers of 1833 and 1966 were, from their descriptions, much more spectacular than the shower shown in this movie.

Two astronomers are observing the meteor swarm through telescopes, before it reaches the Earth. We see a field of rocks large enough to be seen through telescopes, and so densely packed as to block sight lines so that astronomers couldn't see another object at the back of the swarm. This isn't a meteor swarm, a meteor swarm is rocks smaller than pebbles, separated from one another by kilometres of empty space. This is an avalanche in space.

Next, we find out that an object, visible while it's still moving in space, was traveling with the cloud of meteors and is going to strike the moon. Seen from the ground, this object had a visibly different track across the sky, which doesn't make sense if the objects were all traveling together. But if it were traveling in the same direction as the visible meteors, it wouldn't stand out and so would be less desirable from a dramatic standpoint, so we'll let that one pass.

So, this mystery object. Let's forget about the "brown dwarf" babble, and just describe it as a super-dense, magnetized object with, as they say in the movie, a mass twice that of the Earth's. It hit the moon, and bad things happened.

Now, the science used to explain the effects on Earth is all nonsense, of course. The "levitating frog" experiment did not produce anti-gravity. It exerted a force on a frog. A string tied to the frog's leg would also exert a force. This was just like that, but it used a magnetic field to apply the force. Gravity was still affecting the frog, but the frog was being supported against the force of gravity by a force of magnetic origin, one related to the gradient of the magnetic field (how much the field changes over a short distance). So, starting from a misunderstanding of an old news release, the writers created weird fantasy effects where objects that are not too small and not too large levitate in spooky ways in random places on the Earth, then crash to the ground. Whatever, we're not going to talk about that anymore.

OK, back to "small, very heavy object hits the moon". Our astronomers mention that the moon has 1/6 the mass of the Earth. No, it doesn't. It has about 1/6 the surface gravity, but only about 1/80 of the mass of the Earth. This is a common mistake, believing that gravity is a function solely of the mass of the object, and ignoring the different sizes. To take a dramatic example, Saturn has almost 100 times the mass of the Earth, but the force of gravity exerted at the cloud tops is not much higher than the force of gravity at the surface of the Earth, because the cloud tops are over 9 times as far from the centre of Saturn as the surface of the Earth is from its centre.

The moon gets hit by something very small that weighs two Earth masses, and is traveling very fast. And they stick together. 160 times the mass of the moon smacks into it with a speed of, let's say, several kilometres per second. This object wouldn't stop. It would barely even notice the moon. If the entire moon got in its way, it would sweep it up and continue on its path practically unaware that it was now carrying a moon with it. Since the thing is small, only a bit of the moon gets in its way. It's a very small and extremely fast bullet striking a very large soap bubble. You don't expect the soap bubble to be carried away by the bullet, you expect to find a punctured bubble. You certainly don't expect the bullet to stop dead in the bubble.

160 times the mass. Imagine you're driving down a highway, and a raccoon is crossing the road. Just as your car is about to hit it, the raccoon jumps straight up and hits the front of your car. Your car stops dead as if it had struck a concrete wall, and the mid-air raccoon is barely pushed at all. Even cartoons don't try to get you to believe that.

That much mass, stopping all at once within the moon. Just the kinetic energy released is about the same as the total output of the sun over the space of 48 hours. Not the light hitting the Earth, the light leaving the entire solar sphere. The moon would vanish in a puff of gas. The Earth would vanish in a larger puff of gas.

OK, so suddenly the moon weighs twice what the Earth does. This would have some fairly obvious effects. For one thing, the tides on the surface of the Earth would go from a few metres to a few hundred metres in amplitude. That would have a serious effect on the coastal regions (and with those tides, Missouri is a coastal region).

Increase the mass of the Earth-moon system, and the rotational period will decrease. A month would go from about 30 days to about 10 days. But in the movie, the moon was making complete orbits around the Earth on plot-driven timescales. Sometimes the orbital period was a few days, and toward the end of the movie the orbital period seems to have become about 90 days, because they had deduced that the moon would hit the Earth on this orbit, but they still had 40 days left to try to find a solution. And these weird, sudden "orbital shifts" don't make sense. Yes, an uneven mass distribution can result in smooth and gradual changes to orbits, but the moon didn't have an uneven mass distribution. It was a big mass travelling in orbit, with a light, insignificant, moon stuck to it like a bug on a windshield. The pre-impact mass of the moon isn't even an important perturbation on the mass distribution.

Good news, everybody! We just happen to have a lunar expedition fueled up and ready to go, prepared before the impact. Our heroes can fly to the moon and use some special technology to push the big new mass out of the moon. Well, the mass weighs 160 times what the moon does, so Newton's laws tell us that you're not going to push the mass out of the moon, you're going to push the moon away. The mass won't be appreciably disturbed. The plan is to push the mass out of the moon so it flies toward the sun, but really all you'd do is send the moon away at high speed while the big dense mass stays firmly in its orbit around the Earth.

Now, about this lunar mission. The good news is that you don't need as much fuel to cross over, because of the changes to the shape of the gravitational potential fields in the vicinity. The bad news is that the moon's surface gravity is at least 25 times that of the Earth. That assumes that the colliding mass is at the centre of the moon. In the movie, it's actually only partway down, and our heroes have to land near it, so they'll feel a gravitational force much higher than that. OK, they've been working out, they can walk and work in 25 gravities of force. But their lander was designed to land on rockets in 1/6 normal gravity. It would be like designing a parachute to land you safely, and then you decide that you'll change the parameters, the parachute will be used to land a bit more weight. You plus 159 of your friends, all hanging on the one parachute. You might reasonably conclude that the parachute was not designed for that kind of treatment. A similar argument can be made for the lunar lander and that little rocket jumper vehicle, whose engines certainly cannot supply the thrust to land under the new conditions. The lander would probably crumple under its own weight just trying to sit still on the moon, and taking off from the surface would be similarly difficult because of the changed conditions.

OK. Gravitation, tides, astronomy, orbital motion. If you learned something new from this movie, it's almost certainly wrong.

Friday, January 16, 2009

When your on-the-road ISP blocks your outbound mail

Now, we talked about allowing your computer to relay mail through the home machine when the ISP through which you're connecting has made it onto a block list. What do you do when the ISP simply blocks all outgoing connections on port 25? Now you can't even connect to your home computer to relay the mail.

The ISP does this to force you to pass email through their servers. The hope is that infected Windows computers will just try to open connections directly, and not forward the mail through the ISP servers. As noted in this story, that is not necessarily true.

So, now you find yourself unable to open connections on port 25, but you still want to send email. You could set up your computer to relay mail through the ISP's servers, as described in this earlier article, but that may not be convenient if, for instance, you're accessing the Internet at a relative's home, since they would have to give you their passwords for you to do that.

So, the first thing to do is to check that you can connect to your home computer on the ESMTP port number 587. Telnet onto that port number on your home computer, and if you get a response, then this technique will work for you.

First of all, you should already have set up relaying as described here. If you set it up a while ago, verify that your keys are still valid and haven't expired.

As we're discussing this in the spirit of a temporary work-around, we'll be editing the file directly. First, of course, make a backup copy of your current file, because you'll want to reset it to its former behaviour after you stop using this particular ISP.

Now, go into your file and find the smart relay line. It will look something like this:
# "Smart" relay host (may be null)

Change that line to indicate that you're sending ESMTP to your home machine. It will look a bit like this:
# "Smart" relay host (may be null)

Next, we have to tell sendmail that it is to use port 587 for outbound mail to esmtp smart relays. Locate the block in the file that looks like this:
Mesmtp,         P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
A=TCP $h

and change the last line to read:
                A=TCP $h 587

That's it. Restart the sendmail program, and you should be able to relay all mail through your home machine using authenticated relaying on port 587.