LogoLogo
1.0.0
  • Home
  • Install
  • Docs
  • Contribute
  • Journey
  • Welcome
  • The Varphi Language Standard
    • Welcome
    • State Names
    • Tallies and Blanks
    • Head Directions
    • Lines
    • Comments
    • Varphi Programs
    • Addressing Ambiguities
  • Writing Varphi Programs
    • Your First Varphi Program
    • Running Varphi Programs
    • Debugging Varphi Programs
    • The Varphi VS Code Extension
    • Good Practices
    • More Examples
      • Addition By One
      • Add Two Numbers
      • Multiplication By Two
      • Rock, Paper, Scissors
      • Coin Flip
  • Turing Machine Theory
    • The Unary Number System
    • Turing Machine Tapes
    • Turing Machine Heads
    • Turing Machine States
    • Turing Machines
    • Nondeterministic Turing Machines
Powered by GitBook
LogoLogo

© 2025 Hassan El-Sheikha

On this page

Was this helpful?

Edit on GitHub
Export as PDF
  1. Turing Machine Theory

Turing Machines

A Turing machine is a quadruple (Q,s,F,δ)(Q, s, F, \delta)(Q,s,F,δ), where

  • QQQ is a finite nonempty set of states (e.g., {q0,q1,...,qn}\{q_0, q_1,...,q_n\}{q0​,q1​,...,qn​}, for some n∈Nn\in\mathbb{N}n∈N.

  • s∈Qs\in Qs∈Q is the initial state.

  • F⊆QF\subseteq QF⊆Q is the set of final states.

  • δ:(Q∖F)×{0,1}→Q×{0,1}×{L,R}\delta: (Q\setminus F)\times\{0, 1\}\rightarrow Q\times\{0, 1\}\times\{L, R\}δ:(Q∖F)×{0,1}→Q×{0,1}×{L,R} is the transition (partial) function.

NOTE: Above, we represent "tally" using 111, "blank" using 000, "left" using LLL, and "right" using RRR.

Wow! That's a lot to take in. The first three items in the quadruple are pretty straightforward, but what is that fourth item? Let's describe this in a more gentle way:

δ:(Q∖F)×{0,1}→Q×{0,1}×{L,R}\delta: (Q\setminus F)\times\{0, 1\}\rightarrow Q\times\{0, 1\}\times\{L, R\}δ:(Q∖F)×{0,1}→Q×{0,1}×{L,R} is a partial function (may not be defined for some inputs in the domain) mapping pairs of non-final states and tape cell possibilities to triples containing a state, tape cell possibility, and head direction.

For example, if δ\deltaδ maps (q0,0)(q_0, 0)(q0​,0) to (q1,1,R)(q_1, 1, R)(q1​,1,R), then this can be read as "if the machine's state is q0q_0q0​ and the current tape cell is blank, then switch to state q1q_1q1​, place a tally at the current tape cell, and move the head to the tape cell immediately right of the current tape cell.

Since we previously mentioned that states do not need to define rules for all possible tape cell conditions, δ\deltaδ is a partial, not total, function.

Recall our example of adding two tallies to a number on a tape. We used the following algorithm:

Start at state q0q_0q0​. Read the current tape cell.

  • If we are on state q0q_0q0​:

    • If there is a tally at the current tape cell, write a tally to the current tape cell (leaving it as-is) and move to the tape cell immediately to the right of the current one. Stay on state q0q_0q0​. Repeat.

    • If the current tape cell is blank, write a tally to the current tape cell and move to the tape cell immediately to the right of the current one. Switch to state q1q_1q1​. Repeat.

  • If we are on state q1q_1q1​:

    • If the current tape cell is blank, write a tally to the current tape cell and move to the tape cell immediately to the right of the current one. Switch to state q2q_2q2​. Repeat.

The transition function for this algorithm can be represented using a table:

If on state
If read
Then switch to state
Then write
Move

0

Again, 111 means "tally", 000 means "blank", RRR means "right", and LLL means "left" here.

We can write the transition function in an even more compact notation as follows:

q01q01Rq00q11Rq10q21Rq_0\quad 1 \quad q_0 \quad 1 \quad R\\ q_0\quad 0 \quad q_1 \quad 1 \quad R\\ q_1\quad 0 \quad q_2 \quad 1 \quad Rq0​1q0​1Rq0​0q1​1Rq1​0q2​1R

The transition function of a Turing machine is extremely powerful. In fact, supplying just the transition function of a Turing machine gives you everything you need to know about the Turing machine except for the initial state of the machine. However, we will make the assumption that the initial state is the first state mentioned (that is, the state at the top left corner of the Turing program), which is called the Top-Left Rule for Varphi. Writing the transition function in compact notation makes it very easy to describe Turing machines without heavy notation or tables.

Believe it or not, you've just written your first Varphi Program! Here it is in a code block.

q0 1 q0 1 R
q0 0 q1 1 R
q1 0 q2 1 R

Pretty simple, right?

PreviousTuring Machine StatesNextNondeterministic Turing Machines

Last updated 4 months ago

Was this helpful?

q0q_0q0​
111
q0q_0q0​
111
RRR
q0q_0q0​
000
q1q_1q1​
111
RRR
q1q_1q1​
q2q_2q2​
111
RRR