Skip to content

Nejmeddine-Mek/Turing-Machine-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Turing Machine Simulator

A simple simulator of the unary mathematical model of a Turing Machine, as studied at ESI Algiers. This project is designed for educational purposes, helping students visualize and understand how a Turing Machine operates step by step.


Overview

The simulator implements a unary representation of natural numbers and executes algorithms defined as formal Turing Machine instructions. It provides a visual tape, a reading head, and an execution environment similar to a small IDE.


How It Works

The Tape

  • The tape is initially filled with 0s, which represent blanks.
  • The reading head starts at a fixed position and always reads the highlighted cell.

Number Representation (Unary)

  • The machine works only with natural numbers (including 0).
  • A number n is represented using n + 1 bars (|).

Examples:

  • 0|
  • 2|||
  • 5||||||

Arguments Encoding

  • Multiple arguments are separated using an asterisk (*).

Examples:

  • (2, 3)|||*||||
  • (1, 0, 2)||*|*|||

!! No spaces are allowed between symbols.


Instructions Format

Each instruction of the algorithm must follow this exact format:

<current_state>,<read_value>,<action_to_take>,<next_state>

Instruction Fields

1️ <current_state>

  • The current state of the machine.

2️ <read_value>

  • The symbol currently read by the head (0, |, or *).

3️ <action_to_take>

The action can be either a move or a write:

Move actions:

  • R → move one cell to the right
  • L → move one cell to the left

Write actions:

  • 0 → write a blank
  • | → write a bar
  • * → write an asterisk

!! If the machine encounters a state/read-value combination with no defined instruction, the simulator will throw a runtime error.

4️ <next_state>

  • The state to transition to after executing the action.

Two cases:

  • Defined next state → execution continues.
  • Undefined next state → the program halts, marking the end of execution.

Halting the Machine

  • You can manually stop execution at any time using the red “Halt” button in the interface.

Interface Notes

  • On the right side of the screen, below the IDE, you will find a set of remarks.
  • These notes provide helpful guidance for using the simulator.
  • A full and detailed documentation will be uploaded in the future and will replace these remarks.

Purpose

This simulator is intended to:

  • Help students understand formal Turing Machine execution
  • Visualize tape manipulation and state transitions
  • Experiment with unary algorithms in a controlled environment

Future Work

  • Full documentation
  • Example programs (addition, subtraction, comparison, etc.)
  • Improved error messages
  • Export / import of machine definitions

Releases

No releases published

Packages

No packages published