Fundamentals of Informatics

Slides:



Advertisements
Similar presentations
Finite-State Machines with No Output Ying Lu
Advertisements

CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Finite Automata with Output
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
CS21 Decidability and Tractability
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
CS5371 Theory of Computation
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Finite Automata Chapter 5. Formal Language Definitions Why need formal definitions of language –Define a precise, unambiguous and uniform interpretation.
Topics Automata Theory Grammars and Languages Complexities
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Great Theoretical Ideas in Computer Science.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
Lecture 03: Theory of Automata:08 Finite Automata.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
REGULAR LANGUAGES.
CSC312 Automata Theory Lecture # 2 Languages.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Lecture 05: Theory of Automata:08 Kleene’s Theorem and NFA.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
Great Theoretical Ideas in Computer Science.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
CHAPTER 1 Regular Languages
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
Lecture # 12. Nondeterministic Finite Automaton (NFA) Definition: An NFA is a TG with a unique start state and a property of having single letter as label.
CS 203: Introduction to Formal Languages and Automata
Fundamentals of Informatics Lecture 3 Turing Machines Bas Luttik.
Deterministic Finite Automata COMPSCI 102 Lecture 2.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Lecture 04: Theory of Automata:08 Transition Graphs.
using Deterministic Finite Automata & Nondeterministic Finite Automata
Great Theoretical Ideas in Computer Science for Some.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Deterministic Finite Automata Nondeterministic Finite Automata.
L ECTURE 3 T HEORY OF AUTOMATA. E QUIVALENT R EGULAR E XPRESSIONS Definition Two regular expressions are said to be equivalent if they generate the same.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
Lecture 14: Theory of Automata:2014 Finite Automata with Output.
Lecture #4 Thinking of designing an abstract machine acts as finite automata. Advanced Computation Theory.
Theory of Computation Automata Theory Dr. Ayman Srour.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Lecture Three: Finite Automata Finite Automata, Lecture 3, slide 1 Amjad Ali.
CS314 – Section 5 Recitation 2
Theory of Computation Lecture #
Deterministic Finite Automata
Chapter 2 FINITE AUTOMATA.
Deterministic Finite Automata
Some slides by Elsa L Gunter, NJIT, and by Costas Busch
THEORY OF COMPUTATION Lecture One: Automata Theory Automata Theory.
4b Lexical analysis Finite Automata
Deterministic Finite Automaton (DFA)
4b Lexical analysis Finite Automata
Chapter 1 Regular Language
Recap lecture 19 NFA corresponding to Closure of FA, Examples, Memory required to recognize a language, Example, Distinguishing one string from another,
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

Fundamentals of Informatics Lecture 2 Finite Automata and Regular Expressions Bas Luttik

What are the fundamental capabilities and limitations of computing devices? Derived questions: What is a computing device? What is computation? What does it mean to compute something? How can we explore the capabilities and limitations without being able to experiment? Fundamental is key.

Automata Goal: to study automata from conceptual point of view. Abstract from implementation details (which is not to say that these are not important). Coming 3 lectures: study theoretical model of automaton/computer Today: simple (not very powerful) type of automata (vending machines, turnstiles, etc.) Friday and next week: Turing machine as the theoretical model of computer

The OV chip card automaton The gate can be open or closed (i.e., it has two ‘observed’ states). When the gate is closed and the machine detects a valid chip card, it opens. When the gate is open and someone passes through, it closes. We (only) consider the observable behaviour of the chip card automaton. The automaton, in this representation, has a one-bit memory. Closed Open pass chip card

A simple vending machine 5 10+ insert 5 insert 10 close return From the outside, we cannot really see the difference between the state labelled 0 and the state labelled 5.

Definition A finite automaton consists of A finite collection of states exactly one of these states is marked to be the initial state some states are marked to be accepting states A finite alphabet of input symbols A transition table determines a next current state for every possible combination of current state and input symb Example: a b q0 q1 q2 q3 states: q0, q1, q2, q3 initial state: q0 accepting states: q0, q1, q2 input symbols: a, b transition table: Widespread use: Hardware design Software design Linguistics (grammar) Biology (neurological systems) Business process optimisation ...

State-transition diagram states: q0, q1, q2, q3 initial state: q0 accepting states: q0, q1, q2 input symbols: a, b transition table: Example: a b q0 q1 q2 q3 Accepting states are denoted by double circles. The initial state has a small incoming arrow Transitions are denoted by labeled arrows Non-accepting states are denoted by single circles. We prefer presentation as a state-transition diagram: a a a q0 q1 q2 q3 b b b a, b

Exploring automata Consider Automaton 10 at http://www.win.tue.nl/~wstomv/edu/2is80/explore-automata/. Can we reconstruct it by exploration? If we, in addition, know that the automaton has 4 states, then we can completely reconstruct it: q0 q2 q3 q1 a b Without extra knowledge, we could never reconstruct the automaton simply by exploring it. But if we know that it only has four states, then complete exploration can be done with the following sequences: ε- a+ b- bb+ bba- aa- bbab- bbb+ ab- abb+ aab- ba- bab-

Definition A finite automaton consists of A finite collection of states exactly one of these states is marked to be the initial state some states are marked to be accepting states A finite alphabet of input symbols A transition table determines a next current state for every possible combination of current state and input symb Example: a b q0 q1 q2 q3 states: q0, q1, q2, q3 initial state: q0 accepting states: q1, q3 input symbols: a, b transition table:

Definition A finite automaton consists of A finite collection of states exactly one of these states is marked to be the initial state some states are marked to be accepting states A finite alphabet of input symbols A transition table determines a next current state for every possible combination of current state and input symb Note: finite automata (as defined above) are deterministic: every state has exactly one outgoing transition per input symbol! transition tables may not have empty entries.

