[Lowerbounds, Upperbounds]

Algorithms are everywhere.

In the positional number system of base `b`, the representation `d_{n}d_{n-1}…d_{1}d_{0}` denotes the number `\sum_{i = 0}^{n} d_i b^i`. For example, the binary (`b = 2`) number `(1001)_2` is 8 + 1 = 9. Notice that when `d_i \in {0, …, b – 1}`, there is only one way to denote any number. This is what we are all used to.

In a redundant number system, we allow `d_i` to be chosen from a larger set of digits. For this series, we will stick to `{0, …, b – 1, b}`. To make things even more concrete, we further set `b` to 2, i.e., we are considering the redundant binary numbers with the sets of digits {0, 1, 2}.

The decimal number 9 can still be written as `1001` in binary (I am dropping the subscripts and will display binary numbers in math mode). But since we are using the redundant binary system, we also have other choices. In particular, `201` (2 * 4 + 1 = 9) and `121` (4 + 2*2 + 1 = 9) are also valid representations.

Let me introduce three terms before I continue.

  • We say that a redundant binary number is regular if the 2s and 0s alternate. So `2012` is regular, but `2120` is not.
  • When the last non-1 digit of a redundant binary number is 0, we say that it’s 0-exposed. For example, `2001` is 0-exposed. (But note that it is not regular.)
  • When the last non-1 digit is 2, we say that it is 2-exposed. For example, `2102` is 2-exposed.

The regularity constraint is very special. First, convince yourself that even when restricting to regular representations, there are still redundancy in the representation of a number. For example, both `1202` and `1210` denote 18 and both of which are regular since the 2s and the 0s alternate.

Also note that if a number is either 2-exposed or 0-exposed.

The only operation that we will consider in this post is:

  • add 1 to the least significant digit of a number (i.e., the rightmost)

We will denote this operation with an intuitive expression. For example, consider `12(1+1)`. That would be `122`. Easy, huh?

Let’s repeat the operation one more time. Hmm, `12(2+1)` would be `123`, but that wouldn’t be too good since 3 is not an allowed digit. Well, we need carry. `123` = `131` = `211`. OK, problem solved.

At this point, make sure you know how to do this add-one-to-the-last-digit operation.

For those of us that own the whole series of the Worst-Case Scenario Survival Handbook :) , you will have noticed that this operation can take time linear to the number of digits. Consider the input `22222222222222222(2+1)`. Oh no!

This is where the regularity constraint comes in. Suppose the number you start with is regular. How long can add-1 take? Consider the last digit of the number.

  • If it’s a 0 or 1, then you can just bump it up to 1 or 2 respectively.
  • If it’s a 2, then we need to carry 1 to the next digit (to the left). Ah! But since the number is regular, that digit cannot be a 2. The previous case now applies.

So in at most two steps, we will be done. That’s like `O(1)` time, right?

But, we may not be left with a regular number any more. For example, `12(1+1)` is `122` and that’s not regular. The key observation is that we will end up with an irregular number if we start with a 2-exposed regular number. So we never want to increment a 2-exposed number.

The claim is that you can convert a 2-exposed number into a 0-exposed equivalent in `O(1)` time if you know where the rightmost 2 is. Let the number be written as `xy2z`, where `z` is the sequence of digits to the right of the rightmost 2, `y` is the digit immediate to the left of it, and `x` is the sequence to the left of `y`. Due to the regularity constraint, note that `z` must be all 1s if it is not null, and `y` only has two possibilities:

  • `x02z` = `x10z`
    `x` must be 2-exposed, so `x10z` is regular.
  • `x12z` = `x20z`
    `x` must be 0-exposed, so `x20z` is regular.

And both of these are 0-exposed and we know adding 1 to them takes `O(1)` time.

The remaining issue is how we know where the rightmost 2 is. This is easy. We maintain a stack of the locations of the 2s, with the rightmost on the top of the stack. Verify that the above two fixing operations both operate at the top of the stack.

Now do you understand how to add 1 in `O(1)` time?

Indeed, if the number is 2-exposed, fix it to become 0-exposed first. And we know that adding 1 to a 0-exposed number is easy.

But why am I telling you about redundant number systems? That would be the subject of Part 2.

Previously I’ve told you that you can clone an object in PowerPoint by Ctrl-Drag, but I forgot to tell you that you can do so with just the keyboard too. Try Ctrl-D.

P.S. For those of you who wonder why I would blog software entries like this. The usual reason is: someone just asked me (if there is a way to clone objects using just the keyboard and she already knows about copy Ctrl-C and then paste Ctrl-V). :)

