Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ brute-force reference or a closed-form value and has a regression test.
(new module `sofic.shifts.canonical_presentations`) present a sofic shift by the canonical NFAs of its factor
language, trimmed to the essential states.

### Distromaton, xor automata, and the universal automaton

- New module `sofic.automata.canonical.closures` completes the canonical NFAs of Myers, Adámek, Milius & Urbat
(CMCS 2014) and Zetzsche, van Heerdt, Sammartino & Silva (MFPS 2021): `Distromaton` (join-irreducible
intersections of residuals), `minimal_xor_automaton`, `xor_caba_automaton` (the new acceptor of Zetzsche et al.,
on a basis of the Boolean closure read as a GF(2) space), `UniversalAutomaton` (Lombardy & Sakarovitch),
`minimal_structured_dfa` (the minimal DFA whose states form a semilattice, distributive lattice, Boolean algebra
or GF(2) space), and `is_intersection_closed` (Myers et al.'s criterion for the canonical RFSA to be a
state-minimal NFA). Every closure element is stored exactly as a set of atoms, i.e. of states of the minimal
DFA of the reversed language, so derivatives are preimages and all constructions are exact.
- New `sofic.automata.xor.XorAutomaton`: NFA-shaped automata that accept by parity of accepting paths, with the xor
subset construction (`determinize`), `reverse` and serialization. It is not a `LabeledAutomaton`, whose language
operations assume NFA acceptance.
- Tests reproduce the papers' examples ((a+b)\*a and (a+b)\*b(a+b)^n), check the distromaton against Myers et al.'s
second construction (the reverse minimal DFA ordered by inclusion), the minimal xor automaton's size against the
GF(2) rank of a brute-force Hankel matrix, and Corollaries 3.21 and 4.6. Two corrections to the papers: the
xor-CABA example of Zetzsche et al. (Fig. 10) uses four linearly dependent vectors where a basis has three, and
Myers et al.'s remark that {aa} is not intersection-closed contradicts their Example 4.3 (singletons are).
- Shifts: `distromaton_presentation`, `universal_presentation` (also `SoficShift` methods), and
`follower_sets_intersection_closed`, which certifies that `canonical_rfsa_presentation` has the fewest states of
any presentation (brute-force checked against every smaller labeled graph). Canonical presentations now trim the
automaton before building the graph, which the new automata need (their `Σ*` and `∅` states) and which leaves
the existing presentations unchanged.
- Generators: `canonical_rfsa_hmm` and `maximized_prime_atomaton_hmm` are now documented as size-minimal among
generators whose state morphs are mixtures of causal-state morphs, the stochastic counterpart of the canonical
RFSA's minimality, with proof; the minimal xor automaton is cross-referenced as the GF(2) counterpart of
`minimal_quasi_realization`.

### Generator verification

- `GenerativeModelResult` records the returned generator's word-process deviation from the source
Expand Down
1 change: 1 addition & 0 deletions docs/automata/automata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Canonical structures

rfsa
atomaton
canonical_closures
observation_table
learning
wheeler
Expand Down
114 changes: 114 additions & 0 deletions docs/automata/canonical_closures.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
.. canonical_closures.rst
.. py:module:: sofic.automata.canonical.closures

**************************************************
Distromaton, xor automata, and universal automaton
**************************************************

A regular language has no unique state-minimal NFA, but it has several *canonical* ones. Myers, Adámek, Milius and
Urbat :cite:`Myers2014,Myers2015` obtain them all by one recipe: close the residuals :math:`u^{-1}L` under the
operations of an algebraic variety, which gives the minimal deterministic automaton of :math:`L` whose states form
an algebra of that variety (:func:`minimal_structured_dfa`), and take a minimal set of generators of that algebra
as the states of an NFA. Zetzsche, van Heerdt, Sammartino and Silva :cite:`Zetzsche2021` recast the second step as
generators for algebras over a monad and let the algebra of the deterministic automaton differ from the side effect
of the succinct one through distributive law homomorphisms, which brings in the átomaton and a new acceptor, the
minimal xor-CABA automaton.

