From 25f4896175a619ef31e1e9ec99eb8b83cd1ff6f0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 31 Dec 2023 04:54:19 +0000 Subject: [PATCH] Deployed c39df7d with MkDocs version: 1.4.2 --- .nojekyll | 0 404.html | 1388 ++++ api/base-exception-classes/index.html | 1972 +++++ api/class-automaton/index.html | 1919 +++++ api/fa/class-dfa/index.html | 5502 ++++++++++++++ api/fa/class-fa/index.html | 1755 +++++ api/fa/class-gnfa/index.html | 1993 +++++ api/fa/class-nfa/index.html | 2959 ++++++++ api/index.html | 1415 ++++ api/pda/class-dpda/index.html | 1816 +++++ api/pda/class-npda/index.html | 1833 +++++ api/pda/class-pda/index.html | 1699 +++++ api/regular-expressions/index.html | 1887 +++++ api/tm/class-dtm/index.html | 1867 +++++ api/tm/class-mntm/index.html | 2012 +++++ api/tm/class-ntm/index.html | 1892 +++++ api/tm/class-tm/index.html | 1534 ++++ api/tm/tm-exception-classes/index.html | 1614 ++++ assets/_mkdocstrings.css | 64 + assets/images/favicon.png | Bin 0 -> 1870 bytes assets/img/favicon.png | Bin 0 -> 719 bytes assets/img/logo.svg | 20 + assets/javascripts/bundle.fac441b0.min.js | 29 + assets/javascripts/bundle.fac441b0.min.js.map | 8 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ .../workers/search.208ed371.min.js | 42 + .../workers/search.208ed371.min.js.map | 8 + assets/stylesheets/main.85bb2934.min.css | 1 + assets/stylesheets/main.85bb2934.min.css.map | 1 + assets/stylesheets/palette.a6bdf11c.min.css | 1 + .../stylesheets/palette.a6bdf11c.min.css.map | 1 + characteristics/index.html | 1533 ++++ examples/fa-examples/index.html | 1611 ++++ index.html | 1430 ++++ migration/index.html | 1842 +++++ objects.inv | Bin 0 -> 1155 bytes people/index.html | 1471 ++++ search/search_index.json | 1 + sitemap.xml | 108 + sitemap.xml.gz | Bin 0 -> 352 bytes 68 files changed, 50424 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 api/base-exception-classes/index.html create mode 100644 api/class-automaton/index.html create mode 100644 api/fa/class-dfa/index.html create mode 100644 api/fa/class-fa/index.html create mode 100644 api/fa/class-gnfa/index.html create mode 100644 api/fa/class-nfa/index.html create mode 100644 api/index.html create mode 100644 api/pda/class-dpda/index.html create mode 100644 api/pda/class-npda/index.html create mode 100644 api/pda/class-pda/index.html create mode 100644 api/regular-expressions/index.html create mode 100644 api/tm/class-dtm/index.html create mode 100644 api/tm/class-mntm/index.html create mode 100644 api/tm/class-ntm/index.html create mode 100644 api/tm/class-tm/index.html create mode 100644 api/tm/tm-exception-classes/index.html create mode 100644 assets/_mkdocstrings.css create mode 100644 assets/images/favicon.png create mode 100644 assets/img/favicon.png create mode 100644 assets/img/logo.svg create mode 100644 assets/javascripts/bundle.fac441b0.min.js create mode 100644 assets/javascripts/bundle.fac441b0.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.208ed371.min.js create mode 100644 assets/javascripts/workers/search.208ed371.min.js.map create mode 100644 assets/stylesheets/main.85bb2934.min.css create mode 100644 assets/stylesheets/main.85bb2934.min.css.map create mode 100644 assets/stylesheets/palette.a6bdf11c.min.css create mode 100644 assets/stylesheets/palette.a6bdf11c.min.css.map create mode 100644 characteristics/index.html create mode 100644 examples/fa-examples/index.html create mode 100644 index.html create mode 100644 migration/index.html create mode 100644 objects.inv create mode 100644 people/index.html create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..896fcfa6 --- /dev/null +++ b/404.html @@ -0,0 +1,1388 @@ + + + + + + + + + + + + + + + + + + + + Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ +

404 - Not found

+ +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/base-exception-classes/index.html b/api/base-exception-classes/index.html new file mode 100644 index 00000000..238fa542 --- /dev/null +++ b/api/base-exception-classes/index.html @@ -0,0 +1,1972 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Base exception classes - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Base exception classes

+ + +
+ + + + +
+ +

Exception classes shared by all automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ AutomatonException + + +

+ + +
+

+ Bases: Exception

+ + +

The base class for all automaton-related errors.

+ + +
+ +
+ +
+ + + + +

+ DiagramException + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The diagram cannot be produced

+ + +
+ +
+ +
+ + + + +

+ EmptyLanguageException + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The operation cannot be performed because the language is empty

+ + +
+ +
+ +
+ + + + +

+ FinalStateError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

A final state fails to meet some required condition.

+ + +
+ +
+ +
+ + + + +

+ InfiniteLanguageException + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The operation cannot be performed because the language is infinite

+ + +
+ +
+ +
+ + + + +

+ InitialStateError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The initial state fails to meet some required condition.

+ + +
+ +
+ +
+ + + + +

+ InvalidRegexError + + +

+ + +
+

+ Bases: RegexException

+ + +

Regular expression is invalid

+ + +
+ +
+ +
+ + + + +

+ InvalidStateError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

A state is not a valid state for this automaton.

+ + +
+ +
+ +
+ + + + +

+ InvalidSymbolError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

A symbol is not a valid symbol for this automaton.

+ + +
+ +
+ +
+ + + + +

+ LexerError + + + + dataclass + + +

+ + +
+

+ Bases: RegexException

+ + +

An exception raised for issues in lexing

+ + + + +
+ + + + + + + + + + + +
+ +
+ +
+ +
+ + + + +

+ MissingStateError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

A state is missing from the automaton definition.

+ + +
+ +
+ +
+ + + + +

+ MissingSymbolError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

A symbol is missing from the automaton definition.

+ + +
+ +
+ +
+ + + + +

+ RegexException + + +

+ + +
+

+ Bases: Exception

+ + +

The base class for all regular expression related errors

+ + +
+ +
+ +
+ + + + +

+ RejectionException + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The input was rejected by the automaton.

+ + +
+ +
+ +
+ + + + +

+ SymbolMismatchError + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The input symbols between the given automata do not match

+ + +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/class-automaton/index.html b/api/class-automaton/index.html new file mode 100644 index 00000000..e452f222 --- /dev/null +++ b/api/class-automaton/index.html @@ -0,0 +1,1919 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Class Automaton - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class Automaton(metaclass=ABCMeta)

+ + +
+ + + + +
+ + +

An abstract base class for all automata, including Turing machines.

+ + + + +
+ + + + + + + +
+ + + + +

+ input_parameters: Dict[str, Any] + + + property + + +

+ + +
+ +

Return the public attributes for this automaton.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Dict[str, Any] + +
+

A dictionary mapping attribute names to their values.

+
+
+
+ +
+ + + + +
+ + + + +

+ accepts_input(input_str) + +

+ + +
+ +

Return True if this automaton accepts the given input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to check.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if this automaton accepts the given input; False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ copy() + +

+ + +
+ +

Create a deep copy of the automaton.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A deep copy of the automaton.

+
+
+ +
+ +
+ + +
+ + + + +

+ read_input(input_str) + +

+ + +
+ +

Check if the given string is accepted by this automaton.

+

Return the automaton's final configuration if this string is valid.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to check.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ AutomatonStateT + +
+

The final configuration of the automaton after reading the input.

+
+
+ +
+ +
+ + +
+ + + + +

+ read_input_stepwise(input_str) + + + abstractmethod + + +

+ + +
+ +

Return a generator that yields each step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Any, None, None] + +
+

A generator that yields the current configuration of the automaton +after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ NotImplementedError + +
+

If this method has not been implemented by a subclass.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + + + abstractmethod + + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ NotImplementedError + +
+

If this method has not been implemented by a subclass.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/fa/class-dfa/index.html b/api/fa/class-dfa/index.html new file mode 100644 index 00000000..2395ed8c --- /dev/null +++ b/api/fa/class-dfa/index.html @@ -0,0 +1,5502 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class DFA(FA) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class DFA(FA)

+ + +
+ + + + +
+ +

Classes and methods for working with deterministic finite automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ DFA + + +

+ + +
+

+ Bases: FA

+ + +

The DFA class is a subclass of FA and represents a deterministic finite +automaton.

+

Every DFA can be rendered natively inside of a Jupyter notebook +(automatically calling show_diagram without any arguments) if installed +with the visual optional dependency.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[DFAStateT] + +
+

Set of the DFA's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the DFA's valid input symbols, each of which is a singleton +string

+
+
+ required +
transitions + Mapping[DFAStateT, Mapping[str, DFAStateT]] + +
+

Dict consisting of the transitions for each state. Each key is a +state name, and each value is another dict which maps a symbol +(the key) to a state (the value).

+
+
+ required +
initial_state + DFAStateT + +
+

The initial state for this DFA.

+
+
+ required +
final_states + AbstractSet[DFAStateT] + +
+

A set of final states for this DFA

+
+
+ required +
allow_partial + bool + +
+

By default, each DFA state must have a transition to +every input symbol; if this parameter is True, you can disable this +characteristic (such that any DFA state can have fewer transitions than input +symbols). Note that a DFA must always have every state represented in the +transition dictionary, even if there are no transitions on input symbols +leaving a state (dictionary is left empty in that case).

+
+
+ True +
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ cardinality() + +

+ + +
+ +

Returns the cardinality of the language represented by the DFA.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ int + +
+

The cardinality of the language accepted by self.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ InfiniteLanguageException + +
+

Raised if self accepts an infinite language.

+
+
+ +
+ +
+ + +
+ + + + +

+ clear_cache() + +

+ + +
+ +

Resets the word and count caches. +Can be called if too much memory is being used.

+ +
+ +
+ + +
+ + + + +

+ complement(*, retain_names=False, minify=True) + +

+ + +
+ +

Creates a DFA which accepts an input if and only if the old one does not. +Minifies by default. Unreachable states are always removed. Partial DFAs +are converted into complete ones.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
retain_names + bool + +
+

Whether to retain state names through the complement and optional +minify.

+
+
+ False +
minify + bool + +
+

Whether to minify the result of the complement of the input DFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A DFA accepting the complement of the input DFA. State +minimal by default.

+
+
+ +
+ +
+ + +
+ + + + +

+ count_mod(input_symbols, k, *, remainders=None, symbols_to_count=None) + + + classmethod + + +

+ + +
+ +

Directly computes a DFA that counts given symbols and accepts all strings where +the remainder of division by k is in the set of remainders given. +The default value of remainders is {0} and all symbols are counted by default.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
k + int + +
+

The number to divide the length by.

+
+
+ required +
remainders + Optional[AbstractSet[int]] + +
+

The remainders to accept. If set to None, defaults to {0}.

+
+
+ None +
symbols_to_count + Optional[AbstractSet[str]] + +
+

The input symbols to count towards the length of words to accepts. +If set to None, counts all symbols.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ count_words_of_length(k) + +

+ + +
+ +

Returns count of words of length k accepted by the DFA.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
k + int + +
+

The desired word length.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ int + +
+

The number of words of length k accepted by self.

+
+
+ +
+ +
+ + +
+ + + + +

+ difference(other, *, retain_names=False, minify=True) + +

+ + +
+ +

Takes as input two DFAs M1 and M2 which +accept languages L1 and L2 respectively. +Returns a DFA which accepts the difference of L1 and L2.

+

Minifies by default. Unreachable states are always removed. +If either input DFA is partial, the result is partial.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The DFA we want to take a difference with.

+
+
+ required +
retain_names + bool + +
+

Whether to retain state names through the difference and optional minify.

+
+
+ False +
minify + bool + +
+

Whether to minify the result of the difference of the two DFAs.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A DFA accepting the difference of the two input DFAs. State minimal by +default.

+
+
+ +
+ +
+ + +
+ + + + +

+ empty_language(input_symbols) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA rejecting all strings.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_finite_language(input_symbols, language, as_partial=True) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA accepting the finite language given as input. +Uses the algorithm described in Finite-State Techniques by Mihov and Schulz, +Chapter 10

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
language + AbstractSet[str] + +
+

The language to accept.

+
+
+ required +
as_partial + bool + +
+

Whether or not to construct this as a partial DFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_nfa(target_nfa, *, retain_names=False, minify=True) + + + classmethod + + +

+ + +
+ +

Initialize this DFA as one equivalent to the given NFA. Note +that this usually returns a partial DFA by default.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
target_nfa + NFA + +
+

The NFA to construct an equivalent DFA for.

+
+
+ required +
retain_names + bool + +
+

Whether or not to retain state names during processing.

+
+
+ False +
minify + bool + +
+

Whether or not to minify the DFA resulting from the input NFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the language of the input NFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_prefix(input_symbols, prefix, *, contains=True, as_partial=True) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA accepting strings with the +given prefix. If contains is set to False then the complement is +constructed instead.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
prefix + str + +
+

The prefix of strings that are accepted by this DFA.

+
+
+ required +
contains + bool + +
+

Whether or not to construct the compliment DFA.

+
+
+ True +
as_partial + bool + +
+

Whether or not to construct this DFA as a partial DFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_subsequence(input_symbols, subsequence, *, contains=True) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA recognizing strings containing the +given subsequence. If contains is set to False, then the complement +is constructed instead.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
subsequence + str + +
+

The target subsequence of strings that are accepted by this DFA.

+
+
+ required +
contains + bool + +
+

Whether or to construct the compliment DFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_substring(input_symbols, substring, *, contains=True, must_be_suffix=False) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA recognizing strings containing the +given substring. If contains is set to False then the complement +is constructed instead. If must_be_suffix is set to True, then +the substring must be a suffix instead.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
substring + str + +
+

The substring of strings that are accepted by this DFA.

+
+
+ required +
contains + bool + +
+

Whether or to construct the compliment DFA.

+
+
+ True +
must_be_suffix + bool + +
+

Whether or not the target substring must be a suffix.

+
+
+ False +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_suffix(input_symbols, suffix, *, contains=True) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA recognizing strings with the +given suffix. If contains is set to False, then the complement +is constructed instead.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
suffix + str + +
+

The suffix of strings that are accepted by this DFA.

+
+
+ required +
contains + bool + +
+

Whether or not to construct the compliment DFA.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ intersection(other, *, retain_names=False, minify=True) + +

+ + +
+ +

Takes as input two DFAs M1 and M2 which +accept languages L1 and L2 respectively. +Returns a DFA which accepts the intersection of L1 and L2.

+

Minifies by default. Unreachable states are always removed. +If either input DFA is partial, the result is partial.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The DFA we want to take a intersection with.

+
+
+ required +
retain_names + bool + +
+

Whether to retain state names through the intersection and optional minify.

+
+
+ False +
minify + bool + +
+

Whether to minify the result of the intersection of the two DFAs.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A DFA accepting the intersection of the two input DFAs. State minimal by +default.

+
+
+ +
+ +
+ + +
+ + + + +

+ isdisjoint(other) + +

+ + +
+ +

Returns True if the language accepted by self is disjoint from that of other.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The other DFA we are comparing our language against.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if self is disjoint from other, False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ isempty() + +

+ + +
+ +

Returns True if the language accepted by self is empty.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if self accepts the empty language, False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ isfinite() + +

+ + +
+ +

Returns True if the language accepted by self is finite.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if self accepts a finite language, False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ issubset(other) + +

+ + +
+ +

Returns True if the language accepted by self is a subset of that of other.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The other DFA we are comparing our language against.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if self is a subset of other, False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ issuperset(other) + +

+ + +
+ +

Returns True if the language accepted by self is a superset of that of other.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The other DFA we are comparing our language against.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if self is a superset of other, False otherwise.

+
+
+ +
+ +
+ + +
+ + + + +

+ iter_transitions() + +

+ + +
+ +

Iterate over all transitions in the DFA. Each transition is a tuple +of the form (from_state, to_state, symbol).

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Tuple[DFAStateT, DFAStateT, str], None, None] + +
+

The desired generator over the DFA transitions.

+
+
+ +
+ +
+ + +
+ + + + +

+ maximum_word_length() + +

+ + +
+ +

Returns the length of the longest word in the language accepted by the DFA +In the case of infinite languages, None is returned.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Optional[int] + +
+

The length of the longest word accepted by self. None if the language +is infinite.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ EmptyLanguageException + +
+

Raised if self accepts the empty language.

+
+
+ +
+ +
+ + +
+ + + + +

+ minify(retain_names=False) + +

+ + +
+ +

Create a minimal DFA which accepts the same inputs as this DFA.

+

First, non-reachable states are removed. +Then, indistinguishable states are merged using Hopcroft's Algorithm.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
retain_names + bool + +
+

Whether to retain original names when merging states. +New names are from 0 to n-1.

+
+
+ False +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A state-minimal equivalent DFA. May be complete in some cases +if the input is partial.

+
+
+ +
+ +
+ + +
+ + + + +

+ minimum_word_length() + +

+ + +
+ +

Returns the length of the shortest word in the language accepted by the DFA.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ int + +
+

The length of the shortest word accepted by self.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ EmptyLanguageException + +
+

Raised if self accepts an empty language.

+
+
+ +
+ +
+ + +
+ + + + +

+ nth_from_end(input_symbols, symbol, n) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA which accepts all words whose nth +character from the end is symbol, where n is a positive integer.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
symbol + str + +
+

The target input symbol.

+
+
+ required +
n + int + +
+

The position of the target input symbol.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ nth_from_start(input_symbols, symbol, n) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA which accepts all words whose nth +character from the start is symbol, where n is a positive integer.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
symbol + str + +
+

The target input symbol.

+
+
+ required +
n + int + +
+

The position of the target input symbol.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ of_length(input_symbols, *, min_length=0, max_length=None, symbols_to_count=None) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA recognizing strings whose length is +between min_length and max_length, inclusive. To allow arbitrarily +long words, the value None can be passed in for max_length.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
min_length + int + +
+

The minimum length of strings to be accepted by this DFA.

+
+
+ 0 +
max_length + Optional[int] + +
+

The maximum length of strings to be accepted by this DFA. +If set to None, there is no maximum.

+
+
+ None +
symbols_to_count + Optional[AbstractSet[str]] + +
+

The input symbols to count towards the length of words to accepts. +If set to None, counts all symbols.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ predecessor(input_str, *, strict=True, key=None) + +

+ + +
+ +

Returns the first string accepted by the DFA that comes before +the input string in lexicographical order.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The starting input string.

+
+
+ required +
strict + bool + +
+

If set to false and input_str is accepted by the DFA, input_str will be +returned.

+
+
+ True +
key + Optional[Callable] + +
+

Function for defining custom lexicographical ordering. Defaults to using +the standard string ordering.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ str + +
+

The first string accepted by the DFA lexicographically before input_string.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ InfiniteLanguageException + +
+

Raised if the language accepted by self is infinite, as we cannot +generate predecessors in this case.

+
+
+ +
+ +
+ + +
+ + + + +

+ predecessors(input_str, *, strict=True, key=None) + +

+ + +
+ +

Generates all strings that come before the input string +in lexicographical order.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The starting input string.

+
+
+ required +
strict + bool + +
+

If set to false and input_str is accepted by the DFA, input_str will be +returned.

+
+
+ True +
key + Optional[Callable] + +
+

Function for defining custom lexicographical ordering. Defaults to using +the standard string ordering.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[str, None, None] + +
+

A generator for all strings that come before the input string in +lexicographical order.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ InfiniteLanguageException + +
+

Raised if the language accepted by self is infinite, as we cannot +generate predecessors in this case.

+
+
+ +
+ +
+ + +
+ + + + +

+ random_word(k, *, seed=None) + +

+ + +
+ +

Returns a random word of length k accepted by self.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
k + int + +
+

The length of the desired word.

+
+
+ required +
seed + Optional[int] + +
+

The random seed to use for the sampling of the random word.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ str + +
+

A uniformly random word of length k accepted by the DFA self.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ ValueError + +
+

If this DFA does not accept any words of length k.

+
+
+ +
+ +
+ + +
+ + + + +

+ read_input_stepwise(input_str, ignore_rejection=False) + +

+ + +
+ +

Return a generator that yields each step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
ignore_rejection + bool + +
+

Whether to throw an exception if the input string is rejected.

+
+
+ False +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[DFAStateT, None, None] + +
+

A generator that yields the current configuration of the DFA +after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this DFA does not accept the input string.

+
+
+ +
+ +
+ + +
+ + + + +

+ successor(input_str, *, strict=True, key=None) + +

+ + +
+ +

Returns the first string accepted by the DFA that comes after +the input string in lexicographical order.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + Optional[str] + +
+

The starting input string. If None, will generate all words.

+
+
+ required +
strict + bool + +
+

If set to false and input_str is accepted by the DFA, input_str will be +returned.

+
+
+ True +
key + Optional[Callable] + +
+

Function for defining custom lexicographical ordering. Defaults to using +the standard string ordering.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ str + +
+

The first string accepted by the DFA lexicographically before input_string.

+
+
+ +
+ +
+ + +
+ + + + +

+ successors(input_str, *, strict=True, key=None, reverse=False) + +

+ + +
+ +

Generates all strings that come after the input string +in lexicographical order.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + Optional[str] + +
+

The starting input string. If None, will generate all words.

+
+
+ required +
strict + bool + +
+

If set to false and input_str is accepted by the DFA, input_str will be +returned.

+
+
+ True +
key + Optional[Callable] + +
+

Function for defining custom lexicographical ordering. Defaults to using +the standard string ordering.

+
+
+ None +
reverse + bool + +
+

If True, then predecessors will be generated instead of successors.

+
+
+ False +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[str, None, None] + +
+

A generator for all strings that come after the input string in +lexicographical order.

+
+
+ +
+ +
+ + +
+ + + + +

+ symmetric_difference(other, *, retain_names=False, minify=True) + +

+ + +
+ +

Takes as input two DFAs M1 and M2 which +accept languages L1 and L2 respectively. +Returns a DFA which accepts the symmetric difference of L1 and L2.

+

Minifies by default. Unreachable states are always removed. +If either input DFA is partial, the result is partial.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The DFA we want to take a symmetric difference with.

+
+
+ required +
retain_names + bool + +
+

Whether to retain state names through the symmetric difference and optional +minify.

+
+
+ False +
minify + bool + +
+

Whether to minify the result of the symmetric difference of the two DFAs.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A DFA accepting the symmetric difference of the two input DFAs. State +minimal by default.

+
+
+ +
+ +
+ + +
+ + + + +

+ to_complete(trap_state=None) + +

+ + +
+ +

Creates an equivalent complete DFA with trap_state used as the name +for an added trap state. If trap_state is not passed in, defaults to +the largest negative integer which is not already a state name. +If the DFA is already complete, just returns a copy.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
trap_state + Optional[DFAStateT] + +
+

Name for custom trap state to be used.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An equivalent complete DFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ to_partial(*, retain_names=False, minify=True) + +

+ + +
+ +

Turns a DFA (complete or not) into a partial DFA. +Removes dead states and trap states (except the initial state) + and all edges leading to them.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
minify + bool + +
+

Whether to perform a minify operation while converting to +a partial DFA.

+
+
+ True +
retain_names + bool + +
+

Whether to retain state names during minification.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An equivalent partial DFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ union(other, *, retain_names=False, minify=True) + +

+ + +
+ +

Takes as input two DFAs M1 and M2 which +accept languages L1 and L2 respectively. +Returns a DFA which accepts the union of L1 and L2.

+

Minifies by default. Unreachable states are always removed. +If either input DFA is partial, the result is partial.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + DFA + +
+

The DFA we want to take a union with.

+
+
+ required +
retain_names + bool + +
+