Note: it seeems that the web has no lack of copies of this excellent talk. This one is copied from http://www.cs.virginia.edu/~robins/YouAndYourResearch.html. A PDF version is available at http://www.ocf.berkeley.edu/~wwu/readordie/hamming.pdf and here is a local copy.

This talk really makes me think a lot… but…


Richard Hamming


“You and Your Research”

Transcription of the
Bell Communications Research Colloquium
Seminar
7 March 1986


Read the rest of this entry »

Here are some paraphrased comments I have gathered over the years by asking some speakers why they didn’t show me the slide numbers:

  • “It’s a clutter and it distracts my audience.”
  • “It takes up precious screen estate. Look, 1024×768 is not a lot.”
  • “My talk has multiple page animations that make the slide numbers large and that makes my audience feel that I am cramping a lot of material into one hour.”
  • “I just don’t see why having the slide number can be helpful.”
  • “You mean I can have slide numbers? How?”

The best way for me to debunk all these (except the last) is by asking the following question:

Do you know that you can jump to a particular slide in a PowerPoint show by pressing the slide number followed by Enter? Say you want to go to slide 42 during your talk, you press 4 2 Enter (3 keys) and say voila!

This is an important feature that justifies showing the slide number. Why? This means if you show me the slide numbers, then I can ask questions by first telling you which slide I am referring to and, most importantly, you can go to that slide in 2 seconds for the rest of the audience to follow. This is a big time-saver for all of us.

P.S. There are other fully-documented but not well-used keys in the slide show mode of PowerPoint. Press ? (the question mark) in a slide show and you will see.

P.P.S. Maybe I have just sat through another PowerPoint talk with no slide numbers… I don’t remember what happened. Maybe I should consult with the Department of Truth. :P

No, I am not going to admit it.

I’ve never used these geeky terms like foo and bar. There is no evidence of this. All we’ve got are just rumors on the Internets. :P

http://en.wikipedia.org/wiki/Snafu

The setting is a typical research talk. Your room is filled will reasonably intelligent people but not everyone is exactly in your specialty. (Think conferences.)

For such a talk, I am a strong opponent to giving citations using the standard alpha style (as in BibTeX). It’s at most three alphabets followed by two digits, like this: [AMR03].

Maybe it’s just me, but I’ve met some speakers that would say “A M R Oh Three proved a seven-third plus four epsilon over three approximation…” Now that’s really helpful to the rest of us, isn’t it?

And if the speaker is any good, she would actually say the three lastnames in full. I don’t want to offend anyone, but my experience is that a significant fraction of people in the room would have never picked up the words Amir, Krauthgamer and Rao from *my* speech. It’s not just because of my strong accent (and I confess), but also the fact that sometimes we don’t really know how to pronounce a name properly.

My believe is that we should just spell out the complete last names on at least one of the slides. And if none of your slides has enough space for spelling out [Amir-Krauthgamer-Rao 03], then maybe your slides are a bit too dense?

P.S. In case you are interested, [AMR03] is Constant Factor Approximation of Vertex-Cuts in Planar Graphs in STOC. The classic result in vertex-cuts for planar graphs is the 1979 Lipton-Tarjan `O(sqrt n)` separator theorem. But there is no guarantee that their algorithm will return a cut that has a size close to the optimal. This paper achieves that guarantee, with some technicalities.

Besides the mailing list of arXiv.org, I also recommend subscribing to the newsletter of ECCC. It’s pretty simple: just go to http://eccc.uni-trier.de/eccc/info/subscribe.html and you can submit your request there.

The benefit? You get to know some of the hottest results out there, right in your mailbox!

For example, this is what I got this morning:
Read the rest of this entry »

Las Vegas, NV, USA
July 17-20, 2005

P.S. I made the mistake of booking my flights before actually reading the conference program. Thinking that the conference starts on the 17th, oh well, I booked my flight so that I will arrive in the afternoon of the 16th. No, I really did not plan to spend time in the casinos. :P

Update on 2008-01-24:
The “back” feature is no longer needed, at least on Windows Acrobat Reader 8. See: Edit->Preferences->Documents->Restore last view settings when reopening documents

Update on 2007-01-30:
I have patched the source and replaced the zip files so that pdfclose will be less likely to crash Adobe Reader 8. Thanks to this post. Also, apparently pdfopen cannot issue a “back” command to Adobe Reader and you need the full version for that feature.

If you are a Windows user and use Acrobat or Adobe Reader(*) to view PDF files, you may have experienced Acrobat locking your PDF file, making it impossible to overwrite. This is a serious problem when previewing your paper in the PDF format because every time before you generate a new PDF, you need to remember closing the old PDF in Acrobat.

Part of my solution to this problem is to open the PDF using pdfopen:

pdfopen --file foo.pdf

This will allow me to close foo.pdf by:

