Top Banner
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
18

Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Jun 04, 2018

Download

Documents

duonghanh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 2: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Brief Historical Overview

Already in 1930’s Alan Turing studied an abstract ma-

chine, Turing machine!

In 1940’s and 1950’s simpler kinds of machines, fi-

nite 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

Page 3: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 4: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Initially all Intel chips did all arithmetic using integers. Software pro-

grams were instructing the chip how to divide floating-point numbers

using integer arithmetic. The 1993 chips had these instructions inte-

grated 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

Page 5: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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 ac-

cording to their degree of difficulty

COMP 2600 — Introduction to Theory of Computation 5

Page 6: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 7: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 8: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Powers of Alphabet

Σk denotes the set of all strings of length k over Σ

Σk = Σ×Σ×·· ·×Σ︸ ︷︷ ︸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

Page 9: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 10: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Concatenation of Strings

If

x = a1a2 . . .am ∈ Σ∗

y = b1b2 . . .bn ∈ Σ∗

then

x · y = a1a2 . . .amb1b2 . . .bn

ε is the identity for concatenation:

ε · x = x · ε = x

Length:

|x · y|= |x|+ |y|

COMP 2600 — Introduction to Theory of Computation 10

Page 11: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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 1and 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 overany 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

Page 12: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 13: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

Page 14: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

A finite automaton modelling recognition of COMP2600

start C CO COM

COMP

COMP2COMP26COMP260COMP2600

C O M

P

2

600

COMP 2600 — Introduction to Theory of Computation 14

Page 15: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

Start state:

start

Accepting

state:

COMP2600

Transition:

COMP26COMP2600 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

Page 16: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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

����- $0 -2

@@R1

����$1 -

2

���1����

$2 -2

@@R1

����$3���1

��6

2

����� ��$4

��? 1, 2

Slide created by Ranald Clouston. Adapted by Katya Lebedeva.

COMP 2600 — Introduction to Theory of Computation 16

Page 17: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

• Σ = {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 foryour 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

Page 18: Introduction to Theory of Computation - Research School … · Introduction to Theory of Computation COMP2600 — Formal Methods for Software Engineering Katya Lebedeva Australian

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