SlideShare a Scribd company logo
1 of 18
Formal Methods in
Software
Lecture 2. Languages and Machines-1
Vlad Patryshev
SCU
2014
Deterministic State Machine
(In, S, s0∈S, f:In×S → S)
Input
Alphabet
Collection
of States
Initial
State
Transition Function
Example 1. Turnstile
Example 2. String validation
Acceptable states - a subset of S that we assign a
special meaning of being better than others
We Have Monoids, actually
• Alphabet A gives a monoid In=A*: all strings in A, including empty
• Having f: A*×S → S is equivalent to having f’: A* → SS
(where SS is all functions S→S, that is, all transitions)
• SS is a monoid (identity function and composition)
• f’ is a monoidal function
Nondeterministic State Machine
(In, S, s0∈S, f:In×S → P(S))
Input
Alphabet
Collection
of States
Initial
State
Transition Function
Example. Parsing strings
Good Strings Bad Strings
ad,ac,abbbc,abbd... a,ba,aba,abbb
Terminology and TLA/FLA
• FSM - finite state machine (finite number of states)
• DFA - deterministic finite automaton, aka deterministic FSM
• NFA - non-determinisitic FSM
• Acceptable States - a subset of S that we assign a special meaning of
being better than others
• Input Language - strings built of Input Alphabet
• ε, Empty Symbol - empty string (a word in Input Language)
• Regular Language is an input language accepted by an FSM
NFA ↔ DFA
1. DFA is a special case of NFA (every transition is to a singleton)
2. NFA → DFA?
NFA X = (In, S, s0∈S, f:In×S → P(S))
DFX PX = (In, P(S), {s0}∈P(S), f’:In×P(S) → P(S))
where f’(a,B) = ∪{f(a,b)|b∈B}
NFA → DFA, Example
Regular Languages
Example: a, aa, aaa, aaaa…
Counterexample: anbn (for all n)
Regular language is a language accepted by an FSM
Given an FSM, its language is the language accepted by this FSM
Given an alphabet A, a language is a set of words in A
(in other words, a subset of A*)
Building Regular Languages
• Empty language ∅ is regular (its FSM accepts nothing)
• Singleton {a} is regular (its FSM takes a once)
• Union of two languages, A∪B, is regular:
• Concatenation of two languages, A·B, is regular:
• If A is regular, A* is regular:
Formal Grammar
Given an alphabet A, and a language L⊂A*, try to define it via formal
grammar.
(A, N, S∈N, Rules)
Rules: each rule looks like x1x2...xkzxk+1...xn→ y1y2...ym, where
xi∈(A∪N), yi∈(A∪N), z∈N
“Terminal symbols” Nonterminal symbols
Start symbol
Example of Formal Grammar
D → 0
D → 1
N → D
N → DN
S → N
S → X+X
S → X-X
P → S
P → (P)
P → P*P
X → P
X → S
e.g. (0100-0*11)*(111+1-0)
Example in Backus-Naur Form (BNF)
<D> ::= 0|1
<N> ::= <D>|<D><N>
<S> ::= <N>|<X>+<X>|<X>-<X>
<P> ::= <S>|(<S>)|<P>*<P>
<X> ::= <P>|<S>
e.g. (0100-0*11)*(111+1-0)
Grammar of Regular Language
Given an alphabet A, and a regular language L⊂A*, its grammar has a very
simple form:
● B → ε
● B → a
● B → aC
where B and C are nonterminal symbols, a is some terminal symbol.
Regular Expressions
/abc*d?..e/ -- matches abxye, abccccdabe and the like
R → aR1
R1 → bR2
R2 → cR2
R2 → R3
R2 → dR3
R3 → (anything)R4
R4 → (anything)R5
R5 → e
Parsing Regular Expressions
The problem with NFA - exponential time, O(2n). E.g. a?nan against an
Can transform to DFA;
then it’s linear,
O(n) (but may take space).
A simple example in Scala: https://gist.github.com/vpatryshev/3778294
The example is tricky: it’s not an FSM; it uses call stack.
main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
Big O
f(x) = O(g(x)) for x → ∞
means this:
∃x0∃C ∀x>x0 |f(x)/g(x)| < C
E.g.
ax2+bx+c = O(x2)
1/x = O(1)
n! = O((n/2)n)
References
http://www.cs.ox.ac.uk/people/luke.ong/personal/teaching/moc/nfa2up.pdf
http://swtch.com/~rsc/regexp/regexp1.html
https://gist.github.com/vpatryshev/3778294
Wikipedia
Formal methods   2 - languages and machines

