Skip to content

Commit

Permalink
Update Thu Mar 18 20:08:55 PDT 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
zedchance committed Mar 19, 2021
1 parent 3ca4ba3 commit 42e4f24
Show file tree
Hide file tree
Showing 412 changed files with 24,125 additions and 1,593 deletions.
163 changes: 163 additions & 0 deletions content/CS135/CS135-lecture-20210318.md
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 >}}

36 changes: 36 additions & 0 deletions content/CS137/CS137-lecture-20210318.md
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)


2 changes: 1 addition & 1 deletion content/CS138/CS138-lecture-20210202.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Without fiber optic cable we could not span networks across oceans.

Between the source and destination, what if there are N routers?

\((N+1) \frac{L}{R}\)
{{<k>}} (N+1) \frac{L}{R} {{</k>}}

The entire packet must fully arrive at the router before being transmitted. The packet holds the information on where it needs to go, so it needs to be fully stored before being forwarded.

Expand Down
6 changes: 3 additions & 3 deletions content/CS138/CS138-lecture-20210211.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ observe that the `en0` has activity. Double click the card with activity to star
![IMAGE](/notes/1F0420BFFB18E661E3A9F36B7CD5E098.jpg)
![IMAGE](/notes/97A87336AF3F61BF13C9E75F3B8780D6.jpg)

Hl), Hn = IP address, Ht = port number
Hl = MAC address, Hn = IP address, Ht = port number

Each time the packet goes thru a router, it must go up to the network layer and back down.

Expand All @@ -26,8 +26,8 @@ At the destination, the layers are removed on the way up to the application laye

![IMAGE](/notes/8BC37A00DD784CB2C7AE959A767EFA93.jpg)

Transport layer: port number
Network layer: IP address
Transport layer: port number,
Network layer: IP address,
Link layer: MAC address

Most important things about encapsulation:
Expand Down
1 change: 1 addition & 0 deletions content/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ sequenceDiagram
{{< mermaid class="text-center" >}}
sequenceDiagram
Client ->> Server: GET /index
Note right of Server: The server receives the request, and responds
Server ->> Client: OK 200
{{< /mermaid >}}

Expand Down
2 changes: 1 addition & 1 deletion docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<link rel="manifest" href="/notes/manifest.json">
<link rel="icon" href="/notes/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/notes/book.min.a6e33eff9fca295dda99115dabc387fd12b0e1282a347b6e4de6e73b19c96d91.css" integrity="sha256-puM&#43;/5/KKV3amRFdq8OH/RKw4SgqNHtuTebnOxnJbZE=">
<script defer src="/notes/en.search.min.1448ffdc2e7b9337b67946a9671960be5721c86358c86c216f6041ee188c8305.js" integrity="sha256-FEj/3C57kze2eUapZxlgvlchyGNYyGwhb2BB7hiMgwU="></script>
<script defer src="/notes/en.search.min.22a88f8bc829510a23fc80aa14332798a7d139135b9d2560bfd69503ddb936e1.js" integrity="sha256-IqiPi8gpUQoj/ICqFDMnmKfRORNbnSVgv9aVA925NuE="></script>

<script defer src="/notes/sw.min.102e0b752b65c874dd63b7b7ef9f8391b698d86adbb048ed0e6ddf02a6093f83.js" integrity="sha256-EC4LdStlyHTdY7e375&#43;DkbaY2GrbsEjtDm3fAqYJP4M="></script>
<!--
Expand Down
28 changes: 27 additions & 1 deletion docs/CS10/CS10-Processing-labs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<link rel="manifest" href="/notes/manifest.json">
<link rel="icon" href="/notes/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/notes/book.min.a6e33eff9fca295dda99115dabc387fd12b0e1282a347b6e4de6e73b19c96d91.css" integrity="sha256-puM&#43;/5/KKV3amRFdq8OH/RKw4SgqNHtuTebnOxnJbZE=">
<script defer src="/notes/en.search.min.1448ffdc2e7b9337b67946a9671960be5721c86358c86c216f6041ee188c8305.js" integrity="sha256-FEj/3C57kze2eUapZxlgvlchyGNYyGwhb2BB7hiMgwU="></script>
<script defer src="/notes/en.search.min.22a88f8bc829510a23fc80aa14332798a7d139135b9d2560bfd69503ddb936e1.js" integrity="sha256-IqiPi8gpUQoj/ICqFDMnmKfRORNbnSVgv9aVA925NuE="></script>