Whether to retain state names through the union and optional minify.

+
+
+ False +
minify + bool + +
+

Whether to minify the result of the union of the two DFAs.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

A DFA accepting the union of the two input DFAs. State minimal by +default.

+
+
+ +
+ +
+ + +
+ + + + +

+ universal_language(input_symbols) + + + classmethod + + +

+ + +
+ +

Directly computes the minimal DFA accepting all strings.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the DFA over.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The DFA accepting the desired language.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this DFA has invalid states in the transition dictionary.

+
+
+ MissingStateError + +
+

If this DFA has states missing from the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this DFA has invalid symbols in the transition dictionary.

+
+
+ MissingSymbolError + +
+

If this DFA is missing transitions on certain symbols.

+
+
+ +
+ +
+ + +
+ + + + +

+ words_of_length(k) + +

+ + +
+ +

Generates all words of length k in the language accepted by the DFA.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
k + int + +
+

The desired word length.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[str, None, None] + +
+

A generator for all words of length k accepted by the DFA.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/fa/class-fa/index.html b/api/fa/class-fa/index.html new file mode 100644 index 00000000..4f70a40c --- /dev/null +++ b/api/fa/class-fa/index.html @@ -0,0 +1,1755 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class FA(Automaton, metaclass=ABCMeta) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class FA(Automaton, metaclass=ABCMeta)

+ + +
+ + + + +
+ +

Classes and methods for working with all finite automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ FA + + +

+ + +
+

+ Bases: Automaton

+ + +

The FA class is an abstract base class from which all finite automata inherit. +Every subclass of FA can be rendered natively inside of a Jupyter notebook +(automatically calling show_diagram without any arguments) if installed with +the visual optional dependency.

+ + + + +
+ + + + + + + + + + +
+ + + + +

+ iter_transitions() + + + abstractmethod + + +

+ + +
+ +

Iterate over all transitions in the automaton. Each transition is a tuple +of the form (from_state, to_state, symbol)

+ +
+ +
+ + +
+ + + + +

+ show_diagram(input_str=None, path=None, *, layout_method='dot', horizontal=True, reverse_orientation=False, fig_size=None, font_size=14.0, arrow_size=0.85, state_separation=0.5) + +

+ + +
+ +

Generates a diagram of the associated automaton.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + Optional[str] + +
+

String consisting of input symbols. If set, will add processing of +the input string to the diagram.

+
+
+ None +
path + Union[str, PathLike, None] + +
+

Path to output file. If None, the output will not be saved.

+
+
+ None +
horizontal + bool + +
+

Direction of node layout in the output graph.

+
+
+ True +
reverse_orientation + bool + +
+

Reverse direction of node layout in the output graph.

+
+
+ False +
fig_size + Union[Tuple[float, float], Tuple[float], None] + +
+

Figure size.

+
+
+ None +
font_size + float + +
+

Font size in the output graph.

+
+
+ 14.0 +
arrow_size + float + +
+

Arrow size in the output graph.

+
+
+ 0.85 +
state_separation + float + +
+

Distance between nodes in the output graph.

+
+
+ 0.5 +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ AGraph + +
+

A diagram of the given automaton.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/fa/class-gnfa/index.html b/api/fa/class-gnfa/index.html new file mode 100644 index 00000000..cf885662 --- /dev/null +++ b/api/fa/class-gnfa/index.html @@ -0,0 +1,1993 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class GNFA(FA) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class GNFA(FA)

+ + +
+ + + + +
+ +

Classes and methods for working with generalized non-deterministic finite +automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ GNFA + + +

+ + +
+

+ Bases: FA

+ + +

The GNFA class is a subclass of FA and represents a generalized +nondeterministic finite automaton.

+

Its main usage is for conversion of DFAs and NFAs to regular expressions. Note +that because of this, the GNFA doesn't support any binary operators or reading +input (e.g. read_input_stepwise). Every GNFA can be rendered natively inside of- +a Jupyter notebook (automatically calling show_diagram without any arguments) +if installed with the visual optional dependency. Note that input_str +cannot be set as an argument to show_diagram, as the GNFA does not read input.

+

Except for initial_state and final_state, one transition goes from every state +to every other state, and also from each state to itself. To accommodate +this, transitions can be regular expressions and None, in addition to +normal input symbols.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[GNFAStateT] + +
+

Set of the GNFA's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the GNFA's valid input symbols, each of which is a singleton +string.

+
+
+ required +
transitions + Mapping[GNFAStateT, Mapping[GNFAStateT, Optional[str]]] + +
+

A dict with the transitions for each state, except final_state. +Each key is a state name and each value is dict which maps a state +(the key) to the transition expression (the value) or None. +The transition expression is a regular expression (string) over +input_symbols, and the following symbols only: *, |, ?, ().

+

This is a subset of the standard regular expressions using this package.

+
+
+ required +
initial_state + GNFAStateT + +
+

The initial state for this GNFA. Has transitions going to every +other state, but no transitions coming in from any other state.

+
+
+ required +
final_state + GNFAStateT + +
+

A single final state for this GNFA. Has transitions coming in from every +other state, but no transitions going to any other state. +Must be different from the initial_state.

+
+
+ required +
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ from_dfa(target_dfa) + + + classmethod + + +

+ + +
+ +

Initialize this GNFA as one equivalent to the given DFA.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
target_dfa + DFA + +
+

The DFA to construct an equivalent GNFA for.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The GNFA accepting the language of the input DFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_nfa(target_nfa) + + + classmethod + + +

+ + +
+ +

Initialize this GNFA as one equivalent to the given NFA.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
target_nfa + NFA + +
+

The NFA to construct an equivalent GNFA for.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The GNFA accepting the language of the input NFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ iter_transitions() + +

+ + +
+ +

Iterate over all transitions in the GNFA. Each transition is a tuple +of the form (from_state, to_state, symbol).

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Tuple[GNFAStateT, GNFAStateT, str], None, None] + +
+

The desired generator over the GNFA transitions.

+
+
+ +
+ +
+ + +
+ + + + +

+ to_regex() + +

+ + +
+ +

Convert GNFA to regular expression.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ str + +
+

A regular expression equivalent to the input GNFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this GNFA has invalid states in the transition dictionary.

+
+
+ MissingStateError + +
+

If this GNFA has states missing from the transition dictionary.

+
+
+ InvalidRegexError + +
+

If this GNFA has invalid regex in the transition dictionary.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/fa/class-nfa/index.html b/api/fa/class-nfa/index.html new file mode 100644 index 00000000..4cefdf5e --- /dev/null +++ b/api/fa/class-nfa/index.html @@ -0,0 +1,2959 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class NFA(FA) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class NFA(FA)

+ + +
+ + + + +
+ +

Classes and methods for working with nondeterministic finite automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ NFA + + +

+ + +
+

+ Bases: FA

+ + +

The NFA class is a subclass of FA and represents a nondeterministic finite +automaton.

+

Every NFA has the same five DFA properties: state, input_symbols, +transitions, initial_state, and final_states. However, the structure of +the transitions object has been modified slightly to accommodate the fact that +a single state can have more than one transition for the same symbol. Therefore, +instead of mapping a symbol to one end state in each sub-dict, each symbol is +mapped to a set of end states.

+

Every NFA can be rendered natively inside of a Jupyter notebook (automatically +calling show_diagram without any arguments) if installed with the visual +optional dependency.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[NFAStateT] + +
+

Set of the NFA's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the NFA's valid input symbols, each of which is a singleton +string.

+
+
+ required +
transitions + Mapping[NFAStateT, Mapping[str, AbstractSet[NFAStateT]]] + +
+

Dict consisting of the transitions for each state. Each key is a +state name, and each value is another dict which maps a symbol +(the key) to a set of states (the value).

+
+
+ required +
initial_state + NFAStateT + +
+

The initial state for this NFA.

+
+
+ required +
final_states + AbstractSet[NFAStateT] + +
+

A set of final states for this NFA.

