Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Abstract

By the end of this material, readers will understand the intimate relationship between computers and programming, and appreciate the evolutions and motivations of programming languages. They will learn about basic computer architecture, binary data representation, and the structure of a Python program.

Computer

What is a computer?

A calculator that is bigger and more advanced?

Calculator app

Figure 1:A calculator on a computer.

If so, is abacus the first computer ever invented?

Abacus

Figure 2:Abacus - an ancient mechanical computing device.

Is your smartphone a computer?

Run the following cell and click the play button to ask AI for some hints:[1]

%%hermes
What defines a computer? Give me some hints but not the answer.

It might help to know...

What is the architecture of a computer?

A computer contains three main hardware components:

  • Input device

  • Processing unit

  • Output device

Peripherals

Peripherals

Figure 3:Computer peripherals.

Input and output devices connected to a computer are called peripherals.
They allow users to interact with the computer in different ways.

Solution to Exercise 1 #
  • 3D printer available at CityU

%%hermes
Summarize what an output device of a computer is and explain briefly why 
a monitor and a speaker are examples?

An output device is a hardware component that converts processed data from the computer into a form perceivable by humans (or other systems).

  • A monitor displays visual data (text, images, video) — converting digital signals into light on a screen.

  • A speaker produces sound — converting digital audio signals into audible waves.

Both take internal digital results and present them to the user, which is exactly what an output device does.

Solution to Exercise 2 #
  • 3D scanner available at CityU

%%hermes
Summarize what an input device of a computer is and explain briefly why 
a keyboard and a mouse are examples?

An input device is a hardware component that captures data or commands from the outside world (usually the user) and sends it into the computer for processing.

  • A keyboard translates key presses into digital signals representing characters and commands.

  • A mouse translates hand movements and clicks into digital signals controlling a cursor pointer.

Both convert human actions into data the computer can process — which is exactly what an input device does.

%%hermes
Is headset an input device or an output device? Give me hints but not the answer.

Here are some hints:

  • A headset has two distinct parts — think about what each one does separately.

  • One part lets you hear audio from the computer. What category does that fit?

  • The other part captures your voice. What category does that fit?

Think about it — does one label cover all of it, or could there be a third option?

Solution to Exercise 3 #
  • Solid-state dive or Hard disk

  • CD/DVD Rom (writable)

  • Touch screen

Central Processing Unit

An Intel CPU

(a)An Intel CPU

An AMD CPU

(b)An AMD CPU

Figure 4:Central processing units (CPUs) on motherboards.

The brain of a computer is its processor or the Central Processing Unit (CPU). As shown in Figure 4, it is located on the motherboard and connected to different peripherals using different connectors.

For instance, you can check the CPU of your Jupyter Server by running the following shell command escaped using !:

!lscpu
%%hermes
What does the above cell do?

The above cell runs the !lscpu shell command, which displays detailed information about the CPU (Central Processing Unit) of the Jupyter Server — including its architecture, number of cores, model name, clock speed, and cache sizes. The ! prefix tells Jupyter to execute it as a terminal command rather than Python code.

Two important components in the CPU are:

  • Arithmetic and Logic Unit (ALU): Performs arithmetics like a calculator but for binary numbers. (More on this later.)

  • Control Unit (CU): Directs the operations of the processor in executing a program.

To visualize how CPU works, run the CPU Simulator below.

  • Note that all values are zeros in the RAM (Random Acess Memory) initially.

  • Under Settings, click Examples→\to Add two numbers. Observe that the values in the RAM have changed.

  • Click Run at the bottom right-hand corner.

As you can see, in addition to performing arithmetic calculations,

  • a computer can be programmed

  • to perform different tasks.

Can we simply say a computer is a programmable device? If so, what is programming?

%%hermes
Explain very briefly how a universal machine look like.

Done. Added a new markdown cell explaining the universal machine — three components (tape, read/write head, rule set) and why it’s “universal.” It sits right after the %%hermes question cell.

