Sunday, January 09, 2005

Computer science?

Computer science is misnamed. It is not primarily a scientific discipline; though computer scientists do sometimes apply the scientific method, experimental training is not a fundamental component of the usual CS undergraduate curriculum. However, the scientific method does play a role in computer science, and I think it's enlightening to consider that role.

First, the scientific method applies to topics purely within computer science because the systems we build become too complicated to analyze directly. In principle, I could sit down with a program and work out precisely how long the program would take to solve a particular problem on a particular machine (assuming that I can determine in advance that the program will terminate). It might take me a long time, but all the rules are known, and they're all deterministic. But I usually would not do such a thing, because the low-level details are too complicated for convenient reasoning. I don't want to have to analyze all the possible implications of the organization of the memory, the pipeline, the bus, and so forth -- even though those organizational details can make an orders-of-magnitude difference in the performance of my program. So I use a crude mental model that captures the fundamental features of the machine, and then run computational experiments to convince myself that my mental model, though incomplete, included enough details to accurately predict how my program runs.

Perhaps the most common use the scientific method to understand the behavior of a computer program is in debugging. If a program has a bug, that's usually a sign that the programmer's mental model was flawed. To uncover the flaw, the programmer will run a sequence of experiments, guided by knowledge of the consequences of his mental model -- his hypotheses -- until he finds the point where the actual behavior deviates from the behavior he expects. At that point, he has the data he needs to fix his mental model, and from there fix the program. Savvy programmers work hard to make sure that these tests are easy to run, often even including explicit tests of their hypotheses -- called assertions -- as part of the program text.

Second, the scientific method applies to the intersection of computer science with other disciplines where a precisely detailed model is not only inconvenient, but is also unknown. For instance, computer-human interface design must be partly experimental, because we don't really understand how people work. In studying performance trade-offs in the design of a system, there must be some set of sample workloads which one thinks are representative -- usually based on a set of actual workloads -- but the system designer usually doesn't really know enough to definitively describe the typical workload characteristics. And, of course, a large part of computational science involves building a program to make a prediction, and then checking against reality in order

In the way in which the scientific method is employed, there are similarities between computer science and mathematics. Many theorems start life as conjectures, created out of an incomplete mental model in the mind of the mathematician. The conjecture is tested against various examples that provide insight -- and is modified or rejected if it predicts the wrong thing. With luck, the conjecture will be right, and the examples will provide the insight necessary to devise a proof. When a physical system is described in mathematical terms, the observed behavior of the system may be a source of conjectures which can be turned into theorems; or the mathematical description may be the source of theorems which contradict experimental observation, thus leading to a modification of the basic description.

So if computer science is not primarily a scientific discipline, what is it? It's partly engineering, partly mathematics, and partly art...

And it's a lot of fun.