+
+
+ required +
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ concatenate(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the language L1 concatenated with L2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to concatenate with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the language concatenation of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ edit_distance(input_symbols, reference_str, max_edit_distance, *, insertion=True, deletion=True, substitution=True) + + + classmethod + + +

+ + +
+ +

Constructs the Levenshtein NFA for the given reference_str and given +Levenshtein distance. This NFA recognizes strings within the given +Levenshtein distance (commonly called edit distance) of the +reference_str. Parameters control which error types the NFA will +recognize (insertions, deletions, or substitutions). At least one error +type must be set.

+

If insertion and deletion are False and substitution is True, then this +is the same as Hamming distance.

+

If insertion and deletion are True and substitution is False, then this +is the same as LCS distance.

+

insertion, deletion, and substitution all default to True.

+

Code adapted from: +http://blog.notdot.net/2010/07/Damn-Cool-Algorithms-Levenshtein-Automata

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_symbols + AbstractSet[str] + +
+

The set of input symbols to construct the NFA over.

+
+
+ required +
reference_str + str + +
+

The reference string the NFA will use to recognize other close strings.

+
+
+ required +
max_edit_distance + int + +
+

The maximum edit distance from the reference string this NFA will recognize. +Must be positive.

+
+
+ required +
insertion + bool + +
+

Whether to recognize insertion edits relative to the reference string.

+
+
+ True +
deletion + bool + +
+

Whether to recognize deletion edits relative to the reference string.

+
+
+ True +
substitution + bool + +
+

Whether to recognize substitution edits relative to the reference string.

+
+
+ True +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting all strings within the given edit distance to the reference +string.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ ValueError + +
+

Raised if the max_edit_distance is negative or all of the error flags are +set to False (at least one must be True).

+
+
+ +
+ +
+ + +
+ + + + +

+ eliminate_lambda() + +

+ + +
+ +

Returns an equivalent NFA with lambda transitions removed.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The equivalent NFA with lambda transitions removed.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_dfa(target_dfa) + + + classmethod + + +

+ + +
+ +

Initialize this NFA as one equivalent to the given DFA.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
target_dfa + DFA + +
+

The DFA to construct an equivalent NFA for.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The NFA accepting the language of the input DFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ from_regex(regex, *, input_symbols=None) + + + classmethod + + +

+ + +
+ +

Initialize this NFA as one equivalent to the given regular expression.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
regex + str + +
+

The regex to construct an equivalent NFA for.

+
+
+ required +
input_symbols + Optional[AbstractSet[str]] + +
+

The set of input symbols to create the NFA over. If not +set, defaults to all ascii letters and digits.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

The NFA accepting the language of the input regex.

+
+
+ +
+ +
+ + +
+ + + + +

+ intersection(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the intersection of L1 and L2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to take an intersection with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the intersection of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ iter_transitions() + +

+ + +
+ +

Iterate over all transitions in the NFA. Each transition is a tuple +of the form (from_state, to_state, symbol).

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Tuple[NFAStateT, NFAStateT, str], None, None] + +
+

The desired generator over the NFA transitions.

+
+
+ +
+ +
+ + +
+ + + + +

+ kleene_star() + +

+ + +
+ +

Given an NFA which accepts the language L, returns +an NFA which accepts L repeated 0 or more times.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the finite repetition of the input NFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ left_quotient(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the left quotient of L1 with respect to L2 (L2 L1).

+

Construction is based off of the one described here: +https://cs.stackexchange.com/a/102043

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to take a left quotient with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the left quotient of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ option() + +

+ + +
+ +

Given an NFA which accepts the language L, returns +an NFA which accepts L repeated 0 or 1 times.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the optional of the input NFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Return a generator that yields the configuration of this NFA at each +step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[AbstractSet[NFAStateT], None, None] + +
+

A generator that yields the current configuration (a set of states) of +the NFA after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this NFA does not accept the input string.

+
+
+ +
+ +
+ + +
+ + + + +

+ reverse() + +

+ + +
+ +

Given an NFA which accepts the language L, +returns an NFA which accepts the reverse of L.

+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the reversal of the input NFA.

+
+
+ +
+ +
+ + +
+ + + + +

+ right_quotient(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the right quotient of L1 with respect to L2 (L1 / L2).

+

Construction is based off of the one described here: +https://cs.stackexchange.com/a/102043

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to take a right quotient with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the right quotient of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ shuffle_product(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the shuffle of L1 and L2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to take a shuffle product with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the shuffle product of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ union(other) + +

+ + +
+ +

Given two NFAs, M1 and M2, which accept the languages +L1 and L2 respectively, returns an NFA which accepts +the union of L1 and L2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
other + NFA + +
+

The NFA we want to take a union with.

+
+
+ required +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ Self + +
+

An NFA accepting the union of the two input NFAs.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this NFA has invalid states in the transition dictionary.

+
+
+ MissingStateError + +
+

If this NFA has states missing from the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this NFA has invalid symbols in the transition dictionary.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/index.html b/api/index.html new file mode 100644 index 00000000..ec51dfdc --- /dev/null +++ b/api/index.html @@ -0,0 +1,1415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + API - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

API

+

This is the API documentation generated by the class and method docstrings for the automata package.

+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/pda/class-dpda/index.html b/api/pda/class-dpda/index.html new file mode 100644 index 00000000..ee2b7dff --- /dev/null +++ b/api/pda/class-dpda/index.html @@ -0,0 +1,1816 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class DPDA(PDA) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class DPDA(PDA)

+ + +
+ + + + +
+ +

Classes and methods for working with deterministic pushdown automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ DPDA + + +

+ + +
+

+ Bases: PDA

+ + +

The DPDA class is a subclass of PDA and represents a deterministic pushdown +automaton.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[DPDAStateT] + +
+

A set of the DPDA's valid states

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the DPDA's valid input symbols, each of which is a singleton +string.

+
+
+ required +
stack_symbols + AbstractSet[str] + +
+

Set of the DPDA's valid stack symbols, each of which is a singleton +string.

+
+
+ required +
transitions + DPDATransitionsT + +
+

A dict consisting of the transitions for each state; see the +example below for the exact syntax

+
+
+ required +
initial_state + DPDAStateT + +
+

The name of the initial state for this DPDA.

+
+
+ required +
initial_stack_symbol + str + +
+

The name of the initial symbol on the stack for this DPDA.

+
+
+ required +
final_states + AbstractSet[DPDAStateT] + +
+

A set of final states for this DPDA.

+
+
+ required +
acceptance_mode + PDAAcceptanceModeT + +
+

A string defining whether this DPDA accepts by +'final_state', 'empty_stack', or 'both'.

+
+
+ 'both' +
+

Example

+
from automata.pda.dpda import DPDA
+# DPDA which which matches zero or more 'a's, followed by the same
+# number of 'b's (accepting by final state)
+dpda = DPDA(
+    states={'q0', 'q1', 'q2', 'q3'},
+    input_symbols={'a', 'b'},
+    stack_symbols={'0', '1'},
+    transitions={
+        'q0': {
+            'a': {'0': ('q1', ('1', '0'))}  # push '1' to stack
+        },
+        'q1': {
+            'a': {'1': ('q1', ('1', '1'))},  # push '1' to stack
+            'b': {'1': ('q2', '')}  # pop from stack
+        },
+        'q2': {
+            'b': {'1': ('q2', '')},  # pop from stack
+            '': {'0': ('q3', ('0',))}  # no change to stack
+        }
+    },
+    initial_state='q0',
+    initial_stack_symbol='0',
+    final_states={'q3'},
+    acceptance_mode='final_state'
+)
+
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Return a generator that yields the configuration of this DPDA at each +step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[PDAConfiguration, None, None] + +
+

A generator that yields the current configuration of +the DPDA after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this DPDA does not accept the input string.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/pda/class-npda/index.html b/api/pda/class-npda/index.html new file mode 100644 index 00000000..cf427159 --- /dev/null +++ b/api/pda/class-npda/index.html @@ -0,0 +1,1833 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class NPDA(PDA) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class NPDA(PDA)

+ + +
+ + + + +
+ +

Classes and methods for working with nondeterministic pushdown automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ NPDA + + +

+ + +
+

+ Bases: PDA

+ + +

The NPDA class is a subclass of PDA and represents a nondeterministic +pushdown automaton.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[NPDAStateT] + +
+

A set of the NPDA's valid states

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the NPDA's valid input symbols, each of which is a singleton +string.

+
+
+ required +
stack_symbols + AbstractSet[str] + +
+

Set of the NPDA's valid stack symbols, each of which is a singleton +string.

+
+
+ required +
transitions + NPDATransitionsT + +
+

A dict consisting of the transitions for each state; see the +example below for the exact syntax

+
+
+ required +
initial_state + NPDAStateT + +
+

The name of the initial state for this NPDA.

+
+
+ required +
initial_stack_symbol + str + +
+

The name of the initial symbol on the stack for this NPDA.

+
+
+ required +
final_states + AbstractSet[NPDAStateT] + +
+

A set of final states for this NPDA.

+
+
+ required +
acceptance_mode + PDAAcceptanceModeT + +
+

A string defining whether this NPDA accepts by +'final_state', 'empty_stack', or 'both'.

+
+
+ 'both' +
+

Example

+
from automata.pda.npda import NPDA
+# NPDA which matches palindromes consisting of 'a's and 'b's
+# (accepting by final state)
+# q0 reads the first half of the word, q1 the other half, q2 accepts.
+# But we have to guess when to switch.
+npda = NPDA(
+    states={'q0', 'q1', 'q2'},
+    input_symbols={'a', 'b'},
+    stack_symbols={'A', 'B', '#'},
+    transitions={
+        'q0': {
+            '': {
+                '#': {('q2', '#')},  # no change to stack
+            },
+            'a': {
+                '#': {('q0', ('A', '#'))},  # push 'A' to stack
+                'A': {
+                    ('q0', ('A', 'A')),  # push 'A' to stack
+                    ('q1', ''),  # pop from stack
+                },
+                'B': {('q0', ('A', 'B'))},  # push 'A' to stack
+            },
+            'b': {
+                '#': {('q0', ('B', '#'))},  # push 'B' to stack
+                'A': {('q0', ('B', 'A'))},  # push 'B' to stack
+                'B': {
+                    ('q0', ('B', 'B')),  # push 'B' to stack
+                    ('q1', ''),  # pop from stack
+                },
+            },
+        },
+        'q1': {
+            '': {'#': {('q2', '#')}},  # push '#' to (currently empty) stack
+            'a': {'A': {('q1', '')}},  # pop from stack
+            'b': {'B': {('q1', '')}},  # pop from stack
+        },
+    },
+    initial_state='q0',
+    initial_stack_symbol='#',
+    final_states={'q2'},
+    acceptance_mode='final_state'
+)
+
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Return a generator that yields the configuration of this NPDA at each +step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Set[PDAConfiguration], None, None] + +
+

A generator that yields the current configuration of +the NPDA after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this NPDA does not accept the input string.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/pda/class-pda/index.html b/api/pda/class-pda/index.html new file mode 100644 index 00000000..e09d2e8e --- /dev/null +++ b/api/pda/class-pda/index.html @@ -0,0 +1,1699 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class PDA(Automaton, metaclass=ABCMeta) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class PDA(Automaton, metaclass=ABCMeta)

+ + +
+ + + + +
+ +

Classes and methods for working with all pushdown automata.

+ + + +
+ + + + + + + + +
+ + + + +

+ PDA + + +

+ + +
+

+ Bases: Automaton

+ + +

An abstract base class for pushdown automata.

+ + + + +
+ + + + + + + + + + +
+ + + + +

+ iter_transitions() + + + abstractmethod + + +

+ + +
+ +

Iterate over all transitions in the automaton. +Each transition is a tuple of the form +(from_state, to_state, (input_symbol, stack_top_symbol, stack_push_symbols))

+ +
+ +
+ + +
+ + + + +

+ show_diagram(input_str=None, with_machine=True, with_stack=True, path=None, *, layout_method='dot', horizontal=True, reverse_orientation=False, fig_size=None, font_size=14.0, arrow_size=0.85, state_separation=0.5) + +

+ + +
+ +

Generates the graph associated with the given PDA. +Args: + - input_str (str, optional): String list of input symbols. Defaults to None. + - with_machine (bool, optional): Constructs the diagram with states and + transitions. Ignored if input_str is None. Default to True. + - with_stack (bool, optional): Constructs the diagram with stack and its + operations. Ignored if input_str is None. Default to True. + - path (str or os.PathLike, optional): Path to output file. If + None, the output will not be saved. + - horizontal (bool, optional): Direction of node layout. Defaults + to True. + - reverse_orientation (bool, optional): Reverse direction of node + layout. Defaults to False. + - fig_size (tuple, optional): Figure size. Defaults to None. + - font_size (float, optional): Font size. Defaults to 14.0. + - arrow_size (float, optional): Arrow head size. Defaults to 0.85. + - state_separation (float, optional): Node distance. Defaults to 0.5. +Returns: + AGraph corresponding to the given automaton.

+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this PDA has invalid states in the transition dictionary.

+
+
+ MissingStateError + +
+

If this PDA has states missing from the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this PDA has invalid symbols in the transition dictionary.

+
+
+ InvalidAcceptanceModeError + +
+

If this PDA has an invalid acceptance mode.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/regular-expressions/index.html b/api/regular-expressions/index.html new file mode 100644 index 00000000..3aa516e6 --- /dev/null +++ b/api/regular-expressions/index.html @@ -0,0 +1,1887 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Regular Expressions - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Regular Expressions

+ + +
+ + + + +
+ +

A set of tools for working with regular expressions. Can recognize regular expressions +over the alphabet of ascii letters (lower and upper case), ascii digits, and subsets of +these.

+

A regular expression with the following operations only are supported in this library:

+
    +
  • *: Kleene star operation, language repeated zero or more times. Ex: a*,(ab)*
  • +
  • +: Kleene plus operation, language repeated one or more times. Ex: a+,(ab)+
  • +
  • ?: Language repeated zero or one time. Ex: a?
  • +
  • Concatenation. Ex: abcd
  • +
  • |: Union. Ex: a|b
  • +
  • &: Intersection. Ex: a&b
  • +
  • .: Wildcard. Ex: a.b
  • +
  • ^: Shuffle. Ex: a^b
  • +
  • {}: Quantifiers expressing finite repetitions. Ex: a{1,2},a{3,}
  • +
  • (): The empty string.
  • +
  • (...): Grouping.
  • +
+

This is similar to the Python re module, but this library does not support any special +characters other than those given above. All regular languages can be written with +these.

+ + + +
+ + + + + + + + + + +
+ + + + +

+ isequal(re1, re2, *, input_symbols=None) + +

+ + +
+ +

Whether both regular expressions are equivalent.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
re1 + str + +
+

The first regular expression as a string.

+
+
+ required +
re2 + str + +
+

The second regular expression as a string.

+
+
+ required +
input_symbols + Optional[AbstractSet[str]] + +
+

The set of input symbols when doing the comparison. Defaults to +all ascii letters and digits.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

Whether the regular expressions are equivalent.

+
+
+ +
+ +
+ + +
+ + + + +

+ issubset(re1, re2, *, input_symbols=None) + +

+ + +
+ +

Whether re1 is a subset of re2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
re1 + str + +
+

The first regular expression as a string.

+
+
+ required +
re2 + str + +
+

The second regular expression as a string.

+
+
+ required +
input_symbols + Optional[AbstractSet[str]] + +
+

The set of input symbols when doing the comparison. Defaults to +all ascii letters and digits.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if re1 is a subset of re2.

+
+
+ +
+ +
+ + +
+ + + + +

+ issuperset(re1, re2, *, input_symbols=None) + +

+ + +
+ +

Whether re1 is a superset of re2.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
re1 + str + +
+

The first regular expression as a string.

+
+
+ required +
re2 + str + +
+

The second regular expression as a string.

+
+
+ required +
input_symbols + Optional[AbstractSet[str]] + +
+

The set of input symbols when doing the comparison. Defaults to +all ascii letters and digits.

+
+
+ None +
+ + + +

Returns:

+ + + + + + + + + + + + + +
TypeDescription
+ bool + +
+

True if re1 is a superset of re2.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate(regex) + +

+ + +
+ +

Raises an exception if the input regular expression is invalid.

+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ InvalidRegexError + +
+

Raised if the regex given as input is not well defined.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/tm/class-dtm/index.html b/api/tm/class-dtm/index.html new file mode 100644 index 00000000..012252fc --- /dev/null +++ b/api/tm/class-dtm/index.html @@ -0,0 +1,1867 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class DTM(TM) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class DTM(TM)

+ + +
+ + + + +
+ +

Classes and methods for working with deterministic Turing machines.

+ + + +
+ + + + + + + + +
+ + + + +

+ DTM + + +

+ + +
+

+ Bases: TM

+ + +

The DTM class is a subclass of TM and represents a deterministic Turing +machine.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[DTMStateT] + +
+

A set of the DTM's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the DTM's valid input symbols, each of which is a singleton +string.

+
+
+ required +
tape_symbols + AbstractSet[str] + +
+

Set of the DTM's valid tape symbols, each of which is a singleton +string.

+
+
+ required +
transitions + DTMTransitionsT + +
+

Dict consisting of the transitions for each state; each key is a +state name, and each value is a dict which maps a symbol (the key) to +a tuple consisting of the next state, the symbol to write on the +tape, and the direction to move the tape head.

+
+
+ required +
initial_state + DTMStateT + +
+

The name of the initial state for this DTM.

+
+
+ required +
blank_symbol + str + +
+

A symbol from tape_symbols to be used as the blank symbol +for this DTM.

+
+
+ required +
final_states + AbstractSet[DTMStateT] + +
+

A set of final states for this DTM.

+
+
+ required +
+

Example

+
from automata.tm.dtm import DTM
+# DTM which matches all strings beginning with '0's, and followed by
+# the same number of '1's
+dtm = DTM(
+    states={'q0', 'q1', 'q2', 'q3', 'q4'},
+    input_symbols={'0', '1'},
+    tape_symbols={'0', '1', 'x', 'y', '.'},
+    transitions={
+        'q0': {
+            '0': ('q1', 'x', 'R'),
+            'y': ('q3', 'y', 'R')
+        },
+        'q1': {
+            '0': ('q1', '0', 'R'),
+            '1': ('q2', 'y', 'L'),
+            'y': ('q1', 'y', 'R')
+        },
+        'q2': {
+            '0': ('q2', '0', 'L'),
+            'x': ('q0', 'x', 'R'),
+            'y': ('q2', 'y', 'L')
+        },
+        'q3': {
+            'y': ('q3', 'y', 'R'),
+            '.': ('q4', '.', 'R')
+        }
+    },
+    initial_state='q0',
+    blank_symbol='.',
+    final_states={'q4'}
+)
+
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Return a generator that yields the configuration of this DTM at each +step while reading input.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[TMConfiguration, None, None] + +
+

A generator that yields the current configuration of +the DTM after each step of reading input.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this DTM has invalid states in the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this DTM has invalid symbols in the transition dictionary.

+
+
+ InvalidDirectionError + +
+

If this DTM has a transition with an invalid direction.

+
+
+ FinalStateError + +
+

If this DTM has a transition on any final states.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/tm/class-mntm/index.html b/api/tm/class-mntm/index.html new file mode 100644 index 00000000..9ee24351 --- /dev/null +++ b/api/tm/class-mntm/index.html @@ -0,0 +1,2012 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class MNTM(TM) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class MNTM(TM)

+ + +
+ + + + +
+ +

Classes and methods for working with multitape nondeterministic Turing +machines.

+ + + +
+ + + + + + + + +
+ + + + +

+ MNTM + + +

+ + +
+

+ Bases: NTM

+ + +

The MNTM class is a subclass of TM and represents a multitape +(non)deterministic Turing machine.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[MNTMStateT] + +
+

A set of the MNTM's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the MNTM's valid input symbols, each of which is a singleton +string.

+
+
+ required +
tape_symbols + AbstractSet[str] + +
+

Set of the MNTM's valid tape symbols, each of which is a singleton +string.

+
+
+ required +
n_tapes + int + +
+

The number of tapes in this MNTM.

+
+
+ required +
transitions + MNTMTransitionsT + +
+

Dict consisting of the transitions for each state; each key is a +state name, and each value is a dict which maps a symbol (the key) to +a list of tuples consisting of the next state, the symbol to write on the +tape, and the direction to move the tape head.

+
+
+ required +
initial_state + MNTMStateT + +
+

The name of the initial state for this MNTM.

+
+
+ required +
blank_symbol + str + +
+

A symbol from tape_symbols to be used as the blank symbol +for this MNTM.

+
+
+ required +
final_states + AbstractSet[MNTMStateT] + +
+

A set of final states for this MNTM.

+
+
+ required +
+

Example

+
from automata.tm.mntm import MNTM
+# MNTM which accepts all strings in {0, 1}* and writes all
+# 1's from the first tape (input) to the second tape.
+self.mntm1 = MNTM(
+    states={'q0', 'q1'},
+    input_symbols={'0', '1'},
+    tape_symbols={'0', '1', '#'},
+    n_tapes=2,
+    transitions={
+        'q0': {
+            ('1', '#'): [('q0', (('1', 'R'), ('1', 'R')))],
+            ('0', '#'): [('q0', (('0', 'R'), ('#', 'N')))],
+            ('#', '#'): [('q1', (('#', 'N'), ('#', 'N')))],
+        }
+    },
+    initial_state='q0',
+    blank_symbol='#',
+    final_states={'q1'},
+)
+
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ read_input_as_ntm(input_str) + +

+ + +
+ +

Simulates this MNTM as a single-tape Turing machine. +Yields the configuration at each step.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[AbstractSet[TMConfiguration], None, None] + +
+

A generator that yields the current configuration of +the MNTM as a set after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this MNTM does not accept the input string.

+
+
+ +
+ +
+ + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Checks if the given string is accepted by this MNTM machine, +using a BFS of every possible configuration from each configuration. +Yields the current configuration of the machine at each step.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Set[MTMConfiguration], None, None] + +
+

A generator that yields the current configuration of +the DTM after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this MNTM does not accept the input string.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this MNTM has invalid states in the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this MNTM has invalid symbols in the transition dictionary.

+
+
+ InvalidDirectionError + +
+

If this MNTM has a transition with an invalid direction.

+
+
+ FinalStateError + +
+

If this MNTM has a transition on any final states.

+
+
+ InconsistentTapesException + +
+

If this MNTM has inconsistent tape contents.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/tm/class-ntm/index.html b/api/tm/class-ntm/index.html new file mode 100644 index 00000000..acadfc84 --- /dev/null +++ b/api/tm/class-ntm/index.html @@ -0,0 +1,1892 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class NTM(TM) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class NTM(TM)

+ + +
+ + + + +
+ +

Classes and methods for working with nondeterministic Turing machines.

+ + + +
+ + + + + + + + +
+ + + + +

+ NTM + + +

+ + +
+

+ Bases: TM

+ + +

The NTM class is a subclass of TM and represents a +nondeterministic Turing machine.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
states + AbstractSet[NTMStateT] + +
+

A set of the NTM's valid states.

+
+
+ required +
input_symbols + AbstractSet[str] + +
+

Set of the NTM's valid input symbols, each of which is a singleton +string.

+
+
+ required +
tape_symbols + AbstractSet[str] + +
+

Set of the NTM's valid tape symbols, each of which is a singleton +string.

+
+
+ required +
transitions + NTMTransitionsT + +
+

Dict consisting of the transitions for each state; each key is a +state name, and each value is a dict which maps a symbol (the key) to +a set of tuples consisting of the next state, the symbol to write on the +tape, and the direction to move the tape head.

+
+
+ required +
initial_state + NTMStateT + +
+

The name of the initial state for this NTM.

+
+
+ required +
blank_symbol + str + +
+

A symbol from tape_symbols to be used as the blank symbol +for this NTM.

+
+
+ required +
final_states + AbstractSet[NTMStateT] + +
+

A set of final states for this NTM.

+
+
+ required +
+

Example

+
from automata.tm.ntm import NTM
+# NTM which matches all strings beginning with '0's, and followed by
+# the same number of '1's
+# Note that the nondeterminism is not really used here.
+ntm = NTM(
+    states={'q0', 'q1', 'q2', 'q3', 'q4'},
+    input_symbols={'0', '1'},
+    tape_symbols={'0', '1', 'x', 'y', '.'},
+    transitions={
+        'q0': {
+            '0': {('q1', 'x', 'R')},
+            'y': {('q3', 'y', 'R')},
+        },
+        'q1': {
+            '0': {('q1', '0', 'R')},
+            '1': {('q2', 'y', 'L')},
+            'y': {('q1', 'y', 'R')},
+        },
+        'q2': {
+            '0': {('q2', '0', 'L')},
+            'x': {('q0', 'x', 'R')},
+            'y': {('q2', 'y', 'L')},
+        },
+        'q3': {
+            'y': {('q3', 'y', 'R')},
+            '.': {('q4', '.', 'R')},
+        }
+    },
+    initial_state='q0',
+    blank_symbol='.',
+    final_states={'q4'}
+)
+
+ + + + +
+ + + + + + + + + + +
+ + + + +

+ read_input_stepwise(input_str) + +

+ + +
+ +

Check if the given string is accepted by this Turing machine.

+

Yield the current configurations of the machine at each step.

+ + + +

Parameters:

+ + + + + + + + + + + + + + + + + +
NameTypeDescriptionDefault
input_str + str + +
+

The input string to read.

+
+
+ required +
+ + + +

Yields:

+ + + + + + + + + + + + + +
TypeDescription
+ Generator[Set[TMConfiguration], None, None] + +
+

A generator that yields the current configuration of +the NTM after each step of reading input.

+
+
+ + + +

Raises:

+ + + + + + + + + + + + + +
TypeDescription
+ RejectionException + +
+

Raised if this NTM does not accept the input string.

+
+
+ +
+ +
+ + +
+ + + + +

+ validate() + +

+ + +
+ +

Raises an exception if this automaton is not internally consistent.

+ + + +

Raises:

+ + + + + + + + + + + + + + + + + + + + + + + + + +
TypeDescription
+ InvalidStateError + +
+

If this NTM has invalid states in the transition dictionary.

+
+
+ InvalidSymbolError + +
+

If this NTM has invalid symbols in the transition dictionary.

+
+
+ InvalidDirectionError + +
+

If this NTM has a transition with an invalid direction.

+
+
+ FinalStateError + +
+

If this NTM has a transition on any final states.

+
+
+ +
+ +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/tm/class-tm/index.html b/api/tm/class-tm/index.html new file mode 100644 index 00000000..536907d2 --- /dev/null +++ b/api/tm/class-tm/index.html @@ -0,0 +1,1534 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + class TM(Automaton, metaclass=ABCMeta) - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

class TM(Automaton, metaclass=ABCMeta)

+ + +
+ + + + +
+ +

Classes and methods for working with all Turing machines.

+ + + +
+ + + + + + + + +
+ + + + +

+ TM + + +

+ + +
+

+ Bases: Automaton

+ + +

An abstract base class for Turing machines.

+ + + + +
+ + + + + + + + + + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/api/tm/tm-exception-classes/index.html b/api/tm/tm-exception-classes/index.html new file mode 100644 index 00000000..2291c19a --- /dev/null +++ b/api/tm/tm-exception-classes/index.html @@ -0,0 +1,1614 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Turing machine exception classes - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + Skip to content + + +
+
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Turing machine exception classes

+ + +
+ + + + +
+ +

Exception classes specific to Turing machines.

+ + + +
+ + + + + + + + +
+ + + + +

+ InconsistentTapesException + + +

+ + +
+

+ Bases: TMException

+ + +

The number of tapes defined for the multitape Turing machine is +not consistent with the definitions of the transitions.

+ + +
+ +
+ +
+ + + + +

+ InvalidDirectionError + + +

+ + +
+

+ Bases: TMException

+ + +

A direction is not a valid direction for this machine.

+ + +
+ +
+ +
+ + + + +

+ MalformedExtendedTapeError + + +

+ + +
+

+ Bases: TMException

+ + +

Extended tape for simulating an mntm as a ntm is not valid. +Either there are 2 virtual heads for a virtual tape or the +a head symbol is at the leftmost end of a virtual tape.

+ + +
+ +
+ +
+ + + + +

+ TMException + + +

+ + +
+

+ Bases: AutomatonException

+ + +

The base class for all machine-related errors.

+ + +
+ +
+ + + + +
+ +
+ +
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/assets/_mkdocstrings.css b/assets/_mkdocstrings.css new file mode 100644 index 00000000..049a254b --- /dev/null +++ b/assets/_mkdocstrings.css @@ -0,0 +1,64 @@ + +/* Avoid breaking parameter names, etc. in table cells. */ +.doc-contents td code { + word-break: normal !important; +} + +/* No line break before first paragraph of descriptions. */ +.doc-md-description, +.doc-md-description>p:first-child { + display: inline; +} + +/* Max width for docstring sections tables. */ +.doc .md-typeset__table, +.doc .md-typeset__table table { + display: table !important; + width: 100%; +} + +.doc .md-typeset__table tr { + display: table-row; +} + +/* Defaults in Spacy table style. */ +.doc-param-default { + float: right; +} + +/* Keep headings consistent. */ +h1.doc-heading, +h2.doc-heading, +h3.doc-heading, +h4.doc-heading, +h5.doc-heading, +h6.doc-heading { + font-weight: 400; + line-height: 1.5; + color: inherit; + text-transform: none; +} + +h1.doc-heading { + font-size: 1.6rem; +} + +h2.doc-heading { + font-size: 1.2rem; +} + +h3.doc-heading { + font-size: 1.15rem; +} + +h4.doc-heading { + font-size: 1.10rem; +} + +h5.doc-heading { + font-size: 1.05rem; +} + +h6.doc-heading { + font-size: 1rem; +} \ No newline at end of file diff --git a/assets/images/favicon.png b/assets/images/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..1cf13b9f9d978896599290a74f77d5dbe7d1655c GIT binary patch literal 1870 zcmV-U2eJ5xP)Gc)JR9QMau)O=X#!i9;T z37kk-upj^(fsR36MHs_+1RCI)NNu9}lD0S{B^g8PN?Ww(5|~L#Ng*g{WsqleV}|#l zz8@ri&cTzw_h33bHI+12+kK6WN$h#n5cD8OQt`5kw6p~9H3()bUQ8OS4Q4HTQ=1Ol z_JAocz`fLbT2^{`8n~UAo=#AUOf=SOq4pYkt;XbC&f#7lb$*7=$na!mWCQ`dBQsO0 zLFBSPj*N?#u5&pf2t4XjEGH|=pPQ8xh7tpx;US5Cx_Ju;!O`ya-yF`)b%TEt5>eP1ZX~}sjjA%FJF?h7cX8=b!DZl<6%Cv z*G0uvvU+vmnpLZ2paivG-(cd*y3$hCIcsZcYOGh{$&)A6*XX&kXZd3G8m)G$Zz-LV z^GF3VAW^Mdv!)4OM8EgqRiz~*Cji;uzl2uC9^=8I84vNp;ltJ|q-*uQwGp2ma6cY7 z;`%`!9UXO@fr&Ebapfs34OmS9^u6$)bJxrucutf>`dKPKT%%*d3XlFVKunp9 zasduxjrjs>f8V=D|J=XNZp;_Zy^WgQ$9WDjgY=z@stwiEBm9u5*|34&1Na8BMjjgf3+SHcr`5~>oz1Y?SW^=K z^bTyO6>Gar#P_W2gEMwq)ot3; zREHn~U&Dp0l6YT0&k-wLwYjb?5zGK`W6S2v+K>AM(95m2C20L|3m~rN8dprPr@t)5lsk9Hu*W z?pS990s;Ez=+Rj{x7p``4>+c0G5^pYnB1^!TL=(?HLHZ+HicG{~4F1d^5Awl_2!1jICM-!9eoLhbbT^;yHcefyTAaqRcY zmuctDopPT!%k+}x%lZRKnzykr2}}XfG_ne?nRQO~?%hkzo;@RN{P6o`&mMUWBYMTe z6i8ChtjX&gXl`nvrU>jah)2iNM%JdjqoaeaU%yVn!^70x-flljp6Q5tK}5}&X8&&G zX3fpb3E(!rH=zVI_9Gjl45w@{(ITqngWFe7@9{mX;tO25Z_8 zQHEpI+FkTU#4xu>RkN>b3Tnc3UpWzPXWm#o55GKF09j^Mh~)K7{QqbO_~(@CVq! zS<8954|P8mXN2MRs86xZ&Q4EfM@JB94b=(YGuk)s&^jiSF=t3*oNK3`rD{H`yQ?d; ztE=laAUoZx5?RC8*WKOj`%LXEkgDd>&^Q4M^z`%u0rg-It=hLCVsq!Z%^6eB-OvOT zFZ28TN&cRmgU}Elrnk43)!>Z1FCPL2K$7}gwzIc48NX}#!A1BpJP?#v5wkNprhV** z?Cpalt1oH&{r!o3eSKc&ap)iz2BTn_VV`4>9M^b3;(YY}4>#ML6{~(4mH+?%07*qo IM6N<$f(jP3KmY&$ literal 0 HcmV?d00001 diff --git a/assets/img/favicon.png b/assets/img/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..d8af37dffec1d0a2d0326d1bf05b00fdb818bcd0 GIT binary patch literal 719 zcmV;=0x5nVOvIo^)9q@VXhNYyFNN2DY2}w_+WK%b5 z4(%aWbDsLtjmnD$LvsN{7tCT`y#fH)qj;(HvY^969UvJq4jUe*92*kxX`mjMfv9D- z5JjJ8((oZzO96Gj2cX%k`->ER3SidVxTgU5Ab`*707cE|b}rc(W}V+)UkmUaH~~zQ zGEd0>c_2!PuvB68o3EYSnkddsl)M6Y;(PC6YYMXmND){ZERK+w-8tZXPWR0>SL6!3 z-Ru48cgstYDa2{RVi|a8s4d$ilMEDAMJNHhzIAN81 + + + + + + + + + + + + + + + + + + + diff --git a/assets/javascripts/bundle.fac441b0.min.js b/assets/javascripts/bundle.fac441b0.min.js new file mode 100644 index 00000000..4bb4cd67 --- /dev/null +++ b/assets/javascripts/bundle.fac441b0.min.js @@ -0,0 +1,29 @@ +"use strict";(()=>{var Ci=Object.create;var gr=Object.defineProperty;var Ri=Object.getOwnPropertyDescriptor;var ki=Object.getOwnPropertyNames,Ht=Object.getOwnPropertySymbols,Hi=Object.getPrototypeOf,yr=Object.prototype.hasOwnProperty,nn=Object.prototype.propertyIsEnumerable;var rn=(e,t,r)=>t in e?gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,P=(e,t)=>{for(var r in t||(t={}))yr.call(t,r)&&rn(e,r,t[r]);if(Ht)for(var r of Ht(t))nn.call(t,r)&&rn(e,r,t[r]);return e};var on=(e,t)=>{var r={};for(var n in e)yr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Ht)for(var n of Ht(e))t.indexOf(n)<0&&nn.call(e,n)&&(r[n]=e[n]);return r};var Pt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Pi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ki(t))!yr.call(e,o)&&o!==r&&gr(e,o,{get:()=>t[o],enumerable:!(n=Ri(t,o))||n.enumerable});return e};var yt=(e,t,r)=>(r=e!=null?Ci(Hi(e)):{},Pi(t||!e||!e.__esModule?gr(r,"default",{value:e,enumerable:!0}):r,e));var sn=Pt((xr,an)=>{(function(e,t){typeof xr=="object"&&typeof an!="undefined"?t():typeof define=="function"&&define.amd?define(t):t()})(xr,function(){"use strict";function e(r){var n=!0,o=!1,i=null,s={text:!0,search:!0,url:!0,tel:!0,email:!0,password:!0,number:!0,date:!0,month:!0,week:!0,time:!0,datetime:!0,"datetime-local":!0};function a(O){return!!(O&&O!==document&&O.nodeName!=="HTML"&&O.nodeName!=="BODY"&&"classList"in O&&"contains"in O.classList)}function f(O){var Qe=O.type,De=O.tagName;return!!(De==="INPUT"&&s[Qe]&&!O.readOnly||De==="TEXTAREA"&&!O.readOnly||O.isContentEditable)}function c(O){O.classList.contains("focus-visible")||(O.classList.add("focus-visible"),O.setAttribute("data-focus-visible-added",""))}function u(O){O.hasAttribute("data-focus-visible-added")&&(O.classList.remove("focus-visible"),O.removeAttribute("data-focus-visible-added"))}function p(O){O.metaKey||O.altKey||O.ctrlKey||(a(r.activeElement)&&c(r.activeElement),n=!0)}function m(O){n=!1}function d(O){a(O.target)&&(n||f(O.target))&&c(O.target)}function h(O){a(O.target)&&(O.target.classList.contains("focus-visible")||O.target.hasAttribute("data-focus-visible-added"))&&(o=!0,window.clearTimeout(i),i=window.setTimeout(function(){o=!1},100),u(O.target))}function v(O){document.visibilityState==="hidden"&&(o&&(n=!0),Q())}function Q(){document.addEventListener("mousemove",N),document.addEventListener("mousedown",N),document.addEventListener("mouseup",N),document.addEventListener("pointermove",N),document.addEventListener("pointerdown",N),document.addEventListener("pointerup",N),document.addEventListener("touchmove",N),document.addEventListener("touchstart",N),document.addEventListener("touchend",N)}function B(){document.removeEventListener("mousemove",N),document.removeEventListener("mousedown",N),document.removeEventListener("mouseup",N),document.removeEventListener("pointermove",N),document.removeEventListener("pointerdown",N),document.removeEventListener("pointerup",N),document.removeEventListener("touchmove",N),document.removeEventListener("touchstart",N),document.removeEventListener("touchend",N)}function N(O){O.target.nodeName&&O.target.nodeName.toLowerCase()==="html"||(n=!1,B())}document.addEventListener("keydown",p,!0),document.addEventListener("mousedown",m,!0),document.addEventListener("pointerdown",m,!0),document.addEventListener("touchstart",m,!0),document.addEventListener("visibilitychange",v,!0),Q(),r.addEventListener("focus",d,!0),r.addEventListener("blur",h,!0),r.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&r.host?r.host.setAttribute("data-js-focus-visible",""):r.nodeType===Node.DOCUMENT_NODE&&(document.documentElement.classList.add("js-focus-visible"),document.documentElement.setAttribute("data-js-focus-visible",""))}if(typeof window!="undefined"&&typeof document!="undefined"){window.applyFocusVisiblePolyfill=e;var t;try{t=new CustomEvent("focus-visible-polyfill-ready")}catch(r){t=document.createEvent("CustomEvent"),t.initCustomEvent("focus-visible-polyfill-ready",!1,!1,{})}window.dispatchEvent(t)}typeof document!="undefined"&&e(document)})});var cn=Pt(Er=>{(function(e){var t=function(){try{return!!Symbol.iterator}catch(c){return!1}},r=t(),n=function(c){var u={next:function(){var p=c.shift();return{done:p===void 0,value:p}}};return r&&(u[Symbol.iterator]=function(){return u}),u},o=function(c){return encodeURIComponent(c).replace(/%20/g,"+")},i=function(c){return decodeURIComponent(String(c).replace(/\+/g," "))},s=function(){var c=function(p){Object.defineProperty(this,"_entries",{writable:!0,value:{}});var m=typeof p;if(m!=="undefined")if(m==="string")p!==""&&this._fromString(p);else if(p instanceof c){var d=this;p.forEach(function(B,N){d.append(N,B)})}else if(p!==null&&m==="object")if(Object.prototype.toString.call(p)==="[object Array]")for(var h=0;hd[0]?1:0}),c._entries&&(c._entries={});for(var p=0;p1?i(d[1]):"")}})})(typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Er);(function(e){var t=function(){try{var o=new e.URL("b","http://a");return o.pathname="c d",o.href==="http://a/c%20d"&&o.searchParams}catch(i){return!1}},r=function(){var o=e.URL,i=function(f,c){typeof f!="string"&&(f=String(f)),c&&typeof c!="string"&&(c=String(c));var u=document,p;if(c&&(e.location===void 0||c!==e.location.href)){c=c.toLowerCase(),u=document.implementation.createHTMLDocument(""),p=u.createElement("base"),p.href=c,u.head.appendChild(p);try{if(p.href.indexOf(c)!==0)throw new Error(p.href)}catch(O){throw new Error("URL unable to set base "+c+" due to "+O)}}var m=u.createElement("a");m.href=f,p&&(u.body.appendChild(m),m.href=m.href);var d=u.createElement("input");if(d.type="url",d.value=f,m.protocol===":"||!/:/.test(m.href)||!d.checkValidity()&&!c)throw new TypeError("Invalid URL");Object.defineProperty(this,"_anchorElement",{value:m});var h=new e.URLSearchParams(this.search),v=!0,Q=!0,B=this;["append","delete","set"].forEach(function(O){var Qe=h[O];h[O]=function(){Qe.apply(h,arguments),v&&(Q=!1,B.search=h.toString(),Q=!0)}}),Object.defineProperty(this,"searchParams",{value:h,enumerable:!0});var N=void 0;Object.defineProperty(this,"_updateSearchParams",{enumerable:!1,configurable:!1,writable:!1,value:function(){this.search!==N&&(N=this.search,Q&&(v=!1,this.searchParams._fromString(this.search),v=!0))}})},s=i.prototype,a=function(f){Object.defineProperty(s,f,{get:function(){return this._anchorElement[f]},set:function(c){this._anchorElement[f]=c},enumerable:!0})};["hash","host","hostname","port","protocol"].forEach(function(f){a(f)}),Object.defineProperty(s,"search",{get:function(){return this._anchorElement.search},set:function(f){this._anchorElement.search=f,this._updateSearchParams()},enumerable:!0}),Object.defineProperties(s,{toString:{get:function(){var f=this;return function(){return f.href}}},href:{get:function(){return this._anchorElement.href.replace(/\?$/,"")},set:function(f){this._anchorElement.href=f,this._updateSearchParams()},enumerable:!0},pathname:{get:function(){return this._anchorElement.pathname.replace(/(^\/?)/,"/")},set:function(f){this._anchorElement.pathname=f},enumerable:!0},origin:{get:function(){var f={"http:":80,"https:":443,"ftp:":21}[this._anchorElement.protocol],c=this._anchorElement.port!=f&&this._anchorElement.port!=="";return this._anchorElement.protocol+"//"+this._anchorElement.hostname+(c?":"+this._anchorElement.port:"")},enumerable:!0},password:{get:function(){return""},set:function(f){},enumerable:!0},username:{get:function(){return""},set:function(f){},enumerable:!0}}),i.createObjectURL=function(f){return o.createObjectURL.apply(o,arguments)},i.revokeObjectURL=function(f){return o.revokeObjectURL.apply(o,arguments)},e.URL=i};if(t()||r(),e.location!==void 0&&!("origin"in e.location)){var n=function(){return e.location.protocol+"//"+e.location.hostname+(e.location.port?":"+e.location.port:"")};try{Object.defineProperty(e.location,"origin",{get:n,enumerable:!0})}catch(o){setInterval(function(){e.location.origin=n()},100)}}})(typeof global!="undefined"?global:typeof window!="undefined"?window:typeof self!="undefined"?self:Er)});var qr=Pt((Mt,Nr)=>{/*! + * clipboard.js v2.0.11 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */(function(t,r){typeof Mt=="object"&&typeof Nr=="object"?Nr.exports=r():typeof define=="function"&&define.amd?define([],r):typeof Mt=="object"?Mt.ClipboardJS=r():t.ClipboardJS=r()})(Mt,function(){return function(){var e={686:function(n,o,i){"use strict";i.d(o,{default:function(){return Ai}});var s=i(279),a=i.n(s),f=i(370),c=i.n(f),u=i(817),p=i.n(u);function m(j){try{return document.execCommand(j)}catch(T){return!1}}var d=function(T){var E=p()(T);return m("cut"),E},h=d;function v(j){var T=document.documentElement.getAttribute("dir")==="rtl",E=document.createElement("textarea");E.style.fontSize="12pt",E.style.border="0",E.style.padding="0",E.style.margin="0",E.style.position="absolute",E.style[T?"right":"left"]="-9999px";var H=window.pageYOffset||document.documentElement.scrollTop;return E.style.top="".concat(H,"px"),E.setAttribute("readonly",""),E.value=j,E}var Q=function(T,E){var H=v(T);E.container.appendChild(H);var I=p()(H);return m("copy"),H.remove(),I},B=function(T){var E=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body},H="";return typeof T=="string"?H=Q(T,E):T instanceof HTMLInputElement&&!["text","search","url","tel","password"].includes(T==null?void 0:T.type)?H=Q(T.value,E):(H=p()(T),m("copy")),H},N=B;function O(j){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?O=function(E){return typeof E}:O=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},O(j)}var Qe=function(){var T=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},E=T.action,H=E===void 0?"copy":E,I=T.container,q=T.target,Me=T.text;if(H!=="copy"&&H!=="cut")throw new Error('Invalid "action" value, use either "copy" or "cut"');if(q!==void 0)if(q&&O(q)==="object"&&q.nodeType===1){if(H==="copy"&&q.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if(H==="cut"&&(q.hasAttribute("readonly")||q.hasAttribute("disabled")))throw new Error(`Invalid "target" attribute. You can't cut text from elements with "readonly" or "disabled" attributes`)}else throw new Error('Invalid "target" value, use a valid Element');if(Me)return N(Me,{container:I});if(q)return H==="cut"?h(q):N(q,{container:I})},De=Qe;function $e(j){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?$e=function(E){return typeof E}:$e=function(E){return E&&typeof Symbol=="function"&&E.constructor===Symbol&&E!==Symbol.prototype?"symbol":typeof E},$e(j)}function Ei(j,T){if(!(j instanceof T))throw new TypeError("Cannot call a class as a function")}function tn(j,T){for(var E=0;E0&&arguments[0]!==void 0?arguments[0]:{};this.action=typeof I.action=="function"?I.action:this.defaultAction,this.target=typeof I.target=="function"?I.target:this.defaultTarget,this.text=typeof I.text=="function"?I.text:this.defaultText,this.container=$e(I.container)==="object"?I.container:document.body}},{key:"listenClick",value:function(I){var q=this;this.listener=c()(I,"click",function(Me){return q.onClick(Me)})}},{key:"onClick",value:function(I){var q=I.delegateTarget||I.currentTarget,Me=this.action(q)||"copy",kt=De({action:Me,container:this.container,target:this.target(q),text:this.text(q)});this.emit(kt?"success":"error",{action:Me,text:kt,trigger:q,clearSelection:function(){q&&q.focus(),window.getSelection().removeAllRanges()}})}},{key:"defaultAction",value:function(I){return vr("action",I)}},{key:"defaultTarget",value:function(I){var q=vr("target",I);if(q)return document.querySelector(q)}},{key:"defaultText",value:function(I){return vr("text",I)}},{key:"destroy",value:function(){this.listener.destroy()}}],[{key:"copy",value:function(I){var q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{container:document.body};return N(I,q)}},{key:"cut",value:function(I){return h(I)}},{key:"isSupported",value:function(){var I=arguments.length>0&&arguments[0]!==void 0?arguments[0]:["copy","cut"],q=typeof I=="string"?[I]:I,Me=!!document.queryCommandSupported;return q.forEach(function(kt){Me=Me&&!!document.queryCommandSupported(kt)}),Me}}]),E}(a()),Ai=Li},828:function(n){var o=9;if(typeof Element!="undefined"&&!Element.prototype.matches){var i=Element.prototype;i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector}function s(a,f){for(;a&&a.nodeType!==o;){if(typeof a.matches=="function"&&a.matches(f))return a;a=a.parentNode}}n.exports=s},438:function(n,o,i){var s=i(828);function a(u,p,m,d,h){var v=c.apply(this,arguments);return u.addEventListener(m,v,h),{destroy:function(){u.removeEventListener(m,v,h)}}}function f(u,p,m,d,h){return typeof u.addEventListener=="function"?a.apply(null,arguments):typeof m=="function"?a.bind(null,document).apply(null,arguments):(typeof u=="string"&&(u=document.querySelectorAll(u)),Array.prototype.map.call(u,function(v){return a(v,p,m,d,h)}))}function c(u,p,m,d){return function(h){h.delegateTarget=s(h.target,p),h.delegateTarget&&d.call(u,h)}}n.exports=f},879:function(n,o){o.node=function(i){return i!==void 0&&i instanceof HTMLElement&&i.nodeType===1},o.nodeList=function(i){var s=Object.prototype.toString.call(i);return i!==void 0&&(s==="[object NodeList]"||s==="[object HTMLCollection]")&&"length"in i&&(i.length===0||o.node(i[0]))},o.string=function(i){return typeof i=="string"||i instanceof String},o.fn=function(i){var s=Object.prototype.toString.call(i);return s==="[object Function]"}},370:function(n,o,i){var s=i(879),a=i(438);function f(m,d,h){if(!m&&!d&&!h)throw new Error("Missing required arguments");if(!s.string(d))throw new TypeError("Second argument must be a String");if(!s.fn(h))throw new TypeError("Third argument must be a Function");if(s.node(m))return c(m,d,h);if(s.nodeList(m))return u(m,d,h);if(s.string(m))return p(m,d,h);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function c(m,d,h){return m.addEventListener(d,h),{destroy:function(){m.removeEventListener(d,h)}}}function u(m,d,h){return Array.prototype.forEach.call(m,function(v){v.addEventListener(d,h)}),{destroy:function(){Array.prototype.forEach.call(m,function(v){v.removeEventListener(d,h)})}}}function p(m,d,h){return a(document.body,m,d,h)}n.exports=f},817:function(n){function o(i){var s;if(i.nodeName==="SELECT")i.focus(),s=i.value;else if(i.nodeName==="INPUT"||i.nodeName==="TEXTAREA"){var a=i.hasAttribute("readonly");a||i.setAttribute("readonly",""),i.select(),i.setSelectionRange(0,i.value.length),a||i.removeAttribute("readonly"),s=i.value}else{i.hasAttribute("contenteditable")&&i.focus();var f=window.getSelection(),c=document.createRange();c.selectNodeContents(i),f.removeAllRanges(),f.addRange(c),s=f.toString()}return s}n.exports=o},279:function(n){function o(){}o.prototype={on:function(i,s,a){var f=this.e||(this.e={});return(f[i]||(f[i]=[])).push({fn:s,ctx:a}),this},once:function(i,s,a){var f=this;function c(){f.off(i,c),s.apply(a,arguments)}return c._=s,this.on(i,c,a)},emit:function(i){var s=[].slice.call(arguments,1),a=((this.e||(this.e={}))[i]||[]).slice(),f=0,c=a.length;for(f;f{"use strict";/*! + * escape-html + * Copyright(c) 2012-2013 TJ Holowaychuk + * Copyright(c) 2015 Andreas Lubbe + * Copyright(c) 2015 Tiancheng "Timothy" Gu + * MIT Licensed + */var rs=/["'&<>]/;Yo.exports=ns;function ns(e){var t=""+e,r=rs.exec(t);if(!r)return t;var n,o="",i=0,s=0;for(i=r.index;i0&&i[i.length-1])&&(c[0]===6||c[0]===2)){r=0;continue}if(c[0]===3&&(!i||c[1]>i[0]&&c[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function W(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),o,i=[],s;try{for(;(t===void 0||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){s={error:a}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(s)throw s.error}}return i}function D(e,t,r){if(r||arguments.length===2)for(var n=0,o=t.length,i;n1||a(m,d)})})}function a(m,d){try{f(n[m](d))}catch(h){p(i[0][3],h)}}function f(m){m.value instanceof et?Promise.resolve(m.value.v).then(c,u):p(i[0][2],m)}function c(m){a("next",m)}function u(m){a("throw",m)}function p(m,d){m(d),i.shift(),i.length&&a(i[0][0],i[0][1])}}function pn(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ee=="function"?Ee(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(a,f){s=e[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(c){i({value:c,done:a})},s)}}function C(e){return typeof e=="function"}function at(e){var t=function(n){Error.call(n),n.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var It=at(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription: +`+r.map(function(n,o){return o+1+") "+n.toString()}).join(` + `):"",this.name="UnsubscriptionError",this.errors=r}});function Ve(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var Ie=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,n,o,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=Ee(s),f=a.next();!f.done;f=a.next()){var c=f.value;c.remove(this)}}catch(v){t={error:v}}finally{try{f&&!f.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}else s.remove(this);var u=this.initialTeardown;if(C(u))try{u()}catch(v){i=v instanceof It?v.errors:[v]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var m=Ee(p),d=m.next();!d.done;d=m.next()){var h=d.value;try{ln(h)}catch(v){i=i!=null?i:[],v instanceof It?i=D(D([],W(i)),W(v.errors)):i.push(v)}}}catch(v){n={error:v}}finally{try{d&&!d.done&&(o=m.return)&&o.call(m)}finally{if(n)throw n.error}}}if(i)throw new It(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)ln(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&Ve(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&Ve(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();var Sr=Ie.EMPTY;function jt(e){return e instanceof Ie||e&&"closed"in e&&C(e.remove)&&C(e.add)&&C(e.unsubscribe)}function ln(e){C(e)?e():e.unsubscribe()}var Le={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var st={setTimeout:function(e,t){for(var r=[],n=2;n0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var n=this,o=this,i=o.hasError,s=o.isStopped,a=o.observers;return i||s?Sr:(this.currentObservers=null,a.push(r),new Ie(function(){n.currentObservers=null,Ve(a,r)}))},t.prototype._checkFinalizedStatuses=function(r){var n=this,o=n.hasError,i=n.thrownError,s=n.isStopped;o?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new F;return r.source=this,r},t.create=function(r,n){return new xn(r,n)},t}(F);var xn=function(e){ie(t,e);function t(r,n){var o=e.call(this)||this;return o.destination=r,o.source=n,o}return t.prototype.next=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.next)===null||o===void 0||o.call(n,r)},t.prototype.error=function(r){var n,o;(o=(n=this.destination)===null||n===void 0?void 0:n.error)===null||o===void 0||o.call(n,r)},t.prototype.complete=function(){var r,n;(n=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||n===void 0||n.call(r)},t.prototype._subscribe=function(r){var n,o;return(o=(n=this.source)===null||n===void 0?void 0:n.subscribe(r))!==null&&o!==void 0?o:Sr},t}(x);var Et={now:function(){return(Et.delegate||Date).now()},delegate:void 0};var wt=function(e){ie(t,e);function t(r,n,o){r===void 0&&(r=1/0),n===void 0&&(n=1/0),o===void 0&&(o=Et);var i=e.call(this)||this;return i._bufferSize=r,i._windowTime=n,i._timestampProvider=o,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=n===1/0,i._bufferSize=Math.max(1,r),i._windowTime=Math.max(1,n),i}return t.prototype.next=function(r){var n=this,o=n.isStopped,i=n._buffer,s=n._infiniteTimeWindow,a=n._timestampProvider,f=n._windowTime;o||(i.push(r),!s&&i.push(a.now()+f)),this._trimBuffer(),e.prototype.next.call(this,r)},t.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(r),o=this,i=o._infiniteTimeWindow,s=o._buffer,a=s.slice(),f=0;f0?e.prototype.requestAsyncId.call(this,r,n,o):(r.actions.push(this),r._scheduled||(r._scheduled=ut.requestAnimationFrame(function(){return r.flush(void 0)})))},t.prototype.recycleAsyncId=function(r,n,o){var i;if(o===void 0&&(o=0),o!=null?o>0:this.delay>0)return e.prototype.recycleAsyncId.call(this,r,n,o);var s=r.actions;n!=null&&((i=s[s.length-1])===null||i===void 0?void 0:i.id)!==n&&(ut.cancelAnimationFrame(n),r._scheduled=void 0)},t}(Wt);var Sn=function(e){ie(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.flush=function(r){this._active=!0;var n=this._scheduled;this._scheduled=void 0;var o=this.actions,i;r=r||o.shift();do if(i=r.execute(r.state,r.delay))break;while((r=o[0])&&r.id===n&&o.shift());if(this._active=!1,i){for(;(r=o[0])&&r.id===n&&o.shift();)r.unsubscribe();throw i}},t}(Dt);var Oe=new Sn(wn);var _=new F(function(e){return e.complete()});function Vt(e){return e&&C(e.schedule)}function Cr(e){return e[e.length-1]}function Ye(e){return C(Cr(e))?e.pop():void 0}function Te(e){return Vt(Cr(e))?e.pop():void 0}function zt(e,t){return typeof Cr(e)=="number"?e.pop():t}var pt=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function Nt(e){return C(e==null?void 0:e.then)}function qt(e){return C(e[ft])}function Kt(e){return Symbol.asyncIterator&&C(e==null?void 0:e[Symbol.asyncIterator])}function Qt(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function zi(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Yt=zi();function Gt(e){return C(e==null?void 0:e[Yt])}function Bt(e){return un(this,arguments,function(){var r,n,o,i;return $t(this,function(s){switch(s.label){case 0:r=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,et(r.read())];case 3:return n=s.sent(),o=n.value,i=n.done,i?[4,et(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,et(o)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function Jt(e){return C(e==null?void 0:e.getReader)}function U(e){if(e instanceof F)return e;if(e!=null){if(qt(e))return Ni(e);if(pt(e))return qi(e);if(Nt(e))return Ki(e);if(Kt(e))return On(e);if(Gt(e))return Qi(e);if(Jt(e))return Yi(e)}throw Qt(e)}function Ni(e){return new F(function(t){var r=e[ft]();if(C(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function qi(e){return new F(function(t){for(var r=0;r=2;return function(n){return n.pipe(e?A(function(o,i){return e(o,i,n)}):de,ge(1),r?He(t):Dn(function(){return new Zt}))}}function Vn(){for(var e=[],t=0;t=2,!0))}function pe(e){e===void 0&&(e={});var t=e.connector,r=t===void 0?function(){return new x}:t,n=e.resetOnError,o=n===void 0?!0:n,i=e.resetOnComplete,s=i===void 0?!0:i,a=e.resetOnRefCountZero,f=a===void 0?!0:a;return function(c){var u,p,m,d=0,h=!1,v=!1,Q=function(){p==null||p.unsubscribe(),p=void 0},B=function(){Q(),u=m=void 0,h=v=!1},N=function(){var O=u;B(),O==null||O.unsubscribe()};return y(function(O,Qe){d++,!v&&!h&&Q();var De=m=m!=null?m:r();Qe.add(function(){d--,d===0&&!v&&!h&&(p=$r(N,f))}),De.subscribe(Qe),!u&&d>0&&(u=new rt({next:function($e){return De.next($e)},error:function($e){v=!0,Q(),p=$r(B,o,$e),De.error($e)},complete:function(){h=!0,Q(),p=$r(B,s),De.complete()}}),U(O).subscribe(u))})(c)}}function $r(e,t){for(var r=[],n=2;ne.next(document)),e}function K(e,t=document){return Array.from(t.querySelectorAll(e))}function z(e,t=document){let r=ce(e,t);if(typeof r=="undefined")throw new ReferenceError(`Missing element: expected "${e}" to be present`);return r}function ce(e,t=document){return t.querySelector(e)||void 0}function _e(){return document.activeElement instanceof HTMLElement&&document.activeElement||void 0}function tr(e){return L(b(document.body,"focusin"),b(document.body,"focusout")).pipe(ke(1),l(()=>{let t=_e();return typeof t!="undefined"?e.contains(t):!1}),V(e===_e()),J())}function Xe(e){return{x:e.offsetLeft,y:e.offsetTop}}function Kn(e){return L(b(window,"load"),b(window,"resize")).pipe(Ce(0,Oe),l(()=>Xe(e)),V(Xe(e)))}function rr(e){return{x:e.scrollLeft,y:e.scrollTop}}function dt(e){return L(b(e,"scroll"),b(window,"resize")).pipe(Ce(0,Oe),l(()=>rr(e)),V(rr(e)))}var Yn=function(){if(typeof Map!="undefined")return Map;function e(t,r){var n=-1;return t.some(function(o,i){return o[0]===r?(n=i,!0):!1}),n}return function(){function t(){this.__entries__=[]}return Object.defineProperty(t.prototype,"size",{get:function(){return this.__entries__.length},enumerable:!0,configurable:!0}),t.prototype.get=function(r){var n=e(this.__entries__,r),o=this.__entries__[n];return o&&o[1]},t.prototype.set=function(r,n){var o=e(this.__entries__,r);~o?this.__entries__[o][1]=n:this.__entries__.push([r,n])},t.prototype.delete=function(r){var n=this.__entries__,o=e(n,r);~o&&n.splice(o,1)},t.prototype.has=function(r){return!!~e(this.__entries__,r)},t.prototype.clear=function(){this.__entries__.splice(0)},t.prototype.forEach=function(r,n){n===void 0&&(n=null);for(var o=0,i=this.__entries__;o0},e.prototype.connect_=function(){!Wr||this.connected_||(document.addEventListener("transitionend",this.onTransitionEnd_),window.addEventListener("resize",this.refresh),va?(this.mutationsObserver_=new MutationObserver(this.refresh),this.mutationsObserver_.observe(document,{attributes:!0,childList:!0,characterData:!0,subtree:!0})):(document.addEventListener("DOMSubtreeModified",this.refresh),this.mutationEventsAdded_=!0),this.connected_=!0)},e.prototype.disconnect_=function(){!Wr||!this.connected_||(document.removeEventListener("transitionend",this.onTransitionEnd_),window.removeEventListener("resize",this.refresh),this.mutationsObserver_&&this.mutationsObserver_.disconnect(),this.mutationEventsAdded_&&document.removeEventListener("DOMSubtreeModified",this.refresh),this.mutationsObserver_=null,this.mutationEventsAdded_=!1,this.connected_=!1)},e.prototype.onTransitionEnd_=function(t){var r=t.propertyName,n=r===void 0?"":r,o=ba.some(function(i){return!!~n.indexOf(i)});o&&this.refresh()},e.getInstance=function(){return this.instance_||(this.instance_=new e),this.instance_},e.instance_=null,e}(),Gn=function(e,t){for(var r=0,n=Object.keys(t);r0},e}(),Jn=typeof WeakMap!="undefined"?new WeakMap:new Yn,Xn=function(){function e(t){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function.");if(!arguments.length)throw new TypeError("1 argument required, but only 0 present.");var r=ga.getInstance(),n=new La(t,r,this);Jn.set(this,n)}return e}();["observe","unobserve","disconnect"].forEach(function(e){Xn.prototype[e]=function(){var t;return(t=Jn.get(this))[e].apply(t,arguments)}});var Aa=function(){return typeof nr.ResizeObserver!="undefined"?nr.ResizeObserver:Xn}(),Zn=Aa;var eo=new x,Ca=$(()=>k(new Zn(e=>{for(let t of e)eo.next(t)}))).pipe(g(e=>L(ze,k(e)).pipe(R(()=>e.disconnect()))),X(1));function he(e){return{width:e.offsetWidth,height:e.offsetHeight}}function ye(e){return Ca.pipe(S(t=>t.observe(e)),g(t=>eo.pipe(A(({target:r})=>r===e),R(()=>t.unobserve(e)),l(()=>he(e)))),V(he(e)))}function bt(e){return{width:e.scrollWidth,height:e.scrollHeight}}function ar(e){let t=e.parentElement;for(;t&&(e.scrollWidth<=t.scrollWidth&&e.scrollHeight<=t.scrollHeight);)t=(e=t).parentElement;return t?e:void 0}var to=new x,Ra=$(()=>k(new IntersectionObserver(e=>{for(let t of e)to.next(t)},{threshold:0}))).pipe(g(e=>L(ze,k(e)).pipe(R(()=>e.disconnect()))),X(1));function sr(e){return Ra.pipe(S(t=>t.observe(e)),g(t=>to.pipe(A(({target:r})=>r===e),R(()=>t.unobserve(e)),l(({isIntersecting:r})=>r))))}function ro(e,t=16){return dt(e).pipe(l(({y:r})=>{let n=he(e),o=bt(e);return r>=o.height-n.height-t}),J())}var cr={drawer:z("[data-md-toggle=drawer]"),search:z("[data-md-toggle=search]")};function no(e){return cr[e].checked}function Ke(e,t){cr[e].checked!==t&&cr[e].click()}function Ue(e){let t=cr[e];return b(t,"change").pipe(l(()=>t.checked),V(t.checked))}function ka(e,t){switch(e.constructor){case HTMLInputElement:return e.type==="radio"?/^Arrow/.test(t):!0;case HTMLSelectElement:case HTMLTextAreaElement:return!0;default:return e.isContentEditable}}function Ha(){return L(b(window,"compositionstart").pipe(l(()=>!0)),b(window,"compositionend").pipe(l(()=>!1))).pipe(V(!1))}function oo(){let e=b(window,"keydown").pipe(A(t=>!(t.metaKey||t.ctrlKey)),l(t=>({mode:no("search")?"search":"global",type:t.key,claim(){t.preventDefault(),t.stopPropagation()}})),A(({mode:t,type:r})=>{if(t==="global"){let n=_e();if(typeof n!="undefined")return!ka(n,r)}return!0}),pe());return Ha().pipe(g(t=>t?_:e))}function le(){return new URL(location.href)}function ot(e){location.href=e.href}function io(){return new x}function ao(e,t){if(typeof t=="string"||typeof t=="number")e.innerHTML+=t.toString();else if(t instanceof Node)e.appendChild(t);else if(Array.isArray(t))for(let r of t)ao(e,r)}function M(e,t,...r){let n=document.createElement(e);if(t)for(let o of Object.keys(t))typeof t[o]!="undefined"&&(typeof t[o]!="boolean"?n.setAttribute(o,t[o]):n.setAttribute(o,""));for(let o of r)ao(n,o);return n}function fr(e){if(e>999){let t=+((e-950)%1e3>99);return`${((e+1e-6)/1e3).toFixed(t)}k`}else return e.toString()}function so(){return location.hash.substring(1)}function Dr(e){let t=M("a",{href:e});t.addEventListener("click",r=>r.stopPropagation()),t.click()}function Pa(e){return L(b(window,"hashchange"),e).pipe(l(so),V(so()),A(t=>t.length>0),X(1))}function co(e){return Pa(e).pipe(l(t=>ce(`[id="${t}"]`)),A(t=>typeof t!="undefined"))}function Vr(e){let t=matchMedia(e);return er(r=>t.addListener(()=>r(t.matches))).pipe(V(t.matches))}function fo(){let e=matchMedia("print");return L(b(window,"beforeprint").pipe(l(()=>!0)),b(window,"afterprint").pipe(l(()=>!1))).pipe(V(e.matches))}function zr(e,t){return e.pipe(g(r=>r?t():_))}function ur(e,t={credentials:"same-origin"}){return ue(fetch(`${e}`,t)).pipe(fe(()=>_),g(r=>r.status!==200?Ot(()=>new Error(r.statusText)):k(r)))}function We(e,t){return ur(e,t).pipe(g(r=>r.json()),X(1))}function uo(e,t){let r=new DOMParser;return ur(e,t).pipe(g(n=>n.text()),l(n=>r.parseFromString(n,"text/xml")),X(1))}function pr(e){let t=M("script",{src:e});return $(()=>(document.head.appendChild(t),L(b(t,"load"),b(t,"error").pipe(g(()=>Ot(()=>new ReferenceError(`Invalid script: ${e}`))))).pipe(l(()=>{}),R(()=>document.head.removeChild(t)),ge(1))))}function po(){return{x:Math.max(0,scrollX),y:Math.max(0,scrollY)}}function lo(){return L(b(window,"scroll",{passive:!0}),b(window,"resize",{passive:!0})).pipe(l(po),V(po()))}function mo(){return{width:innerWidth,height:innerHeight}}function ho(){return b(window,"resize",{passive:!0}).pipe(l(mo),V(mo()))}function bo(){return Y([lo(),ho()]).pipe(l(([e,t])=>({offset:e,size:t})),X(1))}function lr(e,{viewport$:t,header$:r}){let n=t.pipe(ee("size")),o=Y([n,r]).pipe(l(()=>Xe(e)));return Y([r,t,o]).pipe(l(([{height:i},{offset:s,size:a},{x:f,y:c}])=>({offset:{x:s.x-f,y:s.y-c+i},size:a})))}(()=>{function e(n,o){parent.postMessage(n,o||"*")}function t(...n){return n.reduce((o,i)=>o.then(()=>new Promise(s=>{let a=document.createElement("script");a.src=i,a.onload=s,document.body.appendChild(a)})),Promise.resolve())}var r=class extends EventTarget{constructor(n){super(),this.url=n,this.m=i=>{i.source===this.w&&(this.dispatchEvent(new MessageEvent("message",{data:i.data})),this.onmessage&&this.onmessage(i))},this.e=(i,s,a,f,c)=>{if(s===`${this.url}`){let u=new ErrorEvent("error",{message:i,filename:s,lineno:a,colno:f,error:c});this.dispatchEvent(u),this.onerror&&this.onerror(u)}};let o=document.createElement("iframe");o.hidden=!0,document.body.appendChild(this.iframe=o),this.w.document.open(),this.w.document.write(` + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Automaton Characteristics