More Related Content

What's hot

Regular expressions
Regular expressionsRegular expressions
Regular expressionsEran Zimbler
 
Head First Java Chapter 4
Head First Java Chapter 4Head First Java Chapter 4
Head First Java Chapter 4Tom Henricksen
 
Automata
AutomataAutomata
AutomataGaditek
 
Context free languages
Context free languagesContext free languages
Context free languagesJahurul Islam
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Hakka Labs
 
SPIRE2013-tabei20131009
SPIRE2013-tabei20131009SPIRE2013-tabei20131009
SPIRE2013-tabei20131009Yasuo Tabei
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsBrij Kishore
 
Introduction to the lambda calculus
Introduction to the lambda calculusIntroduction to the lambda calculus
Introduction to the lambda calculusJack Fox
 
Regular expressions quick reference
Regular expressions quick referenceRegular expressions quick reference
Regular expressions quick referencejvinhit
 
String in c programming
String in c programmingString in c programming
String in c programmingDevan Thakur
 
Regular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to VimRegular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to VimStalin Thangaraj
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskellgoncharenko
 
Perl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsPerl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsShaun Griffith
 

What's hot (20)

Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Head First Java Chapter 4
Head First Java Chapter 4Head First Java Chapter 4
Head First Java Chapter 4
 
Automata
AutomataAutomata
Automata
 
Lambda Calculus
Lambda CalculusLambda Calculus
Lambda Calculus
 
Context free languages
Context free languagesContext free languages
Context free languages
 
Minimizing DFA
Minimizing DFAMinimizing DFA
Minimizing DFA
 
Lambda calculus
Lambda calculusLambda calculus
Lambda calculus
 
Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey Lambda Calculus by Dustin Mulcahey
Lambda Calculus by Dustin Mulcahey
 
Ch03
Ch03Ch03
Ch03
 
SPIRE2013-tabei20131009
SPIRE2013-tabei20131009SPIRE2013-tabei20131009
SPIRE2013-tabei20131009
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Regexps
RegexpsRegexps
Regexps
 
Introduction to the lambda calculus
Introduction to the lambda calculusIntroduction to the lambda calculus
Introduction to the lambda calculus
 
python
pythonpython
python
 
Regular expressions quick reference
Regular expressions quick referenceRegular expressions quick reference
Regular expressions quick reference
 
String in c programming
String in c programmingString in c programming
String in c programming
 
String functions in C
String functions in CString functions in C
String functions in C
 
Regular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to VimRegular expressions in Ruby and Introduction to Vim
Regular expressions in Ruby and Introduction to Vim
 
Functional Programming by Examples using Haskell
Functional Programming by Examples using HaskellFunctional Programming by Examples using Haskell
Functional Programming by Examples using Haskell
 
Perl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And SubstitutionsPerl Intro 5 Regex Matches And Substitutions
Perl Intro 5 Regex Matches And Substitutions
 

Similar to Formal methods 2 - languages and machines

Automata
AutomataAutomata
AutomataGaditek
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfDrIsikoIsaac
 
language , grammar and automata
language , grammar and automatalanguage , grammar and automata
language , grammar and automataElakkiyaS11
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2gadisaAdamu
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfdawod yimer
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Dr. Maamoun Ahmed
 
