Subnatural and supernatural

I recently ran across a discussion of quantum mechanics from C. S. Lewis.

The older scientists believed that the smallest particles of matter moved according to strict laws: in other words, that the movements of each particle were “interlocked” with the total system of Nature. Some modern scientists seem to think — if I understand them — that this is not so. They seem to think that the individual unit of matter … moves in an indeterminate or random fashion; moves, in fact, “on its own” or “of its own accord.”

He goes on to explain that the macroscopic behavior of matter appears deterministic because the average behavior of billions of particles is very regular. His explanation is remarkably cogent for a professor of medieval literature writing in the 1940’s. He then discusses the philosophical consequences of quantum mechanics.

Now it will be noticed that if this theory is true we have really admitted something other than Nature. If the movements of the individual units is “on their own,” … then those movements are not part of Nature. It would be, indeed, too great a shock to our habits to describe them as super-natural. I think we should call them sub-natural. But all our confidence that Nature has no doors, and no reality outside herself for doors to open on, would have disappeared. There is something outside her, the Subnatural. … And clearly if she thus has a back door opening on the Subnatural, it is quite on the cards that she may also have a front door opening on the Supernatural …

From Miracles by C. S. Lewis, chapter 3.

Related post: The world looks more mathematical than it is

Transaction costs

“If you make $30 per hour, you should outsource everything you do that you could hire someone else to do for less than $30.” Rubbish. I don’t know how many times I’ve heard this advice. It sounds good, for about two seconds. But it doesn’t work because it ignores transaction costs.

Suppose you’re an accountant making $60,000 per year, an hourly rate of $30. If someone is standing in front of you and says “Hey, I’ll do your yard work for the next hour for $20. Why don’t you go inside and do an hour of accounting?” In that case, it makes sense to take the yard worker up on his offer (unless you want to work outside for non-monetary reasons). But reality is seldom so simple. First of all, if you are a salaried employee, you probably don’t have the option of putting in an extra hour’s work for an extra hour’s pay. But even if you do freelance accounting, you may not be able to find an hour’s work when you want it.

Say you have some freelance accounting to do, and you’d like to get out of your yard work. You’ve got to find someone to do the work unless there happens to be landscaper standing outside your door. You might ask friends for recommendations, search the web, make a few phone calls, etc. Finding a landscaper is easier than finding accounting work, but it still takes effort.

The effort necessary to find work or to find workers is called a transaction cost. So is negotiating compensation, drawing up contracts, etc. If you have a steady stream of accounting work, you might think “I’m going to need to free up some time to do this extra work. I’ll outsource some of my chores, like my yard work.” And that makes sense. But unless you have enough work at hand, it’s worthwhile to do many things for yourself that in theory you could pay someone else to do.

Transaction costs are not all bad. They give life stability and variety. Salaried jobs exist because transaction costs make it expensive to put every task out for bid. And we develop a variety of skills because it is impractical to ask someone else to do everything for us outside of our narrow professional specialization.

Related posts

Counterfeit coins and rare diseases

Here’s a puzzle I saw a long time ago that came to mind recently.

You have a bag of 27 coins. One of these coins is counterfeit and the rest are genuine. The genuine coins all weigh exactly the same, but the counterfeit coin is lighter. You have a simple balance. How can you find the counterfeit coin while using the scale the least number of times?

The surprising answer is that the false coin can be found while only using the scales only three times. Here’s how. Put nine coins on each side of the balance. If one side is lighter, the counterfeit is on that side; otherwise, it is one of the nine not on the scales. Now that you’ve narrowed it down to nine coins, apply the same idea recursively by putting three of the suspect coins on each side of the balance. The false coin is now either on the lighter side if the scales do not balance or one of the three remaining coins if the scales do balance. Now apply the same idea one last time to find which of the remaining three coins is the counterfeit. In general, you can find one counterfeit in 3n coins by using the scales n times.

The counterfeit coin problem came to mind when I was picking out homework problems for a probability class and ran into the following (problem 4.56 here):

A large number, N = mk, of people are subject to a blood test. This can be administered in two ways.

  1. Each person can be tested separately. In this case N tests are required.
  2. The blood samples of k people can be pooled and analyzed together. If the test is negative, this one test suffices for k people. If the test is positive, each of the k people must be tested separately, and, in all, k+1 test are required for the k people.

Suppose each person being tested has the disease with probability p. If the disease is rare, i.e. p is sufficiently small, the second approach will be more efficient. Consider the extremes. If p = 0, the first approach takes mk tests and the second approach takes only m tests. At the other extreme, if p = 1, the first approach still takes mk tests but the second approach now takes m(k+1) tests.

The homework problem asks for the expected number of tests used with each approach as a function of p for fixed k. Alternatively, you could assume that you always use the second method but need to find the optimal value of k. (This includes the possibility that k=1, which is equivalent to using the first method.)

I’d be curious to know whether these algorithms have names. I suspect computer scientists have given the coin testing algorithm a name. I also suspect the idea of pooling blood samples has several names, possibly one name when it is used in literally testing blood samples and other names when the same idea is applied to analogous testing problems.

Software Archeology

The most recent episode of Software Engineering Radio is Software Archeology with Dave Thomas. In his interview, Dave Thomas gives many practical tips for how to read code, especially when inheriting a project. This interview should be required listening for computer science students. They spend the majority of their time writing code while they’re in school and yet they will spend the majority of their time reading code once they get out — reading code in order to debug or extend it, and if they’re smart, reading code to learn from it.

Dave Thomas attributes one of his most unusual suggestions to Ward Cunningham. Thomas says Cunningham recommends pasting code into Microsoft Word and viewing it in a 2 point font. At this font size you cannot possibly read the code, but you can tell a great deal about the structure of the code. For example, you may spot duplicate code by recognizing a recurring shape.

I tested Ward Cunningham’s idea on a couple source files.

Example 1:

Example 2:

Example 1 has short functions. Near the bottom of the clip something is very repetitive. Skimming through the entire file you see several of these repetitive blocks. (This is test code. The blocks are computed values and expected values for comparison.)

Example 2 looks  quite different from Example 1. The image comes from one long function. (This was taken from FORTRAN code that had been programmatically translated in to C++. The frequent short dashes on the left are labels for goto statements.)

Related posts

Shaking a ladder: Monte Carlo in everyday life

In Flaw of Averages, Sam Savage uses the illustration of shaking a ladder to explain why someone would want to use Monte Carlo simulation. Before climbing a ladder, most people shake the ladder a little to make sure it’s sturdy.

When you position a ladder and climb it immediately, you’re saying that you’re satisfied that the ladder’s position is safe. You’re assuming it will stay in the position you placed it. But when you shake the ladder, you’re testing how it will behave at a variety of nearby positions. If the ladder remains sturdy, you have more confidence that accidental motions while you’re on the ladder are not likely to cause an accident. When you stick a single number into a model, you’re acting like someone climbing a ladder immediately. When you stick in a series of random inputs, it’s like you’re shaking the ladder.

The latest INFORMS podcast features an interview with Sam Savage. He mentions the ladder analogy and adds an observation that I don’t recall seeing in his book. One criticism of Monte Carlo methods is that the validity of your results depends on the validity of your input distributions. It’s better to have realistic input distributions, but it’s better to perform a simulation with an incorrect distribution than to not try random input at all. The distribution of random forces likely to result from working while standing on a ladder is different from the distribution of forces from shaking the ladder with your hands. But that doesn’t mean it isn’t a good idea to shake the ladder anyway.

Related post: Mortgages, banks, and Jensen’s inequality

Using Windows without a mouse

Why would you not want to use your mouse? Some tasks are most efficiently done with a mouse, but others can be done more efficiently with the keyboard.The problem isn’t so much using a mouse versus using a keyboard but rather the time it takes to switch between the two modes. Particularly when using a laptop with a touchpad, it’s faster to use the keyboard.

Why does it even matter? So what if you save a few seconds here and there? It’s a matter of keeping up with your thoughts. Suppose some series of tasks takes 20 seconds with a mouse but you can accomplish the same tasks in 12 seconds using the keyboard. The big deal isn’t that you’ve saved 8 seconds; the big deal is that you’re more likely to finish your tasks before you lose the thought that motivated them.

The same could be said for learning to type more quickly. Typing 20% faster doesn’t directly make you 20% more productive unless you’re a professional typist. The benefit is that your fingers can come closer to keeping up with your brain.

If you’d like to get in the habit of using your keyboard more and your mouse less, you may find this helpful. I’ve created a Twitter account for posting one tip per day on using Windows without a mouse. If you’d like to follow using Twitter, it’s @SansMouse. If you don’t use Twitter, you could subscribe via RSS. I’ve written a few dozen tips so far and they’re in a queue to be dribbled one per day. You could practice one simple tip per day until it is natural to use your mouse much less.

I use my mouse fairly often, though I’m trying to get into the habit of using it less. I’ve recently become persuaded that it’s worthwhile to use the keyboard more and that it doesn’t take that much effort.

Related post: Four patterns in Windows keyboard shortcuts

Too much time on their hands?

Dan Wineman shared a profound insight on Twitter:

You say “looks like somebody has too much time on their hands” but all I hear is “I’m sad because I don’t know what creativity feels like.”

In place of “creativity” Wineman might have as easily said “persistence.” I found Wineman’s quote in a post by Dan Meyer responding to criticism of his research projects.

I’ve said that someone has too much time on their hands, but not since I read Meyer’s post. I see now that the phrase is often a sour grapes response to creativity. I don’t want to do that anymore.