+

Automaton instances are immutable

+

All Automaton instances are fully immutable to protect against common pitfalls, +such as mutating an automaton to an invalid state after it's already been +validated.

+

This means that if you wish to make a change to an automaton instance, you must +retrieve its attributes as a dictionary (using the input_parameters property), +make your desired change, then pass those parameters to the relevant +constructor. For example:

+
from automata.fa.dfa import DFA
+
+dfa1 = DFA(
+    states={'q0', 'q1', 'q2'},
+    input_symbols={'0', '1'},
+    transitions={
+        'q0': {'0': 'q0', '1': 'q1'},
+        'q1': {'0': 'q0', '1': 'q2'},
+        'q2': {'0': 'q2', '1': 'q1'}
+    },
+    initial_state='q0',
+    final_states={'q1'}
+)
+# If you want to make a change, you must create a new instance; please note
+# that dfa1.input_parameters is always a deep copy of the input parameters for
+# dfa1 (in other words, mutating dfa1.input_parameters will not actually mutate
+# dfa1)
+params = dfa1.input_parameters
+params['final_states'] = {'q2'}
+dfa2 = DFA(**params)
+
+

Enabling mutable automata

+

Automaton immutability is enforced via a "freeze" step during object +initialization that turns mutable parameters (such as sets or dicts) into their +immutable counterparts (frozensets/frozendicts).