%%hermes
How the problem of decidability has to do with definability and computability?

Programming

What is programming?

Solution to Exercise 4 #

The first six lines of binary sequences in the RAM. The last line Ends the program.

%%hermes
As a hint, summarize what a machine language is and give an example of a program
in machine language.

Done. Added the machine language hint as a markdown cell right after the %%hermes question, explaining binary opcodes with a concrete example that ties back to the CPU simulator’s RAM.

The CPU is capable of carrying out

  • a set of instructions such as Add, Subtract, Store, etc.,

  • for some numbers stored in the RAM.

Both the instructions and the numbers are represented as binary sequences.

Why computer uses binary representation?

Two programmers operating ENIAC.

Figure 5:Programmers controlling the switches of ENIAC.

Notebook Cell
### BEGIN SOLUTION
2 ** 10 # because there are that many binary sequences of length 10.
### END SOLUTION
%%hermes
As a hint, explain the multiplication rule in combinatorics.

There are International Standards for representing characters:

  • ASCII (American Standard Code for Information Interchange) maps English letters and some other symbols to 8-bits (8 binary digits, also called a byte). E.g., A maps to 01000001.

  • Unicode can also represent characters in different languages such as Chinese, Japanese...etc.

There are also additional standards to represent numbers other than non-negative integers:

%%hermes
In addition to the ones in the above cell, what are other standards for 
representing characters/numbers in computers.

Generations of programming languages

Are we going to start with machine language? Start with learning 2’s complement and the binary codes for different instructions?

No. Programmers do not write machine codes directly because it is too hard to think in binary representations.

Instead, programmers write human-readable mnemonics such as ADD, SUB, ...
This is called the assembly language. An example is shown in Figure 6.

Assembly language

Figure 6:A Code written in an assembly language.

%%hermes
What is the assembly language most commonly used by programmers and what is its
main application?
%%hermes
Explain the different instructions used in the different instruction set 
architectures including AMD, ARM, and RISC-V.

Are you going to learn an assembly language?

Both machine language and assembly language are low-level languages which are

  • difficult to write for complicated tasks (requiring many lines of code), and

  • platform-specific, i.e.,

High-level Language

What is a high-level language?

The art of programming

Programmers often write in human-readable languages such as

  • Python

  • Rust

  • C/C++

  • Java

  • JavaScript

  • Typescript

  • Pascal

  • Basic

  • HTML

  • PHP

  • ...

called high-level languages.

  • A program written in a high-level language gets converted automatically to a low-level machine code for the desired platform.

  • This abstracts away low-level details that can be handled by the computer automatically.

For instance, a programmer needs not care about where a value should be physically stored if the computer can find a free location automatically to store the value.

Different high-level languages can have different implementations of the conversion processes:

  • Compilation means converting a program well before executing the program.
    E.g., C++ and Java programs are compiled.

  • Interpretation means converting a program on-the-fly during the execution of a program.
    E.g., JavaScript and Python programs are often interpreted.

%%hermes
Explain in one or two paragraphs whether Python is really an interpreted
language, given that it also has a compiler and, recently, a JIT compiler, and
it can be run as a script like a scripting language.

You will learn to program in Python, which is a popular language. (See TIOBE (The Importance of Being Efficient) Programming Community Index).

%%hermes
What is the popularity of Python according to the TIOBE?

How does a Python program look like?

%%pytutor --input 2026
import datetime  # library to obtain current time

cohort = input("In which year did you join CityU? [e.g., 2020]")
year = (
    datetime.datetime.now().year # current year
    - int(cohort)
    + (1 if datetime.datetime.now().month >= 9 else 0) # Why use current month?
)
print("So you are a year", year, "student.")
Loading...

A Python program contains statements just like sentences in natural languages. E.g.,

cohort = input("In which year did you join CityU? ")

