jweinberger
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Computability, Turing machines, (un)decidability (Based on notes by Dr. J. Gil-Férez) ## Motivating discusion :::warning * What is a regular language? Is every language regular? * What tools do we have to prove that a language is not regular? * Can we use the Pumping Lemma to prove that a language is regular? * What is the main idea of the proof of the Pumping Lemma? ::: ### Discuss the following argument :::warning The language $L = \{10^n 10^m 10^{m+n} : n,m\in\mathbb N\}$ is not regular (why?). Hence, DFAs are insufficient to do Arithmetic. ::: ### Question What is missing in DFAs, if we want to do arithmetic computations? ## Turing's idea of computation :::info * ''Computing is normally done by writing certain symbols on paper. We may suppose this paper is divided into squares like a child's arithmetic book. In elementary arithmetic the two-dimensional character of the paper is sometimes used. But such a use is always avoidable, and I think that it will be agreed that the two-dimensional character of paper is no essential of computation. I assume then that the computation is carried out on one-dimensional paper, i.e. on a tape divided into squares.'' * ''I shall also suppose that the number of symbols which may be printed is finite.'' * ''The behaviour of the computer at any moment is determined by the symbols which he is observing, and his "state of mind" at that moment. [...] We will also suppose that the number of states of mind which need be taken into account is finite.'' * ''Let us imagine the operations performed by the computer to be split up into "simple operations" which are so elementary that it is not easy to imagine them further divided.'' * ''We may suppose that in a simple operation not more than one symbol is altered.'' A. M. Turing, *On computable numbers with an application to the Entscheidungsproblem*, Proc. of the London Mathematical Society, vol s2-42, 1 (1937), pp. 230--265. ::: ## Turing machines A *Turing machine* is a 7-tuple $$ M = (Q,\Sigma,\Gamma,\delta,q_0,B,F),$$ * $Q$ is the finite set of *states*, * $\Sigma$ is the finite set of *input symbols*, * $\Gamma$ is the finite set of *tape symbols* ($\Sigma\subseteq\Gamma$), * $\delta$ is the (partial) *transition function*, * $q_0$ is the *start state*, * $B$ is the *blank symbol* (it is not an input symbol), * $F$ is the set of *accepting states*. The transition function $\delta$ takes a state and a symbol and returns a state, a symbol, and either $R$ or $L$: $$\delta(q,X) = (p,Y,D)$$ * $q$ is the state current state of the machine, * $X$ is the symbol that the machine scans in the current square, * $p$ is the new state (it could be $p=q$) of the machine, * $Y$ is the symbol that is printed in the current square (it could be $Y=X$), * $D$ is either $R$ or $L$: -- if $D = R$ then the head moves to the right of the tape, -- if $D = L$ then the head moves to the left of the tape. :::info **Theorem.** TMs are an extension of DFAs. **Proof.** DFAs can be considered TMs which scan every square of the input exactly once, from left to right, and do not change the input. Thus, all we have to do is "update" the transition function in a trivial way. If the transition function of the DFA maps $\delta(p,X)=q$, the transition function of the TM would be $\delta(p,X)=(q,X,R)$. When the TM finishes scanning the input, it will find the first blank, for which the transition function is not defined, and therefore the TM would halt. $\square$ ::: :::success **Example.** Let's design a TM to accept the binary strings with an even number of 0's. (This can be done by a DFA.) We need three states $q_0$ (even number of 0's), $q_1$ (odd number of 0's). The start state is $q_0$ and the accepting state is also $q_0$. The input symbols are 0 and 1, and the tape symbols include also $B$. The machine should scan the symbols of the input string, one by one. If the machine finds a 0, it should change state (from $q_0$ to $q_1$ and from $q_1$ to $q_0$), write 0, and go to the right. If the machine finds a 1, it should remain in the same state, write 1, and go to the right. If the machine scans $B$, then it should do nothing (halt). | $\delta$ | $0$ | $1$ | $B$ | | -------- | --------- | --------- |---- | | $q_0$ | $q_1,0,R$ | $q_0,1,R$ | | | $q_1$ | $q_0,0,R$ | $q_1,1,R$ | | http://turingmachinesimulator.com/shared/rgakbxmacg ::: :::warning **Exercise A.** 1. Write a TM to accept the language of binary strings $L = \{10^n : n\in\mathbb N\}$ and for the input $10^n$ it returns the string $10^{n+1}$. 1. Write a TM to accept the language of binary strings $L = \{10^n : n\in\mathbb N\}$ and for the input $10^n$ it returns the string $1$. 1. Write a TM to accept the total language of binary strings and, for every string, it returns the string with 0's and 1's swapped. **NB:** Note that $10^n = 1 \underbrace{00\ldots0}_{n \; \; \mathrm{times}}$. ::: :::success **Example 8.2** What follows is a TM that accepts the language $L = \{0^n1^n : n\in\mathbb N\}$. (Notice that this language is not regular due to the pumping lemma.) The idea is to change any $0$ to an $X$ and any $1$ to a $Y$ until all $0$'s and $1$'s have been matched. Concretely, reading a $0$ from the left, the head will move over any $0$ and $Y$ until it finds $1$ which then gets rewritten into $X$, prompting the head to move back to the left until it finds an $X$. It then immediately looks for a $0$ on the right. If it finds one, it changes it to $X$, repeating the process, changing a matching $Y$ to $1$. | $\delta$ | $0$ | $1$ | $X$ | $Y$ | $B$ | | -------- | --------- | --------- | --------- | --------- |---------- | | $q_0$ | $q_1,X,R$ | | | $q_3,Y,R$ | | | $q_1$ | $q_1,0,R$ | $q_2,Y,R$ | | $q_1,Y,R$ | | | $q_2$ | $q_2,0,L$ | | $q_0,X,R$ | $q_2,Y,L$ | | | $q_3$ | | | | $q_3,Y,R$ | $q_4,B,R$ | | $q_4$ | | | | | | http://turingmachinesimulator.com/shared/htdmgnjsak ::: :::warning **Exercise B.** 1. Write a TM to perform unary addition: it should accept the language $L = \{10^n10^m : n,m\in\mathbb N\}$ and for the input $10^n10^m$ it should return $10^n10^m10^{n+m}$. 1. Write a TM to double a binary string: it should accept any binary string, and for the input $w$ it should return $ww$. ::: ## Instantaneous descriptions (IDs) We can encode a specific step of the computation of a TM by writing the symbols on the tape (except for the infinite blanks on the left and on the right), and writing the state name immediately on the left of the next symbol to be scanned. If the start state is $q_0$ and the input is $X_0X_1\dots X_n$, we represent this by the ID: $$q_0X_0X_1\dots X_n.$$ And if the transition function is $\delta(q,X_i) = (p,Y,R)$, then we represent the change from the previous step to the new one by $$X_0\dots X_{i-1}q X_iX_{i+1}\dots X_n \vdash_M X_0\dots X_{i-1}Yp X_{i+1}\dots X_n.$$ We use $\vdash_M^*$ to represent a transition from one ID to another one by several steps of computation. The subscripts of $\vdash_M$ and $\vdash_M^*$ can be omitted if the TM $M$ is understood by context. :::success **Example.** These are the IDs of the first steps of the TM of Example 8.2 with imput $w = 0011$: $$q_00011 \vdash_M Xq_1011 \vdash_M X0q_111 \vdash_M Xq_20Y1 \vdash_M \dots,$$ because $\delta(q_0,0) = (q_1,X,R)$, $\delta(q_1,0) = (q_1,0,R)$, $\delta(q_1,1) = (q_2,Y,L)$. Then, we can write $q_00011\vdash_M^* Xq_20Y1$. ::: ## Transition diagrams TMs can be represented by transition diagrams as DFAs. The difference is that we have to label the arcs, not only with the symbol that the machine is scanning, but also with the symbol to be written, and the direction in which the reader/writer moves along the tape. :::success **Example.** This is the transition diagram of the TM of Example 8.2. ![transition_diagram](https://hackmd.io/_uploads/HkiZWGKp1g.png) ::: Transition diagrams of TMs are also an extension of the transition diagrams of DFAs. In particular, given a transition diagram of a DFAs, we can convert it into the transition diagram of the corresponding TM as follows: in every arc, replace the label $X$ with $X/X\to$. :::warning **Exercise C.** Draw transition diagrams for the TMs of the previous exercises. ::: :::success **Example 8.4.** This machine computes the *monus* operation (proper subtraction) of natural numbers (see pp. 331--334): ![transition diagram monus](https://hackmd.io/_uploads/rkOzNrhpkl.png) http://turingmachinesimulator.com/shared/ogabrxinrf ::: ## The language of a TM and halting A string $w$ in the input language of a TM $M$ with start state $q$ is *accepted* by $M$ if $qw\vdash_M^* xpy$ for some accepting state $p$ and whatever strings $x$ and $y$. The *language* of a TM $M$ is the set $L(M)$ of all the strings that are accepted by $M$. A language $L$ is *recursively enumerable* (RE) if it is the language of a TM $M$, that is, $L = L(M)$. A TM *halts* if it enters a state $q$ scanning the symbol $X$ such that $\delta(q,X)$ is not defined. (Some other formalizations of TMs admit a special order to halt the machine.) :::warning **Exercise D.** Design a Turing machine that accepts the binary strings with at least one $1$, but doesn't halt for any input. ::: A language is *recursive* if it is the language of a TM that halts for every input. A problem is *decidable* if can be solved by a TM that always halts. ## Programming techniques ### Storage in the state and multiple tracks These ideas are usually used in combination. Storing information in the finite control means to create states that "remember" if the machine has read a particular symbol. This is accomplished by "labeling" the states, that is, in the process of designing the machine, we label certain states (possible all), with the symbols of our language. Thus, instead of having states $q$ and $p$, for example, we could have states $[q,A]$, $[q,B]$, $[q,C]$, $[p,A]$, $[p,B]$, $[p,C]$, where $A$, $B$, and $C$ are symbols of our language. The technique of multiple tracks is useful if we want to mark that we have visited a certain square. This is accomplished by "labeling" the symbols of our language with "marking symbols", in the process of designing the machine. Thus, instead of using the alphabet $\{0,1\}$, we could use the alphabet $\{[B,0]$, $[B,1]$, $[*,0]$, $[*,1]\}$. :::success **Example 8.7** This machine accepts the language $L = \{wcw : w \text{ is a nonempty binary string}\}$. (See pp. 339--341.) http://turingmachinesimulator.com/shared/nduyjifsvy ::: ## Extensions of TMs: multitape TMs We can add more than one tape to a TM. The transition function will have instructions to write in all the tapes possibly different symbols and move each tape independently. This doesn't enlarge the class of decidable problems: :::info **Theorem.** Every language accepted by a multitape TM is also accepted by a TM. **Idea of the proof.** Every multitape TM can be simulated by a TM. ::: :::success **Example.** This multitape TM reverses any binary string. Given an input $w$ it returns $w*w^R$. http://turingmachinesimulator.com/shared/uwbozvhxjx ::: :::success **Example.** This multitape TM computes the division with remainder of natural numbers. Given an input $10^n10^m$ it returns $10^n10^m10^q10^r$, where $n = qm + r$. http://turingmachinesimulator.com/shared/shghrorpyu ::: :::warning **Exercise E.** 1. Design a (multitape) TM that accepts any binary string $w$ and returns another string of the form $0^n1^m$, where $n$ and $m$ are the numbers of $0$'s and $1$'s of $w$, respectively. 1. *Chalenge:* Design a (multitape) TM that computes the multiplication of natural numbers: it accepts any binary string of the form $10^n10^m$ and returns $10^n10^m10^{nm}$. ::: ## Final considerations * We have seen how every DFA is can be extended in a trivial way to a TM, which always halt, accepting the same language. Therefore, every regular language is recursive. * TMs constitute a model of computation, but it is not the only one. Church developed (about the same time as Turing) $\lambda$-calculus ("lambda calculus") and Gödel extended Kronecker's work on primitive recursive functions to general recursive functions. Both models, $\lambda$-calculus and general recursive functions, turned out to be equivalent to Turing machines, in that if a problem can be solved by one of them, it can be also solved by the other two. Many other models of computation have been proposed and the more powerful (finitary) ones are always equivalent to Turing machines. A model for computation is calaled *Turing complete* if it can simulate every Turing machine. * The following questions are equivalent and they are open for discussion and future inquiry: - Are there languages that are recursively enumerable but not recursive? - If a language $L$ is accepted by a TM $M$, is there always a TM $M'$ which also accepts $L$ and always halt? - Are there problems that can be solved (by a TM) but are undecidable? * Finally, consider the *halting problem:* Is there an algorithm (i.e., a TM) to decide if any given TM $M$ with any given input $w$ will halt? It turns out that the answer is *no*, showing that there are languages that are not even recursively enumerable.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully