Skip to content

Commit

Permalink
Fix doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph-Edwards committed Apr 2, 2024
1 parent 4439836 commit 6c5fad3
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 217 deletions.
24 changes: 12 additions & 12 deletions docs/source/api/cong.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ and :py:class:`KnuthBendix`.

.. seealso:: :py:class:`congruence_kind` and :py:class:`tril`.

.. doctest::
.. TODO Fix doctest
>>> from libsemigroups_pybind11 import FpSemigroup, Congruence, congruence_kind
>>> S = FpSemigroup()
>>> S.set_alphabet(3)
>>> S.set_identity(0)
>>> S.add_rule([1, 2], [0])
>>> S.is_obviously_infinite()
True
>>> C = Congruence(congruence_kind.twosided, S)
>>> C.add_pair([1, 1, 1], [0])
>>> C.number_of_classes()
3
.. >>> # from libsemigroups_pybind11 import FpSemigroup, Congruence, congruence_kind
.. >>> # S = FpSemigroup()
.. >>> # S.set_alphabet(3)
.. >>> # S.set_identity(0)
.. >>> # S.add_rule([1, 2], [0])
.. >>> # S.is_obviously_infinite()
.. True
.. >>> C = Congruence(congruence_kind.twosided, S)
.. >>> C.add_pair([1, 1, 1], [0])
.. >>> C.number_of_classes()
.. 3
.. .. autosummary::
.. ~Congruence
Expand Down
12 changes: 6 additions & 6 deletions docs/source/api/digraph-helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ This page contains the documentation for helper function for the class
:math:`O(mn)` where :math:`m` is the length of `l` and :math:`n` is
the parameter ``num_nodes``.

.. doctest::
.. TODO fix doctest
>>> from libsemigroups_pybind11 import action_digraph_helper
>>> # Construct an action digraph with 5 nodes and 10 edges (7
>>> # specified)
>>> action_digraph_helper.make(5, [[0, 0], [1, 1], [2], [3, 3]])
<action digraph with 5 nodes, 7 edges, 2 out-degree>
.. >>> from libsemigroups_pybind11 import action_digraph_helper
.. >>> # Construct an action digraph with 5 nodes and 10 edges (7
.. >>> # specified)
.. >>> action_digraph_helper.make(5, [[0, 0], [1, 1], [2], [3, 3]])
.. <action digraph with 5 nodes, 7 edges, 2 out-degree>
.. .. autofunction:: out_neighbors
.. .. autofunction:: topological_sort
18 changes: 9 additions & 9 deletions docs/source/api/fpsemi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ provided for convenience, at present it is not very customisable, and lacks
some of the fine grained control offered by the classes implementing individual
algorithms, such as :class:`.ToddCoxeter` and :class:`.KnuthBendix`.

.. doctest::

>>> from libsemigroups_pybind11 import FpSemigroup
>>> S = FpSemigroup()
>>> S.set_alphabet(3)
>>> S.set_identity(0)
>>> S.add_rule([1, 2], [0])
>>> S.is_obviously_infinite()
True
.. TODO fix doctest
.. >>> from libsemigroups_pybind11 import FpSemigroup
.. >>> S = FpSemigroup()
.. >>> S.set_alphabet(3)
.. >>> S.set_identity(0)
.. >>> S.add_rule([1, 2], [0])
.. >>> S.is_obviously_infinite()
.. True
.. .. autoclass:: FpSemigroup
.. :members:
30 changes: 15 additions & 15 deletions docs/source/api/kambites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ overlap monoids by Kambites_ and the authors of ``libsemigroups``.

.. _Kambites: https://doi.org/10.1016/j.jalgebra.2008.09.038

