-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
412 changed files
with
24,125 additions
and
1,593 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
--- | ||
title: "CS135-lecture-20210318" | ||
# date: 2021-03-18T13:03:19-07:00 | ||
draft: false | ||
bookToc: true | ||
tags: ["context-free language", "pumping lemma"] | ||
--- | ||
|
||
## Pumping lemma for CFL | ||
|
||
PL for RL | ||
|
||
Given {{<k>}} RL, L {{</k>}} | ||
there exists {{<k>}} p {{</k>}} such | ||
that if {{<k>}} w \in L {{</k>}} and {{<k>}} |w| \geq p {{</k>}} | ||
then there exists {{<k>}} w = xyz {{</k>}} where | ||
|
||
- {{<k>}} |y| > 0 {{</k>}} | ||
- {{<k>}} |xy| \leq p {{</k>}} | ||
- {{<k>}} xy^iz \in L {{</k>}} | ||
|
||
We consume {{<k>}} w {{</k>}} and we get to a state | ||
that is the first repeated state. | ||
At some point we come back to it, and then to the accept. | ||
|
||
![image_2021-03-18-13-05-46](/notes/image_2021-03-18-13-05-46.png) | ||
|
||
Since {{<k>}} w {{</k>}} is {{<k>}} p {{</k>}} or longer, it must visit one state more than once. | ||
We can identify this state as the one we get repeated. | ||
The part that gets us there the first time {{<k>}} x {{</k>}}, | ||
the part that gets us there the second time {{<k>}} y {{</k>}}, | ||
and the part that goes to the accept state {{<k>}} z {{</k>}}. | ||
|
||
If {{<k>}} x {{</k>}} gets us to the repeated state, then we can go around {{<k>}} y {{</k>}} as many times we want (or omit). | ||
|
||
## Proof template | ||
|
||
Given context-free language | ||
{{<k>}} L {{</k>}}, there exists {{<k>}} p {{</k>}} such | ||
that if {{<k>}} w \in L {{</k>}} and {{<k>}} |w| \geq p {{</k>}}, | ||
then there exists a {{<k>}} w = uvxyz {{</k>}} where | ||
|
||
- {{<k>}} |vy| > 0 {{</k>}} | ||
- {{<k>}} |vxy| \leq p {{</k>}} | ||
- {{<k>}} uv^ixy^iz \in L {{</k>}} | ||
|
||
Main use: we look for strings that are in the language and at least {{<k>}} p {{</k>}} long, and then apply the pumping lemma to show | ||
that the language is not context-free. | ||
|
||
To prove: | ||
|
||
- Assume {{<k>}} L {{</k>}} is | ||
context-free | ||
- Pick {{<k>}} w \in L {{</k>}} with {{<k>}} |w| \geq p {{</k>}} | ||
- Argue that the pumping lemma says that there exists {{<k>}} w = uvxyz {{</k>}} with | ||
- {{<k>}} |vy| > 0 {{</k>}} | ||
- {{<k>}} |vyx| \leq p {{</k>}} | ||
- {{<k>}} uv^ixy^i \in L {{</k>}} | ||
- Argue that either if we pump down ({{<k>}} i = 0 {{</k>}} gives us {{<k>}} uxz {{</k>}}, | ||
or if we pump up {{<k>}} i > 0 {{</k>}} we get {{<k>}} uvvxyyz {{</k>}} | ||
and show that {{<k>}} e \not \in L {{</k>}} | ||
- Pumping lemma says string is in {{<k>}} L {{</k>}}, contradiction, so {{<k>}} L {{</k>}} is not | ||
context-free. | ||
|
||
### Example | ||
|
||
Consider {{<k>}} L = \{a^n b^n c^n : n \geq 0\} {{</k>}} | ||
|
||
This starts by consuming {{<k>}} a {{</k>}}'s and pushing them onto the stack. | ||
Then when we start seeing {{<k>}} b {{</k>}}'s we pop the {{<k>}} a {{</k>}}'s off. | ||
When we reach the {{<k>}} c {{</k>}}'s we don't have a way to remember how many {{<k>}} a {{</k>}}'s or {{<k>}} b {{</k>}}'s we saw. | ||
|
||
{{< hint info >}} | ||
Note: A Turning machine can do this because it has 2 stacks. | ||
{{< /hint >}} | ||
|
||
So lets prove its not context-free using the pumping lemma. | ||
|
||
The string we pick must be length {{<k>}} p {{</k>}} and exist in {{<k>}} L {{</k>}}: | ||
|
||
{{<k display>}} | ||
\begin{aligned} | ||
w = a^p b^p c^p | ||
\end{aligned} | ||
{{</k>}} | ||
|
||
{{<k>}} w {{</k>}} exists in the language and is at least {{<k>}} p {{</k>}} long (it is in fact {{<k>}} 3p {{</k>}} long). | ||
|
||
So lets assume that this language is context-free, and apply the pumping lemma. | ||
|
||
Possible divisions for {{<k>}} w {{</k>}}: | ||
|
||
![image_2021-03-18-13-24-55](/notes/image_2021-03-18-13-24-55.png) | ||
|
||
Since {{<k>}} w = uvxyz {{</k>}}, we don't know exactly where they are however | ||
|
||
![image_2021-03-18-13-25-22](/notes/image_2021-03-18-13-25-22.png) | ||
|
||
We do know that {{<k>}} 0 < |vxy| \leq p {{</k>}} | ||
|
||
![image_2021-03-18-13-26-20](/notes/image_2021-03-18-13-26-20.png) | ||
|
||
Its possible that {{<k>}} vxy {{</k>}}: | ||
- appear in the region of just {{<k>}} a {{</k>}}'s, since there are at least {{<k>}} p {{</k>}} {{<k>}} a {{</k>}}'s. | ||
So {{<k>}} vxy = {{</k>}} all {{<k>}} a {{</k>}}'s. | ||
- appear in the {{<k>}} a {{</k>}}'s and {{<k>}} b {{</k>}}'s. | ||
- any other combination of 2, but not all 3 | ||
|
||
![image_2021-03-18-13-29-16](/notes/image_2021-03-18-13-29-16.png) | ||
|
||
So, {{<k>}} uvvxyyz {{</k>}} will increase 1 or 2 types of characters, but not all 3. | ||
Thus it is out of balance, and the string is not in {{<k>}} L {{</k>}}. | ||
|
||
{{<k display>}} | ||
\begin{aligned} | ||
uvvxyyz \not \in L | ||
\end{aligned} | ||
{{</k>}} | ||
|
||
Therefore, the language {{<k>}} L = \{a^n b^n c^n : n \geq 0\} {{</k>}} | ||
is not context-free. | ||
|
||
## Why the pumping lemma is true | ||
|
||
If {{<k>}} L {{</k>}} is | ||
context-free, then there is a context-free grammar for it. | ||
So, every string {{<k>}} w \in L {{</k>}} has a parse tree: | ||
|
||
![image_2021-03-18-13-34-54](/notes/image_2021-03-18-13-34-54.png) | ||
|
||
where the fringe is {{<k>}} w {{</k>}} and the interior is non-terminals. | ||
|
||
![image_2021-03-18-13-35-42](/notes/image_2021-03-18-13-35-42.png) | ||
|
||
Observe, | ||
|
||
- The longer that {{<k>}} w {{</k>}} is, the taller the tree | ||
- The taller the tree, the more non-terminals in the longest root-to-leaf path | ||
- Once the root-to-leaf path is long enough, some non-terminal must repeat in it | ||
|
||
There are a finite number of productions in the grammar, and so as the tree gets longer and longer until there must be a repeat. | ||
This is where the pumping lemma comes in. | ||
|
||
As an abstraction: | ||
|
||
![image_2021-03-18-13-39-20](/notes/image_2021-03-18-13-39-20.png) | ||
|
||
Some part of {{<k>}} w {{</k>}} will be derived from {{<k>}} A {{</k>}}. | ||
|
||
![image_2021-03-18-13-40-12](/notes/image_2021-03-18-13-40-12.png) | ||
![image_2021-03-18-13-40-42](/notes/image_2021-03-18-13-40-42.png) | ||
|
||
This tells us that | ||
- {{<k>}} x \in L(A) {{</k>}}, and | ||
- {{<k>}} vxy \in L(A) {{</k>}} | ||
|
||
So each time that {{<k>}} A {{</k>}} is reached, we can replace it with {{<k>}} x {{</k>}} or {{<k>}} vxy {{</k>}}, | ||
we can pump the {{<k>}} v {{</k>}} and {{<k>}} y {{</k>}} as many times we want. | ||
|
||
{{< hint info >}} | ||
Note: This is similar to the pumping lemma for regular languages because it also uses the pigeon hole principle. | ||
{{< /hint >}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: "CS137-lecture-20210318" | ||
# date: 2021-03-18T19:04:36-07:00 | ||
draft: false | ||
bookToc: true | ||
tags: ["sequential circuits", "finite state machine"] | ||
--- | ||
|
||
# FSM cont. | ||
|
||
## Design rules | ||
|
||
- If we cannot determine function(s) of combinational circuit(s) in advance: | ||
1. Model FSM as FSD | ||
- May need to design bit-slice 1st | ||
2. Determine number of flip flops (dependent on the number of states you need) | ||
3. Convert the FSD to truth table | ||
4. Find minimal expressions for next state variable(s) and output(s) | ||
5. Draw the complete circuit with flip-flops | ||
- Otherwise | ||
- Use bit-serial design with known modules | ||
- Or, bit-parallel design with known modules | ||
|
||
### Example | ||
|
||
Lets design a Moore state machine that accepts the string {{<k>}} 101 {{</k>}}. | ||
|
||
As a box diagram: | ||
|
||
![image_2021-03-18-19-20-24](/notes/image_2021-03-18-19-20-24.png) | ||
|
||
Step 1, create a finite state diagram: | ||
|
||
![image_2021-03-18-20-08-09](/notes/image_2021-03-18-20-08-09.png) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.