Models of Computation lecture

Models of Computation

In this lecture we are going to learn about models of computation and computability.

We are following the goal of building a model of a computer.

Mathematics and Problem Solving

4. Models of Computation

David Gundry

Learning Outcomes

    Discuss what computation is
    1. Describe the mapping account of computation
    2. Give three examples of models of computation
    Create and reason about Finite State Machine
    1. Interpret a FSM diagram
    2. Interpret and use Kleene star notation for describing regular languages
    3. Determine whether a finite state machine accepts or rejects a string
    4. Describe the language that is accepted by a simple provided FSM
    5. Reason whether given simple problems can be decided by any finite state machine
    Create and reason about Rewriting Systems
    1. Check whether a transition is permitted within a given Rewriting System
    2. Generate derivations in a rewriting system and provide terminal words
    3. Generate and reason about the language generated by a rewriting system

Learning Outcomes

  1. Discuss what computation is
  2. Create and reason about Finite State Machine
  3. Create and reason about Rewriting Systems

Introduction

We usually think of computers as

  • Magical boxes with user-friendly interfaces
  • von Neumann architecture

But that's just what we're used to. For most of history, "computers" were human. Calculations were broken down into steps and then performed by teams of people.

We can also imagine computation being performed by other physical systems. Slime mould computes the shortest path, e.g. through a maze or a topographical map of the US. The conductive properties of a lump of carbon nanotubes when perturbed by small currents can be used to perform computation. Inputs are encoded into voltages and the output voltages is the 'result' of the computation.

Computation

Computers

Question:

What is a computer?

A diagram showing a CPU connected to a memory, both attached to an input device and an output device
CC BY-SA 3.0 Kapooht
A large room of people sitting at desks in rows
Image: Computer History Museum
Slime mould growing over a 3D plastic map of the United States

(Adamatzky, 2013)

A plastic slide with a lump of carbon nanotubes connected to several wires

(Dale et al., 2017)

Computation

The physical instantiation of the computation can vary

  • Transistors
  • Humans
  • Mould
  • Carbon Nanotubes
  • Buckets of water
  • The universe?

If so, how do we understand computation?

The Mapping account of computation

A physical system performs computation when there is a mapping between states of the system and computational state

Let's remove the physical world from this picture. What's left?

  1. States in a model
  2. Rules of transition

We will call this a formal system model

Computers perform computation by physically instantiating problems

We can also understand computation mathematically as a formal system

The Mapping account of computation

A diagram showing a mapping between changes in a model of computation (top) and changes in physical states of a system (bottom)

Overview

In this lecture we will see three models of computation.

The first model of computation we will look at is the Finite State Machine. We will see how finite state machines can be used to model certain kinds of computation. We will see how we can create finite state machines to perform computation such as accepting or rejecting input strings. We will also look at some of the limitations of finite state machines.

Next we will briefly look at Turing Machines and see some inherent limitations in the power of computation.

Finally we will look at string rewriting systems. Rewriting systems are formal systems, and understanding the mechanics of string rewriting will help us to understand formal logic over the next several lectures.

Overview

  1. Finite State Machines
  2. Turing Machines
  3. String Rewriting Systems

Finite State Machines

A finite state machine is a simple and useful model of computation, though one that has limitations on the computational problems that it can solve.

An abstract machine is a description of a computational system that can precisely defined in mathematics. There are various types of commonly discussed abstract machine. We will look at two in this lecture: Finite State Machines, and Turing Machines.

Finite State Machines

Turnstile Example

Finite State Machines let us model certain kinds of computational system. For example, imagine a coin-operated turnstile, like you see at the entrance to toilets in the London Underground. The turnstile starts as locked. If you enter a coin, it unlocks, allowing you to push through the turnstile. Once you've pushed through, it locks after you to require the next person to enter a coin before they can enter. This is represented in the following state diagram:

image/svg+xmlLockedUn-lockedCoinCoinPushPush

A finite state machine can be in one of a set of states. For example, 'locked' and 'unlocked' in the above example. When it receives an input symbol it transitions to a new state according to a set of rules. These rules describe:

  • The state the machine must be in for the rule to apply
  • The input symbol that triggers the rule
  • The new state the machine transitions to (this may be the same as its current state)
For example, in the above example we have the rule:
  • When the turnstile is in the 'locked' state
  • and it receives the 'coin' symbol
  • transition to the 'unlocked' state

Turnstile example

A photograph of a turnstile
image/svg+xmlLockedUn-lockedCoinCoinPushPush

