Models of Computing Regular Expressions 1. Formal models of computation What can be computed? What is a valid program? What is a valid name of a variable.

Slides:



Advertisements
Similar presentations
CS 345: Chapter 9 Algorithmic Universality and Its Robustness
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
CS5371 Theory of Computation
Theory of Computation What types of things are computable? How can we demonstrate what things are computable?
1 CSCI-2400 Models of Computation. 2 Computation CPU memory.
Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Fall 2008.
1 Finite Automata. 2 Finite Automaton Input “Accept” or “Reject” String Finite Automaton Output.
1 Languages and Finite Automata or how to talk to machines...
Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Scanner Front End The purpose of the front end is to deal with the input language Perform a membership test: code  source language? Is the.
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
Thopson NFA Presenter: Yuen-Shuo Li Date: 2014/5/7 Department of Computer Science and Information Engineering National Cheng Kung University, Taiwan R.O.C.
CMPS 3223 Theory of Computation Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided.
1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 Web: Time: 9:10-12:10 PM, Monday Place: BL 103.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Lecture 23: Finite State Machines with no Outputs Acceptors & Recognizers.
1 An Introduction to Formal Languages and Automata Provided by : Babak Salimi webAdd:
CSCI 2670 Introduction to Theory of Computing September 28, 2005.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Languages and Automata
CSC312 Automata Theory Lecture # 2 Languages.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 111 Computability, etc. Midterm review. Turing machines. Finite state machines. Push down automata. Homework: FSA, PDA, TM problems (can work in teams)
Theory of Computation - Lecture 3 Regular Languages What is a computer? Complicated, we need idealized computer for managing mathematical theories... Hence:
Introduction to CS Theory Lecture 15 –Turing Machines Piotr Faliszewski
1 Context-Free Languages. 2 Regular Languages 3 Context-Free Languages.
1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 Web: Time: 9:10-12:10 PM, Monday Place: BL.
Models of Computation. Computation: Computation is a general term for any type of information processing information processing CPU memory.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
CSCI 2670 Introduction to Theory of Computing October 13, 2005.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
using Deterministic Finite Automata & Nondeterministic Finite Automata
1 Course Overview Why this course “formal languages and automata theory?” What do computers really do? What are the practical benefits/application of formal.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Turing Machines - Chap 8 Turing Machines Recursive and Recursively Enumerable Languages.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
C Sc 132 Computing Theory Professor Meiliu Lu Computer Science Department.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Copyright © Curt Hill Other Automata Pushdown through Turing machines.
Deterministic Finite Automata Nondeterministic Finite Automata.
Theory of Languages and Automata By: Mojtaba Khezrian.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Theory of Languages and Automata By: Mojtaba Khezrian.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Formal Foundations-II [Theory of Automata]
Languages.
CSE 105 theory of computation
Theory of Computation Theory of computation is mainly concerned with the study of how problems can be solved using algorithms.  Therefore, we can infer.
G. Pullaiah College of Engineering and Technology
Pushdown Automata PDAs
Formal Language Theory
Week 14 - Friday CS221.
CSCI-2400 Models of Computation Costas Busch - RPI.
Intro to Data Structures
Context-Free Languages
Regular Expressions
CSE 105 theory of computation
CSC312 Automata Theory Lecture # 2 Languages.
Formal Languages and Automata Theory BODDEDA HARITHA LAKSHMI,
Automata theory and formal languages COS 3112 – AUTOMATA THEORY PRELIM PERIOD WEEK 1 AND 2.
Presentation transcript:

Models of Computing Regular Expressions 1

Formal models of computation What can be computed? What is a valid program? What is a valid name of a variable in python? What is the strongest possible programming language? What is the simplest possible computer? Can we say something about “all the possible algorithms”? How much time is required (by the “best” algorithm) for solving a given computational task? How “complicated” is solving that task? 2

Three types of theories What can be computed using “simple” computing machines or simple computing processes?  “Automata and Formal Languages” What can be computed by general computers?  “Computability Theory” (" חישוביות ") What can be computed efficiently?  “Complexity Theory” ( סיבוכיות ") 3

Machines vs. Functions Study the computing machines “Finite State Machines” – Finite memory “Push Down Automata” – + Stack “Turing Machines” – + Array-like Memory Study the computed functions Regular languages – Simple rules Context-Free languages – + Simple recursion Computable Languages – Anything 4

Functions that machines compute Mathematicians: – Function : Natural Numbers  Natural Numbers Computer Scientists: – Function : Strings  Strings Basically the same: – A natural number can be encoded by a string: str(x) – A string can be encoded by a number:  i ord(s[i])*base i Theoretical Computer Scientists: – Function : Strings  Yes/No (Called a “Language”) Basically the same: – Consider each bit of the answer 5

Finite Automata Very simply model of a machine with finite memory. Input: a String. Output: accept/reject 6 start accept 0  reject 1  accept 10  reject 11  reject 100  accept …  reject  reject  accpet …

Regular Languages: Rules of the game Finite “Alphabet” Compose a “regular expression” from a finite combination of the following ingredients: – Empty String – Single letter – Concatenation – Or (Notation: A | B) – Repetition (Notation A*) The “Language” of this regular expression is the set of Strings that fit the expression 7

Examples with Alphabet = {0, 1} (0 | 1) (0 | 1) (0 | 1) – 010 0(00)* – (0 | 1)* 0 – (00 | 11)* – (1 0 0*)* 1 – (0* 1 0* 1 0*)* –

More examples Int = 0 | (+ | - |  )( (1 | 2 | … | 9) (0 | 1 |... | 9)*) – -530 Int_List = [  | Int (, Int)* ] – [34,12] The (boy | girl | dog) (ate | lost) the (apple | pear) – The boy ate the pear The boy ran very* fast from the scary* lion – The boy ran very very very fast from the lion 9 Empty string

Context Free Languages Recursive definitions: exp: number | ( exp ) | exp op exp 10 ( ) - ( ) ( E + E ) - ( E + E ) ( E ) - ( E ) E - E E

The algorithmic problem Input: regular expression, text Output: does the text fit the regular expression Variants: – Does it contain the regexp as a substring? – Which parts match which parts? Algorithm 1: Recursion + Memoization Algorithm 2: Use Finite State Machines… 11

Regular Expressions in Python 12

Some Convenient Syntax “[1fg]” == 1|f|g “[a-e]” == [abcde] “[^abc]” == any letter except a|b|c “.” == any letter “^” == beginning of line “$” == end of line 13

Repetitions * : 0 or more times + : 1 or more times ? : 0 or 1 times {m} : Exactly m times {m,n} : between m and n times 14

The annoying backslash “\” is used in python as an “escape character”, e.g. “\n” “\” is used in regular expressions for various purposes such as matching the “special characters” The python notation r`abc’ gives “raw” strings, eliminating the python escapes 15

Groups 16

Parsing Phone Numbers 17