Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to FroidurePin that maybe returns UNDEFINED #207

Merged
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
12 changes: 6 additions & 6 deletions libsemigroups_pybind11/froidure_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,10 @@ def __iter__(self: Self) -> Iterator:
########################################################################

def current_elements(self: Self) -> Iterator:
return map(
lambda x: to_py(self.Element, x), self._cxx_obj.current_elements()
)
return map(lambda x: to_py(self.Element, x), self._cxx_obj.current_elements())

def idempotents(self: Self) -> Iterator:
return map(
lambda x: to_py(self.Element, x), self._cxx_obj.idempotents()
)
return map(lambda x: to_py(self.Element, x), self._cxx_obj.idempotents())

def sorted_elements(self: Self) -> Iterator:
return map(
Expand All @@ -184,6 +180,10 @@ def generator(self: Self, i: int) -> Element:
def sorted_at(self: Self, i: int) -> Element:
return self._cxx_obj.sorted_at(i)

@may_return_undefined
def current_position(self: Self, x: Element) -> Element:
return self._cxx_obj.current_position(to_cxx(x))


########################################################################
# Helpers -- from froidure-pin.cpp
Expand Down
39 changes: 29 additions & 10 deletions tests/test_froidure_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
BMat8,
froidure_pin,
LibsemigroupsError,
UNDEFINED,
)


Expand Down Expand Up @@ -101,7 +102,8 @@ def check_mem_compare(S):
# [S.position(froidure_pin.factorisation(S, x)) for x in S], list(range(S.size()))
# )
assert [
froidure_pin.current_position(S, froidure_pin.factorisation(S, x)) for x in S
froidure_pin.current_position(S, froidure_pin.factorisation(S, x))
for x in S
] == list(range(S.size()))

assert [S.current_position(x) for x in S] == list(range(S.size()))
Expand Down Expand Up @@ -189,17 +191,21 @@ def check_factor_prod_rels(S):
# (minimal_)factorisation + to_element
for i, x in enumerate(S):
assert froidure_pin.to_element(S, froidure_pin.factorisation(S, x)) == x
assert froidure_pin.to_element(S, froidure_pin.minimal_factorisation(S, i)) == x
assert (
froidure_pin.to_element(S, froidure_pin.minimal_factorisation(S, i))
== x
)

# rules, number_of_rules
assert len(list(froidure_pin.rules(S))) == S.number_of_rules()

for lhs, rhs in froidure_pin.rules(S):
assert froidure_pin.current_position(S, lhs) == froidure_pin.current_position(
S, rhs
)
assert froidure_pin.current_position(
S, lhs
) == froidure_pin.current_position(S, rhs)
assert (
froidure_pin.factorisation(S, froidure_pin.current_position(S, rhs)) == rhs
froidure_pin.factorisation(S, froidure_pin.current_position(S, rhs))
== rhs
)

# product_by_reduction + fast_product
Expand Down Expand Up @@ -471,7 +477,9 @@ def test_froidure_pin_min_plus(checks_for_froidure_pin, checks_for_generators):
check(FroidurePin(gens))


def test_froidure_pin_proj_max_plus(checks_for_froidure_pin, checks_for_generators):
def test_froidure_pin_proj_max_plus(
checks_for_froidure_pin, checks_for_generators
):
ReportGuard(False)
x = Matrix(MatrixKind.ProjMaxPlus, 2, 2)
gens = [Matrix(MatrixKind.ProjMaxPlus, [[1, 0], [0, x.scalar_zero()]])]
Expand All @@ -484,7 +492,9 @@ def test_froidure_pin_proj_max_plus(checks_for_froidure_pin, checks_for_generato
check(FroidurePin(gens))


def test_froidure_pin_max_plus_trunc(checks_for_froidure_pin, checks_for_generators):
def test_froidure_pin_max_plus_trunc(
checks_for_froidure_pin, checks_for_generators
):
ReportGuard(False)
gens = [Matrix(MatrixKind.MaxPlusTrunc, 11, [[1, 0], [0, 1]])]
assert FroidurePin(gens).size() == 12
Expand All @@ -496,7 +506,9 @@ def test_froidure_pin_max_plus_trunc(checks_for_froidure_pin, checks_for_generat
check(FroidurePin(gens))


def test_froidure_pin_min_plus_trunc(checks_for_froidure_pin, checks_for_generators):
def test_froidure_pin_min_plus_trunc(
checks_for_froidure_pin, checks_for_generators
):
ReportGuard(False)
gens = [Matrix(MatrixKind.MinPlusTrunc, 11, [[1, 0], [0, 1]])]
assert FroidurePin(gens).size() == 2
Expand Down Expand Up @@ -545,7 +557,9 @@ def test_froidure_pin_method_wrap():

S.init()
with pytest.raises(LibsemigroupsError):
S.add_generators([Perm([0, 1, 2, 3, 4, 5]), Perm([0, 1, 2, 3, 4, 5, 6])])
S.add_generators(
[Perm([0, 1, 2, 3, 4, 5]), Perm([0, 1, 2, 3, 4, 5, 6])]
)

S = FroidurePin(Perm([1, 0, 2, 3, 4, 5, 6]), Perm([1, 2, 3, 4, 5, 6, 0]))

Expand All @@ -569,6 +583,11 @@ def test_froidure_pin_method_wrap():
# TODO more


def test_froidure_pin_return_undefined_1():
S = FroidurePin(Perm([1, 0, 2, 3, 4, 5, 6]))
assert S.current_position(Perm([1, 0, 2])) is UNDEFINED


# def test_froidure_pin_tce(checks_for_froidure_pin):
# ReportGuard(False)
# tc = ToddCoxeter(congruence_kind.twosided)
Expand Down
Loading