Professional Documents
Culture Documents
CS314 Recitation 1
CS314 Recitation 1
Important Information
● Contact Info: Chun
○ Email: larryl@cs.rutgers.edu
○ Office hours: Thursday 1PM to 3PM at CoRE 305
● Contact Info: Xinyu
○ Email: xz653@rutgers.edu
○ Office hours: Tuesday 10AM to 12PM at CoRE 305
● Contact Info: Zining
○ Email: zf140@scarletmail.rutgers.edu
○ Office hours: Wednesday 10AM to 12PM at CoRE 305
● Rewrite Systems
● Regular Expressions
How to use ilabs
Access iLab machines with WebLogin
● Go to services.cs.rutgers.edu/accounts/activate/activate to active your iLab account
and set your CS password.
● Go to weblogin.cs.rutgers.edu and enter your Rutgers NetId and CS password in the
login screen.
● For iLab machines status check, use
report.cs.rutgers.edu/nagiosnotes/iLab-machines.html
Today’s Topics
● How to use ilabs
● Rewrite Systems
● Regular Expressions
Rewrite Systems
● A rewrite system is a set of rules which we can apply to transform a string.
● In lecture, we discussed a rewrite system with these characteristics:
○ Input is a binary string, bracketed by $ and # characters. (e.g. $0101#)
○ There are six rewrite rules:
■ $1 => 1&
■ $0 => 0$
■ &1 => 1$
■ &0 => 0&
■ $# => A
■ &# => B
Applying Our Rewrite System
● Given input $01001# let's apply the rewrite system from
lecture.
● $01001#
Rules:
1. $1 => 1&
● => 0$1001# by rule 2
2. $0 => 0$
● => 01&001# by rule 1
3. &1 => 1$
● => 010&01# by rule 4 4. &0 => 0&
● => 0100&1# by rule 4 5. $# => A
● => 01001$# by rule 3 6. &# => B
● => 01001A by rule 5
Another Rewrite System
● Suppose the input remains the same: the input is a binary string, bracketed by
$ and # characters.
● New rules:
○ $0 -> $
○ $1 -> 1$
○ $# -> ε
Applying Our Rewrite System
● Given input $10110# let's apply our rewrite system to
remove all 0’s.
● $10110#
● 1$0110# by rule 2 Rules:
● 1$110# by rule 1 1. $0 -> $
● 11$10# by rule 2 2. $1 -> 1$
● 111$0# by rule 2 3. $# -> ε
● 111$# by rule 1
● 111 by rule 3
Different Rule Application Order
● Suppose inputs are binary strings. A rewrite system is
given below.
● Given input 10110 let's apply our rewrite system to
remove all 0’s.
Rules:
● 10110 1. 01 -> 1
● 1011 by rule 2 2. 10 -> 1
● 111 by rule 1 3. 00 -> 0
Rules:
● 10110 1. 01 -> 1
● 1110 by rule 1 2. 10 -> 1
● 111 by rule 2 3. 00 -> 0
Rewrite Systems: Questions
● Can we construct a rewrite system that loops infinitely?
○ Yes! Suppose we had a rule that stated 0 -> 00 and 1 -> 11.
● Rewrite Systems
● Regular Expressions
Regular Expressions
● Regular expressions are a way of recognizing regular languages.
● They use these rules:
○ (x) accepts x
○ x* accepts 0 or more copies of x
○ x+ accepts 1 or more copies of x
○ xy accepts x followed by y
○ x|y accepts either x or y
Regex to NFA
1. Literal String (sequential), e.g., ab 3. “*” (0 or more copies), e.g, A*
ε
a b ε ε
0 1 2 0 A 2
ε A ε
ε
0 2 ε ε
0 A 2
ε B ε
Regex to NFA
Example: a(b|c)* Example Match Transitions:
- a ➡ 01278
- abc ➡ 01234725678
Tool: https://cyberzhg.github.io/toolbox/min_dfa
NFA to DFA
(4)
(1)
(2)
(5)
(3)