========================== ========================== ====================== ===========================================
algebra of the DFA closure of the residuals states of the NFA canonical automaton
========================== ========================== ====================== ===========================================
join-semilattice unions join-irreducibles canonical RFSA (*jiromaton*), :doc:`rfsa`
distributive lattice unions, intersections join-irreducibles :class:`Distromaton`
Boolean algebra Boolean operations atoms átomaton, :doc:`atomaton`
GF(2) vector space symmetric difference a basis :func:`minimal_xor_automaton`
Boolean algebra as GF(2) Boolean operations a basis :func:`xor_caba_automaton`
========================== ========================== ====================== ===========================================

The universal automaton :cite:`LombardySakarovitch2008` (:class:`UniversalAutomaton`) keeps *every* intersection
of residuals; the distromaton is its subautomaton on the join-irreducible ones.

All constructions here are exact. Every language in these closures is a union of atoms of :math:`L`, and the atoms
are the states of the minimal complete DFA :math:`D` of :math:`L^R` :cite:`BrzozowskiTamm2014`, so a language is
stored as a set of states of :math:`D`: the residual :math:`u^{-1}L` is :math:`\{q : \delta(q, u^R) \in F\}`, the
derivative :math:`a^{-1}K` is the preimage :math:`\{q : \delta(q, a) \in K\}`, :math:`\varepsilon \in K` iff the
start state is in :math:`K`, and the lattice and vector-space operations are set operations.

Distromaton
===========

The distromaton's states are the intersections of residuals that are not unions of smaller intersections; a state
:math:`K` is initial iff :math:`K \subseteq L`, accepting iff :math:`\varepsilon \in K`, and
:math:`K \xrightarrow{a} K'` iff :math:`K' \subseteq a^{-1}K` :cite:`Myers2014`. There is one state per atom
(the intersection of the residuals containing it), so the distromaton and the átomaton have the same number of
states once the átomaton counts the negative atom (:cite:`Myers2014`, Corollary 3.21). Their transition structures
differ: the distromaton is the reverse of the minimal DFA of :math:`L^R` *ordered by inclusion*, with
:math:`z \xrightarrow{a} z'` whenever :math:`\delta(z', a)` includes :math:`z`, where the átomaton requires
equality.

Xor automata
============

A :class:`~sofic.automata.xor.XorAutomaton` is shaped like an NFA but accepts a word when it labels an odd number of
accepting paths :cite:`VuilleminGama2010`; it is a weighted automaton over GF(2), and
:meth:`~sofic.automata.xor.XorAutomaton.determinize` is the xor subset construction. The minimal xor automaton has
a basis of the span of the residuals as states. It is minimal among all xor automata and never larger than the
minimal DFA, but canonical only up to the basis; :func:`minimal_xor_automaton` picks the residuals greedily in
shortlex order of their access words. It is the GF(2) instance of the minimal linear representation that
:func:`~sofic.generators.minimal_quasi_realization.minimal_quasi_realization` computes over the reals.

The minimal xor-CABA automaton :cite:`Zetzsche2021` uses a basis of the whole Boolean closure, read as a GF(2)
space, so it has one state per atom. With ``basis="residuals"`` the basis extends that of the minimal xor
automaton, which is then its accessible part; with ``basis="atoms"`` it is the átomaton plus the negative atom,
because the átomaton is co-deterministic with one accepting state and so has at most one accepting path per word.

Minimality and state-minimal NFAs
=================================

Each canonical automaton is size-minimal in a class of acceptors (:cite:`Myers2014`, Section 4;
:cite:`Zetzsche2021`, Section 6):

======================== ===========================================================================
automaton has the fewest states among
======================== ===========================================================================
canonical RFSA NFAs whose states accept unions of residuals
átomaton NFAs whose accepted languages (over all initial sets) are closed under complement
distromaton NFAs whose accepted languages are closed under intersection
minimal xor automaton all xor automata
minimal xor-CABA xor automata whose accepted languages have equal GF(2) and Boolean closures
======================== ===========================================================================