+

If your application requires maximum performance, you can disable this +conversion via the allow_mutable_automata global configuration option. If +enabled, the user must ensure that their automaton instances are never modified, +otherwise correct behavior cannot be guaranteed.

+
import automata.base.config as global_config
+
+global_config.allow_mutable_automata = True
+# The rest of your code...
+
+

Automaton instances are validated by default

+

By default, all Automaton instances are checked for common inconsistencies when +they are instantiated. If inconsistencies are found, the appropriate exception +from automata.base.exceptions is raised.

+

Because this validation can be performance-intensive for large automaton +instances with many states/transitions, you can disable the automatic validation +using the global configuration feature (introduced in v7):

+
import automata.base.config as global_config
+
+global_config.should_validate_automata = False
+
+# The rest of your code...
+
+

If, at any point, you wish to opt into validation for a specific Automaton instance, you can call the validate method:

+
my_automaton.validate()
+
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/examples/fa-examples/index.html b/examples/fa-examples/index.html new file mode 100644 index 00000000..09658f39 --- /dev/null +++ b/examples/fa-examples/index.html @@ -0,0 +1,1611 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + FA Examples - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

FA Examples

+

On this page, we give some short examples with discussion for the finite +automata classes and methods.

+

Reading basic input

+

The following code snippet creates a DFA and prints whether it accepts or +rejects user input.

+
from automata.fa.dfa import DFA
+
+# DFA which matches all binary strings ending in an odd number of '1's
+my_dfa = DFA(
+    states={'q0', 'q1', 'q2'},
+    input_symbols={'0', '1'},
+    transitions={
+        'q0': {'0': 'q0', '1': 'q1'},
+        'q1': {'0': 'q0', '1': 'q2'},
+        'q2': {'0': 'q2', '1': 'q1'}
+    },
+    initial_state='q0',
+    final_states={'q1'}
+)
+
+try:
+    while True:
+        if my_dfa.accepts_input(input('Please enter your input: ')):
+            print('Accepted')
+        else:
+            print('Rejected')
+except KeyboardInterrupt:
+    print('')
+
+

Subset for NFAs

+

The NFA does not have a built-in method for checking whether it is a subset +of another NFA. However, this can be done using existing methods.

+
# In the following, we have nfa1 and nfa2 and want to determine whether
+# nfa1 is a subset of nfa2.
+
+# If taking the union of nfa2 with nfa1 is equal to nfa2 again,
+# nfa1 didn't accept any strings that nfa2 did not, so it is a subset.
+if (nfa1 | nfa2) == nfa2:
+    print('nfa1 is a subset of nfa2.')
+else:
+    print('nfa1 is not a subset of nfa2.')
+
+

Edit distance automaton

+

The following example is inspired by this blog post. +Essentially, we want to determine which strings in a given set are within +the target edit distance to a reference string.

+
from automata.fa.dfa import DFA
+from automata.fa.nfa import NFA
+import string
+
+input_symbols = set(string.ascii_lowercase)
+
+# Construct DFA recognizing target words
+target_words = {'these', 'are', 'target', 'words', 'them', 'those'}
+
+target_words_dfa = DFA.from_finite_language(
+  input_symbols,
+  target_words,
+)
+
+# Next, construct NFA recognizing all strings
+# within given edit distance of target word
+reference_string = 'they'
+edit_distance = 2
+
+words_within_edit_distance_dfa = DFA.from_nfa(
+  NFA.edit_distance(
+    input_symbols,
+    reference_string,
+    edit_distance,
+  )
+)
+
+# Take intersection and print results
+found_words_dfa = target_words_dfa & words_within_edit_distance_dfa
+found_words = list(found_words_dfa)
+
+print(
+    f"All words within edit distance {edit_distance} of "
+    f"'{reference_string}': {found_words}"
+)
+
+

Making a transition table

+

The example below is adapted from the +visual automata library. +This function takes in a DFA or NFA and returns the +corresponding transition table.

+

The start state is prefixed with and final states are prefixed +with *.

+
import pandas as pd
+
+def make_table(target_fa) -> pd.DataFrame:
+    initial_state = target_fa.initial_state
+    final_states = target_fa.final_states
+
+    table = {}
+
+    for from_state, to_state, symbol in target_fa.iter_transitions():
+        # Prepare nice string for from_state
+        if isinstance(from_state, frozenset):
+            from_state_str = str(set(from_state))
+        else:
+            from_state_str = str(from_state)
+
+        if from_state in final_states:
+            from_state_str = "*" + from_state_str
+        if from_state == initial_state:
+            from_state_str = "→" + from_state_str
+
+        # Prepare nice string for to_state
+        if isinstance(to_state, frozenset):
+            to_state_str = str(set(to_state))
+        else:
+            to_state_str = str(to_state)
+
+        if to_state in final_states:
+            to_state_str = "*" + to_state_str
+
+        # Prepare nice symbol
+        if symbol == "":
+            symbol = "λ"
+
+        from_state_dict = table.setdefault(from_state_str, dict())
+        from_state_dict.setdefault(symbol, set()).add(to_state_str)
+
+    # Reformat table for singleton sets
+    for symbol_dict in table.values():
+        for symbol in symbol_dict:
+            if len(symbol_dict[symbol]) == 1:
+                symbol_dict[symbol] = symbol_dict[symbol].pop()
+
+
+    df = pd.DataFrame.from_dict(table).fillna("∅").T
+    return df.reindex(sorted(df.columns), axis=1)
+
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..47b519d3 --- /dev/null +++ b/index.html @@ -0,0 +1,1430 @@ + + + + + + + + + + + + + + + + + + + + + + + + Automata - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Automata

+

Copyright 2016-2024 Caleb Evans
+Released under the MIT license

+

tests +Coverage Status +status

+

Automata is a Python 3 library implementing structures and algorithms for manipulating finite automata, +pushdown automata, and Turing machines. The algorithms have been optimized and are capable of +processing large inputs. Visualization logic has also been implemented. This package is suitable for +both researchers wishing to manipulate automata and for instructors teaching courses on theoretical +computer science.

+

The library requires Python 3.8 or newer.

+

Installing

+

You can install the latest version of Automata via pip:

+
pip install automata-lib
+
+

To install the optional visual dependencies, use the visual extra:

+
pip install 'automata-lib[visual]'
+
+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/migration/index.html b/migration/index.html new file mode 100644 index 00000000..38ce2ca9 --- /dev/null +++ b/migration/index.html @@ -0,0 +1,1842 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + Automata Migration Guide - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+
+ + + + + + + +

Automata Migration Guide

+

Backwards-incompatible changes from v7 to v8

+

Dependency Changes

+

Python 3.7 support has been dropped. Please upgrade to Python 3.8 or later to +use Automata v8.

+

Diagrams are no longer being generated using pydot; this dependency has been +dropped in favor of using the visual optional dependency, which will install +pygraphviz and coloraide used for generating figures. You should install +this optional dependency if you wish to generate figures. This change was to +allow for native support for displaying finite automaton in Jupyter notebooks. +The style of the diagrams has been lifted from the visual automata package, +so you should take a look at the diagrams generated and see if they are still +satisfactory.

+

Other new dependencies have been added, but these will be installed automatically +along with v8 of the package.

+

Greater Support for Partial DFAs

+

There is now greater support for partial DFAs, which included changing the +DFA.from_nfa() function to return a partial DFA instead of a complete one. +To obtain a complete DFA, you must now call DFA.from_nfa().to_complete(trap_state_name), +where trap_state_name will be used as the name for a trap state if one needs to +be added.

+

Type Hints

+

Type hints have now been added, meaning that code which previously called functions +with incorrect types may not have been flagged. See output from your typechecker +for more information.

+

NFA.from_regex default input symbols

+

The default set of input symbols for NFA.from_regex was changed to all ascii letters and digits. +If needing to use a specific set of input symbols, use the input_symbols parameter.

+

Backwards-incompatible changes from v6 to v7

+

Immutable instances

+

All Automaton instances are now fully immutable to protect against common +pitfalls, such as mutating an automaton to an invalid state after it's already +been validated.

+

This means that if you wish to make a change to an automaton instance, you must +retrieve its attributes as a dictionary (using the new input_parameters +property), make your desired change, then pass those parameters to the relevant +constructor. For example:

+
from automata.fa.dfa import DFA
+
+dfa1 = DFA(
+    states={'q0', 'q1', 'q2'},
+    input_symbols={'0', '1'},
+    transitions={
+        'q0': {'0': 'q0', '1': 'q1'},
+        'q1': {'0': 'q0', '1': 'q2'},
+        'q2': {'0': 'q2', '1': 'q1'}
+    },
+    initial_state='q0',
+    final_states={'q1'}
+)
+# You can still copy an automaton just fine
+dfa2 = dfa.copy()
+# If you want to make a change, you must create a new instance; please note
+# that dfa2.input_parameters is always a deep copy of the input parameters for
+# dfa2 (in other words, mutating dfa2.input_parameters will not actually mutate
+# dfa2)
+params = dfa2.input_parameters
+params['final_states'] = {'q2'}
+dfa3 = DFA(**params)
+
+

Renamed Regex Module

+

The automata.base.regex module has been renamed to automata.regex.regex +alongside the other regular expression-related modules.

+

DFA.minify() defaults

+

