Module I: The mystery of the computer
(An Intel Xeon E7 v2 die, 15 cores, 4.3 billion 22nm transistors. Intel Newsroom Photo Gallery.)
Having learnt the fundamentals of the art of computer programming, an aspiring computer scientist ought to pause and reflect at the capabilities of this marvellous artefact that obediently executes our programs.
Copy and paste the following fragment of code into a console:
def test(m: Long) =
var i = 1L
var s = 0L
while i <= m do
s = s + i
i = i + 1
end while
s
end test
val NANOS_PER_SEC = 1e9
val test_start_time = System.nanoTime
test(4000000000L)
val test_end_time = System.nanoTime
val test_duration = test_end_time - test_start_time
println("the test took %.2f seconds".format(test_duration/NANOS_PER_SEC))
We observe the following:
the test took 1.06 seconds
(This on an 2022 Dell laptop running an 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz × 8 processor and 16 GiB of main memory.)
In just over one second, the machine has evaluated the sum of the first four billion positive integers. This means that the machine must make just under four loop iteration every nanosecond.
The speed of light in vacuum is roughly \(3.0\times 10^8\) meters per second. In one nanosecond, that is, \(1.0\times 10^{-9}\) seconds, light travels about 30 centimetres.
In other words, the computer can execute many operations in the interval of time it takes for light travelling from the screen to your eye.
It thus appears to be quite a powerful artefact that we have at our command.
But it is only a machine. How does it operate? By what principles?
How are such machines designed and built?
How does the machine accept our programs and do what we instruct it to do by means of, for example, the Scala programming language?
What is computation?
This is what we will set out to understand in Module I: The mystery of the computer, while learning further aspects of the art of computer programming.