CC BY-SA N/A 4.0 (Via Wikipedia)

Formalising an FSM

The basic components of a Finite State Machine are:

\( \Sigma \) - Input alphabet. This is a set of symbols that the FSM can receive as an input

\( S \) - Set of states the FSM can be in. This set is finite (hence the name Finite State Machine).

\( s_0 \) - Initial state; the state the machine begins in before it reads the first symbol.

\( \delta : S \times \Sigma \rightarrow S \) - Transition function; the rules that tell the machine what to do when it is in a given state and receives a given input symbol.

Components of an FSM

\( \Sigma \) - Input alphabet

\( S \) - Set of states

\( s_0 \) - Initial state

\( \delta : S \times \Sigma \rightarrow S \) - Transition function

Turnstile Example

\[ \Sigma \]
Input symbol
Coin
Push
\[ S \]
States
Locked
Unlocked
\[ \delta : S \times \Sigma \rightarrow S \]
StateInputGo to
LockedCoinUnlocked
UnlockedCoinUnlocked
.........

Input tape

We often think about what happens when an FSM receives a given sequence of input symbols. We will call the string of input symbols that the machine receives as the input tape. This term comes from the design of the Turing Machine (which we will see later on) which is described in terms of physical tapes.

For example, if the turnstile received the following inputs, what state would it be in?

CoinPushCoinPushPushCoin

We can work through a description of the turnstile FSM to find out that the machine would be in the 'Unlocked' state. Indeed, here is an interactive Finite State Machine tool. You can step through the computation below to see how each rule applies as the FSM works through the input tape.

Finite State Automaton Rules
Starting stateInput tape:
StateInputGo to
Finite State Automaton
Read head
Input tapeCPCPPC
Current stateLocked
Finite State Automaton Rules
Starting stateInput tape:
StateInputGo to
Finite State Automaton
Read head
Input tapeCPCPPC
Current stateLocked

Classify strings using an FSM

What would happen if we had no rule in our turnstile FSM to handle what happened if you were in the 'Unlocked' state and a coin was entered? We would not know what state to transition to, and the computation would crash. Thus we can design FSMs that crash on certain inputs.

We can then ask the question: what input tapes does a given machine crash on? Equivalently, what tapes does a given machine accept?

Let's take out two of the rules from our turnstile FSM. Now there is no rule to describe what happens if we are in the 'locked' state and receive the 'Push' input, or what happens if we are in the 'unlocked' state and receive the 'coin' input.

Now we see that the string we considered above CPCPPC causes the FSM to crash. We will say this string is rejected by the FSM.

Finite State Automaton Rules
Starting stateInput tape:
StateInputGo to
Finite State Automaton
Read head
Input tapeCPCPPC
Current stateLocked

Classify strings using an FSM

What tapes of the input alphabet can a given FSM accept?

Accept: Results in a valid state

Reject: Missing rule/transition when computing

Questions

  1. Are there any input tapes that the turnstile FSM would reject?
  2. How would you describe the set of all possible strings that the turnstile FSM accepts?
Finite State Automaton Rules
Starting stateInput tape:
StateInputGo to
Finite State Automaton
Read head
Input tapeCPCPPC
Current stateLocked

Languages

What strings are accepted and what strings are rejected by this FSM? We will call the set of accepted strings the language accepted by this FSM.

AcceptReject
CPP
CPCCPP
CPCPCCP
......

Different kinds of abstract machines can recognise different kinds of language.

Regular Languages

Abstract machines recognise a language (set of strings)

Finite state machines recognise regular languages, e.g.

FormulaExample strings
\( \{a^*\} \)$\epsilon$aaaaaa
\( \{a^*b^*\} \)$\epsilon$abaa
\( \{a^*ba^*\} \)babaaabaaabaa
\( \{(ab)^*\} \)$\epsilon$abababababab

Regular Language Notation

Empty String: \( \epsilon \) represents an empty string

Brackets: \( ( ... ) \) group symbols together

Kleene Star: \( * \) represents zero or more of preceding symbol/group

Question

Does language \( \{(a^*(bc)^*)*\} \) include:

  1. abca
  2. bcaabc
  1. aaabbc
  2. \( \epsilon \)

Limitations of Finite State Machines

We can reason about any computation in terms of the accepting or rejecting of given strings (though this is not the only way or always the most useful). That is, we can describe the computational power of an abstract model of computation in terms of the kinds of languages that it can accept.

Let's take the example of detecting palindromes. A palindrome is a string that is the same forwards as backwards. For example, the word 'racecar' is a palindrome.

Palindromes