When :func:`is_intersection_closed` holds -- every intersection of two residuals is a union of residuals -- the
canonical RFSA is a state-minimal NFA outright, and the distromaton and átomaton have at most one more state
(:cite:`Myers2014`, Theorem 4.4 and Corollary 4.6). For sofic shifts this certifies that the canonical RFSA
presentation is a smallest presentation
(:func:`~sofic.shifts.canonical_presentations.follower_sets_intersection_closed`).

.. code-block:: python

from sofic.automata.canonical.closures import (
Distromaton, minimal_xor_automaton, xor_caba_automaton, is_intersection_closed, minimal_structured_dfa,
)

Distromaton.from_language(nfa)
xor = minimal_xor_automaton(nfa) # an XorAutomaton
xor.recognizes(word) # odd number of accepting paths
xor.determinize() # DFA of the same language
minimal_structured_dfa(nfa, "lattice") # the distributive-lattice DFA the distromaton is read from
is_intersection_closed(nfa) # then the canonical RFSA is a state-minimal NFA

API
===

.. autoclass:: Distromaton
:members: from_language
.. autofunction:: distromaton_from_language
.. autoclass:: UniversalAutomaton
:members: from_language
.. autofunction:: universal_automaton_from_language
.. autofunction:: minimal_xor_automaton
.. autofunction:: xor_caba_automaton
.. autofunction:: minimal_structured_dfa
.. autofunction:: is_intersection_closed

.. autoclass:: sofic.automata.xor.XorAutomaton
:members: from_language, recognizes, run, step, determinize, minimize, reverse
6 changes: 5 additions & 1 deletion docs/automata/rfsa.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ states the primes containing the empty word, and a transition
:math:`p \xrightarrow{a} p'` whenever :math:`L_{p'} \subseteq a^{-1} L_p`
:cite:`Denis2002`. It is never larger than the minimal DFA and can be
exponentially smaller: for :math:`\Sigma^* a \Sigma^n` the minimal DFA has
:math:`2^{n+1}` states and the canonical RFSA :math:`n + 2`.
:math:`2^{n+1}` states and the canonical RFSA :math:`n + 2`. Myers et al. call it
the *jiromaton* :cite:`Myers2014`: its states are the join-irreducibles of the
semilattice of unions of residuals, and it has the fewest states among NFAs whose
states accept unions of residuals. The other canonical NFAs of that construction
are in :doc:`canonical_closures`.

Reversing a canonical RFSA gives the maximized prime átomaton of the reversed
language (:meth:`CanonicalRFSA.dual`; see :doc:`atomaton`). NL\* learns the
Expand Down
24 changes: 24 additions & 0 deletions docs/generators/canonical_generators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ known.

The topological counterparts for sofic shifts are in :mod:`sofic.shifts.canonical_presentations`.

Minimality within a class
-------------------------

The canonical RFSA is size-minimal among NFAs whose states accept unions of residuals (:cite:`Myers2014`,
Corollary 4.11; :cite:`Zetzsche2021`, Corollary 34). The analogue, with mixtures in place of unions, holds for
:func:`canonical_rfsa_hmm`: a generator of the process in which the future morph
:math:`h_g(w) = \Pr(w \mid G_0 = g)` of every state of positive stationary probability is a mixture of
causal-state morphs has at least as many states as :func:`canonical_rfsa_hmm`. By the Markov property

.. math::

\Pr(\cdot \mid \text{past}) = \sum_g \Pr(G_0 = g \mid \text{past}) \, h_g,

