Title: Go Over 1'1'3 from HW
1Go Over 1.1.3 from HW 1
- Let S1m, S2n
- Induction on S2
- Basis S21 S1?aS1S1?a, a?U.
- Assume theorem true for S2n, show for n1
- Consider any set S3 with n1 elements.
- S3S2?a for some S2n, a?U, a ? S2.
- S1?S3S1?S2S1?aS1?S2S1
- mnm m(n1) S1?S3!
2Roman Numeral Acceptor
- Long line of states, transitions on
- MMMMDCCCCLXXXXVIIII
- Jump ahead on, say, X if in M's, etc.
- If you get C after X, for example, you need to
reject the word (no matter what else comes in) - MUCH easier problem if we allow non-determinism
- Straight line of states, l or letter transitions
- (stay tuned for more details next class)
32a Deterministic Finite Acceptors 2.1
- JavaScript Finite-State Machine Simulator
- Deterministic Finite Acceptor (dfa)
- Languages and dfas
- Regular Languages
- Not All Languages are Regular
4JavaScript dfa Simulator
- http//cs.union.edu/csc140/
- Loading a canned machine
- Running the simulation
- Entering a new machine
- Printout of your own simulation is required
- If you want extra credit (and to make the "list")
you need to do something creative
5Problems suitable for dfa
- See Finite-State HW.doc in course folder
6Formal Definition of dfa
- M (Q, ?, ?, q0, F) ordered quintuple
- Q finite set of states
- ? input alphabet
- ? Q x ? ? Q transition function
- total function in this text
- q0 ? Q initial state
- F ? Q set of final states (accepting)
7Specifying the Transitions
- Functions
- ?(even,0) even ?(even,1) odd?(odd,0)
odd ?(odd,1) even - Tables
- Graphs
- Arrow from nowhere into initial state
- Double circle for final state
8Extended Transition Function
- ? Q x ? ? Q
- What state after 3 inputs? 7 inputs? etc.
- even/odd machine after 011?
- after 0011100?
9Language of a dfa
- L(M) w ? ? ?(q0,w) ? F
- Language of even/odd machine set of all words
over 0,1 with an odd number of 1s - dfa Accepting Complement of L(M)
- must start with dfa and total transition function
- Why? (we will come back to this in exercise
2.3.6) - make all non-final states final, and all final
states non-final
10Trap State
- Any words with prefixes that take you to a trap
state will not be accepted - Example Machine accepting words over 0,1 that
start with 0
11Trap States in Roman Numeral dfa
- More than 4 of the same symbol in a row
- X followed by C, I followed by M, etc.
12? 0,1, accept if and only if odd parity
- For all languages, it is important to accept ALL
words in the desired language, but also NOT to
accept words that are not in the language - one-state dfa with loops on 0 and 1 accepts this
language plus a whole lot more - likewise S?0S1S? generates this language, but
also lots of other words - likewise (01) includes this language
13Accept if number of 1's 1 mod 5
- Like Odd/Even machine only more so!
- 5 states (q0-q4), stay put on 0, move clockwise
around the circle on 1 - q1 will be the only accepting state
14Words with odd a's, even b's
- 4 states EaEb, EaOb, OaEb, OaOb
- Could draw it 2-dimensionally
- as move horizontally
- bs move vertically
15Exercises 2.1.2(c,d) page 45
- (c) 5 states
- 0 as, 1 a, 2 as, 3 as, more-than-3 as
- all accepting state except last one (trap)
- (d) 2 rows of 4 states
- top row no as, bottom row got an a
- first column no bs, next column 1 b, third
column 2 bs, fourth column more - only accepting state bottom row 3rd column
16Exercise 2.1.7(a) page 45
- 3 states
- go around the triangle in same direction on both
a and b - initial state is only final state
17? a,b, "aaa" is not a substring
- (note the need for a trap state)
- 4 states 0, 1, 2, 3 as in a row
- b from any state except 3 takes you back to the
start - 3 is the only non-accepting state
18Exercise 2.1.9(a) page 46
- again note the need for a trap
- 4 states no 0s, one 0 in a row, two in a row,
three or more in a row - do not accept if you just saw two 0s in a row
(need the trailing 1), nor if more than two 0s
in a row (trap)
19Exercise 2.1.9(c) page 46
- How can we possibly remember the first symbol
all the way until we get to the last symbol? - Only way we have to remember information in a
finite-state machine is by the state we are in
(no auxiliary storage)
20Regular Languages
- Family of Languages
- Accepted by some dfa
- To prove regular, give dfa accepting it
21Regular Language Examples
- Exercise 2.1.20 page 47 page 43
- Given L awa w ? a,b, show that L is
regular. - What is L?
- What is L? L ? what?
- Exercise 2.1.22
- If L is regular not containing ?, show that
truncate(L) is also regular. Where truncate drops
last symbol from each word. construct new dfa
from original - Illustrate with 1(01),101, abc machines
22Not all Languages are Regular
- L 0i1i i ? 0 is a non-regular language
- L ? Li, i ? 0, where
- L0 ?
- L1 01
- L2 0011
- etc.
- Machine for each Li exists
- Machine for union exists for any finite i
23Related Languages Regular?
- L 0i1j i, j?0
- Proof?
- L (01)i i?0
- Proof?
24In-Class ExerciseJavaScript Simulator
- Work in groups of 2 or 3
- Use Internet Explorer to link to
- cs.union.edu/csc140/simulators
- Run the built-in Finite-State simulations
- Addition Modulo 5
- Pattern Recognition
- Create a machine to search for one of 2 words
- Be sure you dont accept extra words
25In-Class ExerciseAnswer
- Make sure your machine accepts the desired
pattern anywhere in the input. - Make sure your machine does NOT accept strings
without the pattern.