pdfclose --file foo.pdf

Integrating these two commands into your work-flow is left as an exercise to the reader. :)

But there is still an important usability problem that these two commands won’t solve. Every time you re-open a PDF, you will not be on the same page when you closed it. Instead, you will be on the first page. How would I to fix this? One solution would be to press Alt-Left after I re-opened the PDF file. This goes back in history and brings me to the last view I was at. But I’ve got something better.

I’ve modified the source code of pdfopen from TUG to include an extra option --back to do the obvious thing. So instead of the above, you should open a PDF file by:

pdfopen --file foo.pdf --back

Now the cycle is complete. Phew!

I have posted the exe files in a zip. The source files are available too.

For the record, you can obtain the original pdfopen and pdfclose at this URL:
http://www.tug.org/tex-archive/systems/win32/web2c/current/binary/bin-pdftools-win32.zip

BTW, I’ve read that recent versions of TeXnicCenter and WinEdt can both perform this Acrobat cycle too. But I am not sure if they can go back to the previous view. Heh, surely I know my Emacs can. :P

P.S. I am also aware that you can use gsview32 to preview PDFs and gsview32 does not lock PDF files. That’s one way to avoid this problem.

(*) Really, it’s called Adobe Reader. I don’t know since when they dropped the middle word.

Ever wondered if LaTeX has a particular symbol you want?

http://www.ctan.org/tex-archive/info/symbols/comprehensive/

P.S. For those of us that use MiKTeX, there is already a local copy at C:\TeXMF\doc\guides\symbols\.

After reading a comment at Lance Fortnow’s blog, I suppose I should write more about Computer Science. :P To do that, first I followed the steps of our friendly alumus Andrej Bauer and installed ASCIIMathML.

The actual syntax of ASCIIMathML is not exactly LaTeX as the author Peter Jispen wants a syntax that is

  1. close to standard mathematical notation
  2. easy to read
  3. easy to type

Oh well, so much for the dollar signs. (But let me note that LaTeX syntax is supported to some degree.)

If you are using IE, then you need to install MathPlayer. If you are using Firefox, you want to visit the MathML page at Mozilla.org. In particular, you will need to install the fonts from their Fonts page.

Here is an example copied from the ASCIIMathML page for testing.

Solving the quadratic equation.
Suppose `ax^2+bx+c=0` and `a!=0`. We first divide by `a` to get `x^2+b/ax+c/a=0`.

Then we complete the square and obtain `x^2+b/ax+(b/(2a))^2-(b/(2a))^2+c/a=0`.
The first three terms factor to give `(x+b/(2a))^2=(b^2)/(4a^2)-c/a`.
Now we take square roots on both sides and get `x+b/(2a)=+-sqrt((b^2)/(4a^2)-c/a)`.

Finally we move the `b/(2a)` to the right and simplify to get
the two solutions: `x_(1,2)=(-b+-sqrt(b^2-4ac))/(2a)`

Now we are one step closer to make this blog more relevant to its title. :P

Those of us that use Microsoft Office should be familiar with the concept of a clipboard manager (since it has one built-in for the Office applications). Basically, a clipboard manager lets you maintain a history of your clipboard contents.

Say you want to copy a number of objects from several different slides to a new slide. Without a clipboard manager, you copy the objects from the first source slide, then you go to the destination slide, paste the clipboard content onto it, and then you repeat by going to the second source slide. Notice that you need to keep going back and forth to the destination slide because your clipboard content will be overwritten by a subsequent copy command. See how a clipboard manager can help?

But what if you are not working in an Office application? Well, that’s what CLCL is for. It’s a free clipboard manager for Windows and works for all applications.

http://www.nakka.com/soft/clcl/index_eng.html

But in my experience the single most important feature of CLCL turns out to be its ability to beep when you copy something to the clipboard. I love this audio feedback because some applications (Firefox in particular) seem to have trouble copying things. I don’t want to wait till I paste to realize that the copy did not happen. For this feature alone, I happily keep CLCL running all the time. :P

To enable this audio feedback, download the tool_utl plugin from CLCL’s homepage. Then go to Options->Tool->Add. The DLL you want is tool_utl.dll and the function name is play_sound. Then click Properties and go to the Windows\Media directory to select your favorite wave file. I use windows xp pop-up blocked.wav.

P.S. I was told that in Mac there is actually an visual feedback to indicate that the copy (Command-C) was successful. Specifically, the Edit menu item will blink once. But there is a problem. It blinks so fast that it is hard to spot. So what some users end up doing is to hold down Command-C to repeat the blinking (basically turning Edit into reverse video). Heh, I guess we all have our problems.

Just saw this at http://www.emacswiki.org/cgi-bin/emacs-en/ColorTheme:

