-
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
470 changed files
with
10,003 additions
and
880 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,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) | ||
|
||
|
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
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.