Skip to content

Nicolas-Saavedra/mercury-lib

Repository files navigation

Project generated with PyScaffold

Mercury

An automata tool based around delta functions for ease of use

Graphical interface showing off mercury

Installation:

# For basic package usage
pip install mercury-lib

# For graphical interface support
pip install mercury-lib[web]

# For full functionality support (requires graphviz installed)
pip install mercury-lib[all]

Usage:

from mercury.automata import DeterministicFiniteAutomata
from mercury.decorators import DeltaFunction
from mercury.operations.sets import S

states = S({"a", "b"}) * S(range(3)) | S({0})
input_symbols = "abx"
initial_state = ("a", 0)
final_states = [("b", 0)]

delta = DeltaFunction()


@delta.definition()
def _(_: int, next: str):
    return 0


@delta.definition()
def _(w: str, y: int, next: str):
    if w == "a" and next == "a":
        return (w, (y + 1) % 3)
    elif w == "a" and next == "b":
        return (w, y)
    elif w == "a" and next == "x":
        return ("b", (3 - y) % 3)
    elif w == "b" and next == "b":
        return (w, (y + 1) % 3)
    elif w == "b" and next == "a":
        return (w, y)
    else:
        return 0


automata = DeterministicFiniteAutomata(
    states, input_symbols, initial_state, final_states, delta
)

print(automata.accepts_input("x"))
print(automata.accepts_input("aaaxbbb"))
print(automata.accepts_input("aaax"))
print(not automata.accepts_input("axbb"))

More information can be found at the documentation hosted at Github Pages

Note

This project has been set up using PyScaffold 4.6. For details and usage information on PyScaffold see https://pyscaffold.org/.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published