so every causal-state morph lies in :math:`\operatorname{conv}\{h_g\}`. The hypothesis gives the reverse
inclusion, so the two polytopes coincide and each vertex is one of the :math:`h_g`; :func:`canonical_rfsa_hmm`
has one state per vertex and belongs to the class. Reversing time gives the same statement for
:func:`maximized_prime_atomaton_hmm`, with past morphs and reverse causal states. Generators outside the class can
be smaller. The argument is not from the literature.

The other canonical NFAs of :doc:`/automata/canonical_closures` have no analogue here: the distromaton and the
universal automaton are built from intersections of residuals, and mixtures of morphs have no meet. The minimal
xor automaton is a minimal linear representation over GF(2); its counterpart over the reals is
:func:`~sofic.generators.minimal_quasi_realization.minimal_quasi_realization`.

.. autofunction:: canonical_rfsa_hmm
.. autofunction:: maximized_prime_atomaton_hmm
.. autofunction:: atomaton_hmm
4 changes: 3 additions & 1 deletion docs/generators/minimal_quasi_realization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ over all pairs of words :math:`u, v`, and is the dimension of Upper's
generalized-state space :cite:`Upper1997`. It is a lower bound on the number of
states of every HMM presentation of the process, including the ε-machine, and
can be strictly smaller than all of them: the minimal representation is in
general only a quasi-realization with signed entries.
general only a quasi-realization with signed entries. The same minimization over
the two-element field instead of the reals gives the minimal xor automaton of a
regular language (:func:`~sofic.automata.canonical.closures.minimal_xor_automaton`).

:func:`minimal_quasi_realization` grows bases :math:`R` (rows) and :math:`O`
(columns) of the reachable and observable spaces breadth-first over words,
Expand Down
46 changes: 46 additions & 0 deletions docs/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -1797,3 +1797,49 @@ @article{Myers2015
year = {2015},
doi = {10.1016/j.tcs.2015.03.035},
}

