Skip to main content

Formal automata for the Chomsky hierarchy — pure Python.

Project description

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 🔄 planned 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 — planned v0.2.0)

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

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.

Project details


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.1.0.tar.gz (89.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.1.0-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fsm_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 89.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fsm_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce9046a8d42f037305e34ef455da2309017a7fe19b21b15170a334a714575a44
MD5 78f25c333f470145680d7040988d5146
BLAKE2b-256 1f00d32c35e8ce1c893904cdb4b228a58ce8003897a24a7efebfab9d5bec6571

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fsm_tools-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fsm_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ae1ff86b6054a0f6c33e037e0e3814c5e6d7273ce8bdbba8c4a02e34aa44398
MD5 cc06a391809046882feef219217d9f0f
BLAKE2b-256 16c1b81a58ad198664c4d2997c0918f22230a77235e4165bf71fa0f717621a57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page