270 likes | 395 Views
Information Science 2 -Finite State Automata and Turing Machines-. College of Information Science and Engineering Ritsumeikan University. Autumn : Week 14. Agenda. A Happy New Year to you all Terms and concepts from Week 13 Computation and (abstract) computational devices
E N D
InformationScience 2-Finite State Automata and Turing Machines- College of Information Science and EngineeringRitsumeikan University Autumn : Week 14
Agenda • A Happy New Year to you all • Terms and concepts from Week 13 • Computation and (abstract) computational devices • Finite (state) automata • Regular languages and expressions • Regular grammars • Turing machines
Random variables • Descriptive statistics • Mean, Variance • PDF, PMF, Histogram • (True) random numbers • Pseudorandom numbers (PRN) • PRN generator (PRNG) • Evaluating PRNG algorithms • Monte Carlo method • Simulation Recall concepts from Week 13
Today’s objective • Learn the concepts of abstract computational devices • After this lecture and study, you must be able to: • Understand the concepts of finite state automata, regular languages and expressions, regular grammars, and Turing machines • Understand and draw simple state diagrams of (finite) automations
Computation • Computation is a mapping of a binary input to a binary output. Solving a problem with computers then is finding a particular (“desired,” “required,” etc) mapping. For example, a decision problem is always a mapping from a given input to 0 or 1 (Yes or No) • (Abstract) computational devices are simplified models of real computations. Automata theory is the study of abstract computational devices • Finite (state) automata are devices used to model (analyze and compare) “small” (but not necessarily simple) computers. Turing machines are to model any computers • Regular languages, expressions, and grammars provide mathematics for finite automation
a POWER b a 0 0 start a b b b b a 1 0 a Why do we need models? • Consider a simple “computer:” • The lamp (printer, etc) is on if and only if both switches, a and b were flipped an odd number of times • A simple modelcan be used to analyze this computer: • Inputs: switches a and b • Actions:a for “flip switch a”, and b for “flip switch b” • States:0, 1 • Accepting (final, “good,” “desired,” or “Yes”) state:1
a 0 0 start a b b b b a 1 0 a Finite state automation (FSA) • We can now use the obtained model to analyze, for example, various inputs to our “computer:” • Input “aabb” State “0” • Input “abbb” State “1” • Input “aaaaa” State “0” • Input “aaaaab” State “1” • We can use similar diagrams (called state diagrams) to reason about and test much more complicated devices • State diagrams represent finite state automation (FSA) – a method to model computation
Formal definitions • An alphabetis a finite set of symbols • A languageL over an alphabet (written as L()) is any subset of the set of all possible strings over • The set of all possible strings, including the empty string denoted , is written as * • Example: • = {a, b} • * = {, a, b, ab, ba, aa, bb, aab, bba, …} • a language L1 can be defined as the set of strings of length less than or equal to 2:L1 = {, a, b, aa, ab, bb, ba}
FSA formal definition • A (deterministic) finite state automaton (FSA) is a 5-tuple M = Q, , , q0, F where • Q is a finite set of states • is an alphabet (for the input set) • : Q ×→ Q is a transition function • q0Q is the initial state • F Q is a set of accepting states • In state diagrams, states are denoted by circles, the accepting states by double circles, transitions by arrows, and the initial state by the arrow with no state on the left
c c, d d c s0 c s0 d c d d s1 s2 s1 s2 Simple example • Let M be the automaton with the input setA = {c, d}, state set S = {s0, s1, s2}, and accepting state set Y = {s1 , s2}. Draw a state diagramD = D(M) of M or or ... draw yourself a few other possible diagrams
Regular languages • The language LM of (or recognized by) FSA M = Q, , , q0, F is the set of all strings over that, starting from q0 and following the transitions as the string is read left to right, will reach an accepting state • Example: Not really formal… M: LM= {anbn: n is odd} • A regular language (over an alphabet ) is any language for which there exists a finite automaton that recognizes this language
Regular expressions • A regular expression is a mathematical model for defining a language. Regular expressions are similar to arithmetic expressions, but are defined recursively to work with symbols and strings • Formally, for an alphabet , regular expressions are ,, and any r . Other regular expressions for can be constructed using only the following operations: • Union:r1 + r2= L(r1) L(r2) for any r1, r2 • Concatenation:r1 • r2= L(r1) L(r2) • Repetition:r1*= (L(r1))* for any r1
Simple examples • Example 1: What language does 0*(0+ 1) represent? • It represents zero or more 0's followed by either 0 or 1. Therefore,L = {0, 1, 00, 01, 000, 001, 0000, 0001,…} • Example 2: Find a regular expression for the language of the FSA defined as follows: • The language must include all strings over {a, b} that contain an odd number of a's and an odd number of b's. Therefore,L = ((aa)*a(bb)*b + (bb)*b(aa)*a)*
Regular grammars • (Regular) grammars provide an alternative method for modeling (regular) languages • A grammar is formally defined as a 4-tupleG= V, T, S, P where • V is a finite set of variables • T is a finite set of symbols, called terminals • S is in V and is called the start symbol • P is a finite set of productions, which are rules of the form (i.e. if then ), where and are strings consisting of terminals and variables
a b S A b a Simple examples • Example 1: LetS → aA,A → abS | b,wherea, b T, A V , and A → abS | b is a “short-hand” for A → abS,A → b. Draw a state diagram of the corresponding FSA • Example 2: Find a regular grammar forL =aab*a.Solution: • S → aA • A → aB • B → bB • B → a
FSA, expressions, and grammars • FSA is easy to program but is hard to analyze • Regular expressions can be used to analyze FSA (e.g. using Set Theory). It is, however, not always easy to find a regular expression of the language of a particular FSA. On the other hand, it is not obvious how to generate the language using a regular expression • Regular grammars are convenient for language generation, but are often not easy to create, understand, and analyze Regularexpressions FSA Regulargrammars
Turing machines • Turing machines (first proposed by Alan Turing in 1937) are similar to FSA. Unlike FSA, they may be difficult to program but are (very) convenient to understand and analyze even (“reasonably”) complex computations ... Tape Read/Write Head Current State: Rules: Control Device
Turing machine: The idea ... Tape Read/Write Head Current State: Rules: Control Device • A Turing machine can do the following: • Write a character to the current tape cell • Move the Read/Write Head one cell to the left or right • Go into a new state • Its behavior depends only on the input (i.e. the character in the current tape cell) and the current state
Turing machine: Example ... a b b a Tape Read/Write Head Current State: A Rules: Control Device State Symbol | Write Move State Aa | a R A Ab | a R B Bb | a R B
Example (cont-d) ... a b b a Tape Read/Write Head Current State: A Rules: Control Device State Symbol | Write Move State A a | a R A Ab | aRB Bb | aRB
Example (cont-d) ... a b b a Tape Read/Write Head Current State: A Rules: Control Device State Symbol | Write Move State A a | a R A A b |aRB Bb | aRB
Example (cont-d) ... a a b a Tape Read/Write Head Current State: B Rules: Control Device State Symbol | Write Move State Aa |a R A A b |aRB Bb |aRB
Example (cont-d) ... a a a a Tape Read/Write Head Current State: B Rules: Control Device State Symbol | Write Move State Aa |a R A A b |aRB Bb | aRB
Example (cont-d) ... a a a a Tape Read/Write Head Current State: B Rules: Control Device State Symbol | Write Move State Aa |a R A A b |aRB Bb | aRB • Computation finishes (the machine stops) when there is no suitable rule
Summary of this lecture After this class, you are expected to know the following: • What is computation • What we need abstract computational devices for • What is FSA • What are regular expressions and grammars • What is a Turing Machine (and how it “works”)
Homework • Read these Power Point slides • There is no self-preparation assignment this time BUT review all the examples in these slides! There will be similar problems in your final exam • Learn the English terms new for you
Next class • Course overview and preparations for the final exam • Important terms and concepts of “Information Science 2”