“Hello Kitty” Colour Theme Request

After a discussion on #emacs, it was found that we could attract more women and young children to being Emacs users if we had a “Hello Kitty” colour theme; something with a soft pink and yellow.

Interesting idea, but is the color theme really the problem? :P

Kathy Sierra has written a very strong post against the use of PowerPoint and even transparencies for her presentations. To quote her:

Sometimes the best presentation is… no presentation. Ditch the slides completely. Put the projector in the closet, roll the screen back up, and turn the damn lights back on!

Even though you may not want to stop using PowerPoint because it’s not obvious how to use it right, you definitely want to read her post and learn how not to commit the mistakes she mentioned. Some of them are definitely avoidable with practice, such as talking to the slides and dimming the lights, both of which are likely to turn your talk into a unidirectional broadcast.

Among the comments, I discovered this interesting wiki about WhyWeDoNotUsePowerPoint. Heh.

Imagine you have a large PDF document that you want to submit to some three-letter government agency. Besides having the document as one big PDF, the agency also asks you to submit the abstract and the biography as two separate PDFs.

Well, you are running out of time, and your coauthors are still working on their sections. You even wrote a make file to automate the document generation because you don’t want to run LaTeX multiple times manually to resolve all the references…

But how do you do make these two PDF files efficiently, preferably in an automatic way? Well, if you have Acrobat (the full version), then you can use Document -> Extract Pages to save the relevant pages into separate PDFs. But that’s not easy to automate. And what if you didn’t shell out the \$\$\$ to buy Acrobat?

Here is the good news. To extract pages from a PDF, we can use the free software pdftk. Suppose you know(*) the abstract happens to be on pages 2 and 3 and the biography spans from page 30 to the end. Here is an example usage for our imaginary situation (dont_ask is used to suppress the prompt to overwrite existing files):

pdftk foo.pdf cat 2-3 output abstract.pdf dont_ask
pdftk foo.pdf cat 30-end output biography.pdf dont_ask

Besides page extraction, pdftk can also catenate PDFs and perform several other PDF magic tricks. You can discover all these from reading this page. For example, you can discover that you can compute the number of pages of a PDF by

pdftk foo.pdf dump_data output - | grep NumberOfPages | cut -d' ' -f 2-

(*) How you can know these ranges automatically is another story to be written later. Hint: use pdftotext.

PsTools from Sysinternals is a collection of command line utilities that let you manipulate processes in Windows. Among the tools, I personally use pslist and pskill every single day(*). Check it out!

And if you have pslist, then put the following into a batch file, say mlist.bat. It’s very handy for nailing down memory leaks. (Note that the @ sign in the front of a command in a batch file suppresses the echoing of the command. That’s why many batch files start with @echo off.)

@pslist | sort -n +5 | tail -n 10

BTW, with the release of Windows XP and Windows Server 2003, Microsoft has bundled two command line tools that do similar things (tasklist and taskkill). However, their command line interface is awkward. I recommend you forget about them and stick with PsTools.

(*) largely because of Firefox and Acrobat

Lea Kissner

Privacy-Preserving Distributed Information Sharing
July 5, 2005
10:30 AM
Wean 5409

ABSTRACT:
Read the rest of this entry »

This weekend (today till July 4th) I will be upgrading the software installations on Jasmine. Many upgrades will be done during this period and so you will see some intermittent down-time. For those of you that aren’t involved in maintaining Jasmine, this machine actually hosts many services for our Theory group.

Of special note is the upgrade to Subversion 1.2. Once this is done, we can finally self-host www.aladdin.cs.cmu.edu and we can also roll out the Subversion server for other projects. (I know, you may not know what Subversion is or how you can use it. But if you actually visit this blog, you will notice that there is already a Subversion category in this blog except I have not started writing about it. :P )

P.S. This morning I just spent an hour upgrading Apache from 2.0.53 to 2.0.54 because I forgot to take away the custom configuration files between the removal and re-installation. If you run Apache on Windows, this is the proper upgrade procedure:

  1. Uninstall the old version. You will be left with files that you manually put in the Apache2 directory. Among those files are your configuration files in the conf directory.
  2. Move the conf directory to somewhere else.
  3. Install the new version. (If you don’t do the previous step, Apache may not be able to register itself as a service. You will see an error message “no installed service named Apache2″, indicating that the service registration has failed. You may try to outsmart it and manually do Apache -k install -n Apache2, but that will not work either in my experience.)
  4. Start Apache with the default configuration files.
  5. Verify that it starts well by looking at the log files.
  6. Stop Apache.
  7. Restore the conf directory that contains your custom files.
  8. Start Apache and be happy that you saved an hour of your life.