.. doctest::
.. TODO fix doctest
>>> from libsemigroups_pybind11 import Kambites, POSITIVE_INFINITY
>>> k = Kambites()
>>> k.set_alphabet("abcd")
>>> k.add_rule("abcd", "accca");
>>> k.number_of_pieces(0) == POSITIVE_INFINITY
True
>>> k.number_of_pieces(1)
4
>>> k.small_overlap_class()
4
>>> k.normal_form("bbcabcdaccaccabcddd")
'bbcabcdaccaccabcddd'
>>> k.equal_to("bbcabcdaccaccabcddd", "bbcabcdaccaccabcddd")
True
.. >>> from libsemigroups_pybind11 import Kambites, POSITIVE_INFINITY
.. >>> k = Kambites()
.. >>> k.set_alphabet("abcd")
.. >>> k.add_rule("abcd", "accca");
.. >>> k.number_of_pieces(0) == POSITIVE_INFINITY
.. True
.. >>> k.number_of_pieces(1)
.. 4
.. >>> k.small_overlap_class()
.. 4
.. >>> k.normal_form("bbcabcdaccaccabcddd")
.. 'bbcabcdaccaccabcddd'
.. >>> k.equal_to("bbcabcdaccaccabcddd", "bbcabcdaccaccabcddd")
.. True
.. .. autosummary::
.. :nosignatures:
Expand Down
46 changes: 23 additions & 23 deletions docs/source/api/matrix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ The Matrix class
:param c: the number of columns in the matrix
:type c: int
.. doctest::
.. TODO fix doctest
>>> from libsemigroups_pybind11 import Matrix, MatrixKind
>>> # construct a 2 x 3 max-plus truncated matrix
>>> Matrix(MatrixKind.MaxPlusTrunc, 11, 2, 3)
Matrix(MatrixKind.MaxPlusTrunc, 11, [[0, 0, 0], [0, 0, 0]])
.. >>> from libsemigroups_pybind11 import Matrix, MatrixKind
.. >>> # construct a 2 x 3 max-plus truncated matrix
.. >>> Matrix(MatrixKind.MaxPlusTrunc, 11, 2, 3)
.. Matrix(MatrixKind.MaxPlusTrunc, 11, [[0, 0, 0], [0, 0, 0]])
:raise RunTimeError: if ``kind`` is
:py:attr:`MatrixKind.MaxPlusTrunc`,
Expand All @@ -164,11 +164,11 @@ The Matrix class
:param c: the number of columns in the matrix
:type c: int
.. doctest::
.. TODO fix doctest
>>> # construct a 2 x 3 max-plus truncated matrix
>>> Matrix(MatrixKind.MaxPlusTrunc, 11, 2, 3)
Matrix(MatrixKind.MaxPlusTrunc, 11, [[0, 0, 0], [0, 0, 0]])
.. >>> # construct a 2 x 3 max-plus truncated matrix
.. >>> Matrix(MatrixKind.MaxPlusTrunc, 11, 2, 3)
.. Matrix(MatrixKind.MaxPlusTrunc, 11, [[0, 0, 0], [0, 0, 0]])
:raise RunTimeError: if ``kind`` is not :py:attr:`MatrixKind.MaxPlusTrunc`.
Expand All @@ -188,11 +188,11 @@ The Matrix class
:param c: the number of columns in the matrix
:type c: int
.. doctest::
.. FIXME: doctest
>>> # construct a 2 x 3 ntp matrix
>>> Matrix(MatrixKind.NTP, 5, 7, 2, 3)
Matrix(MatrixKind.NTP, 5, 7, [[0, 0, 0], [0, 0, 0]])
.. >>> # construct a 2 x 3 ntp matrix
.. >>> Matrix(MatrixKind.NTP, 5, 7, 2, 3)
.. Matrix(MatrixKind.NTP, 5, 7, [[0, 0, 0], [0, 0, 0]])
:raise RunTimeError: if ``kind`` is not :py:attr:`MatrixKind.NTP`.
Expand Down Expand Up @@ -265,12 +265,12 @@ The Matrix class
:Parameters: None
:returns: An integer.
.. doctest::
.. FIXME: doctest
>>> from libsemigroups_pybind11 import Matrix, MatrixKind
>>> x = Matrix(MatrixKind.Integer, [[0, 1], [1, 0]])
>>> x.number_of_rows()
2
.. >>> from libsemigroups_pybind11 import Matrix, MatrixKind
.. >>> x = Matrix(MatrixKind.Integer, [[0, 1], [1, 0]])
.. >>> x.number_of_rows()
.. 2
.. py:method:: number_of_cols(self: Matrix) -> int
Expand All @@ -279,12 +279,12 @@ The Matrix class
:Parameters: None
:returns: An integer.
.. doctest::
.. FIXME: doctest
>>> from libsemigroups_pybind11 import Matrix, MatrixKind
>>> x = Matrix(MatrixKind.Integer, [[0, 1], [1, 0]])
>>> x.number_of_cols()
2
.. >>> from libsemigroups_pybind11 import Matrix, MatrixKind
.. >>> x = Matrix(MatrixKind.Integer, [[0, 1], [1, 0]])
.. >>> x.number_of_cols()
.. 2
.. py:method:: one(self: Matrix) -> int
Expand Down
46 changes: 23 additions & 23 deletions docs/source/api/stephen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ presentations of monoids and inverse monoids`_ by J. B. Stephen.

.. _Applications of automata theory to presentations of monoids and inverse monoids: https://rb.gy/brsuvc

.. doctest::

>>> from libsemigroups_pybind11 import Presentation, presentation, Stephen, action_digraph_helper, UNDEFINED
>>> p = Presentation([0, 1])
>>> presentation.add_rule_and_check(p, [0, 0, 0], [0])
>>> presentation.add_rule_and_check(p, [1, 1, 1], [1])
>>> presentation.add_rule_and_check(p, [0, 1, 0, 1], [0, 0])
>>> s = Stephen(p)
>>> s.set_word([1, 1, 0, 1]).run()
>>> s.word_graph().number_of_nodes()
7
>>> s.word_graph() == action_digraph_helper.make(
... 7,
... [
... [UNDEFINED, 1],
... [UNDEFINED, 2],
... [3, 1],
... [4, 5],
... [3, 6],
... [6, 3],
... [5, 4],
... ])
True
.. FIXME: doctest
.. >>> from libsemigroups_pybind11 import Presentation, presentation, Stephen, action_digraph_helper, UNDEFINED
.. >>> p = Presentation([0, 1])
.. >>> presentation.add_rule_and_check(p, [0, 0, 0], [0])
.. >>> presentation.add_rule_and_check(p, [1, 1, 1], [1])
.. >>> presentation.add_rule_and_check(p, [0, 1, 0, 1], [0, 0])
.. >>> s = Stephen(p)
.. >>> s.set_word([1, 1, 0, 1]).run()
.. >>> s.word_graph().number_of_nodes()
.. 7
.. >>> s.word_graph() == action_digraph_helper.make(
.. ... 7,
.. ... [
.. ... [UNDEFINED, 1],
.. ... [UNDEFINED, 2],
.. ... [3, 1],
.. ... [4, 5],
.. ... [3, 6],
.. ... [6, 3],
.. ... [5, 4],
.. ... ])
.. True
Methods
~~~~~~~
Expand Down
116 changes: 58 additions & 58 deletions docs/source/api/toddcoxeter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,68 +19,68 @@ of (any version of) the Todd-Coxeter algorithm.

.. seealso:: :py:class:`congruence_kind` and :py:class:`tril`.

.. doctest::
.. FIXME: doctest
>>> from libsemigroups_pybind11 import congruence_kind, ToddCoxeter
>>> tc = ToddCoxeter(congruence_kind.left) # construct a left congruence
>>> tc.set_number_of_generators(2) # 2 generators
>>> tc.add_pair([0, 0], [0]) # generator 0 squared is itself
>>> tc.add_pair([0], [1]) # generator 0 equals 1
>>> tc.strategy(ToddCoxeter.strategy_options.felsch) # set the strategy
<ToddCoxeter object with 2 generators and 2 pairs>
>>> tc.number_of_classes() # calculate number of classes
1
>>> tc.contains([0, 0, 0, 0], [0, 0]) # check if 2 words are equal
True
>>> tc.word_to_class_index([0, 0, 0, 0]) # get the index of a class
0
>>> tc.standardize(ToddCoxeter.order.lex) # standardize to lex order
True
.. >>> from libsemigroups_pybind11 import congruence_kind, ToddCoxeter
.. >>> tc = ToddCoxeter(congruence_kind.left) # construct a left congruence
.. >>> tc.set_number_of_generators(2) # 2 generators
.. >>> tc.add_pair([0, 0], [0]) # generator 0 squared is itself
.. >>> tc.add_pair([0], [1]) # generator 0 equals 1
.. >>> tc.strategy(ToddCoxeter.strategy_options.felsch) # set the strategy
.. <ToddCoxeter object with 2 generators and 2 pairs>
.. >>> tc.number_of_classes() # calculate number of classes
.. 1
.. >>> tc.contains([0, 0, 0, 0], [0, 0]) # check if 2 words are equal
.. True
.. >>> tc.word_to_class_index([0, 0, 0, 0]) # get the index of a class
.. 0
.. >>> tc.standardize(ToddCoxeter.order.lex) # standardize to lex order
.. True
.. doctest::
.. FIXME: doctest
>>> from libsemigroups_pybind11 import congruence_kind, ToddCoxeter
>>> tc = ToddCoxeter(congruence_kind.twosided)
>>> tc.set_number_of_generators(4)
>>> tc.add_pair([0, 0], [0])
>>> tc.add_pair([1, 0], [1])
>>> tc.add_pair([0, 1], [1])
>>> tc.add_pair([2, 0], [2])
>>> tc.add_pair([0, 2], [2])
>>> tc.add_pair([3, 0], [3])
>>> tc.add_pair([0, 3], [3])
>>> tc.add_pair([1, 1], [0])
>>> tc.add_pair([2, 3], [0])
>>> tc.add_pair([2, 2, 2], [0])
>>> tc.add_pair([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], [0])
>>> tc.add_pair([1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3,
... 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3], [0])
>>> tc.strategy(ToddCoxeter.strategy_options.hlt).standardize(False)
<ToddCoxeter object with 4 generators and 12 pairs>
>>> tc.lookahead(ToddCoxeter.lookahead_options.partial).save(False)
<ToddCoxeter object with 4 generators and 12 pairs>
>>> tc.number_of_classes()
10752
>>> tc.complete()
True
>>> tc.compatible()
True
>>> S = tc.quotient_froidure_pin() # quotient semigroup
>>> S.size()
10752
>>> S.number_of_idempotents()
1
>>> tc.standardize(ToddCoxeter.order.recursive)
True
>>> it = tc.normal_forms()
>>> [next(it) for _ in range(10)]
[[0], [1], [2], [2, 1], [1, 2], [1, 2, 1], [2, 2], [2, 2, 1], [2, 1, 2], [2, 1, 2, 1]]
>>> tc.standardize(ToddCoxeter.order.lex)
True
>>> it = tc.normal_forms()
>>> [next(it) for _ in range(10)]
[[0], [0, 1], [0, 1, 2], [0, 1, 2, 1], [0, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1], [0, 1, 2, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1, 2, 1], [0, 1, 2, 1, 2, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1, 2, 1, 2, 1]]
.. >>> from libsemigroups_pybind11 import congruence_kind, ToddCoxeter
.. >>> tc = ToddCoxeter(congruence_kind.twosided)
.. >>> tc.set_number_of_generators(4)
.. >>> tc.add_pair([0, 0], [0])
.. >>> tc.add_pair([1, 0], [1])
.. >>> tc.add_pair([0, 1], [1])
.. >>> tc.add_pair([2, 0], [2])
.. >>> tc.add_pair([0, 2], [2])
.. >>> tc.add_pair([3, 0], [3])
.. >>> tc.add_pair([0, 3], [3])
.. >>> tc.add_pair([1, 1], [0])
.. >>> tc.add_pair([2, 3], [0])
.. >>> tc.add_pair([2, 2, 2], [0])
.. >>> tc.add_pair([1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2], [0])
.. >>> tc.add_pair([1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3,
.. ... 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3, 1, 2, 1, 3], [0])
.. >>> tc.strategy(ToddCoxeter.strategy_options.hlt).standardize(False)
.. <ToddCoxeter object with 4 generators and 12 pairs>
.. >>> tc.lookahead(ToddCoxeter.lookahead_options.partial).save(False)
.. <ToddCoxeter object with 4 generators and 12 pairs>
.. >>> tc.number_of_classes()
.. 10752
.. >>> tc.complete()
.. True
.. >>> tc.compatible()
.. True
.. >>> S = tc.quotient_froidure_pin() # quotient semigroup
.. >>> S.size()
.. 10752
.. >>> S.number_of_idempotents()
.. 1
.. >>> tc.standardize(ToddCoxeter.order.recursive)
.. True
.. >>> it = tc.normal_forms()
.. >>> [next(it) for _ in range(10)]
.. [[0], [1], [2], [2, 1], [1, 2], [1, 2, 1], [2, 2], [2, 2, 1], [2, 1, 2], [2, 1, 2, 1]]
.. >>> tc.standardize(ToddCoxeter.order.lex)
.. True
.. >>> it = tc.normal_forms()
.. >>> [next(it) for _ in range(10)]
.. [[0], [0, 1], [0, 1, 2], [0, 1, 2, 1], [0, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1], [0, 1, 2, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1, 2, 1], [0, 1, 2, 1, 2, 1, 2, 1, 2], [0, 1, 2, 1, 2, 1, 2, 1, 2, 1]]
.. .. autosummary::
.. ~ToddCoxeter
Expand Down
Loading

0 comments on commit 6c5fad3

Please sign in to comment.