Theory of Computation.pptx
Theory of Computation.pptxTheory of Computation.pptx
Theory of Computation.pptxsavita325705
 
Flat notes iii i (1)(7-9-20)
Flat notes iii i (1)(7-9-20)Flat notes iii i (1)(7-9-20)
Flat notes iii i (1)(7-9-20)saithirumalg
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdfkenilpatel65
 
Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Srimatre K
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdfImranBhatti58
 

Similar to Formal methods 2 - languages and machines (20)

Automata
AutomataAutomata
Automata
 
Ch02
Ch02Ch02
Ch02
 
Chapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdfChapter2CDpdf__2021_11_26_09_19_08.pdf
Chapter2CDpdf__2021_11_26_09_19_08.pdf
 
language , grammar and automata
language , grammar and automatalanguage , grammar and automata
language , grammar and automata
 
compiler Design course material chapter 2
compiler Design course material chapter 2compiler Design course material chapter 2
compiler Design course material chapter 2
 
Chapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdfChapter 3 REGULAR EXPRESSION.pdf
Chapter 3 REGULAR EXPRESSION.pdf
 
draft
draftdraft
draft
 
Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5Theory of Computation - Lectures 4 and 5
Theory of Computation - Lectures 4 and 5
 
Theory of Computation.pptx
Theory of Computation.pptxTheory of Computation.pptx
Theory of Computation.pptx
 
Lec1.pptx
Lec1.pptxLec1.pptx
Lec1.pptx
 
Module 1 TOC.pptx
Module 1 TOC.pptxModule 1 TOC.pptx
Module 1 TOC.pptx
 
Ch2 automata.pptx
Ch2 automata.pptxCh2 automata.pptx
Ch2 automata.pptx
 
Flat notes iii i (1)(7-9-20)
Flat notes iii i (1)(7-9-20)Flat notes iii i (1)(7-9-20)
Flat notes iii i (1)(7-9-20)
 
Syntax Analyzer.pdf
Syntax Analyzer.pdfSyntax Analyzer.pdf
Syntax Analyzer.pdf
 
Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2Formal Languages and Automata Theory unit 2
Formal Languages and Automata Theory unit 2
 
Ch3.ppt
Ch3.pptCh3.ppt
Ch3.ppt
 
RegularExpressions.pdf
RegularExpressions.pdfRegularExpressions.pdf
RegularExpressions.pdf
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
Lexicalanalyzer
LexicalanalyzerLexicalanalyzer
Lexicalanalyzer
 
QB104541.pdf
QB104541.pdfQB104541.pdf
QB104541.pdf
 

More from Vlad Patryshev

Formal methods 6 - elements of algebra
Formal methods   6 - elements of algebraFormal methods   6 - elements of algebra
Formal methods 6 - elements of algebraVlad Patryshev
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introductionVlad Patryshev
 
Formal methods 7 - category theory
Formal methods   7 - category theoryFormal methods   7 - category theory
Formal methods 7 - category theoryVlad Patryshev
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)Vlad Patryshev
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture hVlad Patryshev
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture gVlad Patryshev
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture fVlad Patryshev
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture eVlad Patryshev
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture dVlad Patryshev
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture cVlad Patryshev
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture bVlad Patryshev
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture aVlad Patryshev
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9Vlad Patryshev
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8Vlad Patryshev
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7Vlad Patryshev
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6Vlad Patryshev
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5Vlad Patryshev
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4Vlad Patryshev
 
Truth, deduction, computation; lecture 3
Truth, deduction, computation;  lecture 3Truth, deduction, computation;  lecture 3
Truth, deduction, computation; lecture 3Vlad Patryshev
 
Truth, deduction, computation; lecture 2
Truth, deduction, computation;   lecture 2Truth, deduction, computation;   lecture 2
Truth, deduction, computation; lecture 2Vlad Patryshev
 

