Exemplo n.º 1
0
 def test_with_123_subclass_12req(self, strategy):
     t2 = Tiling(
         obstructions=[
             GriddedPerm((2, 1, 0), ((0, 0),) * 3),
             GriddedPerm((1, 0, 3, 2), ((0, 0),) * 4),
         ],
         requirements=[[GriddedPerm((1, 0), ((0, 0),) * 2)]],
     )
     assert strategy.verified(t2)
     genf = strategy.get_genf(t2)
     assert taylor_expand(genf, 16) == [
         0,
         0,
         1,
         4,
         12,
         32,
         79,
         184,
         410,
         884,
         1861,
         3852,
         7880,
         15992,
         32283,
         64944,
         130358,
     ]
Exemplo n.º 2
0
 def test_corner(self, strategy):
     t = Tiling(
         obstructions=(
             GriddedPerm(Perm((0, )), ((1, 1), )),
             GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
             GriddedPerm(Perm((0, 1)), ((0, 1), (0, 1))),
             GriddedPerm(Perm((0, 1)), ((1, 0), (1, 0))),
         ),
         requirements=((GriddedPerm(Perm((0, )), ((0, 0), )), ), ),
     )
     expected_enum = [0, 1, 5, 17, 50, 138, 370, 979, 2575, 6755, 17700]
     assert strategy.verified(t)
     assert taylor_expand(strategy.get_genf(t)) == expected_enum
Exemplo n.º 3
0
 def test_corner(self):
     t = Tiling(
         obstructions=(
             GriddedPerm((0, ), ((1, 1), )),
             GriddedPerm((0, 1), ((0, 0), (0, 0))),
             GriddedPerm((0, 1), ((0, 1), (0, 1))),
             GriddedPerm((0, 1), ((1, 0), (1, 0))),
         ),
         requirements=((GriddedPerm((0, ), ((0, 0), )), ), ),
     )
     enum = MonotoneTreeEnumeration(t)
     expected_enum = [0, 1, 5, 17, 50, 138, 370, 979, 2575, 6755, 17700]
     assert enum.verified()
     assert taylor_expand(enum.get_genf()) == expected_enum
Exemplo n.º 4
0
def test_reverse_equiv():
    """A specification that should use reverse equivalence."""
    pack = TileScopePack(
        initial_strats=[
            strat.FactorFactory(),
            strat.RequirementCorroborationFactory(),
            strat.RequirementPlacementFactory(partial=False),
        ],
        inferral_strats=[strat.RowColumnSeparationStrategy()],
        expansion_strats=[[strat.CellInsertionFactory()]],
        ver_strats=[strat.BasicVerificationStrategy()],
        iterative=False,
        name="test pack",
    )
    basis = (Perm((0, 1, 3, 2)), Perm((0, 2, 3, 1)), Perm((1, 0, 3, 2)))
    # From https://oeis.org/A033321
    expected_enum = [
        1, 1, 2, 6, 21, 79, 311, 1265, 5275, 22431, 96900, 424068, 1876143
    ]
    x, f = sympy.symbols("x f")
    expected_min_poly = sympy.sympify("-4*f^2*x^2 + 8*f^2*x - 4*f*x - 4*f + 4")
    searcher = TileScope(basis, pack)
    spec = searcher.auto_search(smallest=True)
    assert [spec.count_objects_of_size(i) for i in range(13)] == expected_enum
    genf = spec.get_genf()
    assert sympy.simplify(expected_min_poly.subs(f, genf)) == 0
    assert taylor_expand(genf, 12) == expected_enum
    # In order to avoid ReccursionError we go incrementally
    for i in range(0, 100):
        spec.count_objects_of_size(i)
    assert spec.count_objects_of_size(50) == 86055297645519796258217673160170
    assert (
        spec.count_objects_of_size(100) ==
        2733073112795720153237297124938915907723365837935699807314396095313)
    len4_perms = tuple(spec.generate_objects_of_size(4))
    assert len(len4_perms) == 21
    assert all(p not in len4_perms for p in basis)
    len8_perms = tuple(spec.generate_objects_of_size(8))
    assert len(len8_perms) == 5275
    assert len(set(len8_perms)) == 5275
    for _ in range(10):
        gp = spec.random_sample_object_of_size(10)
        print(gp)
        assert gp.patt.avoids(*basis)

    av = Av(basis)
    for i in range(10):
        assert set(av.of_length(i)) == set(
            gp.patt for gp in spec.generate_objects_of_size(i))
        assert spec.random_sample_object_of_size(i).patt in av
Exemplo n.º 5
0
 def test_genf_with_req(self, strategy):
     t = Tiling(
         obstructions=[
             GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
             GriddedPerm(Perm((0, 1)), ((1, 0), ) * 2),
         ],
         requirements=[
             [GriddedPerm(Perm((1, 0)), ((0, 0), ) * 2)],
             [GriddedPerm(Perm((0, )), ((1, 0), ))],
         ],
     )
     print(t)
     assert strategy.verified(t)
     genf = strategy.get_genf(t).expand()
     terms = [0, 0, 0, 3, 10, 25, 56, 119, 246, 501, 1012]
     assert taylor_expand(genf) == terms