<script defer src="/notes/sw.min.102e0b752b65c874dd63b7b7ef9f8391b698d86adbb048ed0e6ddf02a6093f83.js" integrity="sha256-EC4LdStlyHTdY7e375&#43;DkbaY2GrbsEjtDm3fAqYJP4M="></script>
<!--
Expand Down Expand Up @@ -1434,6 +1434,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS135/CS135-lecture-20210318/" class="">CS135-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down Expand Up @@ -1638,6 +1651,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS137/CS137-lecture-20210318/" class="">CS137-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down
28 changes: 27 additions & 1 deletion docs/CS10/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="manifest" href="/notes/manifest.json">
<link rel="icon" href="/notes/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/notes/book.min.a6e33eff9fca295dda99115dabc387fd12b0e1282a347b6e4de6e73b19c96d91.css" integrity="sha256-puM&#43;/5/KKV3amRFdq8OH/RKw4SgqNHtuTebnOxnJbZE=">
<script defer src="/notes/en.search.min.1448ffdc2e7b9337b67946a9671960be5721c86358c86c216f6041ee188c8305.js" integrity="sha256-FEj/3C57kze2eUapZxlgvlchyGNYyGwhb2BB7hiMgwU="></script>
<script defer src="/notes/en.search.min.22a88f8bc829510a23fc80aa14332798a7d139135b9d2560bfd69503ddb936e1.js" integrity="sha256-IqiPi8gpUQoj/ICqFDMnmKfRORNbnSVgv9aVA925NuE="></script>

<script defer src="/notes/sw.min.102e0b752b65c874dd63b7b7ef9f8391b698d86adbb048ed0e6ddf02a6093f83.js" integrity="sha256-EC4LdStlyHTdY7e375&#43;DkbaY2GrbsEjtDm3fAqYJP4M="></script>
<link rel="alternate" type="application/rss+xml" href="http://zedchance.github.io/notes/CS10/index.xml" title="Notes" />
Expand Down Expand Up @@ -1434,6 +1434,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS135/CS135-lecture-20210318/" class="">CS135-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down Expand Up @@ -1638,6 +1651,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS137/CS137-lecture-20210318/" class="">CS137-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down
28 changes: 27 additions & 1 deletion docs/CS12/CS12-lecture-notes/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<link rel="manifest" href="/notes/manifest.json">
<link rel="icon" href="/notes/favicon.png" type="image/x-icon">
<link rel="stylesheet" href="/notes/book.min.a6e33eff9fca295dda99115dabc387fd12b0e1282a347b6e4de6e73b19c96d91.css" integrity="sha256-puM&#43;/5/KKV3amRFdq8OH/RKw4SgqNHtuTebnOxnJbZE=">
<script defer src="/notes/en.search.min.1448ffdc2e7b9337b67946a9671960be5721c86358c86c216f6041ee188c8305.js" integrity="sha256-FEj/3C57kze2eUapZxlgvlchyGNYyGwhb2BB7hiMgwU="></script>
<script defer src="/notes/en.search.min.22a88f8bc829510a23fc80aa14332798a7d139135b9d2560bfd69503ddb936e1.js" integrity="sha256-IqiPi8gpUQoj/ICqFDMnmKfRORNbnSVgv9aVA925NuE="></script>

<script defer src="/notes/sw.min.102e0b752b65c874dd63b7b7ef9f8391b698d86adbb048ed0e6ddf02a6093f83.js" integrity="sha256-EC4LdStlyHTdY7e375&#43;DkbaY2GrbsEjtDm3fAqYJP4M="></script>
<!--
Expand Down Expand Up @@ -1438,6 +1438,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS135/CS135-lecture-20210318/" class="">CS135-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down Expand Up @@ -1642,6 +1655,19 @@ <h2 class="book-brand">
</li>



<li>





<a href="http://zedchance.github.io/notes/CS137/CS137-lecture-20210318/" class="">CS137-lecture-20210318</a>


</li>


</ul>

</li>
Expand Down

0 comments on commit 42e4f24

Please sign in to comment.