More from Vlad Patryshev (20)

Formal methods 6 - elements of algebra
Formal methods   6 - elements of algebraFormal methods   6 - elements of algebra
Formal methods 6 - elements of algebra
 
Formal methods 1 - introduction
Formal methods   1 - introductionFormal methods   1 - introduction
Formal methods 1 - introduction
 
Formal methods 7 - category theory
Formal methods   7 - category theoryFormal methods   7 - category theory
Formal methods 7 - category theory
 
Truth, deduction, computation lecture i (last one)
Truth, deduction, computation   lecture i (last one)Truth, deduction, computation   lecture i (last one)
Truth, deduction, computation lecture i (last one)
 
Truth, deduction, computation lecture h
Truth, deduction, computation   lecture hTruth, deduction, computation   lecture h
Truth, deduction, computation lecture h
 
Truth, deduction, computation lecture g
Truth, deduction, computation   lecture gTruth, deduction, computation   lecture g
Truth, deduction, computation lecture g
 
Truth, deduction, computation lecture f
Truth, deduction, computation   lecture fTruth, deduction, computation   lecture f
Truth, deduction, computation lecture f
 
Truth, deduction, computation lecture e
Truth, deduction, computation   lecture eTruth, deduction, computation   lecture e
Truth, deduction, computation lecture e
 
Truth, deduction, computation lecture d
Truth, deduction, computation   lecture dTruth, deduction, computation   lecture d
Truth, deduction, computation lecture d
 
Truth, deduction, computation lecture c
Truth, deduction, computation   lecture cTruth, deduction, computation   lecture c
Truth, deduction, computation lecture c
 
Truth, deduction, computation lecture b
Truth, deduction, computation   lecture bTruth, deduction, computation   lecture b
Truth, deduction, computation lecture b
 
Truth, deduction, computation lecture a
Truth, deduction, computation   lecture aTruth, deduction, computation   lecture a
Truth, deduction, computation lecture a
 
Truth, deduction, computation lecture 9
Truth, deduction, computation   lecture 9Truth, deduction, computation   lecture 9
Truth, deduction, computation lecture 9
 
Truth, deduction, computation lecture 8
Truth, deduction, computation   lecture 8Truth, deduction, computation   lecture 8
Truth, deduction, computation lecture 8
 
Truth, deduction, computation lecture 7
Truth, deduction, computation   lecture 7Truth, deduction, computation   lecture 7
Truth, deduction, computation lecture 7
 
Truth, deduction, computation lecture 6
Truth, deduction, computation   lecture 6Truth, deduction, computation   lecture 6
Truth, deduction, computation lecture 6
 
Truth, deduction, computation; lecture 5
Truth, deduction, computation;  lecture 5Truth, deduction, computation;  lecture 5
Truth, deduction, computation; lecture 5
 
Truth, deduction, computation; lecture 4
Truth, deduction, computation;  lecture 4Truth, deduction, computation;  lecture 4
Truth, deduction, computation; lecture 4
 
Truth, deduction, computation; lecture 3
Truth, deduction, computation;  lecture 3Truth, deduction, computation;  lecture 3
Truth, deduction, computation; lecture 3
 
Truth, deduction, computation; lecture 2
Truth, deduction, computation;   lecture 2Truth, deduction, computation;   lecture 2
Truth, deduction, computation; lecture 2
 

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

