Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering

Katya Lebedeva Australian National University Semester 2, 2016 Slides created by Katya Lebedeva

COMP 2600 — Introduction to Theory of Computation

1

Brief Historical Overview

Already in 1930’s Alan Turing studied an abstract machine, Turing machine!

In 1940’s and 1950’s simpler kinds of machines, finite automata, were studied. In the late 1950’s Noam Chomsky began his study of formal grammar.

In 1969 Stephen Cook separated problems that are “intractable” (also called “NP-hard”).

COMP 2600 — Introduction to Theory of Computation

2

http://www.nytimes.com/1994/11/24/business/company-news-flaw-undermines- accuracy-of-pentium-chips.html

COMP 2600 — Introduction to Theory of Computation

3

Initially all Intel chips did all arithmetic using integers. Software programs were instructing the chip how to divide floating-point numbers using integer arithmetic. The 1993 chips had these instructions integrated into them. This makes calculations much faster. In 1994 Thomas R. Nicely discovered that the processor could return incorrect decimal results when dividing large prime numbers. http://www.trnicely.net/pentbug/bugmail1.html. The replacement of flawed chips costed Intel US$475 million! Intel CEO Andy Grove: “Intel survived the crisis and was made stronger by it. We dramatically improved our validation methodology to quickly capture and fix errata, and investigated innovative ways to design products that are error-free right from the beginning.” http://www.techradar.com/au/news/computing-components/processors/pentium-fdiv- the-processor- bug-that- shook- the-world- 1270773

COMP 2600 — Introduction to Theory of Computation

4

Three Major branches of Theory of Computation 1. Automata Theory deals with definitions and properties of computation models. Examples:

• Deterministic Finite Automata (July 18, July 20) • Nondeterministic Finite Automata (July 22) • Context-Free Grammars (July 27) • Turing Machines (August 1, August 3, August 5) 2. Computability Theory - the study of decidability - classifies problems as being solvable or unsolvable (August 5) 3. Complexity Theory - the study of intractability - classifies problems according to their degree of difficulty

COMP 2600 — Introduction to Theory of Computation

5

Basic Definitions of Automata Theory Alphabet is a finite, nonempty set of symbols Examples:

Σ1 = {0, 1} Σ2 = {a, b, . . . , z} Σ3 = {A, B, . . . , Z}

COMP 2600 — Introduction to Theory of Computation

6

String (word) is a finite sequence of symbols chosen from some alphabet

01011 is a string from Σ1 gobbledygook is a string from Σ2 • Empty string is the string with no symbols ε can be chosen from any alphabet! • Length of a string the number of positions for symbols in the string (“number of symbols” is often said though)

|01011| is 5 and not 2 |gobbledygook| is 12 and not 8 |ε| is 0

COMP 2600 — Introduction to Theory of Computation

7

Powers of Alphabet

Σk denotes the set of all strings of length k over Σ Σk = Σ × Σ × · · · × Σ | {z } k times

Σ0 = {ε} for all Σ For Σ1 = {0, 1},

Σ11 = {0, 1} Σ21 = {00, 01, 10, 11}

COMP 2600 — Introduction to Theory of Computation

8

Closure of an alphabet Σ:

Σ∗ is the set of all strings over Σ Σ∗ = Σ0 ∪ Σ1 ∪ Σ2 ∪ . . . The set of non-empty strings from alphabet Σ:

Σ+ = Σ1 ∪ Σ2 ∪ Σ3 ∪ . . . Hence Σ∗ = Σ+ ∪ {ε}

Note: All strings in Σ∗ and Σ+ are finite.

Σ∗ and Σ+ are infinite sets. COMP 2600 — Introduction to Theory of Computation

9

Concatenation of Strings If

x = a1 a2 . . . am ∈ Σ∗ y = b1 b2 . . . bn ∈ Σ∗ then

x · y = a1 a2 . . . am b1 b2 . . . bn ε is the identity for concatenation: ε·x = x·ε = x Length:

|x · y| = |x| + |y| COMP 2600 — Introduction to Theory of Computation

10

Language

L over Σ is any subset of Σ∗ (i.e. L ⊆ Σ∗ ) • set of all English words is a language over {A, B, . . . , Z, a, d, . . . , z} • {ε, 01, 0011, 000111, . . . }, i.e. all strings with equal number of 0 and 1 and with all 0’s preceeding 1’s, is a language over {0, 1} • 0/ , the empty language, is a language over any alphabet • {ε}, the language consisting of only the empty string, is a language over any alphabet Note that a language may be infinite. Note that L is also a language over any alphabet that is a superset of Σ. COMP 2600 — Introduction to Theory of Computation

11

Finite State Automata Neurophysiologists Warren S. McCullough and Walter Pitts published in 1943 the paper “A Logical Calculus of the Ideas Immanent in Nervous Activity” that is considered as a seminal contribution to the theory of automata. Nowadays FSA are a useful model for many important kinds of hardware and software, such as:

• software for digital circuits • software for validating protocols • lexical analizers

COMP 2600 — Introduction to Theory of Computation

12

State is a snapshot of a system’s history The advantage of having finite number of states is that we can implement the system with fixed set of resources.

An automaton works as follows:

• it is always in one of finitely many states at a time • starts in some state • changes state in response to an external input (i.e. makes a transition) • accepts input by ending in an accepting (also called final) state

The accepted strings constitute the language defined by the automaton!

COMP 2600 — Introduction to Theory of Computation

13

A finite automaton modelling recognition of COMP2600 C

start

O C

M CO

COM

P

COMP

2 0 COMP2600

0 COMP260

COMP 2600 — Introduction to Theory of Computation

6 COMP26

COMP2

14

start Start state:

COMP2600 Accepting state: 0 COMP260 Transition:

COMP26

When the FA is in state COMP26 and it sees a “0” in the input, it moves to state COMP260 and advances on the input.

COMP 2600 — Introduction to Theory of Computation

15

Vending Machine

• accepts $1 and $2 coins • refunds all money if more than $4 is added • is ready to deliver if exactly $4 has been added  1, 2 ?     2 2 - $0 - $2 - $4     1 1 @    6@ R @ R @ 1 1 - $3 $1 2    2

Slide created by Ranald Clouston. Adapted by Katya Lebedeva.

COMP 2600 — Introduction to Theory of Computation

16

• Σ = {1, 2} • The start state is “$0”. This is indicated by the → at the left of it. • At the accepting state “$4” (double circled) you have the exact credit for your purchase Which of the following strings does this automaton accept?

• the empty string ε × • 22 X • 1222 × • 1222221111 X

Slide created by Ranald Clouston. Adapted by Katya Lebedeva.

COMP 2600 — Introduction to Theory of Computation

17

Finite Automaton and Language • each FA defines a language: the set of all strings that result in a sequence of state transitions from the start state to an accepting state

• each string is a sequence of input labels along the path from the start state to an accepting state

• languages that can be described by FA are regular languages The study of FA and the study of formal languages are therefore linked:

• given a FA, find the language that is accepted by this automaton • given a language, find the FA that accepts this language

COMP 2600 — Introduction to Theory of Computation

18