Exemplo n.º 6
0
 def test_genf_with_req(self):
     t = Tiling(
         obstructions=[
             GriddedPerm((0, 1), ((0, 0), ) * 2),
             GriddedPerm((0, 1), ((1, 0), ) * 2),
         ],
         requirements=[
             [GriddedPerm((1, 0), ((0, 0), ) * 2)],
             [GriddedPerm((0, ), ((1, 0), ))],
         ],
     )
     enum = MonotoneTreeEnumeration(t)
     print(t)
     assert enum.verified()
     genf = enum.get_genf().expand()
     terms = [0, 0, 0, 3, 10, 25, 56, 119, 246, 501, 1012]
     assert taylor_expand(genf) == terms
Exemplo n.º 7
0
 def get_genf(self, **kwargs) -> Expr:
     # pylint: disable=too-many-locals
     if not self.verified():
         raise InvalidOperationError("The tiling is not verified")
     if self.tiling.extra_parameters:
         raise NotImplementedError(
             "Not implemented monotone verified with extra parameters."
         )
     try:
         start = next(
             c
             for c in self.tiling.active_cells
             if not self.tiling.is_monotone_cell(c)
         )
     except StopIteration:
         start = next(iter(self.tiling.active_cells))
     start_basis = self.tiling.cell_basis()[start][0]
     start_reqs = [[p] for p in self.tiling.cell_basis()[start][1]]
     start_tiling = self.tiling.from_perms(
         obstructions=start_basis, requirements=start_reqs
     )
     start_gf = start_tiling.get_genf()
     F = start_gf.subs({x: x * self._cell_variable(start)})
     visited = set([start])
     for cell in self._cell_tree_traversal(start):
         interleaving_cells = self._visted_cells_aligned(cell, visited)
         substitutions = {
             scv: scv * self._tracking_var
             for scv in map(self._cell_variable, interleaving_cells)
         }
         F_tracked = F.subs(substitutions)
         minlen, maxlen = self._cell_num_point(cell)
         if maxlen is None:
             F = self._interleave_any_length(F_tracked, cell)
             if minlen > 0:
                 F -= self._interleave_fixed_lengths(F_tracked, cell, 0, minlen - 1)
         else:
             F = self._interleave_fixed_lengths(F_tracked, cell, minlen, maxlen)
         visited.add(cell)
     F = simplify(F.subs({v: 1 for v in F.free_symbols if v != x}))
     # A simple test to warn us if the code is wrong
     if __debug__:
         lhs = taylor_expand(F, n=6)
         rhs = [len(list(self.tiling.objects_of_size(i))) for i in range(7)]
     assert lhs == rhs, f"Bad genf\n{lhs}\n{rhs}"
     return F
Exemplo n.º 8
0
 def test_with_two_reqs(self):
     t = Tiling(
         obstructions=(
             GriddedPerm((0, ), ((1, 1), )),
             GriddedPerm((0, 1), ((0, 0), (0, 0))),
             GriddedPerm((0, 1), ((0, 1), (0, 1))),
             GriddedPerm((0, 1), ((1, 0), (1, 0))),
             GriddedPerm((1, 0), ((0, 1), (0, 1))),
         ),
         requirements=(
             (GriddedPerm((0, ), ((0, 0), )), ),
             (GriddedPerm((0, ), ((0, 1), )), ),
         ),
     )
     enum = MonotoneTreeEnumeration(t)
     expected_enum = [0, 0, 2, 7, 19, 47, 111, 255, 575, 1279, 2815]
     assert enum.verified()
     assert taylor_expand(enum.get_genf()) == expected_enum
Exemplo n.º 9
0
 def test_with_two_reqs(self, strategy):
     t = Tiling(
         obstructions=(
             GriddedPerm(Perm((0, )), ((1, 1), )),
             GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
             GriddedPerm(Perm((0, 1)), ((0, 1), (0, 1))),
             GriddedPerm(Perm((0, 1)), ((1, 0), (1, 0))),
             GriddedPerm(Perm((1, 0)), ((0, 1), (0, 1))),
         ),
         requirements=(
             (GriddedPerm(Perm((0, )), ((0, 0), )), ),
             (GriddedPerm(Perm((0, )), ((0, 1), )), ),
         ),
     )
     expected_enum = [0, 0, 2, 7, 19, 47, 111, 255, 575, 1279, 2815]
     assert strategy.verified(t)
     assert (sympy.simplify(
         strategy.get_genf(t) -
         sympy.sympify("x**2*(3*x - 2)/(4*x**3 - 8*x**2 + 5*x - 1)")) == 0)
     assert taylor_expand(strategy.get_genf(t)) == expected_enum
Exemplo n.º 10
0
def test_132_321_genf():
    searcher = TileScope("132_321", point_placements)
    spec = searcher.auto_search(smallest=True)
    assert isinstance(spec, CombinatorialSpecification)
    gf = spec.get_genf()
    assert taylor_expand(gf, 15) == [
        1,
        1,
        2,
        4,
        7,
        11,
        16,
        22,
        29,
        37,
        46,
        56,
        67,
        79,
        92,
        106,
    ]
def test_specification_with_genf(specification):
    genf = specification.get_genf()
    assert taylor_expand(genf) == [1, 2, 4, 8, 15, 27, 48, 87, 157, 283, 511]