Skip to content

Commit

Permalink
Update Sat Apr 24 21:03:16 PDT 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
zedchance committed Apr 25, 2021
1 parent 88889e9 commit 77505f6
Show file tree
Hide file tree
Showing 470 changed files with 10,003 additions and 880 deletions.
122 changes: 122 additions & 0 deletions content/CS135/CS135-lecture-20210423.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: "CS135-lecture-20210423"
# date: 2021-04-23T13:59:40-07:00
draft: false
bookToc: true
tags: ["turing machine"]
---

## Introduction to Turing machines

{{< hint info >}}
Note: See text book readings for formal history of the Turing machine.
{{< /hint >}}

A Turing machine has a tape that is infinitely long in both directions.
The machine has a tape head that can read and write to the tape.

The control unit of the Turing machine is an automata.
Each transition has a pair {{<k>}} x,y {{</k>}}, follow the arrow if
the tape head is over {{<k>}} x {{</k>}}, and do operation {{<k>}} y {{</k>}}.

![image_2021-04-23-14-10-17](/notes/image_2021-04-23-14-10-17.png)

{{<k>}} y {{</k>}} can be:
- {{<k>}} R {{</k>}}, move right
- {{<k>}} L {{</k>}}, move left
- {{<k>}} y {{</k>}}, write {{<k>}} y {{</k>}}, can be a blank (indicated by {{<k>}} B {{</k>}}).

Turing machines are deterministic, and have no {{<k>}} \lambda {{</k>}} transitions.
The machine halts when no transition matches, so Turing machines don't require a transition for every alphabet character.

There are two types:
- Recognizer, which accepts/rejects input.
- Transducer, which takes input and produces output.

![image_2021-04-23-14-16-56](/notes/image_2021-04-23-14-16-56.png)

By convention, the tape head always starts at the far left of the input, and ends at the far left of the output.

### First example

With a tape starting with {{<k>}} n {{</k>}} 1s, we want the output to be {{<k>}} n {{</k>}} 0s.

![image_2021-04-23-14-23-23](/notes/image_2021-04-23-14-23-23.png)

Some simple pseudo code might be

```
while head is over 1
write 0
move R
move L
while head is over 0
move L
move R
```

Make sure to check edge cases, i.e. only a single 1 being on the tape.
Also check if the tape is empty initially.

This starts out as a self loop on the initial state that has the pair {{<k>}} 1,0 {{</k>}}.

![image_2021-04-23-14-30-35](/notes/image_2021-04-23-14-30-35.png)

The `move R` can be added as another pair {{<k>}} 0,R {{</k>}}.

![image_2021-04-23-14-31-13](/notes/image_2021-04-23-14-31-13.png)

{{< hint info >}}
Note: This would be a problem if we had any 0s in the input to begin with, we are assuming the input is good.
To handle this we could have a state like

![image_2021-04-23-14-32-04](/notes/image_2021-04-23-14-32-04.png)

Which would halt on a 0 in the initial input.
{{< /hint >}}

When this loop finishes, it means we are no longer over a 1.
The head should be over a blank.
So to transition to the next state we have the pair {{<k>}} B,L {{</k>}}.

![image_2021-04-23-14-33-20](/notes/image_2021-04-23-14-33-20.png)

The next loop can be handled by {{<k>}} 0,L {{</k>}}.
And when we reach the far right blank we can move right.

![image_2021-04-23-14-33-56](/notes/image_2021-04-23-14-33-56.png)

The last state has no arrows, so the program will halt.

### Second example

![image_2021-04-23-14-36-06](/notes/image_2021-04-23-14-36-06.png)
![image_2021-04-23-14-38-11](/notes/image_2021-04-23-14-38-11.png)
![image_2021-04-23-14-38-36](/notes/image_2021-04-23-14-38-36.png)
![image_2021-04-23-14-39-53](/notes/image_2021-04-23-14-39-53.png)
![image_2021-04-23-14-43-07](/notes/image_2021-04-23-14-43-07.png)
![image_2021-04-23-14-44-14](/notes/image_2021-04-23-14-44-14.png)
![image_2021-04-23-14-44-28](/notes/image_2021-04-23-14-44-28.png)
![image_2021-04-23-14-44-53](/notes/image_2021-04-23-14-44-53.png)
![image_2021-04-23-14-45-02](/notes/image_2021-04-23-14-45-02.png)
![image_2021-04-23-14-45-33](/notes/image_2021-04-23-14-45-33.png)
![image_2021-04-23-14-45-45](/notes/image_2021-04-23-14-45-45.png)
![image_2021-04-23-14-45-53](/notes/image_2021-04-23-14-45-53.png)
![image_2021-04-23-14-46-01](/notes/image_2021-04-23-14-46-01.png)
![image_2021-04-23-14-46-18](/notes/image_2021-04-23-14-46-18.png)
![image_2021-04-23-14-46-32](/notes/image_2021-04-23-14-46-32.png)

The pair {{<k>}} B,B {{</k>}} is kind of like "no operation".

![image_2021-04-23-14-50-09](/notes/image_2021-04-23-14-50-09.png)

### Testing

![image_2021-04-23-14-51-52](/notes/image_2021-04-23-14-51-52.png)
![image_2021-04-23-14-52-29](/notes/image_2021-04-23-14-52-29.png)
![image_2021-04-23-14-52-31](/notes/image_2021-04-23-14-52-31.png)
![image_2021-04-23-14-52-34](/notes/image_2021-04-23-14-52-34.png)
![image_2021-04-23-14-52-43](/notes/image_2021-04-23-14-52-43.png)
![image_2021-04-23-14-52-47](/notes/image_2021-04-23-14-52-47.png)


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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

<script defer src="/notes/sw.min.102e0b752b65c874dd63b7b7ef9f8391b698d86adbb048ed0e6ddf02a6093f83.js" integrity="sha256-EC4LdStlyHTdY7e375&#43;DkbaY2GrbsEjtDm3fAqYJP4M="></script>
<!--
Expand Down
15 changes: 14 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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></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 @@ -1525,6 +1525,19 @@ <h2 class="book-brand">
</li>



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS12/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></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/CS12/index.xml" title="Notes" />
Expand Down Expand Up @@ -1525,6 +1525,19 @@ <h2 class="book-brand">
</li>



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS13/CS13-lecture-notes/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS13/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></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/CS13/index.xml" title="Notes" />
Expand Down Expand Up @@ -1525,6 +1525,19 @@ <h2 class="book-brand">
</li>



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS130/CS130-exercise-solutions-1/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS130/CS130-lecture-20200831/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down
15 changes: 14 additions & 1 deletion docs/CS130/CS130-lecture-20200902/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.34d39affea38872062a785187100688e198de4a3bb065d09f33b0b6cc4723e7f.js" integrity="sha256-NNOa/&#43;o4hyBip4UYcQBojhmN5KO7Bl0J8zsLbMRyPn8="></script>
<script defer src="/notes/en.search.min.41900a506556cc45e79567397bb7e3d2a02048a627349c913b0eaf92f3e0f339.js" integrity="sha256-QZAKUGVWzEXnlWc5e7fj0qAgSKYnNJyROw6vkvPg8zk="></script>

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



<li>





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


</li>


</ul>

</li>
Expand Down

0 comments on commit 77505f6

Please sign in to comment.