The default value of the retain_names parameter for DFA.minify() has been +corrected from True to False; the API documentation has always stated that +the default value should be False, however the default value in the code was +actually True; therefore, the code has been updated to match the documentation +(#59) + - Since this code correction may break existing developer code, this is labeled + as a backwards-incompatible change rather than just a mere bugfix

+

Backwards-incompatible changes from v5 to v6

+

Python 3.6 support has been dropped, since it has been end-of-life since +December 2021. Please upgrade to Python 3.7 or later to use Automata v6.

+

The networkx package has been added as a required dependency, providing +substantial performance improvements for certain DFA/NFA methods, and also +streamlining the code to improve maintainability.

+

Backwards-incompatible changes from v4 to v5

+

Python 3.5 support has been dropped, since it has been end-of-life since +September 2020. Please upgrade to Python 3.6 or later to use Automata v5.

+

To support the new graph visualization capabilities, pydot has been added as a +project dependency. The pydot package will be installed when you run pip install automata-lib.

+

Backwards-incompatible changes from v3 to v4

+

The only backwards-incompatible change from v3 to v4 is that support for Python +3.4 has been dropped. This is because Python 3.4 has reached end-of-life, and +will no longer receive updates. For more information, please refer to the +Python 3.4.10 release notes.

+

There have been no API changes from v3 to v4.

+

Backwards-incompatible changes from v2 to v3

+

There have been a number of backwards-incompatible changes from Automata v2 to +v3 to support the new features, including:

+

Some types made immutable

+

The PDAStack type is now immutable and hashable; it still represents the +current stack of a PDA.

+

Likewise, the TMTape is now immutable and hashable; it still represents the +tape of a TM and the current cursor position.

+

copy() methods removed for (now) immutable types

+

The copy methods on TMTape and PDAStack have been removed, since they are +now immutable types. This change is similar to how list has a copy() method +but tuple does not.

+

Acceptance mode of PDAs is now configurable

+

DPDA and NPDA have a new config option which specifies when to accept. This +can be either 'empty_stack', 'final_state' or 'both'. The default is +'both'.

+

Backwards-incompatible changes from v1 to v2

+

There have been a number of backwards-incompatible changes from Automata v1 to +v2 to clean up the API, including:

+

Renames

+

The following methods and classes have been renamed for better clarity:

+

Shared module

+

The automata.shared package has been renamed to automata.base.

+

Before:
+

from automata.shared.automaton import Automaton
+from automata.shared.exceptions import FinalStateError
+

+

After:
+

from automata.base.automaton import Automaton
+from automata.base.exceptions import FinalStateError
+

+

Input validation methods

+

The validate_input() method has been renamed to read_input(). The +validate_input(step=True) form has also been converted to the standalone +method read_input_stepwise().

+

Before:
+

final_state = dfa.validate_input('0011')
+steps = dfa.validate_input('0011', step=True)
+

+

After:
+

final_state = dfa.read_input('0011')
+steps = dfa.read_input_stepwise('0011')
+

+

Automaton validation methods

+

The validate_self() method has been renamed to validate().

+

Before:
+

dfa.validate_self()
+

+

After:
+

dfa.validate()
+

+

Exceptions

+

The top-level *Error exception classes has been renamed to *Exception.

+

Before:
+

from automata.shared.exceptions import AutomatonError
+from automata.shared.exceptions import RejectionError
+from automata.pda.exceptions import PDAError
+from automata.tm.exceptions import TMError
+

+

After:
+

from automata.base.exceptions import AutomatonException
+from automata.base.exceptions import RejectionException
+from automata.pda.exceptions import PDAException
+from automata.tm.exceptions import TMException
+

+

Constructor polymorphism removed

+

In v1, you could copy an automaton (or convert it to another type) by passing it +into the constructor for an Automaton subtype.

+

Copying an automaton

+

Before:
+

dfa = DFA(dfa)
+

+

After:
+

dfa = dfa.copy()
+

+

Converting NFA to DFA

+

Before:
+

dfa = DFA(nfa)
+

+

After:
+

dfa = DFA.from_nfa(nfa)
+

+

Converting DFA to NFA

+

Before:
+

nfa = NFA(dfa)
+

+

After:
+

nfa = NFA.from_dfa(dfa)
+

+ + + + + + +
+
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/objects.inv b/objects.inv new file mode 100644 index 0000000000000000000000000000000000000000..f5fc448539a802f6f028dac9dbc6d334ba8dcb84 GIT binary patch literal 1155 zcmV-}1bq7=AX9K?X>NERX>N99Zgg*Qc_4OWa&u{KZXhxWBOp+6Z)#;@bUGkGb#!lS zVRT^%BOq2~a&u{KZaN?^E-)@I3L_v?Xk{RBWo=<;Ze(S0Aa78b#rNMXCQiPX<{x4c-pm@QE%Hg49DN^Qxv#+jfT6&dmE7MP+%zz zTi*@Vq7!YF>`C&PeEXyAB)c{?ElcW~8~Oh$Nzo)_L+2X}9>g;^6fpkP81eCPb=RK$ zE^Bb^?$0}D)raAFbG`Ay?|Rj{Xh&I`TQtv`JRv+rP!dC{Mgf%>bbZMnC$v00c8rcy?Ed>@M+ z2(8}1<{>@5;2w|JsqbU!*OPv3>U`MGcto2Iw^Pn3v(N1Ng__y-ao@A%=@xTpTAWmf?Wd1#|6!0wlwf6FZIqwtt$~ah!4@Ty2aIPl zx~);8@d=2|_<{nLNO)5x#=Fr3#jcsZxAWrk_K{@)QqoQn_!9N_dWFzUCwn^i1T3M z_bR z_#{S42}=i_XhdgHsywNGQhkFuy`3{J0Kx#N;}SRTPTwz>VRu%ss-n+R+@X1)G#uV1 ztR?IX=WD+@tr7n`G9EAJ#?eIb^I8zYq%qdSe~Cp8pzRNbDU6WBpJuSzIHwTY9&#c& zm6($3Gz+$}43x@K+ESlgsGU5eRy0GvaEj2+5~4vNIk^m2OaT@VI&Slj6-mv4zSoEb zhe0TsQDfzcA6?_s!ZDhqG;LBuR!$!atiH=7=+*v^AtLTT2fG^S%t}vu8P8el`K&sm zUflv(Nu9ctw*`xSyL9FLa#|&}|88%pR=6@S85V(tcfic6#3Sp#l5({JGeF+{S&d+g zXJsLkDHOFZ^MqoU1m+M!l^54q|0;&`YgdEa;E_&W&h>uIt6z8Ezb2lXsg^y%QvI8! z$@zbsP0YKF^`O~z9_vudMlFN97SijRo$~tfh||@SLTsOQZ*x6J6!?sWu^88R0P`i3 zZuffe)&DDocrY~eIhxm~Z#_YaZuWac9DVR}tL*t>$kYdm81N42s<9g7{gEt}D0|zp z(VuqdQP74<&VF@TBX*BWelF<#pQ7N3vk7zgwE`BB?@PFll%Hm>p`23)E{>dNt=}vw V#OX-@=koOZg7NpF_zy|(W)E=iH);R? literal 0 HcmV?d00001 diff --git a/people/index.html b/people/index.html new file mode 100644 index 00000000..de057e19 --- /dev/null +++ b/people/index.html @@ -0,0 +1,1471 @@ + + + + + + + + + + + + + + + + + + + + + + + + People - Automata + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + +
+
+ + + +
+
+
+ + + + + + + + +
+
+
+ + + + +
+ +
+ + +
+ + + +
+ + + +
+
+
+
+ + + + + + + + + \ No newline at end of file diff --git a/search/search_index.json b/search/search_index.json new file mode 100644 index 00000000..384b4682 --- /dev/null +++ b/search/search_index.json @@ -0,0 +1 @@ +{"config":{"lang":["en"],"separator":"[\\s\\-\\.]","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Automata","text":"

Copyright 2016-2024 Caleb Evans Released under the MIT license

Automata is a Python 3 library implementing structures and algorithms for manipulating finite automata, pushdown automata, and Turing machines. The algorithms have been optimized and are capable of processing large inputs. Visualization logic has also been implemented. This package is suitable for both researchers wishing to manipulate automata and for instructors teaching courses on theoretical computer science.

The library requires Python 3.8 or newer.

"},{"location":"#installing","title":"Installing","text":"

You can install the latest version of Automata via pip:

pip install automata-lib\n

To install the optional visual dependencies, use the visual extra:

pip install 'automata-lib[visual]'\n
"},{"location":"characteristics/","title":"Automaton Characteristics","text":""},{"location":"characteristics/#automaton-instances-are-immutable","title":"Automaton instances are immutable","text":"

All Automaton instances are fully immutable to protect against common pitfalls, such as mutating an automaton to an invalid state after it's already been validated.

This means that if you wish to make a change to an automaton instance, you must retrieve its attributes as a dictionary (using the input_parameters property), make your desired change, then pass those parameters to the relevant constructor. For example:

from automata.fa.dfa import DFA\ndfa1 = DFA(\nstates={'q0', 'q1', 'q2'},\ninput_symbols={'0', '1'},\ntransitions={\n'q0': {'0': 'q0', '1': 'q1'},\n'q1': {'0': 'q0', '1': 'q2'},\n'q2': {'0': 'q2', '1': 'q1'}\n},\ninitial_state='q0',\nfinal_states={'q1'}\n)\n# If you want to make a change, you must create a new instance; please note\n# that dfa1.input_parameters is always a deep copy of the input parameters for\n# dfa1 (in other words, mutating dfa1.input_parameters will not actually mutate\n# dfa1)\nparams = dfa1.input_parameters\nparams['final_states'] = {'q2'}\ndfa2 = DFA(**params)\n
"},{"location":"characteristics/#enabling-mutable-automata","title":"Enabling mutable automata","text":"

Automaton immutability is enforced via a \"freeze\" step during object initialization that turns mutable parameters (such as sets or dicts) into their immutable counterparts (frozensets/frozendicts).

If your application requires maximum performance, you can disable this conversion via the allow_mutable_automata global configuration option. If enabled, the user must ensure that their automaton instances are never modified, otherwise correct behavior cannot be guaranteed.

import automata.base.config as global_config\nglobal_config.allow_mutable_automata = True\n# The rest of your code...\n
"},{"location":"characteristics/#automaton-instances-are-validated-by-default","title":"Automaton instances are validated by default","text":"

By default, all Automaton instances are checked for common inconsistencies when they are instantiated. If inconsistencies are found, the appropriate exception from automata.base.exceptions is raised.

Because this validation can be performance-intensive for large automaton instances with many states/transitions, you can disable the automatic validation using the global configuration feature (introduced in v7):

import automata.base.config as global_config\nglobal_config.should_validate_automata = False\n# The rest of your code...\n

If, at any point, you wish to opt into validation for a specific Automaton instance, you can call the validate method:

my_automaton.validate()\n
"},{"location":"migration/","title":"Automata Migration Guide","text":""},{"location":"migration/#backwards-incompatible-changes-from-v7-to-v8","title":"Backwards-incompatible changes from v7 to v8","text":""},{"location":"migration/#dependency-changes","title":"Dependency Changes","text":"

Python 3.7 support has been dropped. Please upgrade to Python 3.8 or later to use Automata v8.

Diagrams are no longer being generated using pydot; this dependency has been dropped in favor of using the visual optional dependency, which will install pygraphviz and coloraide used for generating figures. You should install this optional dependency if you wish to generate figures. This change was to allow for native support for displaying finite automaton in Jupyter notebooks. The style of the diagrams has been lifted from the visual automata package, so you should take a look at the diagrams generated and see if they are still satisfactory.

Other new dependencies have been added, but these will be installed automatically along with v8 of the package.

"},{"location":"migration/#greater-support-for-partial-dfas","title":"Greater Support for Partial DFAs","text":"

There is now greater support for partial DFAs, which included changing the DFA.from_nfa() function to return a partial DFA instead of a complete one. To obtain a complete DFA, you must now call DFA.from_nfa().to_complete(trap_state_name), where trap_state_name will be used as the name for a trap state if one needs to be added.

"},{"location":"migration/#type-hints","title":"Type Hints","text":"

Type hints have now been added, meaning that code which previously called functions with incorrect types may not have been flagged. See output from your typechecker for more information.

"},{"location":"migration/#nfafrom_regex-default-input-symbols","title":"NFA.from_regex default input symbols","text":"

The default set of input symbols for NFA.from_regex was changed to all ascii letters and digits. If needing to use a specific set of input symbols, use the input_symbols parameter.

"},{"location":"migration/#backwards-incompatible-changes-from-v6-to-v7","title":"Backwards-incompatible changes from v6 to v7","text":""},{"location":"migration/#immutable-instances","title":"Immutable instances","text":"

All Automaton instances are now fully immutable to protect against common pitfalls, such as mutating an automaton to an invalid state after it's already been validated.

This means that if you wish to make a change to an automaton instance, you must retrieve its attributes as a dictionary (using the new input_parameters property), make your desired change, then pass those parameters to the relevant constructor. For example:

from automata.fa.dfa import DFA\ndfa1 = DFA(\nstates={'q0', 'q1', 'q2'},\ninput_symbols={'0', '1'},\ntransitions={\n'q0': {'0': 'q0', '1': 'q1'},\n'q1': {'0': 'q0', '1': 'q2'},\n'q2': {'0': 'q2', '1': 'q1'}\n},\ninitial_state='q0',\nfinal_states={'q1'}\n)\n# You can still copy an automaton just fine\ndfa2 = dfa.copy()\n# If you want to make a change, you must create a new instance; please note\n# that dfa2.input_parameters is always a deep copy of the input parameters for\n# dfa2 (in other words, mutating dfa2.input_parameters will not actually mutate\n# dfa2)\nparams = dfa2.input_parameters\nparams['final_states'] = {'q2'}\ndfa3 = DFA(**params)\n
"},{"location":"migration/#renamed-regex-module","title":"Renamed Regex Module","text":"

The automata.base.regex module has been renamed to automata.regex.regex alongside the other regular expression-related modules.

"},{"location":"migration/#dfaminify-defaults","title":"DFA.minify() defaults","text":"

The default value of the retain_names parameter for DFA.minify() has been corrected from True to False; the API documentation has always stated that the default value should be False, however the default value in the code was actually True; therefore, the code has been updated to match the documentation (#59) - Since this code correction may break existing developer code, this is labeled as a backwards-incompatible change rather than just a mere bugfix

"},{"location":"migration/#backwards-incompatible-changes-from-v5-to-v6","title":"Backwards-incompatible changes from v5 to v6","text":"

Python 3.6 support has been dropped, since it has been end-of-life since December 2021. Please upgrade to Python 3.7 or later to use Automata v6.

The networkx package has been added as a required dependency, providing substantial performance improvements for certain DFA/NFA methods, and also streamlining the code to improve maintainability.

"},{"location":"migration/#backwards-incompatible-changes-from-v4-to-v5","title":"Backwards-incompatible changes from v4 to v5","text":"

Python 3.5 support has been dropped, since it has been end-of-life since September 2020. Please upgrade to Python 3.6 or later to use Automata v5.

To support the new graph visualization capabilities, pydot has been added as a project dependency. The pydot package will be installed when you run pip install automata-lib.

"},{"location":"migration/#backwards-incompatible-changes-from-v3-to-v4","title":"Backwards-incompatible changes from v3 to v4","text":"

The only backwards-incompatible change from v3 to v4 is that support for Python 3.4 has been dropped. This is because Python 3.4 has reached end-of-life, and will no longer receive updates. For more information, please refer to the Python 3.4.10 release notes.

There have been no API changes from v3 to v4.

"},{"location":"migration/#backwards-incompatible-changes-from-v2-to-v3","title":"Backwards-incompatible changes from v2 to v3","text":"

There have been a number of backwards-incompatible changes from Automata v2 to v3 to support the new features, including:

"},{"location":"migration/#some-types-made-immutable","title":"Some types made immutable","text":"

The PDAStack type is now immutable and hashable; it still represents the current stack of a PDA.

Likewise, the TMTape is now immutable and hashable; it still represents the tape of a TM and the current cursor position.

"},{"location":"migration/#copy-methods-removed-for-now-immutable-types","title":"copy() methods removed for (now) immutable types","text":"

The copy methods on TMTape and PDAStack have been removed, since they are now immutable types. This change is similar to how list has a copy() method but tuple does not.

"},{"location":"migration/#acceptance-mode-of-pdas-is-now-configurable","title":"Acceptance mode of PDAs is now configurable","text":"

DPDA and NPDA have a new config option which specifies when to accept. This can be either 'empty_stack', 'final_state' or 'both'. The default is 'both'.

"},{"location":"migration/#backwards-incompatible-changes-from-v1-to-v2","title":"Backwards-incompatible changes from v1 to v2","text":"

There have been a number of backwards-incompatible changes from Automata v1 to v2 to clean up the API, including:

"},{"location":"migration/#renames","title":"Renames","text":"

The following methods and classes have been renamed for better clarity:

"},{"location":"migration/#shared-module","title":"Shared module","text":"

The automata.shared package has been renamed to automata.base.

Before:

from automata.shared.automaton import Automaton\nfrom automata.shared.exceptions import FinalStateError\n

After:

from automata.base.automaton import Automaton\nfrom automata.base.exceptions import FinalStateError\n

"},{"location":"migration/#input-validation-methods","title":"Input validation methods","text":"

The validate_input() method has been renamed to read_input(). The validate_input(step=True) form has also been converted to the standalone method read_input_stepwise().

Before:

final_state = dfa.validate_input('0011')\nsteps = dfa.validate_input('0011', step=True)\n

After:

final_state = dfa.read_input('0011')\nsteps = dfa.read_input_stepwise('0011')\n

"},{"location":"migration/#automaton-validation-methods","title":"Automaton validation methods","text":"

The validate_self() method has been renamed to validate().

Before:

dfa.validate_self()\n

After:

dfa.validate()\n

"},{"location":"migration/#exceptions","title":"Exceptions","text":"

The top-level *Error exception classes has been renamed to *Exception.

Before:

from automata.shared.exceptions import AutomatonError\nfrom automata.shared.exceptions import RejectionError\nfrom automata.pda.exceptions import PDAError\nfrom automata.tm.exceptions import TMError\n

After:

from automata.base.exceptions import AutomatonException\nfrom automata.base.exceptions import RejectionException\nfrom automata.pda.exceptions import PDAException\nfrom automata.tm.exceptions import TMException\n

"},{"location":"migration/#constructor-polymorphism-removed","title":"Constructor polymorphism removed","text":"

In v1, you could copy an automaton (or convert it to another type) by passing it into the constructor for an Automaton subtype.

"},{"location":"migration/#copying-an-automaton","title":"Copying an automaton","text":"

Before:

dfa = DFA(dfa)\n

After:

dfa = dfa.copy()\n

"},{"location":"migration/#converting-nfa-to-dfa","title":"Converting NFA to DFA","text":"

Before:

dfa = DFA(nfa)\n

After:

dfa = DFA.from_nfa(nfa)\n

"},{"location":"migration/#converting-dfa-to-nfa","title":"Converting DFA to NFA","text":"

Before:

nfa = NFA(dfa)\n

After:

nfa = NFA.from_dfa(dfa)\n

"},{"location":"people/","title":"People","text":""},{"location":"people/#maintainers","title":"Maintainers","text":"
  • caleb531
  • eliotwrobson
"},{"location":"people/#contributors","title":"Contributors","text":"
  • lewiuberg
  • YtvwlD
  • dengl11
  • Tagl
  • CamiloMartinezM
  • abhinavsinha-adrino
"},{"location":"api/","title":"API","text":"

This is the API documentation generated by the class and method docstrings for the automata package.

"},{"location":"api/base-exception-classes/","title":"Base exception classes","text":"

Exception classes shared by all automata.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.AutomatonException","title":"AutomatonException","text":"

Bases: Exception

The base class for all automaton-related errors.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.DiagramException","title":"DiagramException","text":"

Bases: AutomatonException

The diagram cannot be produced

"},{"location":"api/base-exception-classes/#automata.base.exceptions.EmptyLanguageException","title":"EmptyLanguageException","text":"

Bases: AutomatonException

The operation cannot be performed because the language is empty

"},{"location":"api/base-exception-classes/#automata.base.exceptions.FinalStateError","title":"FinalStateError","text":"

Bases: AutomatonException

A final state fails to meet some required condition.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.InfiniteLanguageException","title":"InfiniteLanguageException","text":"

Bases: AutomatonException

The operation cannot be performed because the language is infinite

"},{"location":"api/base-exception-classes/#automata.base.exceptions.InitialStateError","title":"InitialStateError","text":"

Bases: AutomatonException

The initial state fails to meet some required condition.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.InvalidRegexError","title":"InvalidRegexError","text":"

Bases: RegexException

Regular expression is invalid

"},{"location":"api/base-exception-classes/#automata.base.exceptions.InvalidStateError","title":"InvalidStateError","text":"

Bases: AutomatonException

A state is not a valid state for this automaton.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.InvalidSymbolError","title":"InvalidSymbolError","text":"

Bases: AutomatonException

A symbol is not a valid symbol for this automaton.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.LexerError","title":"LexerError dataclass","text":"

Bases: RegexException

An exception raised for issues in lexing

"},{"location":"api/base-exception-classes/#automata.base.exceptions.MissingStateError","title":"MissingStateError","text":"

Bases: AutomatonException

A state is missing from the automaton definition.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.MissingSymbolError","title":"MissingSymbolError","text":"

Bases: AutomatonException

A symbol is missing from the automaton definition.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.RegexException","title":"RegexException","text":"

Bases: Exception

The base class for all regular expression related errors

"},{"location":"api/base-exception-classes/#automata.base.exceptions.RejectionException","title":"RejectionException","text":"

Bases: AutomatonException

The input was rejected by the automaton.

"},{"location":"api/base-exception-classes/#automata.base.exceptions.SymbolMismatchError","title":"SymbolMismatchError","text":"

Bases: AutomatonException

The input symbols between the given automata do not match

"},{"location":"api/class-automaton/","title":"class Automaton(metaclass=ABCMeta)","text":"

An abstract base class for all automata, including Turing machines.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.input_parameters","title":"input_parameters: Dict[str, Any] property","text":"

Return the public attributes for this automaton.

Returns:

Type Description Dict[str, Any]

A dictionary mapping attribute names to their values.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.accepts_input","title":"accepts_input(input_str)","text":"

Return True if this automaton accepts the given input.

Parameters:

Name Type Description Default input_str str

The input string to check.

required

Returns:

Type Description bool

True if this automaton accepts the given input; False otherwise.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.copy","title":"copy()","text":"

Create a deep copy of the automaton.

Returns:

Type Description Self

A deep copy of the automaton.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.read_input","title":"read_input(input_str)","text":"

Check if the given string is accepted by this automaton.

Return the automaton's final configuration if this string is valid.

Parameters:

Name Type Description Default input_str str

The input string to check.

required

Returns:

Type Description AutomatonStateT

The final configuration of the automaton after reading the input.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.read_input_stepwise","title":"read_input_stepwise(input_str) abstractmethod","text":"

Return a generator that yields each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[Any, None, None]

A generator that yields the current configuration of the automaton after each step of reading input.

Raises:

Type Description NotImplementedError

If this method has not been implemented by a subclass.

"},{"location":"api/class-automaton/#automata.base.automaton.Automaton.validate","title":"validate() abstractmethod","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description NotImplementedError

If this method has not been implemented by a subclass.

"},{"location":"api/regular-expressions/","title":"Regular Expressions","text":"

A set of tools for working with regular expressions. Can recognize regular expressions over the alphabet of ascii letters (lower and upper case), ascii digits, and subsets of these.

A regular expression with the following operations only are supported in this library:

  • *: Kleene star operation, language repeated zero or more times. Ex: a*,(ab)*
  • +: Kleene plus operation, language repeated one or more times. Ex: a+,(ab)+
  • ?: Language repeated zero or one time. Ex: a?
  • Concatenation. Ex: abcd
  • |: Union. Ex: a|b
  • &: Intersection. Ex: a&b
  • .: Wildcard. Ex: a.b
  • ^: Shuffle. Ex: a^b
  • {}: Quantifiers expressing finite repetitions. Ex: a{1,2},a{3,}
  • (): The empty string.
  • (...): Grouping.

This is similar to the Python re module, but this library does not support any special characters other than those given above. All regular languages can be written with these.

"},{"location":"api/regular-expressions/#automata.regex.regex.isequal","title":"isequal(re1, re2, *, input_symbols=None)","text":"

Whether both regular expressions are equivalent.

Parameters:

Name Type Description Default re1 str

The first regular expression as a string.

required re2 str

The second regular expression as a string.

required input_symbols Optional[AbstractSet[str]]

The set of input symbols when doing the comparison. Defaults to all ascii letters and digits.

None

Returns:

Type Description bool

Whether the regular expressions are equivalent.

"},{"location":"api/regular-expressions/#automata.regex.regex.issubset","title":"issubset(re1, re2, *, input_symbols=None)","text":"

Whether re1 is a subset of re2.

Parameters:

Name Type Description Default re1 str

The first regular expression as a string.

required re2 str

The second regular expression as a string.

required input_symbols Optional[AbstractSet[str]]

The set of input symbols when doing the comparison. Defaults to all ascii letters and digits.

None

Returns:

Type Description bool

True if re1 is a subset of re2.

"},{"location":"api/regular-expressions/#automata.regex.regex.issuperset","title":"issuperset(re1, re2, *, input_symbols=None)","text":"

Whether re1 is a superset of re2.

Parameters:

Name Type Description Default re1 str

The first regular expression as a string.

required re2 str

The second regular expression as a string.

required input_symbols Optional[AbstractSet[str]]

The set of input symbols when doing the comparison. Defaults to all ascii letters and digits.

None

Returns:

Type Description bool

True if re1 is a superset of re2.

"},{"location":"api/regular-expressions/#automata.regex.regex.validate","title":"validate(regex)","text":"

Raises an exception if the input regular expression is invalid.

Raises:

Type Description InvalidRegexError

Raised if the regex given as input is not well defined.

"},{"location":"api/fa/class-dfa/","title":"class DFA(FA)","text":"

Classes and methods for working with deterministic finite automata.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA","title":"DFA","text":"

Bases: FA

The DFA class is a subclass of FA and represents a deterministic finite automaton.

Every DFA can be rendered natively inside of a Jupyter notebook (automatically calling show_diagram without any arguments) if installed with the visual optional dependency.

Parameters:

Name Type Description Default states AbstractSet[DFAStateT]

Set of the DFA's valid states.

required input_symbols AbstractSet[str]

Set of the DFA's valid input symbols, each of which is a singleton string

required transitions Mapping[DFAStateT, Mapping[str, DFAStateT]]

Dict consisting of the transitions for each state. Each key is a state name, and each value is another dict which maps a symbol (the key) to a state (the value).

required initial_state DFAStateT

The initial state for this DFA.

required final_states AbstractSet[DFAStateT]

A set of final states for this DFA

required allow_partial bool

By default, each DFA state must have a transition to every input symbol; if this parameter is True, you can disable this characteristic (such that any DFA state can have fewer transitions than input symbols). Note that a DFA must always have every state represented in the transition dictionary, even if there are no transitions on input symbols leaving a state (dictionary is left empty in that case).

True"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.cardinality","title":"cardinality()","text":"

Returns the cardinality of the language represented by the DFA.

Returns:

Type Description int

The cardinality of the language accepted by self.

Raises:

Type Description InfiniteLanguageException

Raised if self accepts an infinite language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.clear_cache","title":"clear_cache()","text":"

Resets the word and count caches. Can be called if too much memory is being used.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.complement","title":"complement(*, retain_names=False, minify=True)","text":"

Creates a DFA which accepts an input if and only if the old one does not. Minifies by default. Unreachable states are always removed. Partial DFAs are converted into complete ones.

Parameters:

Name Type Description Default retain_names bool

Whether to retain state names through the complement and optional minify.

False minify bool

Whether to minify the result of the complement of the input DFA.

True

Returns:

Type Description Self

A DFA accepting the complement of the input DFA. State minimal by default.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.count_mod","title":"count_mod(input_symbols, k, *, remainders=None, symbols_to_count=None) classmethod","text":"

Directly computes a DFA that counts given symbols and accepts all strings where the remainder of division by k is in the set of remainders given. The default value of remainders is {0} and all symbols are counted by default.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required k int

The number to divide the length by.

required remainders Optional[AbstractSet[int]]

The remainders to accept. If set to None, defaults to {0}.

None symbols_to_count Optional[AbstractSet[str]]

The input symbols to count towards the length of words to accepts. If set to None, counts all symbols.

None

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.count_words_of_length","title":"count_words_of_length(k)","text":"

Returns count of words of length k accepted by the DFA.

Parameters:

Name Type Description Default k int

The desired word length.

required

Returns:

Type Description int

The number of words of length k accepted by self.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.difference","title":"difference(other, *, retain_names=False, minify=True)","text":"

Takes as input two DFAs M1 and M2 which accept languages L1 and L2 respectively. Returns a DFA which accepts the difference of L1 and L2.

Minifies by default. Unreachable states are always removed. If either input DFA is partial, the result is partial.

Parameters:

Name Type Description Default other DFA

The DFA we want to take a difference with.

required retain_names bool

Whether to retain state names through the difference and optional minify.

False minify bool

Whether to minify the result of the difference of the two DFAs.

True

Returns:

Type Description Self

A DFA accepting the difference of the two input DFAs. State minimal by default.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.empty_language","title":"empty_language(input_symbols) classmethod","text":"

Directly computes the minimal DFA rejecting all strings.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_finite_language","title":"from_finite_language(input_symbols, language, as_partial=True) classmethod","text":"

Directly computes the minimal DFA accepting the finite language given as input. Uses the algorithm described in Finite-State Techniques by Mihov and Schulz, Chapter 10

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required language AbstractSet[str]

The language to accept.

required as_partial bool

Whether or not to construct this as a partial DFA.

True

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_nfa","title":"from_nfa(target_nfa, *, retain_names=False, minify=True) classmethod","text":"

Initialize this DFA as one equivalent to the given NFA. Note that this usually returns a partial DFA by default.

Parameters:

Name Type Description Default target_nfa NFA

The NFA to construct an equivalent DFA for.

required retain_names bool

Whether or not to retain state names during processing.

False minify bool

Whether or not to minify the DFA resulting from the input NFA.

True

Returns:

Type Description Self

The DFA accepting the language of the input NFA.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_prefix","title":"from_prefix(input_symbols, prefix, *, contains=True, as_partial=True) classmethod","text":"

Directly computes the minimal DFA accepting strings with the given prefix. If contains is set to False then the complement is constructed instead.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required prefix str

The prefix of strings that are accepted by this DFA.

required contains bool

Whether or not to construct the compliment DFA.

True as_partial bool

Whether or not to construct this DFA as a partial DFA.

True

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_subsequence","title":"from_subsequence(input_symbols, subsequence, *, contains=True) classmethod","text":"

Directly computes the minimal DFA recognizing strings containing the given subsequence. If contains is set to False, then the complement is constructed instead.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required subsequence str

The target subsequence of strings that are accepted by this DFA.

required contains bool

Whether or to construct the compliment DFA.

True

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_substring","title":"from_substring(input_symbols, substring, *, contains=True, must_be_suffix=False) classmethod","text":"

Directly computes the minimal DFA recognizing strings containing the given substring. If contains is set to False then the complement is constructed instead. If must_be_suffix is set to True, then the substring must be a suffix instead.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required substring str

The substring of strings that are accepted by this DFA.

required contains bool

Whether or to construct the compliment DFA.

True must_be_suffix bool

Whether or not the target substring must be a suffix.

False

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.from_suffix","title":"from_suffix(input_symbols, suffix, *, contains=True) classmethod","text":"

Directly computes the minimal DFA recognizing strings with the given suffix. If contains is set to False, then the complement is constructed instead.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required suffix str

The suffix of strings that are accepted by this DFA.

required contains bool

Whether or not to construct the compliment DFA.

True

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.intersection","title":"intersection(other, *, retain_names=False, minify=True)","text":"

Takes as input two DFAs M1 and M2 which accept languages L1 and L2 respectively. Returns a DFA which accepts the intersection of L1 and L2.

Minifies by default. Unreachable states are always removed. If either input DFA is partial, the result is partial.

Parameters:

Name Type Description Default other DFA

The DFA we want to take a intersection with.

required retain_names bool

Whether to retain state names through the intersection and optional minify.

False minify bool

Whether to minify the result of the intersection of the two DFAs.

True

Returns:

Type Description Self

A DFA accepting the intersection of the two input DFAs. State minimal by default.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.isdisjoint","title":"isdisjoint(other)","text":"

Returns True if the language accepted by self is disjoint from that of other.

Parameters:

Name Type Description Default other DFA

The other DFA we are comparing our language against.

required

Returns:

Type Description bool

True if self is disjoint from other, False otherwise.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.isempty","title":"isempty()","text":"

Returns True if the language accepted by self is empty.

Returns:

Type Description bool

True if self accepts the empty language, False otherwise.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.isfinite","title":"isfinite()","text":"

Returns True if the language accepted by self is finite.

Returns:

Type Description bool

True if self accepts a finite language, False otherwise.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.issubset","title":"issubset(other)","text":"

Returns True if the language accepted by self is a subset of that of other.

Parameters:

Name Type Description Default other DFA

The other DFA we are comparing our language against.

required

Returns:

Type Description bool

True if self is a subset of other, False otherwise.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.issuperset","title":"issuperset(other)","text":"

Returns True if the language accepted by self is a superset of that of other.

Parameters:

Name Type Description Default other DFA

The other DFA we are comparing our language against.

required

Returns:

Type Description bool

True if self is a superset of other, False otherwise.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.iter_transitions","title":"iter_transitions()","text":"

Iterate over all transitions in the DFA. Each transition is a tuple of the form (from_state, to_state, symbol).

Returns:

Type Description Generator[Tuple[DFAStateT, DFAStateT, str], None, None]

The desired generator over the DFA transitions.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.maximum_word_length","title":"maximum_word_length()","text":"

Returns the length of the longest word in the language accepted by the DFA In the case of infinite languages, None is returned.

Returns:

Type Description Optional[int]

The length of the longest word accepted by self. None if the language is infinite.

Raises:

Type Description EmptyLanguageException

Raised if self accepts the empty language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.minify","title":"minify(retain_names=False)","text":"

Create a minimal DFA which accepts the same inputs as this DFA.

First, non-reachable states are removed. Then, indistinguishable states are merged using Hopcroft's Algorithm.

Parameters:

Name Type Description Default retain_names bool

Whether to retain original names when merging states. New names are from 0 to n-1.

False

Returns:

Type Description Self

A state-minimal equivalent DFA. May be complete in some cases if the input is partial.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.minimum_word_length","title":"minimum_word_length()","text":"

Returns the length of the shortest word in the language accepted by the DFA.

Returns:

Type Description int

The length of the shortest word accepted by self.

Raises:

Type Description EmptyLanguageException

Raised if self accepts an empty language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.nth_from_end","title":"nth_from_end(input_symbols, symbol, n) classmethod","text":"

Directly computes the minimal DFA which accepts all words whose nth character from the end is symbol, where n is a positive integer.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required symbol str

The target input symbol.

required n int

The position of the target input symbol.

required

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.nth_from_start","title":"nth_from_start(input_symbols, symbol, n) classmethod","text":"

Directly computes the minimal DFA which accepts all words whose nth character from the start is symbol, where n is a positive integer.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required symbol str

The target input symbol.

required n int

The position of the target input symbol.

required

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.of_length","title":"of_length(input_symbols, *, min_length=0, max_length=None, symbols_to_count=None) classmethod","text":"

Directly computes the minimal DFA recognizing strings whose length is between min_length and max_length, inclusive. To allow arbitrarily long words, the value None can be passed in for max_length.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required min_length int

The minimum length of strings to be accepted by this DFA.

0 max_length Optional[int]

The maximum length of strings to be accepted by this DFA. If set to None, there is no maximum.

None symbols_to_count Optional[AbstractSet[str]]

The input symbols to count towards the length of words to accepts. If set to None, counts all symbols.

None

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.predecessor","title":"predecessor(input_str, *, strict=True, key=None)","text":"

Returns the first string accepted by the DFA that comes before the input string in lexicographical order.

Parameters:

Name Type Description Default input_str str

The starting input string.

required strict bool

If set to false and input_str is accepted by the DFA, input_str will be returned.

True key Optional[Callable]

Function for defining custom lexicographical ordering. Defaults to using the standard string ordering.

None

Returns:

Type Description str

The first string accepted by the DFA lexicographically before input_string.

Raises:

Type Description InfiniteLanguageException

Raised if the language accepted by self is infinite, as we cannot generate predecessors in this case.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.predecessors","title":"predecessors(input_str, *, strict=True, key=None)","text":"

Generates all strings that come before the input string in lexicographical order.

Parameters:

Name Type Description Default input_str str

The starting input string.

required strict bool

If set to false and input_str is accepted by the DFA, input_str will be returned.

True key Optional[Callable]

Function for defining custom lexicographical ordering. Defaults to using the standard string ordering.

None

Returns:

Type Description Generator[str, None, None]

A generator for all strings that come before the input string in lexicographical order.

Raises:

Type Description InfiniteLanguageException

Raised if the language accepted by self is infinite, as we cannot generate predecessors in this case.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.random_word","title":"random_word(k, *, seed=None)","text":"

Returns a random word of length k accepted by self.

Parameters:

Name Type Description Default k int

The length of the desired word.

required seed Optional[int]

The random seed to use for the sampling of the random word.

None

Returns:

Type Description str

A uniformly random word of length k accepted by the DFA self.

Raises:

Type Description ValueError

If this DFA does not accept any words of length k.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.read_input_stepwise","title":"read_input_stepwise(input_str, ignore_rejection=False)","text":"

Return a generator that yields each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required ignore_rejection bool

Whether to throw an exception if the input string is rejected.

False

Yields:

Type Description Generator[DFAStateT, None, None]

A generator that yields the current configuration of the DFA after each step of reading input.

Raises:

Type Description RejectionException

Raised if this DFA does not accept the input string.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.successor","title":"successor(input_str, *, strict=True, key=None)","text":"

Returns the first string accepted by the DFA that comes after the input string in lexicographical order.

Parameters:

Name Type Description Default input_str Optional[str]

The starting input string. If None, will generate all words.

required strict bool

If set to false and input_str is accepted by the DFA, input_str will be returned.

True key Optional[Callable]

Function for defining custom lexicographical ordering. Defaults to using the standard string ordering.

None

Returns:

Type Description str

The first string accepted by the DFA lexicographically before input_string.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.successors","title":"successors(input_str, *, strict=True, key=None, reverse=False)","text":"

Generates all strings that come after the input string in lexicographical order.

Parameters:

Name Type Description Default input_str Optional[str]

The starting input string. If None, will generate all words.

required strict bool

If set to false and input_str is accepted by the DFA, input_str will be returned.

True key Optional[Callable]

Function for defining custom lexicographical ordering. Defaults to using the standard string ordering.

None reverse bool

If True, then predecessors will be generated instead of successors.

False

Returns:

Type Description Generator[str, None, None]

A generator for all strings that come after the input string in lexicographical order.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.symmetric_difference","title":"symmetric_difference(other, *, retain_names=False, minify=True)","text":"

Takes as input two DFAs M1 and M2 which accept languages L1 and L2 respectively. Returns a DFA which accepts the symmetric difference of L1 and L2.

Minifies by default. Unreachable states are always removed. If either input DFA is partial, the result is partial.

Parameters:

Name Type Description Default other DFA

The DFA we want to take a symmetric difference with.

required retain_names bool

Whether to retain state names through the symmetric difference and optional minify.

False minify bool

Whether to minify the result of the symmetric difference of the two DFAs.

True

Returns:

Type Description Self

A DFA accepting the symmetric difference of the two input DFAs. State minimal by default.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.to_complete","title":"to_complete(trap_state=None)","text":"

Creates an equivalent complete DFA with trap_state used as the name for an added trap state. If trap_state is not passed in, defaults to the largest negative integer which is not already a state name. If the DFA is already complete, just returns a copy.

Parameters:

Name Type Description Default trap_state Optional[DFAStateT]

Name for custom trap state to be used.

None

Returns:

Type Description Self

An equivalent complete DFA.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.to_partial","title":"to_partial(*, retain_names=False, minify=True)","text":"

Turns a DFA (complete or not) into a partial DFA. Removes dead states and trap states (except the initial state) and all edges leading to them.

Parameters:

Name Type Description Default minify bool

Whether to perform a minify operation while converting to a partial DFA.

True retain_names bool

Whether to retain state names during minification.

True

Returns:

Type Description Self

An equivalent partial DFA.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.union","title":"union(other, *, retain_names=False, minify=True)","text":"

Takes as input two DFAs M1 and M2 which accept languages L1 and L2 respectively. Returns a DFA which accepts the union of L1 and L2.

Minifies by default. Unreachable states are always removed. If either input DFA is partial, the result is partial.

Parameters:

Name Type Description Default other DFA

The DFA we want to take a union with.

required retain_names bool

Whether to retain state names through the union and optional minify.

False minify bool

Whether to minify the result of the union of the two DFAs.

True

Returns:

Type Description Self

A DFA accepting the union of the two input DFAs. State minimal by default.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.universal_language","title":"universal_language(input_symbols) classmethod","text":"

Directly computes the minimal DFA accepting all strings.

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the DFA over.

required

Returns:

Type Description Self

The DFA accepting the desired language.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this DFA has invalid states in the transition dictionary.

MissingStateError

If this DFA has states missing from the transition dictionary.

InvalidSymbolError

If this DFA has invalid symbols in the transition dictionary.

MissingSymbolError

If this DFA is missing transitions on certain symbols.

"},{"location":"api/fa/class-dfa/#automata.fa.dfa.DFA.words_of_length","title":"words_of_length(k)","text":"

Generates all words of length k in the language accepted by the DFA.

Parameters:

Name Type Description Default k int

The desired word length.

required

Returns:

Type Description Generator[str, None, None]

A generator for all words of length k accepted by the DFA.

"},{"location":"api/fa/class-fa/","title":"class FA(Automaton, metaclass=ABCMeta)","text":"

Classes and methods for working with all finite automata.

"},{"location":"api/fa/class-fa/#automata.fa.fa.FA","title":"FA","text":"

Bases: Automaton

The FA class is an abstract base class from which all finite automata inherit. Every subclass of FA can be rendered natively inside of a Jupyter notebook (automatically calling show_diagram without any arguments) if installed with the visual optional dependency.

"},{"location":"api/fa/class-fa/#automata.fa.fa.FA.iter_transitions","title":"iter_transitions() abstractmethod","text":"

Iterate over all transitions in the automaton. Each transition is a tuple of the form (from_state, to_state, symbol)

"},{"location":"api/fa/class-fa/#automata.fa.fa.FA.show_diagram","title":"show_diagram(input_str=None, path=None, *, layout_method='dot', horizontal=True, reverse_orientation=False, fig_size=None, font_size=14.0, arrow_size=0.85, state_separation=0.5)","text":"

Generates a diagram of the associated automaton.

Parameters:

Name Type Description Default input_str Optional[str]

String consisting of input symbols. If set, will add processing of the input string to the diagram.

None path Union[str, PathLike, None]

Path to output file. If None, the output will not be saved.

None horizontal bool

Direction of node layout in the output graph.

True reverse_orientation bool

Reverse direction of node layout in the output graph.

False fig_size Union[Tuple[float, float], Tuple[float], None]

Figure size.

None font_size float

Font size in the output graph.

14.0 arrow_size float

Arrow size in the output graph.

0.85 state_separation float

Distance between nodes in the output graph.

0.5

Returns:

Type Description AGraph

A diagram of the given automaton.

"},{"location":"api/fa/class-gnfa/","title":"class GNFA(FA)","text":"

Classes and methods for working with generalized non-deterministic finite automata.

"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA","title":"GNFA","text":"

Bases: FA

The GNFA class is a subclass of FA and represents a generalized nondeterministic finite automaton.

Its main usage is for conversion of DFAs and NFAs to regular expressions. Note that because of this, the GNFA doesn't support any binary operators or reading input (e.g. read_input_stepwise). Every GNFA can be rendered natively inside of- a Jupyter notebook (automatically calling show_diagram without any arguments) if installed with the visual optional dependency. Note that input_str cannot be set as an argument to show_diagram, as the GNFA does not read input.

Except for initial_state and final_state, one transition goes from every state to every other state, and also from each state to itself. To accommodate this, transitions can be regular expressions and None, in addition to normal input symbols.

Parameters:

Name Type Description Default states AbstractSet[GNFAStateT]

Set of the GNFA's valid states.

required input_symbols AbstractSet[str]

Set of the GNFA's valid input symbols, each of which is a singleton string.

required transitions Mapping[GNFAStateT, Mapping[GNFAStateT, Optional[str]]]

A dict with the transitions for each state, except final_state. Each key is a state name and each value is dict which maps a state (the key) to the transition expression (the value) or None. The transition expression is a regular expression (string) over input_symbols, and the following symbols only: *, |, ?, ().

This is a subset of the standard regular expressions using this package.

required initial_state GNFAStateT

The initial state for this GNFA. Has transitions going to every other state, but no transitions coming in from any other state.

required final_state GNFAStateT

A single final state for this GNFA. Has transitions coming in from every other state, but no transitions going to any other state. Must be different from the initial_state.

required"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA.from_dfa","title":"from_dfa(target_dfa) classmethod","text":"

Initialize this GNFA as one equivalent to the given DFA.

Parameters:

Name Type Description Default target_dfa DFA

The DFA to construct an equivalent GNFA for.

required

Returns:

Type Description Self

The GNFA accepting the language of the input DFA.

"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA.from_nfa","title":"from_nfa(target_nfa) classmethod","text":"

Initialize this GNFA as one equivalent to the given NFA.

Parameters:

Name Type Description Default target_nfa NFA

The NFA to construct an equivalent GNFA for.

required

Returns:

Type Description Self

The GNFA accepting the language of the input NFA.

"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA.iter_transitions","title":"iter_transitions()","text":"

Iterate over all transitions in the GNFA. Each transition is a tuple of the form (from_state, to_state, symbol).

Returns:

Type Description Generator[Tuple[GNFAStateT, GNFAStateT, str], None, None]

The desired generator over the GNFA transitions.

"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA.to_regex","title":"to_regex()","text":"

Convert GNFA to regular expression.

Returns:

Type Description str

A regular expression equivalent to the input GNFA.

"},{"location":"api/fa/class-gnfa/#automata.fa.gnfa.GNFA.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this GNFA has invalid states in the transition dictionary.

MissingStateError

If this GNFA has states missing from the transition dictionary.

InvalidRegexError

If this GNFA has invalid regex in the transition dictionary.

"},{"location":"api/fa/class-nfa/","title":"class NFA(FA)","text":"

Classes and methods for working with nondeterministic finite automata.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA","title":"NFA","text":"

Bases: FA

The NFA class is a subclass of FA and represents a nondeterministic finite automaton.

Every NFA has the same five DFA properties: state, input_symbols, transitions, initial_state, and final_states. However, the structure of the transitions object has been modified slightly to accommodate the fact that a single state can have more than one transition for the same symbol. Therefore, instead of mapping a symbol to one end state in each sub-dict, each symbol is mapped to a set of end states.

Every NFA can be rendered natively inside of a Jupyter notebook (automatically calling show_diagram without any arguments) if installed with the visual optional dependency.

Parameters:

Name Type Description Default states AbstractSet[NFAStateT]

Set of the NFA's valid states.

required input_symbols AbstractSet[str]

Set of the NFA's valid input symbols, each of which is a singleton string.

required transitions Mapping[NFAStateT, Mapping[str, AbstractSet[NFAStateT]]]

Dict consisting of the transitions for each state. Each key is a state name, and each value is another dict which maps a symbol (the key) to a set of states (the value).

required initial_state NFAStateT

The initial state for this NFA.

required final_states AbstractSet[NFAStateT]

A set of final states for this NFA.

required"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.concatenate","title":"concatenate(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the language L1 concatenated with L2.

Parameters:

Name Type Description Default other NFA

The NFA we want to concatenate with.

required

Returns:

Type Description Self

An NFA accepting the language concatenation of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.edit_distance","title":"edit_distance(input_symbols, reference_str, max_edit_distance, *, insertion=True, deletion=True, substitution=True) classmethod","text":"

Constructs the Levenshtein NFA for the given reference_str and given Levenshtein distance. This NFA recognizes strings within the given Levenshtein distance (commonly called edit distance) of the reference_str. Parameters control which error types the NFA will recognize (insertions, deletions, or substitutions). At least one error type must be set.

If insertion and deletion are False and substitution is True, then this is the same as Hamming distance.

If insertion and deletion are True and substitution is False, then this is the same as LCS distance.

insertion, deletion, and substitution all default to True.

Code adapted from: http://blog.notdot.net/2010/07/Damn-Cool-Algorithms-Levenshtein-Automata

Parameters:

Name Type Description Default input_symbols AbstractSet[str]

The set of input symbols to construct the NFA over.

required reference_str str

The reference string the NFA will use to recognize other close strings.

required max_edit_distance int

The maximum edit distance from the reference string this NFA will recognize. Must be positive.

required insertion bool

Whether to recognize insertion edits relative to the reference string.

True deletion bool

Whether to recognize deletion edits relative to the reference string.

True substitution bool

Whether to recognize substitution edits relative to the reference string.

True

Returns:

Type Description Self

An NFA accepting all strings within the given edit distance to the reference string.

Raises:

Type Description ValueError

Raised if the max_edit_distance is negative or all of the error flags are set to False (at least one must be True).

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.eliminate_lambda","title":"eliminate_lambda()","text":"

Returns an equivalent NFA with lambda transitions removed.

Returns:

Type Description Self

The equivalent NFA with lambda transitions removed.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.from_dfa","title":"from_dfa(target_dfa) classmethod","text":"

Initialize this NFA as one equivalent to the given DFA.

Parameters:

Name Type Description Default target_dfa DFA

The DFA to construct an equivalent NFA for.

required

Returns:

Type Description Self

The NFA accepting the language of the input DFA.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.from_regex","title":"from_regex(regex, *, input_symbols=None) classmethod","text":"

Initialize this NFA as one equivalent to the given regular expression.

Parameters:

Name Type Description Default regex str

The regex to construct an equivalent NFA for.

required input_symbols Optional[AbstractSet[str]]

The set of input symbols to create the NFA over. If not set, defaults to all ascii letters and digits.

None

Returns:

Type Description Self

The NFA accepting the language of the input regex.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.intersection","title":"intersection(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the intersection of L1 and L2.

Parameters:

Name Type Description Default other NFA

The NFA we want to take an intersection with.

required

Returns:

Type Description Self

An NFA accepting the intersection of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.iter_transitions","title":"iter_transitions()","text":"

Iterate over all transitions in the NFA. Each transition is a tuple of the form (from_state, to_state, symbol).

Returns:

Type Description Generator[Tuple[NFAStateT, NFAStateT, str], None, None]

The desired generator over the NFA transitions.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.kleene_star","title":"kleene_star()","text":"

Given an NFA which accepts the language L, returns an NFA which accepts L repeated 0 or more times.

Returns:

Type Description Self

An NFA accepting the finite repetition of the input NFA.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.left_quotient","title":"left_quotient(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the left quotient of L1 with respect to L2 (L2 L1).

Construction is based off of the one described here: https://cs.stackexchange.com/a/102043

Parameters:

Name Type Description Default other NFA

The NFA we want to take a left quotient with.

required

Returns:

Type Description Self

An NFA accepting the left quotient of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.option","title":"option()","text":"

Given an NFA which accepts the language L, returns an NFA which accepts L repeated 0 or 1 times.

Returns:

Type Description Self

An NFA accepting the optional of the input NFA.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Return a generator that yields the configuration of this NFA at each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[AbstractSet[NFAStateT], None, None]

A generator that yields the current configuration (a set of states) of the NFA after each step of reading input.

Raises:

Type Description RejectionException

Raised if this NFA does not accept the input string.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.reverse","title":"reverse()","text":"

Given an NFA which accepts the language L, returns an NFA which accepts the reverse of L.

Returns:

Type Description Self

An NFA accepting the reversal of the input NFA.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.right_quotient","title":"right_quotient(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the right quotient of L1 with respect to L2 (L1 / L2).

Construction is based off of the one described here: https://cs.stackexchange.com/a/102043

Parameters:

Name Type Description Default other NFA

The NFA we want to take a right quotient with.

required

Returns:

Type Description Self

An NFA accepting the right quotient of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.shuffle_product","title":"shuffle_product(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the shuffle of L1 and L2.

Parameters:

Name Type Description Default other NFA

The NFA we want to take a shuffle product with.

required

Returns:

Type Description Self

An NFA accepting the shuffle product of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.union","title":"union(other)","text":"

Given two NFAs, M1 and M2, which accept the languages L1 and L2 respectively, returns an NFA which accepts the union of L1 and L2.

Parameters:

Name Type Description Default other NFA

The NFA we want to take a union with.

required

Returns:

Type Description Self

An NFA accepting the union of the two input NFAs.

"},{"location":"api/fa/class-nfa/#automata.fa.nfa.NFA.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this NFA has invalid states in the transition dictionary.

MissingStateError

If this NFA has states missing from the transition dictionary.

InvalidSymbolError

If this NFA has invalid symbols in the transition dictionary.

"},{"location":"api/pda/class-dpda/","title":"class DPDA(PDA)","text":"

Classes and methods for working with deterministic pushdown automata.

"},{"location":"api/pda/class-dpda/#automata.pda.dpda.DPDA","title":"DPDA","text":"

Bases: PDA

The DPDA class is a subclass of PDA and represents a deterministic pushdown automaton.

Parameters:

Name Type Description Default states AbstractSet[DPDAStateT]

A set of the DPDA's valid states

required input_symbols AbstractSet[str]

Set of the DPDA's valid input symbols, each of which is a singleton string.

required stack_symbols AbstractSet[str]

Set of the DPDA's valid stack symbols, each of which is a singleton string.

required transitions DPDATransitionsT

A dict consisting of the transitions for each state; see the example below for the exact syntax

required initial_state DPDAStateT

The name of the initial state for this DPDA.

required initial_stack_symbol str

The name of the initial symbol on the stack for this DPDA.

required final_states AbstractSet[DPDAStateT]

A set of final states for this DPDA.

required acceptance_mode PDAAcceptanceModeT

A string defining whether this DPDA accepts by 'final_state', 'empty_stack', or 'both'.

'both'"},{"location":"api/pda/class-dpda/#automata.pda.dpda.DPDA--example","title":"Example","text":"
from automata.pda.dpda import DPDA\n# DPDA which which matches zero or more 'a's, followed by the same\n# number of 'b's (accepting by final state)\ndpda = DPDA(\n    states={'q0', 'q1', 'q2', 'q3'},\n    input_symbols={'a', 'b'},\n    stack_symbols={'0', '1'},\n    transitions={\n        'q0': {\n            'a': {'0': ('q1', ('1', '0'))}  # push '1' to stack\n        },\n        'q1': {\n            'a': {'1': ('q1', ('1', '1'))},  # push '1' to stack\n            'b': {'1': ('q2', '')}  # pop from stack\n        },\n        'q2': {\n            'b': {'1': ('q2', '')},  # pop from stack\n            '': {'0': ('q3', ('0',))}  # no change to stack\n        }\n    },\n    initial_state='q0',\n    initial_stack_symbol='0',\n    final_states={'q3'},\n    acceptance_mode='final_state'\n)\n
"},{"location":"api/pda/class-dpda/#automata.pda.dpda.DPDA.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Return a generator that yields the configuration of this DPDA at each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[PDAConfiguration, None, None]

A generator that yields the current configuration of the DPDA after each step of reading input.

Raises:

Type Description RejectionException

Raised if this DPDA does not accept the input string.

"},{"location":"api/pda/class-npda/","title":"class NPDA(PDA)","text":"

Classes and methods for working with nondeterministic pushdown automata.

"},{"location":"api/pda/class-npda/#automata.pda.npda.NPDA","title":"NPDA","text":"

Bases: PDA

The NPDA class is a subclass of PDA and represents a nondeterministic pushdown automaton.

Parameters:

Name Type Description Default states AbstractSet[NPDAStateT]

A set of the NPDA's valid states

required input_symbols AbstractSet[str]

Set of the NPDA's valid input symbols, each of which is a singleton string.

required stack_symbols AbstractSet[str]

Set of the NPDA's valid stack symbols, each of which is a singleton string.

required transitions NPDATransitionsT

A dict consisting of the transitions for each state; see the example below for the exact syntax

required initial_state NPDAStateT

The name of the initial state for this NPDA.

required initial_stack_symbol str

The name of the initial symbol on the stack for this NPDA.

required final_states AbstractSet[NPDAStateT]

A set of final states for this NPDA.

required acceptance_mode PDAAcceptanceModeT

A string defining whether this NPDA accepts by 'final_state', 'empty_stack', or 'both'.

'both'"},{"location":"api/pda/class-npda/#automata.pda.npda.NPDA--example","title":"Example","text":"
from automata.pda.npda import NPDA\n# NPDA which matches palindromes consisting of 'a's and 'b's\n# (accepting by final state)\n# q0 reads the first half of the word, q1 the other half, q2 accepts.\n# But we have to guess when to switch.\nnpda = NPDA(\n    states={'q0', 'q1', 'q2'},\n    input_symbols={'a', 'b'},\n    stack_symbols={'A', 'B', '#'},\n    transitions={\n        'q0': {\n            '': {\n                '#': {('q2', '#')},  # no change to stack\n            },\n            'a': {\n                '#': {('q0', ('A', '#'))},  # push 'A' to stack\n                'A': {\n                    ('q0', ('A', 'A')),  # push 'A' to stack\n                    ('q1', ''),  # pop from stack\n                },\n                'B': {('q0', ('A', 'B'))},  # push 'A' to stack\n            },\n            'b': {\n                '#': {('q0', ('B', '#'))},  # push 'B' to stack\n                'A': {('q0', ('B', 'A'))},  # push 'B' to stack\n                'B': {\n                    ('q0', ('B', 'B')),  # push 'B' to stack\n                    ('q1', ''),  # pop from stack\n                },\n            },\n        },\n        'q1': {\n            '': {'#': {('q2', '#')}},  # push '#' to (currently empty) stack\n            'a': {'A': {('q1', '')}},  # pop from stack\n            'b': {'B': {('q1', '')}},  # pop from stack\n        },\n    },\n    initial_state='q0',\n    initial_stack_symbol='#',\n    final_states={'q2'},\n    acceptance_mode='final_state'\n)\n
"},{"location":"api/pda/class-npda/#automata.pda.npda.NPDA.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Return a generator that yields the configuration of this NPDA at each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[Set[PDAConfiguration], None, None]

A generator that yields the current configuration of the NPDA after each step of reading input.

Raises:

Type Description RejectionException

Raised if this NPDA does not accept the input string.

"},{"location":"api/pda/class-pda/","title":"class PDA(Automaton, metaclass=ABCMeta)","text":"

Classes and methods for working with all pushdown automata.

"},{"location":"api/pda/class-pda/#automata.pda.pda.PDA","title":"PDA","text":"

Bases: Automaton

An abstract base class for pushdown automata.

"},{"location":"api/pda/class-pda/#automata.pda.pda.PDA.iter_transitions","title":"iter_transitions() abstractmethod","text":"

Iterate over all transitions in the automaton. Each transition is a tuple of the form (from_state, to_state, (input_symbol, stack_top_symbol, stack_push_symbols))

"},{"location":"api/pda/class-pda/#automata.pda.pda.PDA.show_diagram","title":"show_diagram(input_str=None, with_machine=True, with_stack=True, path=None, *, layout_method='dot', horizontal=True, reverse_orientation=False, fig_size=None, font_size=14.0, arrow_size=0.85, state_separation=0.5)","text":"

Generates the graph associated with the given PDA. Args: - input_str (str, optional): String list of input symbols. Defaults to None. - with_machine (bool, optional): Constructs the diagram with states and transitions. Ignored if input_str is None. Default to True. - with_stack (bool, optional): Constructs the diagram with stack and its operations. Ignored if input_str is None. Default to True. - path (str or os.PathLike, optional): Path to output file. If None, the output will not be saved. - horizontal (bool, optional): Direction of node layout. Defaults to True. - reverse_orientation (bool, optional): Reverse direction of node layout. Defaults to False. - fig_size (tuple, optional): Figure size. Defaults to None. - font_size (float, optional): Font size. Defaults to 14.0. - arrow_size (float, optional): Arrow head size. Defaults to 0.85. - state_separation (float, optional): Node distance. Defaults to 0.5. Returns: AGraph corresponding to the given automaton.

"},{"location":"api/pda/class-pda/#automata.pda.pda.PDA.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this PDA has invalid states in the transition dictionary.

MissingStateError

If this PDA has states missing from the transition dictionary.

InvalidSymbolError

If this PDA has invalid symbols in the transition dictionary.

InvalidAcceptanceModeError

If this PDA has an invalid acceptance mode.

"},{"location":"api/tm/class-dtm/","title":"class DTM(TM)","text":"

Classes and methods for working with deterministic Turing machines.

"},{"location":"api/tm/class-dtm/#automata.tm.dtm.DTM","title":"DTM","text":"

Bases: TM

The DTM class is a subclass of TM and represents a deterministic Turing machine.

Parameters:

Name Type Description Default states AbstractSet[DTMStateT]

A set of the DTM's valid states.

required input_symbols AbstractSet[str]

Set of the DTM's valid input symbols, each of which is a singleton string.

required tape_symbols AbstractSet[str]

Set of the DTM's valid tape symbols, each of which is a singleton string.

required transitions DTMTransitionsT

Dict consisting of the transitions for each state; each key is a state name, and each value is a dict which maps a symbol (the key) to a tuple consisting of the next state, the symbol to write on the tape, and the direction to move the tape head.

required initial_state DTMStateT

The name of the initial state for this DTM.

required blank_symbol str

A symbol from tape_symbols to be used as the blank symbol for this DTM.

required final_states AbstractSet[DTMStateT]

A set of final states for this DTM.

required"},{"location":"api/tm/class-dtm/#automata.tm.dtm.DTM--example","title":"Example","text":"
from automata.tm.dtm import DTM\n# DTM which matches all strings beginning with '0's, and followed by\n# the same number of '1's\ndtm = DTM(\n    states={'q0', 'q1', 'q2', 'q3', 'q4'},\n    input_symbols={'0', '1'},\n    tape_symbols={'0', '1', 'x', 'y', '.'},\n    transitions={\n        'q0': {\n            '0': ('q1', 'x', 'R'),\n            'y': ('q3', 'y', 'R')\n        },\n        'q1': {\n            '0': ('q1', '0', 'R'),\n            '1': ('q2', 'y', 'L'),\n            'y': ('q1', 'y', 'R')\n        },\n        'q2': {\n            '0': ('q2', '0', 'L'),\n            'x': ('q0', 'x', 'R'),\n            'y': ('q2', 'y', 'L')\n        },\n        'q3': {\n            'y': ('q3', 'y', 'R'),\n            '.': ('q4', '.', 'R')\n        }\n    },\n    initial_state='q0',\n    blank_symbol='.',\n    final_states={'q4'}\n)\n
"},{"location":"api/tm/class-dtm/#automata.tm.dtm.DTM.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Return a generator that yields the configuration of this DTM at each step while reading input.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[TMConfiguration, None, None]

A generator that yields the current configuration of the DTM after each step of reading input.

"},{"location":"api/tm/class-dtm/#automata.tm.dtm.DTM.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this DTM has invalid states in the transition dictionary.

InvalidSymbolError

If this DTM has invalid symbols in the transition dictionary.

InvalidDirectionError

If this DTM has a transition with an invalid direction.

FinalStateError

If this DTM has a transition on any final states.

"},{"location":"api/tm/class-mntm/","title":"class MNTM(TM)","text":"

Classes and methods for working with multitape nondeterministic Turing machines.

"},{"location":"api/tm/class-mntm/#automata.tm.mntm.MNTM","title":"MNTM","text":"

Bases: NTM

The MNTM class is a subclass of TM and represents a multitape (non)deterministic Turing machine.

Parameters:

Name Type Description Default states AbstractSet[MNTMStateT]

A set of the MNTM's valid states.

required input_symbols AbstractSet[str]

Set of the MNTM's valid input symbols, each of which is a singleton string.

required tape_symbols AbstractSet[str]

Set of the MNTM's valid tape symbols, each of which is a singleton string.

required n_tapes int

The number of tapes in this MNTM.

required transitions MNTMTransitionsT

Dict consisting of the transitions for each state; each key is a state name, and each value is a dict which maps a symbol (the key) to a list of tuples consisting of the next state, the symbol to write on the tape, and the direction to move the tape head.

required initial_state MNTMStateT

The name of the initial state for this MNTM.

required blank_symbol str

A symbol from tape_symbols to be used as the blank symbol for this MNTM.

required final_states AbstractSet[MNTMStateT]

A set of final states for this MNTM.

required"},{"location":"api/tm/class-mntm/#automata.tm.mntm.MNTM--example","title":"Example","text":"
from automata.tm.mntm import MNTM\n# MNTM which accepts all strings in {0, 1}* and writes all\n# 1's from the first tape (input) to the second tape.\nself.mntm1 = MNTM(\n    states={'q0', 'q1'},\n    input_symbols={'0', '1'},\n    tape_symbols={'0', '1', '#'},\n    n_tapes=2,\n    transitions={\n        'q0': {\n            ('1', '#'): [('q0', (('1', 'R'), ('1', 'R')))],\n            ('0', '#'): [('q0', (('0', 'R'), ('#', 'N')))],\n            ('#', '#'): [('q1', (('#', 'N'), ('#', 'N')))],\n        }\n    },\n    initial_state='q0',\n    blank_symbol='#',\n    final_states={'q1'},\n)\n
"},{"location":"api/tm/class-mntm/#automata.tm.mntm.MNTM.read_input_as_ntm","title":"read_input_as_ntm(input_str)","text":"

Simulates this MNTM as a single-tape Turing machine. Yields the configuration at each step.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[AbstractSet[TMConfiguration], None, None]

A generator that yields the current configuration of the MNTM as a set after each step of reading input.

Raises:

Type Description RejectionException

Raised if this MNTM does not accept the input string.

"},{"location":"api/tm/class-mntm/#automata.tm.mntm.MNTM.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Checks if the given string is accepted by this MNTM machine, using a BFS of every possible configuration from each configuration. Yields the current configuration of the machine at each step.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[Set[MTMConfiguration], None, None]

A generator that yields the current configuration of the DTM after each step of reading input.

Raises:

Type Description RejectionException

Raised if this MNTM does not accept the input string.

"},{"location":"api/tm/class-mntm/#automata.tm.mntm.MNTM.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this MNTM has invalid states in the transition dictionary.

InvalidSymbolError

If this MNTM has invalid symbols in the transition dictionary.

InvalidDirectionError

If this MNTM has a transition with an invalid direction.

FinalStateError

If this MNTM has a transition on any final states.

InconsistentTapesException

If this MNTM has inconsistent tape contents.

"},{"location":"api/tm/class-ntm/","title":"class NTM(TM)","text":"

Classes and methods for working with nondeterministic Turing machines.

"},{"location":"api/tm/class-ntm/#automata.tm.ntm.NTM","title":"NTM","text":"

Bases: TM

The NTM class is a subclass of TM and represents a nondeterministic Turing machine.

Parameters:

Name Type Description Default states AbstractSet[NTMStateT]

A set of the NTM's valid states.

required input_symbols AbstractSet[str]

Set of the NTM's valid input symbols, each of which is a singleton string.

required tape_symbols AbstractSet[str]

Set of the NTM's valid tape symbols, each of which is a singleton string.

required transitions NTMTransitionsT

Dict consisting of the transitions for each state; each key is a state name, and each value is a dict which maps a symbol (the key) to a set of tuples consisting of the next state, the symbol to write on the tape, and the direction to move the tape head.

required initial_state NTMStateT

The name of the initial state for this NTM.

required blank_symbol str

A symbol from tape_symbols to be used as the blank symbol for this NTM.

required final_states AbstractSet[NTMStateT]

A set of final states for this NTM.

required"},{"location":"api/tm/class-ntm/#automata.tm.ntm.NTM--example","title":"Example","text":"
from automata.tm.ntm import NTM\n# NTM which matches all strings beginning with '0's, and followed by\n# the same number of '1's\n# Note that the nondeterminism is not really used here.\nntm = NTM(\n    states={'q0', 'q1', 'q2', 'q3', 'q4'},\n    input_symbols={'0', '1'},\n    tape_symbols={'0', '1', 'x', 'y', '.'},\n    transitions={\n        'q0': {\n            '0': {('q1', 'x', 'R')},\n            'y': {('q3', 'y', 'R')},\n        },\n        'q1': {\n            '0': {('q1', '0', 'R')},\n            '1': {('q2', 'y', 'L')},\n            'y': {('q1', 'y', 'R')},\n        },\n        'q2': {\n            '0': {('q2', '0', 'L')},\n            'x': {('q0', 'x', 'R')},\n            'y': {('q2', 'y', 'L')},\n        },\n        'q3': {\n            'y': {('q3', 'y', 'R')},\n            '.': {('q4', '.', 'R')},\n        }\n    },\n    initial_state='q0',\n    blank_symbol='.',\n    final_states={'q4'}\n)\n
"},{"location":"api/tm/class-ntm/#automata.tm.ntm.NTM.read_input_stepwise","title":"read_input_stepwise(input_str)","text":"

Check if the given string is accepted by this Turing machine.

Yield the current configurations of the machine at each step.

Parameters:

Name Type Description Default input_str str

The input string to read.

required

Yields:

Type Description Generator[Set[TMConfiguration], None, None]

A generator that yields the current configuration of the NTM after each step of reading input.

Raises:

Type Description RejectionException

Raised if this NTM does not accept the input string.

"},{"location":"api/tm/class-ntm/#automata.tm.ntm.NTM.validate","title":"validate()","text":"

Raises an exception if this automaton is not internally consistent.

Raises:

Type Description InvalidStateError

If this NTM has invalid states in the transition dictionary.

InvalidSymbolError

If this NTM has invalid symbols in the transition dictionary.

InvalidDirectionError

If this NTM has a transition with an invalid direction.

FinalStateError

If this NTM has a transition on any final states.

"},{"location":"api/tm/class-tm/","title":"class TM(Automaton, metaclass=ABCMeta)","text":"

Classes and methods for working with all Turing machines.

"},{"location":"api/tm/class-tm/#automata.tm.tm.TM","title":"TM","text":"

Bases: Automaton

An abstract base class for Turing machines.

"},{"location":"api/tm/tm-exception-classes/","title":"Turing machine exception classes","text":"

Exception classes specific to Turing machines.

"},{"location":"api/tm/tm-exception-classes/#automata.tm.exceptions.InconsistentTapesException","title":"InconsistentTapesException","text":"

Bases: TMException

The number of tapes defined for the multitape Turing machine is not consistent with the definitions of the transitions.

"},{"location":"api/tm/tm-exception-classes/#automata.tm.exceptions.InvalidDirectionError","title":"InvalidDirectionError","text":"

Bases: TMException

A direction is not a valid direction for this machine.

"},{"location":"api/tm/tm-exception-classes/#automata.tm.exceptions.MalformedExtendedTapeError","title":"MalformedExtendedTapeError","text":"

Bases: TMException

Extended tape for simulating an mntm as a ntm is not valid. Either there are 2 virtual heads for a virtual tape or the a head symbol is at the leftmost end of a virtual tape.

"},{"location":"api/tm/tm-exception-classes/#automata.tm.exceptions.TMException","title":"TMException","text":"

Bases: AutomatonException

The base class for all machine-related errors.

"},{"location":"examples/fa-examples/","title":"FA Examples","text":"

On this page, we give some short examples with discussion for the finite automata classes and methods.

"},{"location":"examples/fa-examples/#reading-basic-input","title":"Reading basic input","text":"

The following code snippet creates a DFA and prints whether it accepts or rejects user input.

from automata.fa.dfa import DFA\n# DFA which matches all binary strings ending in an odd number of '1's\nmy_dfa = DFA(\nstates={'q0', 'q1', 'q2'},\ninput_symbols={'0', '1'},\ntransitions={\n'q0': {'0': 'q0', '1': 'q1'},\n'q1': {'0': 'q0', '1': 'q2'},\n'q2': {'0': 'q2', '1': 'q1'}\n},\ninitial_state='q0',\nfinal_states={'q1'}\n)\ntry:\nwhile True:\nif my_dfa.accepts_input(input('Please enter your input: ')):\nprint('Accepted')\nelse:\nprint('Rejected')\nexcept KeyboardInterrupt:\nprint('')\n
"},{"location":"examples/fa-examples/#subset-for-nfas","title":"Subset for NFAs","text":"

The NFA does not have a built-in method for checking whether it is a subset of another NFA. However, this can be done using existing methods.

# In the following, we have nfa1 and nfa2 and want to determine whether\n# nfa1 is a subset of nfa2.\n# If taking the union of nfa2 with nfa1 is equal to nfa2 again,\n# nfa1 didn't accept any strings that nfa2 did not, so it is a subset.\nif (nfa1 | nfa2) == nfa2:\nprint('nfa1 is a subset of nfa2.')\nelse:\nprint('nfa1 is not a subset of nfa2.')\n
"},{"location":"examples/fa-examples/#edit-distance-automaton","title":"Edit distance automaton","text":"

The following example is inspired by this blog post. Essentially, we want to determine which strings in a given set are within the target edit distance to a reference string.

from automata.fa.dfa import DFA\nfrom automata.fa.nfa import NFA\nimport string\ninput_symbols = set(string.ascii_lowercase)\n# Construct DFA recognizing target words\ntarget_words = {'these', 'are', 'target', 'words', 'them', 'those'}\ntarget_words_dfa = DFA.from_finite_language(\ninput_symbols,\ntarget_words,\n)\n# Next, construct NFA recognizing all strings\n# within given edit distance of target word\nreference_string = 'they'\nedit_distance = 2\nwords_within_edit_distance_dfa = DFA.from_nfa(\nNFA.edit_distance(\ninput_symbols,\nreference_string,\nedit_distance,\n)\n)\n# Take intersection and print results\nfound_words_dfa = target_words_dfa & words_within_edit_distance_dfa\nfound_words = list(found_words_dfa)\nprint(\nf\"All words within edit distance {edit_distance} of \"\nf\"'{reference_string}': {found_words}\"\n)\n
"},{"location":"examples/fa-examples/#making-a-transition-table","title":"Making a transition table","text":"

The example below is adapted from the visual automata library. This function takes in a DFA or NFA and returns the corresponding transition table.

The start state is prefixed with \u2192 and final states are prefixed with *.

import pandas as pd\ndef make_table(target_fa) -> pd.DataFrame:\ninitial_state = target_fa.initial_state\nfinal_states = target_fa.final_states\ntable = {}\nfor from_state, to_state, symbol in target_fa.iter_transitions():\n# Prepare nice string for from_state\nif isinstance(from_state, frozenset):\nfrom_state_str = str(set(from_state))\nelse:\nfrom_state_str = str(from_state)\nif from_state in final_states:\nfrom_state_str = \"*\" + from_state_str\nif from_state == initial_state:\nfrom_state_str = \"\u2192\" + from_state_str\n# Prepare nice string for to_state\nif isinstance(to_state, frozenset):\nto_state_str = str(set(to_state))\nelse:\nto_state_str = str(to_state)\nif to_state in final_states:\nto_state_str = \"*\" + to_state_str\n# Prepare nice symbol\nif symbol == \"\":\nsymbol = \"\u03bb\"\nfrom_state_dict = table.setdefault(from_state_str, dict())\nfrom_state_dict.setdefault(symbol, set()).add(to_state_str)\n# Reformat table for singleton sets\nfor symbol_dict in table.values():\nfor symbol in symbol_dict:\nif len(symbol_dict[symbol]) == 1:\nsymbol_dict[symbol] = symbol_dict[symbol].pop()\ndf = pd.DataFrame.from_dict(table).fillna(\"\u2205\").T\nreturn df.reindex(sorted(df.columns), axis=1)\n
"}]} \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 00000000..cd2b7189 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,108 @@ + + + + https://automata.site.to.be.created.org/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/characteristics/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/migration/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/people/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/base-exception-classes/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/class-automaton/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/regular-expressions/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/fa/class-dfa/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/fa/class-fa/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/fa/class-gnfa/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/fa/class-nfa/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/pda/class-dpda/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/pda/class-npda/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/pda/class-pda/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/tm/class-dtm/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/tm/class-mntm/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/tm/class-ntm/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/tm/class-tm/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/api/tm/tm-exception-classes/ + 2023-12-31 + daily + + + https://automata.site.to.be.created.org/examples/fa-examples/ + 2023-12-31 + daily + + \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz new file mode 100644 index 0000000000000000000000000000000000000000..33262f87b87a36a91d64c03e15b7c687cbb6bee2 GIT binary patch literal 352 zcmV-m0iXUKiwFq%^N?i%|8r?{Wo=<_E_iKh0M*ycZi6rk0N{I{0&x%N&t;n^z3mCM z2XKQ+BaxrR>Ds;h9LlQRr%81#n8;Y4f(1#tySlOZ!bCRsZM|xib%ox9-uhu%e}25H zmwMMN+H)ESbH&M?w)HXR_@?#ca%sqBbP%ZtY0zYjd_#Jk)XV0z?iLk~Qs5R%qaB0k zN)_TVaL&O&hN)JQL$k-mB!rCpRJGM5`|)9*>_XqIm+OsMt<`45Df8SznmK|W@R0D- z^*x4aL<~RQQ)QBOD`20?YRt9npgbJ?)V`%_o z*h5G%>=RbanG(9Upc4+~5fZO?Oi1NBD`d3~FfVw|ku0$|@ZiOf#fW2nZ{!jRGkbw% yG34xiJA)%xV&}z?<%tD>vy-^1!z(!6-xL2<)II)p^>pF$Z1)4E)AOVM4gdfM5V$7* literal 0 HcmV?d00001