DevTools Logo

FSM & Turing Machine Simulator

FSM & Turing Machine Simulator

Run deterministic finite automata and single-tape Turing machines with a step-by-step trace.

Runs in your browser
Deterministic machines only. NFAs and epsilon moves are not supported.
Try an example

Machine definition

36 lines · 516 chars

Execution trace

7 rows

Accepted

Final state q_even · 6 transitions

StepStateReadAction
0q_evenstartstart
1q_even1q_odd
2q_even0q_odd
3q_even1q_even
4q_even1q_odd
5q_even0q_odd
6q_even1q_even

Step trace

Examples

Mod-3 accept versus reject

Input
runDfa(binaryModuloThreeDfa, "110") / runDfa(binaryModuloThreeDfa, "101")
Output
"110" -> accepted, finalState r0 / "101" -> not-accepting, finalState r2

110 is 6 (divisible by 3) so it ends in r0; 101 is 5, ending in r2 outside the accept set.

Binary increment halts on tape

Input
runTuringMachine(binaryIncrementTuringMachine, "1011")
Output
accepted, tape "1100_"

The scan/carry machine flips trailing ones and halts in accept with the incremented value.

About this tool

FSM Turing Simulator runs deterministic automata with runDfa(definition, input) and runTuringMachine(definition, input, maxSteps = 1000): DFA results carry accepted, reason, finalState, and a per-symbol trace, while TM results carry accepted, halted, state, tape, head, steps, and a per-step trace. Bundled machines include binaryEvenOnesDfa, binaryModuloThreeDfa (r0/r1/r2), and binaryIncrementTuringMachine.

DFA reasons are exact: accepted when the final state is accepting, missing-transition when no (state, symbol) entry exists, not-accepting when input is consumed outside an accept state, and invalid-definition for a bad start state, bad accept state, duplicate key, or a transition naming an unknown state. TM reasons add rejected (entered a reject state) and step-limit (maxSteps reached with halted false).

Everything is deterministic and client-side: identical definitions always produce identical traces, tape grows with blanks on demand, and head moves left past zero by unshifting blanks.

How to use this tool

  1. Define or pick a machine

    Use a preset (even-ones, mod-3, binary increment) or supply states, startState, acceptStates, and transitions explicitly.

  2. Run the input

    Call runDfa with the input string, or runTuringMachine with input plus an optional step budget (default 1000).

  3. Read reason and trace

    Check accepted plus reason first — missing-transition versus not-accepting versus step-limit point at different fixes — then walk the trace steps.

  4. Fix invalid definitions

    An invalid-definition reason means a start, accept, or nextState outside states, or a duplicated (state, symbol) key — correct the table and re-run.

Use cases

Teaching DFA acceptance

Show how even-ones and mod-3 machines consume symbols step by step into accept or reject.

Debugging transition tables

Distinguish a missing (state, symbol) entry from a correct run that ends outside accept states.

Bounding TM execution

Use maxSteps and the step-limit reason to demonstrate looping machines that never halt.

Common mistakes

Mistake:Treating missing-transition and not-accepting as the same failure.

Fix:Missing-transition means the table has no entry mid-input; not-accepting means the run completed outside acceptStates — inspect finalState and the rejected trace step to tell them apart.

Mistake:Referencing states that are not declared in states.

Fix:Every startState, acceptState, transition state, and nextState must be listed — anything else returns invalid-definition immediately.

Mistake:Expecting a looping TM to halt on its own.

Fix:Pass an explicit maxSteps and handle the step-limit result (halted false) instead of waiting for acceptance.

Frequently asked questions

What does this tool do?

It runs deterministic automata: runDfa(definition, input) returns accepted, reason, finalState, and a trace, while runTuringMachine(definition, input, maxSteps = 1000) returns accepted, halted, state, tape, head, steps, and a trace — with bundled binaryEvenOnesDfa, binaryModuloThreeDfa, and binaryIncrementTuringMachine presets.

What is the difference between missing-transition and not-accepting?

missing-transition means the table had no (state, symbol) entry mid-input (e.g. second 0 in a one-edge machine); not-accepting means the run consumed everything but ended outside acceptStates (e.g. 111 in the even-ones DFA). Check finalState and the rejected trace step.

Is my automaton uploaded or stored?

No. DFA stepping, TM tape growth, and trace recording run entirely in your browser.

Why did I get invalid-definition or step-limit?

invalid-definition means a start, accept, or nextState outside states or a duplicated key — fix the table. step-limit means maxSteps ran out with halted false, typical for looping machines; raise the budget or accept non-halting.

References & standards