Question

Can an FSM of finite complexity accept only palindromes (of any length)? e.g.

\[ 00 \]
\[ 0110 \]
\[ 010010 \]

Equivalent: Is the set of palindromes a Regular Language?

Palindromes

Question

Can an FSM accept only palindromes?

Answer: No

An infinitely long palindrome would require infinite memory

  • FSMs compute in a single pass
  • FSMs only have finite memory (=states)
Models of computation have limits on what they can compute

Turing Machines

Turing Machine Rules
Starting stateInput tape:
StateInputWriteGo toMove
Turing Machine
Read head
Tape010010
Current state Start
Time taken0

Turing Machines

Physical Turing machine model

A physical model of a turing machine. There is a tape on two motorised reels. Between the reels is a device that can read and write to the tape

CC BY 3.0 Rocky Acosta

Turing Machine Rules
Starting stateInput tape:
StateInputWriteGo toMove
Turing Machine
Read head
Tape010010
Current state Start
Time taken0

Decision Problem

Yes/no question - accepts/reject for all possible input tapes, e.g.

"Does the input tape contain 4-bit numbers that sum to 10?"
  1. Encode input on tape, e.g. 011000110001
  2. Abstract machine provides decision procedure

Any problem can be expressed as a decision problem

Halting Problem

Decision problem

Would the Turing Machine encoded on the input tape halt?

(or would it run forever?)

Provably undecidable

To decide, it would need to evaluate the Turing Machine and wait to see if it halts

There are Turing Machines which never halt

Church-Turing Thesis

No reasonable model of computation can decide languages that cannot be decided by a Turing Machine

Rewriting Systems

Over the next several weeks we are going to build directly on the idea of formal systems to model human reasoning using logic. However, all of mathematics might be understood as a kind of formal system.

When we are talking about something being 'formal' we mean something that obeys strict rules. If we make a formal model of a system, then we can only manipulate that model according to its rules. Take algebra for example. We are not allowed to rearrange the equations shown above however we like. For our answer to be valid we have to always follow the rules of algebra.

One type of formal system is a rewriting system.

A rewriting system is a set of rules that transforms strings into other strings

Rewriting Systems

Alphabets and Words

If $Σ$ is a finite alphabet of symbols, then let $Σ^*$ be the set of all finite length strings that can be formed using symbols from $Σ$

So given the alphabet \( Σ = \{a, b\} \) we have the set of words on $Σ$:

\[ Σ^* = \{a, b, aa, bb, ab, ba, aaa, \dots\} \]

$ \epsilon $ represents an empty string.

Each state in our rewriting system is a word on $Σ$, meaning it is a string formed of symbols in our alphabet

For example, we might have the words:

\[ A = aaa \]
\[ B = aba \]
\[ C = abb \]

Alphabets and Words

Let $Σ$ be the finite alphabet of symbols

\[ Σ = \{a, b\} \]

$\Sigma^*$ is the set of words on $\Sigma$:

\[ Σ^* = \{a, b, aa, bb, ab, ba, aaa, \dots\} \]

Rewriting Rules

The rules of a rewriting system allow us to transform one string into another by substitution. The following rule allows us to replace one instance of the symbol $a$ with $b$

\[ a ↷ b \]

We call such rules that operate on symbols in $\Sigma$, $\Sigma$ rewriting rules. A $Σ$ writing system is a finite list of such $Σ$ rewriting rules \( \alpha_1 ↷ \beta_1, \dots, \alpha_n ↷ \beta_n \)

$\Sigma$ Rewriting rules

Rewriting rules apply to a single substring anywhere in the word

Example

\[ a ↷ ab \]

Replace one instance of $a$ with $ab$.

There are 3 words derivable from $aaa$ using the rule \( a ↷ ab \)

\[ aaa ⇒ abaa \]
\[ aaa ⇒ aaba \]
\[ aaa ⇒ aaab \]

Transitions in a rewriting system

In a rewriting system, rewriting rules apply to only a single substring at a time. Thus if we had the rule $a \curvearrowright b$, and we had some word $\dots a\dots$, we could derive a new word by replacing that $a$ with $b$, and leaving the rest of the string untouched: $\dots b\dots$

If we can obtain a word by a single application of a rule in $P$, we will write this as:

\[ A ⇒_P B \]

Which we will read "$B$ can be obtained from $A$ in one step under rules $P$"

A derivation in rewriting system $P$ is a list of words $A_1, A_2, \\dots, A_n$ so that

\[ A_1 ⇒ A_2 ⇒ \dots ⇒ A_n \]