@inproceedings{Myers2014,
author = {Myers, Robert S. R. and Ad{\'a}mek, Ji{\v r}{\'\i} and Milius, Stefan and Urbat, Henning},
title = {Canonical Nondeterministic Automata},
booktitle = {Coalgebraic Methods in Computer Science (CMCS 2014)},
editor = {Bonsangue, Marcello M.},
series = {Lecture Notes in Computer Science},
volume = {8446},
pages = {189--210},
publisher = {Springer},
year = {2014},
doi = {10.1007/978-3-662-44124-4_11},
}

@inproceedings{Zetzsche2021,
author = {Zetzsche, Stefan and van Heerdt, Gerco and Sammartino, Matteo and Silva, Alexandra},
title = {Canonical Automata via Distributive Law Homomorphisms},
booktitle = {Proceedings of the 37th Conference on Mathematical Foundations of Programming Semantics (MFPS 2021)},
editor = {Sokolova, Ana},
series = {Electronic Proceedings in Theoretical Computer Science},
volume = {351},
pages = {296--313},
year = {2021},
doi = {10.4204/EPTCS.351.18},
}

@techreport{VuilleminGama2010,
author = {Vuillemin, Jean and Gama, Nicolas},
title = {Efficient Equivalence and Minimization for Non Deterministic Xor Automata},
institution = {LIENS, {\'E}cole Normale Sup{\'e}rieure},
type = {Research report},
year = {2010},
url = {https://hal.inria.fr/inria-00487031},
}

@incollection{LombardySakarovitch2008,
author = {Lombardy, Sylvain and Sakarovitch, Jacques},
title = {The Universal Automaton},
booktitle = {Logic and Automata: History and Perspectives},
editor = {Flum, J{\"o}rg and Gr{\"a}del, Erich and Wilke, Thomas},
series = {Texts in Logic and Games},
volume = {2},
pages = {457--504},
publisher = {Amsterdam University Press},
year = {2008},
}
24 changes: 19 additions & 5 deletions docs/shifts/canonical_presentations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,37 @@ Canonical NFA presentations
.. currentmodule:: sofic.shifts.canonical_presentations

A sofic shift is determined by its factor language, which is factorial and extendable :cite:`LindMarcus1995`.
Any automaton for that language with every state accepting presents the shift once trimmed to the states on
bi-infinite paths, so the canonical NFAs of the factor language -- the átomaton :cite:`BrzozowskiTamm2014`, the
canonical residual finite-state automaton :cite:`Denis2002` and the maximized prime átomaton
:cite:`MaarandTamm2022` -- give canonical, generally non-resolving presentations beside the Fischer and Krieger
covers. The residual-side states are follower sets that are not unions of other follower sets.
Any automaton for that language presents the shift once trimmed and restricted to the states on bi-infinite paths,
so the canonical NFAs of the factor language -- the átomaton :cite:`BrzozowskiTamm2014`, the canonical residual
finite-state automaton :cite:`Denis2002`, the maximized prime átomaton :cite:`MaarandTamm2022`, the distromaton
:cite:`Myers2014` and the universal automaton :cite:`LombardySakarovitch2008` -- give canonical, generally
non-resolving presentations beside the Fischer and Krieger covers. The residual-side states are follower sets that
are not unions of other follower sets; the distromaton's are intersections of follower sets that are not unions of
smaller intersections. The minimal xor automaton has no counterpart, since it accepts by parity of paths.

When every intersection of two follower sets is a union of follower sets
(:func:`follower_sets_intersection_closed`), the canonical RFSA of the factor language is a state-minimal NFA
(:cite:`Myers2014`, Theorem 4.4). A smallest presentation is essential, and an essential presentation is an NFA for
the factor language with every state initial and accepting, so the canonical RFSA presentation is then a
presentation with the fewest states. The golden mean shift is an example.

.. code-block:: python

shift = machine.to_sofic_shift()
shift.canonical_rfsa_presentation()
shift.maximized_prime_atomaton_presentation()
shift.atomaton_presentation()
shift.distromaton_presentation()
shift.universal_presentation()
follower_sets_intersection_closed(shift) # then canonical_rfsa_presentation is smallest

The stochastic analogues, which replace unions of residuals by mixtures of future morphs, are in
:mod:`sofic.generators.canonical_generators`.

.. autofunction:: canonical_rfsa_presentation
.. autofunction:: maximized_prime_atomaton_presentation
.. autofunction:: atomaton_presentation
.. autofunction:: distromaton_presentation
.. autofunction:: universal_presentation
.. autofunction:: follower_sets_intersection_closed
.. autofunction:: factor_language_nfa
5 changes: 5 additions & 0 deletions sofic/automata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sofic.automata.base import LabeledAutomaton
from sofic.automata.buchi import BuchiAutomaton
from sofic.automata.canonical.atomaton import Atomaton, AtomicAutomaton, MaximizedPrimeAtomaton
from sofic.automata.canonical.closures import Distromaton, UniversalAutomaton
from sofic.automata.canonical.rfsa import CanonicalRFSA, ResidualFiniteStateAutomaton
from sofic.automata.dfa import DFA
from sofic.automata.enumeration.icdfa import (
Expand Down Expand Up @@ -117,6 +118,7 @@
wheeler_state_index,
)
from sofic.automata.wheeler_index import WheelerIndex, wheeler_index
from sofic.automata.xor import XorAutomaton

__all__ = [
"Atomaton",
Expand All @@ -140,6 +142,7 @@
"CanonicalRFSA",
"DFA",
"DeterministicVisiblyPushdownAutomaton",
"Distromaton",
"DyckAlphabet",
"ERROR_STATE",
"ERROR_SYMBOL",
Expand All @@ -162,11 +165,13 @@
"SubsequentialTransducer",
"Transducer",
"UnifilarAutomaton",
"UniversalAutomaton",
"WeightedFiniteStateTransducer",
"WheelerError",
"WheelerIndex",
"WheelerOrder",
"VisiblyPushdownAutomaton",
"XorAutomaton",
"automaton_to_regex",
"colex_width",
"generator_product",
Expand Down
Loading
Loading