When we see that someone has spent a thousand hours on a project that we think was a frivolous, it’s easy to say “what a waste of time.” We think how much good could have been done with that same amount of effort. But what was the realistic alternative? If that same person had spent a thousand hours in front of their television instead, no one would ever know and no one would ever criticize them. Instead, they created something.

Treehouse photo from Succeed Blog

Tree house photo from Succeed Blog. Full size photo.

How to delete pages from a PDF without Adobe Acrobat

How can you delete pages from a PDF file if you don’t have Adobe Acrobat?

Download PDFCreator from SourceForge. It installs as a printer. It lets you create PDFs from any application by selecting PDFCreator as your “printer.” To delete pages from an existing PDF, open the PDF in Adobe Reader and print to PDFCreator the pages you don’t want to delete.

I don’t have a lot of experience with PDFCreator; I just downloaded it today. But it looks good and it worked well for what I was trying to do.

Update: I tried pdftk, recommended in the comments, and it works well. It’s a command line program with more features than PDFCreator.

Four patterns in Windows keyboard shortcuts

Here are four patterns for organizing the most common keyboard shortcuts for Windows. First I’ll list the patterns, then I’ll give some qualifications and elaborate on the patterns.

  1. Keyboard shortcuts involving letters are all of the form Control-<letter> or Windows-<letter>.
  2. The letters used in Control shortcuts and Windows shortcuts don’t overlap.
  3. Control in combination with navigation keys moves the cursor. Shift in combination with navigation keys makes a selection.
  4. The Tab key cycles through things. What the key cycles through depends on what it is paired with.

When I say Control-<letter> I refer to shortcuts such as Control-C, holding down the Control key and pressing C in order to copy something. When I say Windows-<letter> I refer to holding down the Windows logo key in and pressing some letter.

My goal here is to stick to the most common shortcuts, ones that work across several versions of Windows and with many applications. Also, I’m not including any accessibility sequences such as sticky keys etc.

Control key with letters

Here are the common Windows keyboard shortcuts of the form Control key followed by a letter.

A Select all
B Toggle bold
C Copy
F Find
G Go to
H Find and replace
I Toggle italics
N New
O Open
P Print
S Save
U Toggle underlining
V Paste
W Close document
X Cut
Y Redo
Z Undo

Windows key with letters

Here are the common shortcuts using the Windows key with a letter.

D Show desktop
E Open file explorer
F Find
L Lock computer
M Minimize all windows
R Run command

Exceptions

There is one common shortcut that uses a letter and more than just the Control key or Windows key: the combination Windows-Shift-M maximizes all minimized windows. But there are no common shortcuts of the form Alt-<letter> or Control-Shift-<letter> etc.

F is the only letter used with both the Control key and the Windows key. In both cases the command finds something. Control-F finds text within a file and Windows-F searches across directories.

Navigation keys

All the navigation key shortcuts come in pairs.

Control-Home moves the cursor to the top of a document; Control-End moves the cursor to the end.

Control-Left Arrow moves the cursor to the left one word; Control-Right Arrow moves the cursor to the right one word.

Control-Up Arrow moves the cursor up a paragraph; Control-Down Arrow moves the cursor down a paragraph.

Control-Shift-Home selects from the top of the document to the cursor location; Control-Shift-End selects from the current location to the bottom of the document.

Control-Shift-Left Arrow selects one word to the left; Control-Shift-Right Arrow selects one word to the right.

Shift-Left-Arrow expands the selection one character to the left; Shift-Right-Arrow expands the selection one character to the right.

Shift-Up-Arrow selects one line up; Shift-Down-Arrow selects one line down.

Tabbing

The Tab key alone moves the focus in a window, cycling through the controls in the order specified by the application.

Control-Tab cycles through tabs or through windows in an application with multiple windows.

Alt-Tab cycles through running applications.

Windows-Tab cycles through the Task Bar.

Adding the Shift key to any of the above key reverses the cycle order. For example, Alt-Shift-Tab cycles through applications in the opposite order of Alt-Tab.

Miscellaneous shortcuts

Most common Windows keyboard shortcuts are listed above. However, there are several shortcuts that are commonly used but do not fall into a regular pattern. Some of these shortcuts are listed below.

  • Shift-F10 brings up a properties dialog, just like right-clicking.
  • Shift-Delete permanently deletes a file, bypassing the recycle bin.
  • Alt-F4 closes the active window or opens the shutdown dialog if there is no active window.
  • Alt-Down Arrow opens a drop down list box.
  • Alt-Print Screen grabs an image of the active window rather than the entire screen.
  • Alt-Space opens the current window’s system menu.
  • Windows-Pause brings up the System Properties dialog.

Most of the function keys are not used often. The most commonly used function keys are

  • F1 to bring up help,
  • F5 to refresh, and
  • F10 to activate an application’s menu bar.

Related posts