Skip to main content

Python CI codecov PyPI

Lire en français


fsm-tools

A formal Python library for modelling automata in the Chomsky hierarchy.

Overview

fsm-tools provides a rigorous implementation of the four automaton families defined by Chomsky's grammar and language hierarchy:

Type Automaton Language family Status
0 TuringMachine Recursively enumerable ✅ v0.0.4
1 LinearBoundedAutomaton Context-sensitive ✅ v0.0.4
2 PushdownAutomaton Context-free ✅ v0.1.0
3 FiniteStateAutomaton Regular ✅ v0.2.0

Each class is a formal restriction of the one above it — inheriting its structure and constraining it further. The hierarchy is implemented as a strict inheritance chain:

Automaton
└── TuringMachine               (Type 0)
    └── LinearBoundedAutomaton  (Type 1)
        └── PushdownAutomaton   (Type 2)
            └── FiniteStateAutomaton  (Type 3)

Installation

pip install fsm-tools

Quick start

Turing Machine (Type 0)

from fsm_tools import TuringMachine

tm = TuringMachine(
    name="BinaryIncrement",
    chomsky="Recursively Enumerable",
    axes=1,
    blank_symbol="_",
    movement={"R": [1], "L": [-1]},
    register="q0",
    accept="qAccept",
    reject="qReject",
)

Pushdown Automaton (Type 2)

Recognition of the context-free language L = { aⁿbⁿ | n ≥ 1 }:

from fsm_tools import PushdownAutomaton

pda = PushdownAutomaton(
    name="anbn",
    stack_alphabet={"A"},
    bottom_symbol="Z",
)
pda.add_terminals("a", "b")
pda.set_register("q0")
pda.add_non_terminals("q1", "q2")

pda.add_transition("q0", "a", "Z", "q0", ["A", "Z"])
pda.add_transition("q0", "a", "A", "q0", ["A", "A"])
pda.add_transition("q0", "b", "A", "q1", [])
pda.add_transition("q1", "b", "A", "q1", [])
pda.add_transition("q1", "b", "Z", "q2", [])

pda.validate(["a", "b"])        # True
pda.validate(["a", "a", "b"])   # False

Extended hierarchy (pedagogical)

extended.py provides pedagogical variants that lift specific formal restrictions without changing the class of languages recognised — a direct illustration of the Church-Turing thesis:

Class Extends Adds Since
ExtendedTuringMachine TuringMachine n-dimensional, bidirectional tape v0.0.4
ExtendedLBA LinearBoundedAutomaton n-dimensional bounded tape v0.0.4
ExtendedPushdownAutomaton PushdownAutomaton Epsilon-transitions, epsilon-closure validate() v0.3.0
from fsm_tools import ExtendedPushdownAutomaton

# L = { aⁿbⁿ | n ≥ 0 } — the epsilon-transition covers n = 0, which the
# base PushdownAutomaton rejects unconditionally.
epda = ExtendedPushdownAutomaton(name="anbn-eps", stack_alphabet={"A"}, bottom_symbol="Z")
epda.add_terminals("a", "b")
epda.set_register("q0")
epda.add_non_terminals("q1", "q2")

epda.add_transition("q0", "a", "Z", "q0", ["A", "Z"])
epda.add_transition("q0", "a", "A", "q0", ["A", "A"])
epda.add_transition("q0", "b", "A", "q1", [])
epda.add_transition("q1", "b", "A", "q1", [])
epda.add_transition("q1", "b", "Z", "q2", [])
epda.add_transition("q0", None, "Z", "q2", ["Z"])   # epsilon: accept n = 0

epda.validate([])               # True
epda.validate(["a", "b"])       # True

Documentation

Full documentation is available at fsm-tools.readthedocs.io.

Links

License

This project is licensed under the CeCILL-C license. The French version is the legally authoritative reference — see LICENSE.fr.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fsm_tools-0.3.0.tar.gz (108.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fsm_tools-0.3.0-py3-none-any.whl (57.7 kB view details)

Uploaded Python 3

File details

Details for the file fsm_tools-0.3.0.tar.gz.

File metadata

  • Download URL: fsm_tools-0.3.0.tar.gz
  • Upload date:
  • Size: 108.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fsm_tools-0.3.0.tar.gz
Algorithm Hash digest
SHA256 735974622bf6738c8c0ffb0936008ac05855089a00e800241df968aa21ad8644
MD5 a6b848fac1a64b2c2ab6372e3dff6f0d
BLAKE2b-256 07ab90ac6815dbd5d753734428e8f7fe7f1850406d12b31b0b89b59d3343d9ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for fsm_tools-0.3.0.tar.gz:

Publisher: ci-publish-pypi.yml on biface/automata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fsm_tools-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: fsm_tools-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 57.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fsm_tools-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1745068ff7d364fc984036b13ec08293eb35eb1b662fee484288e3c8e330e2b0
MD5 d5ac6444193ac83913032e8281a7a17d
BLAKE2b-256 851625020148659061be9b9e27d37feee9019b2dca16979e9e6ae007ff7c8f7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for fsm_tools-0.3.0-py3-none-any.whl:

Publisher: ci-publish-pypi.yml on biface/automata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

0.0.1.post1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page