which obtains some information from user input.

For the purpose of computations, a statement often contains expressions that evaluate to certain values. E.g.,

input("In which year did you join CityU? ")

is an expression with the value equal to what you input to the prompt.
That value is then given the name cohort.

Expressions can be composed of the following objects:

  • Functions such as input, now, and int, etc., which are like math functions the return some values based on its arguments, if any.

  • Literals such as the string "In which year did you join CityU? " and the integer 1. They are values you type out literally.

  • Variables such as cohort and year, which are meaningful names to values.

To help others understand the code, there are also comments that start with #.
These are meant to explain the code to human but not to be executed by the computer.

Solution to Exercise 6
  • Programming using natural language. A step towards this direction: Vibe coding.

  • Write programs that people enjoy reading, like literate programming. A step towards this direction: nbdev.

    Literate programming

  • Specify a goal and let an AI agent plan, code, execute, debug, and iterate autonomously — agentic coding. This goes beyond asking AI to write code: the agent forms a plan-execute-reflect loop.

%%hermes
What do you think the next generation programming should be?
Loading...
🌿 Fork/new: main (will create on click)

Agentic Coding

What is agentic coding?

In traditional programming (3rd generation), you write step-by-step instructions for the computer to follow. The computer executes them literally but has no understanding of your goal.

In agentic coding, you specify a goal — “build a webpage that shows weather data” — and an AI agent plans, writes code, runs it, debugs errors, and iterates until the goal is met. You shift from writing every line to specifying outcomes and supervising the process.

Table 1:Comparing programming paradigms

GenerationParadigmYou say...Computer does...
1stMachine language01000001 (binary)Executes the exact binary operation
2ndAssemblyADD R1, R2Adds two registers
3rdHigh-level (Python)for i in range(10): print(i)Loops and prints — follows your steps
4th?Agentic“Create a graph showing prime number distribution”Plans, codes, runs, debugs, delivers

How does an agent work?

An agentic coder follows a plan-execute-reflect loop:

  1. Plan — Break the goal into sub-tasks

  2. Write — Generate code for each sub-task

  3. Execute — Run the code and observe output or errors

  4. Reflect — If errors or incomplete results, revise and repeat

The key difference from just asking AI to “write code” is the iteration loop: The agent runs its own code, reads error messages, and fixes problems autonomously. You act as the product manager, not the line-by-line implementer.

Try it yourself

Run the cell below. Describe a small programming task in natural language and observe how the AI agent responds:

%%hermes
Task: Write a Python function that takes a list of words and returns a 
dictionary counting the frequency of each word, case-insensitive.
Then test it with ["Hello", "World", "hello", "WORLD", "Python", "PYTHON"].
Loading...
↻ Session: main (ACP: 1e68edf8-554…)
Solution to Exercise 7 #
  • Agentic coder: Quick data analysis, web scraping, generating boilerplate, exploring new libraries — tasks where speed matters more than perfect control.

  • Traditional Python: Core algorithms for assignments, code where you need to understand every line for learning, or debugging when something goes wrong — tasks where understanding is the goal.

Footnotes
  1. You can run a cell by selecting the cell and press Shift + Enter.

  2. Click me to see the hints.

  3. To edit a markdown cell, double click the cell until you see a cursor. Run the cell to render the markdown code.

  4. The CPU simulator follows the von Neumann architecture, which realizes Turing’s conception of the stored-program computer, where program and data are stored in the same memory. This is in contrast to the Harvard architecture, which uses separate memories for program and data.

References
  1. Turing, A. M. (1937). On Computable Numbers, with an Application to the Entscheidungsproblem. Proceedings of the London Mathematical Society, s2-42(1), 230–265. 10.1112/plms/s2-42.1.230
  2. von Neumann, J. (1993). First draft of a report on the EDVAC. IEEE Annals of the History of Computing, 15(4), 27–75. 10.1109/85.238389