A simple vending machine 5 10+ insert 5 insert 10 close return Examples of ‘open door’ sequences: insert 5, insert 5 insert 10 insert 10, close insert 10 insert 5, insert 10, close, insert 5, insert 5 …

Language accepted by an automaton To determine whether a finite automaton accepts a sequence of input symbols: Let the initial state be the current state. Repeat: take the left-most symbol from the sequence, and look up in the transition table what should be the new current state after processing the symbol. When there are no symbols left in the sequence, check if the current state is an accepting state. If so, then the automaton accepts the sequence; otherwise, it does not. The language of an automaton is the set of all sequences of input symbols it accepts.

Example a a a q0 q1 q2 q3 b b b a, b a a b b The string is: accepted! Accepted language consists of all strings with less than three a’s. The string is: accepted!

Example a a a q0 q1 q2 q3 b b b a, b a a b a The string is: Accepted language consists of all strings with less than three a’s. The string is: not accepted!

Example a a a q0 q1 q2 q3 b b b a, b Accepted sequences: aabb ε (the empty sequence) bbbbb aabbbbb … Non-accepted sequences: aaba aaab aaababababa bababa … Accepted language consists of all strings with less than three a’s. What is the language accepted by this automaton?

Designing Finite Automata Example 1 Design a finite automaton (with input symbols a and b) that accepts the language consisting all sequences with at least two a’s. a b a, b

Designing Finite Automata Example 2 Design a finite automaton (with input symbols a and b) that accepts the language consisting all sequences with an even number of b’s. a b

Designing Finite Automata Example 3 Design a finite automaton (with input symbols a and b) that accepts the language consisting all sequences with at least two a’s and an even number of b’s. even number of b’s two a’s detected a b a

Designing Finite Automata Exercise Design a finite automaton (with input symbols a and b) that accepts the language consisting all sequences with the pattern aa and an even number of b’s. even number of b’s subsequence aa detected a b a

Application: password policy A strong password has length greater than or equal to 8 contains one or more uppercase characters contains one or more lowercase characters contains one or more numeric values contains one or more special characters The above describes the language of strong passwords. Given the rules above it is straightforward to construct a finite automaton accepting exactly all strong passwords (and no weak passwords).

Regular expressions A regular expression is an expression that can be obtained by a number of applications of the following rules: input symbols a, b, c, 0, 1, … are regular expressions; if r1 and r2 are regular expressions, then so is their concatenation r1r2 and their sum r1+r2; and if r is a regular expression, then so is its iteration r*. Examples: a* consists of the sequences ε, a, aa, aaa, aaaa, … (a+b)*(aaa)(a+b)* consists of all sequences with the pattern aaa a*(ba*ba*)* consists of all sequences with an even number of b’s

Example regular expressions Exercise (non-trivial!): Give a regular expression for the language consisting all sequences over a, b, with an even number of b’s that contain the pattern aa. a*(ba*ba*)*(aa)a*(ba*ba*)* + a*ba*(ba*ba*)*(aa)a*ba*(ba*ba*)*

Applications E-mail addresses: [a-z0-9._%-]+@[a-z0-9.-]+.[a-z]{2,4} [a-z0-9._%+-] abbreviates a+…+z+0+…+9+.+%+- r+ abbreviates rr* r{2,4} abbreviates rr+rrrr Valid dates: (19+20)[0-9][0-9]-(0[1-9]+1[012])-(0[1-9]+[12][0-9]+3[01]) Credit card numbers: (4[0-9]{12}([0-9]{3}+ε)? # Visa + 5[1-5][0-9]{14} # MasterCard + 3[47][0-9]{13} # American Express + 3(0[0-5]+[68][0-9])[0-9]{11} # Diners Club + 6(011+5[0-9]{2})[0-9]{12}       # Discover + (2131+1800+35[0-9]{3})[0-9]{11}    # JCB …

Kleene’s theorem (1956) There is a direct correspondence between the languages described by a regular expression, and those accepted by a finite automaton: every language described by a regular expression is accepted by some finite automaton and, moreover, In fact, there are straightforward methods for constructing a finite automaton that accepts the language denoted by a regular expression, and associating a regular expression with a finite automaton. So: the validity of e-mail addresses, dates, credit card numbers can be checked with a finite automaton! every language accepted by a finite automaton is described by a regular expression Stephen Kleene (1909-1994) Disclaimer: for this result it is necessary to add symbols ε and Ø denoting the empty language and the language containing the empty string to the language of regular expressions; we left them out for simplicity.

Regular languages Languages accepted by a finite automaton (or, equivalently: described by a regular expression) are called regular. Fundamental question: Is every language regular? Consider, e.g., the language of marked palindromes consisting of all sequences of the shape sms-1 in which s is a sequence of symbols, m is a special marker symbol and s-1 is the reverse of s. There is no finite automaton that accepts the language of marked palindromes. So, the answer to the above fundamental questions is: NO!

Some concluding remarks Variations on the definition of finite automaton (e.g., Moore machines, Mealy machines, …) are particularly relevant in hardware design. We have discussed so-called deterministic finite automata by requiring a complete transition table (for every combination of a state and an input symbol there is a next state). This requirement can be relaxed, yielding non-deterministic finite automata. Finite state automata are useful to model devices with a very limited memory. We need automata with unbounded memory to model more sophisticated computational devices. In the next lecture we will introduce Turing machines as a conceptual model of conventional computers.

Material Reading material: Chapter 2: Finite Automata (see reader, for sale in dictatenverkoop) Practice material: Assignment: Assignment A1 deadline: Friday 20-11-2015 Practice set P1 (Practice set and assignment available in OASE.)