We allow derivations of length zero. So we will always have $A ⇒^* A$

Derivation

Transition

\[ A ⇒_R B \]

Derive word $B$ from word $A$ following rewriting rules $P$

Derivation

A derivation is a list of words $A_1, A_2, \dots, A_k$ so that

\[ A_1 ⇒ A_2 ⇒ \dots ⇒ A_n \]

Which we will write \( A_1 ⇒^* A_n \)

Derivation Question

Given the rewriting system

\[ Σ = \{ a, b, X \} \]
\[ P = \{ X ↷ ab, X ↷ aXb \} \]

Is it possible to derive $aabb$ from $X$?

Yes, here is an example derivation:

\[ X \]
\[ aXb \]
\[ aabb \]

Derivation Question

Consider the rewriting system

\[ Σ = \{ a, b, X \} \]
\[ P = \{ X ↷ ab, X ↷ aXb \} \]

Question

Is it possible to derive $aabb$ from $X$?

(i.e. is \( X ⇒_P^* aabb \) true?)

Languages

Languages

What is a language?

A formalisable set of words or strings

  1. Decision problem
  2. Programming language
  3. Regular expression
  4. Specifications (e.g. URIs)
  5. Models of natural language

Grammars

Definition: A grammar is a rewriting system $P$ together with an initial word $I$. Such a grammar $(P, I)$ generates the language

A word $W$ is terminal in rewriting system $P$ if there is no other words that can be derived from that word.

A language is a set of all possible terminal words generated from a grammar. That is, given initial word $I$ in $\Sigma^*$ and set of $\Sigma$ rewriting rules, the language $L$ is defined as the set of all words derivable from $I$ from which no further derivation is possible.

For example, the initial word $X$ and rules

\[ X ↷ ab \]
\[ X ↷ aXb \]

Generates the language \( \{ab, aabb, aaabbb, aaaabbbb, ... \} \). Note that the symbol $X$ never appears in this language as due to the rules above $X$ can never be in a terminal word. Thus while words such as $aXb$ and $aaXbb$ can be derived from this initial word, it is not included in the language this grammar defines.

Grammar

A grammar is a pair:

  1. Initial word
  2. Rewriting rules

A grammar defines a language, e.g.

\[ I = X \]
\[ P = \{ X ↷ ab, X ↷ aXb \} \]

Only terminal words are included in a language

Word in language
a
ab
aabb
aaabbb
aaaabbb

Example Language

Consider the alphabet \( Σ = \{ a, b \} \) and the $\Sigma$ rewriting system \( P = \{ ab ↷ a \} \). Lets say we have the initial word \( I = abbb \). Note that $I ∈ Σ^*$.

We can consider the language or the subset of $\Sigma^*$ defined by this grammar. In this case, the language contains exactly one string: $a$. Here $a$ is the only terminal word in the grammar.

What is the language?

You have the grammar

\[ I = abc \quad P = \{ a ↷ b, a ↷ d, b ↷ c \} \]

What is the language generated by this grammar?

We attempt all possible derivations and find the unique terminal words:

\[ (abc → bbc → cbc → ccc) \]
\[ (abc → bbc → bcc → ccc) \]
\[ (abc → acc → bcc → ccc) \]
\[ (abc → dbc → dcc) \]
\[ (abc → acc → dcc) \]

The language generated by this grammar is

\[ L = \{ ccc, dcc \} \]

Exercise

What is the language generated by this grammar?

\[ I = abc \]
\[ P = \{ a ↷ b, a ↷ d, b ↷ c \} \]

Words in language must be:

  1. Derived from $I$
  2. Terminal (no further derivation possible)

Summary

Summary

Finite State Machines

Components

Input alphabet

States

State transition rules

Regular languages

Kleene star notation

\( \{(ab)^*\} \)
image/svg+xmlLockedUn-lockedCoinCoinPushPush

Turing Machines

Universal model of computation

Rewrite symbols on tape

Move left or right

Decision Problem

Any problem can be represented as a decision problem

A physical model of a turing machine. There is a tape on two motorised reels. Between the reels is a device that can read and write to the tape

Some problems are uncomputable (e.g. Halting Problem)

Rewriting Systems

Rewrite one word into another by replacing a substring

A rewriting rule is written \( \alpha ↷ \beta \) where $\alpha, \beta$ are in $\Sigma^*$

Language

A grammar is a initial word and a set of rewriting rules

  • By repeatedly applying the rules, the grammar generates a language
  • A language contains only terminal words
LecturePracticalAssessment