Formal methods 2 - languages and machines

  • 1. Formal Methods in Software Lecture 2. Languages and Machines-1 Vlad Patryshev SCU 2014
  • 2. Deterministic State Machine (In, S, s0∈S, f:In×S → S) Input Alphabet Collection of States Initial State Transition Function Example 1. Turnstile Example 2. String validation Acceptable states - a subset of S that we assign a special meaning of being better than others
  • 3. We Have Monoids, actually • Alphabet A gives a monoid In=A*: all strings in A, including empty • Having f: A*×S → S is equivalent to having f’: A* → SS (where SS is all functions S→S, that is, all transitions) • SS is a monoid (identity function and composition) • f’ is a monoidal function
  • 4. Nondeterministic State Machine (In, S, s0∈S, f:In×S → P(S)) Input Alphabet Collection of States Initial State Transition Function Example. Parsing strings Good Strings Bad Strings ad,ac,abbbc,abbd... a,ba,aba,abbb
  • 5. Terminology and TLA/FLA • FSM - finite state machine (finite number of states) • DFA - deterministic finite automaton, aka deterministic FSM • NFA - non-determinisitic FSM • Acceptable States - a subset of S that we assign a special meaning of being better than others • Input Language - strings built of Input Alphabet • ε, Empty Symbol - empty string (a word in Input Language) • Regular Language is an input language accepted by an FSM
  • 6. NFA ↔ DFA 1. DFA is a special case of NFA (every transition is to a singleton) 2. NFA → DFA? NFA X = (In, S, s0∈S, f:In×S → P(S)) DFX PX = (In, P(S), {s0}∈P(S), f’:In×P(S) → P(S)) where f’(a,B) = ∪{f(a,b)|b∈B}
  • 7. NFA → DFA, Example
  • 8. Regular Languages Example: a, aa, aaa, aaaa… Counterexample: anbn (for all n) Regular language is a language accepted by an FSM Given an FSM, its language is the language accepted by this FSM Given an alphabet A, a language is a set of words in A (in other words, a subset of A*)
  • 9. Building Regular Languages • Empty language ∅ is regular (its FSM accepts nothing) • Singleton {a} is regular (its FSM takes a once) • Union of two languages, A∪B, is regular: • Concatenation of two languages, A·B, is regular: • If A is regular, A* is regular:
  • 10. Formal Grammar Given an alphabet A, and a language L⊂A*, try to define it via formal grammar. (A, N, S∈N, Rules) Rules: each rule looks like x1x2...xkzxk+1...xn→ y1y2...ym, where xi∈(A∪N), yi∈(A∪N), z∈N “Terminal symbols” Nonterminal symbols Start symbol
  • 11. Example of Formal Grammar D → 0 D → 1 N → D N → DN S → N S → X+X S → X-X P → S P → (P) P → P*P X → P X → S e.g. (0100-0*11)*(111+1-0)
  • 12. Example in Backus-Naur Form (BNF) <D> ::= 0|1 <N> ::= <D>|<D><N> <S> ::= <N>|<X>+<X>|<X>-<X> <P> ::= <S>|(<S>)|<P>*<P> <X> ::= <P>|<S> e.g. (0100-0*11)*(111+1-0)
  • 13. Grammar of Regular Language Given an alphabet A, and a regular language L⊂A*, its grammar has a very simple form: ● B → ε ● B → a ● B → aC where B and C are nonterminal symbols, a is some terminal symbol.
  • 14. Regular Expressions /abc*d?..e/ -- matches abxye, abccccdabe and the like R → aR1 R1 → bR2 R2 → cR2 R2 → R3 R2 → dR3 R3 → (anything)R4 R4 → (anything)R5 R5 → e
  • 15. Parsing Regular Expressions The problem with NFA - exponential time, O(2n). E.g. a?nan against an Can transform to DFA; then it’s linear, O(n) (but may take space). A simple example in Scala: https://gist.github.com/vpatryshev/3778294 The example is tricky: it’s not an FSM; it uses call stack. main(int c,char**v){return!m(v[1],v[2]);}m(char*s,char*t){return*t-42?*s?63==*t|*s==*t&&m(s+1,t+1):!*t:m(s,t+1)||*s&&m(s+1,t);}
  • 16. Big O f(x) = O(g(x)) for x → ∞ means this: ∃x0∃C ∀x>x0 |f(x)/g(x)| < C E.g. ax2+bx+c = O(x2) 1/x = O(1) n! = O((n/2)n)