def test_cell_order(separable_tiling1):
    rcs = _RowColSeparationSingleApplication(separable_tiling1)
    ob = GriddedPerm(Perm((0, 1)), ((0, 0), (0, 1)))
    assert rcs._col_cell_order(ob) == ((0, 1), (0, 0))
    ob = GriddedPerm(Perm((1, 0)), ((0, 1), (0, 0)))
    assert rcs._col_cell_order(ob) == ((0, 0), (0, 1))
    ob = GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0)))
    assert rcs._row_cell_order(ob) == ((1, 0), (0, 0))
    ob = GriddedPerm(Perm((1, 0)), ((0, 0), (1, 0)))
    assert rcs._row_cell_order(ob) == ((0, 0), (1, 0))
示例#2
0
def tplaced_tracked(tplaced):
    return Tiling(
        tplaced.obstructions,
        tplaced.requirements,
        [
            TrackingAssumption([GriddedPerm.single_cell(Perm((0,)), (0, 0))]),
            TrackingAssumption([GriddedPerm.single_cell(Perm((0,)), (0, 0))]),
            TrackingAssumption([GriddedPerm.single_cell(Perm((0,)), (2, 0))]),
        ],
    )
def test_splitting_gf():
    parent = Tiling(
        obstructions=(
            GriddedPerm.single_cell((0, 1), (0, 1)),
            GriddedPerm.single_cell((0, 1), (1, 0)),
        ),
        assumptions=(
            TrackingAssumption([
                GriddedPerm.point_perm((0, 1)),
                GriddedPerm.point_perm((1, 0))
            ]),
            TrackingAssumption([GriddedPerm.point_perm((1, 0))]),
        ),
    )
    child = Tiling(
        obstructions=(
            GriddedPerm.single_cell((0, 1), (0, 1)),
            GriddedPerm.single_cell((0, 1), (1, 0)),
        ),
        assumptions=(
            TrackingAssumption([GriddedPerm.point_perm((0, 1))]),
            TrackingAssumption([GriddedPerm.point_perm((1, 0))]),
        ),
    )
    strat = SplittingStrategy()
    rule = strat(parent)
    x, k0, k1 = var("x k_0 k_1")
    parent_func = Function("F_0")(x, k0, k1)
    child_func = Function("F_1")(x, k0, k1)
    expected_eq = Eq(parent_func, child_func.subs({k1: k0 * k1}))

    assert len(rule.children) == 1
    assert rule.children[0] == child
    assert rule.constructor.get_equation(parent_func,
                                         (child_func, )) == expected_eq
def test_crossing_insertion():
    t = Tiling(
        obstructions=[
            GriddedPerm((0, 1), ((0, 0), (0, 0))),
            GriddedPerm((0, 1), ((0, 0), (1, 0))),
            GriddedPerm((0, 1), ((1, 0), (1, 0))),
        ],
        requirements=[[GriddedPerm((0,), ((0, 0),))]],
    )
    ci = RequirementInsertionFactory(maxreqlen=2, limited_insertion=False)
    assert set(ci.req_lists_to_insert(t)) == set(
        [
            (GriddedPerm((0,), ((0, 0),)),),
            (GriddedPerm((0,), ((1, 0),)),),
            (GriddedPerm((1, 0), ((0, 0), (0, 0))),),
            (GriddedPerm((1, 0), ((1, 0), (1, 0))),),
            (GriddedPerm((1, 0), ((0, 0), (1, 0))),),
        ]
    )
    assert len(list(ci(t))) == 5
    ci2 = RequirementInsertionFactory(maxreqlen=3, limited_insertion=False)
    assert len(list(ci2(t))) == 9
    ci3 = RequirementInsertionFactory(
        maxreqlen=3, extra_basis=[Perm((2, 1, 0))], limited_insertion=False
    )
    assert len(list(ci3(t))) == 5
示例#5
0
 def test_fusable(self, col_fusion, row_fusion, not_prechecked_fusion):
     assert col_fusion.fusable()
     assert row_fusion.fusable()
     assert not not_prechecked_fusion.fusable()
     t = Tiling(obstructions=[
         GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (0, 0))),
         GriddedPerm((0, 1, 2), ((0, 0), (0, 0), (1, 0))),
         GriddedPerm((0, 1, 2), ((0, 0), (1, 0), (1, 0))),
         GriddedPerm((0, 1, 2), ((1, 0), (1, 0), (1, 0))),
     ])
     assert not ComponentFusion(t, col_idx=0).fusable()
示例#6
0
 def test_positive_fusion(self):
     t = Tiling(
         obstructions=[
             GriddedPerm((0, 1), [(0, 0), (0, 0)]),
             GriddedPerm((0, 1), [(0, 0), (1, 0)]),
             GriddedPerm((0, 1), [(1, 0), (1, 0)]),
         ],
         requirements=[[GriddedPerm((0, ), [(0, 0)])]],
     )
     algo = Fusion(t, col_idx=0)
     assert algo.min_left_right_points() == (1, 0)
示例#7
0
 def test_fusable(self, row_fusion, col_fusion, col_fusion_big,
                  fusion_with_req):
     assert row_fusion.fusable()
     assert col_fusion.fusable()
     assert fusion_with_req.fusable()
     assert not col_fusion_big.fusable()
     t = Tiling(obstructions=[
         GriddedPerm((0, 1), ((0, 0), (0, 0))),
         GriddedPerm((0, 1), ((1, 0), (1, 0))),
     ])
     assert not Fusion(t, row_idx=0).fusable()
示例#8
0
 def test_requirements_fuse_counters(self, row_fusion, fusion_with_req):
     assert row_fusion.requirements_fuse_counters == []
     print(fusion_with_req._tiling)
     assert fusion_with_req.requirements_fuse_counters == [
         {
             GriddedPerm((0, 1), ((0, 0), (1, 0))): 2
         },
         {
             GriddedPerm((1, 0), ((1, 0), (1, 0))): 1
         },
     ]
def test_map_gridded_perm(separable_tiling1):
    rcs = _RowColSeparationSingleApplication(separable_tiling1)
    ob = GriddedPerm(Perm((0, 1, 2)), ((0, 0), (1, 0), (1, 0)))
    cell_map = {(0, 0): (0, 0), (1, 0): (1, 1)}
    assert rcs._map_gridded_perm(cell_map,
                                 ob) == GriddedPerm(Perm((0, 1, 2)),
                                                    ((0, 0), (1, 1), (1, 1)))
    ob = GriddedPerm(Perm((0, 1, 2)), ((0, 0), (1, 0), (1, 0)))
    assert rcs._map_gridded_perm(cell_map,
                                 ob) == GriddedPerm(Perm((0, 1, 2)),
                                                    ((0, 0), (1, 1), (1, 1)))
示例#10
0
def test_remove_cells(simpleob, everycellob):
    assert simpleob.remove_cells([(0, 0)]) == GriddedPerm((1, 0),
                                                          ((2, 2), (2, 1)))
    assert simpleob.remove_cells([(0, 0), (2, 2)]) == GriddedPerm((0, ),
                                                                  ((2, 1), ))
    assert simpleob.remove_cells([(0, 1), (1, 2)]) == simpleob
    gen = (cell for cell in ((0, 1), (1, 0)))
    assert everycellob.remove_cells(gen) == GriddedPerm(
        Perm((0, 4, 2, 5, 1, 3, 6)),
        ((0, 0), (0, 2), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)),
    )
示例#11
0
 def test_with_finite_monotone_cell(self):
     t = Tiling(obstructions=[
         GriddedPerm((0, 1), ((0, 0), ) * 2),
         GriddedPerm((1, 0), ((0, 0), ) * 2),
         GriddedPerm((0, 1), ((1, 0), ) * 2),
         GriddedPerm((1, 0), ((1, 0), ) * 2),
     ])
     enum = MonotoneTreeEnumeration(t)
     print(t)
     assert enum.verified()
     assert enum.get_genf().expand() == sympy.sympify("1+2*x+2*x**2")
示例#12
0
 def tiling1(self):
     t = Tiling(
         obstructions=[
             GriddedPerm((0, 1), ((1, 0), (1, 0))),
             GriddedPerm((0, 1), ((0, 0), (0, 0))),
             GriddedPerm((0, 1), ((0, 0), (1, 0))),
             GriddedPerm((1, 0), ((0, 0), (1, 0))),
         ],
         requirements=[[GriddedPerm((0, ), ((0, 0), ))]],
     )
     return t
    def test_get_genf_simple(self, strategy):
        t = Tiling(
            obstructions=[
                GriddedPerm((0, 1), ((0, 0),) * 2),
                GriddedPerm((1, 0), ((1, 0),) * 2),
            ]
        )

        print(t)
        assert strategy.verified(t)
        assert sympy.simplify(strategy.get_genf(t) - sympy.sympify("1/(1-2*x)")) == 0
示例#14
0
 def test_with_finite_monotone_cell(self, strategy):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
         GriddedPerm(Perm((1, 0)), ((0, 0), ) * 2),
         GriddedPerm(Perm((0, 1)), ((1, 0), ) * 2),
         GriddedPerm(Perm((1, 0)), ((1, 0), ) * 2),
     ])
     print(t)
     assert strategy.verified(t)
     assert sympy.simplify(
         strategy.get_genf(t) - sympy.sympify("1+2*x+2*x**2")) == 0
示例#15
0
 def test_with_finite_monotone_cell2(self, strategy):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
         GriddedPerm(Perm((1, 0)), ((0, 1), ) * 2),
         GriddedPerm(Perm((0, 1)), ((0, 1), ) * 2),
         GriddedPerm(Perm((1, 0)), ((1, 1), ) * 2),
     ])
     print(t)
     assert strategy.verified(t)
     assert (sympy.sympify("x/(1-x)**4 + 1/(1-x)**2") -
             strategy.get_genf(t)).simplify() == 0
 def test_decompostion_function(self, strategy):
     new_strat = strategy.change_basis([Perm((0, 1, 2, 3))], False)
     t = Tiling(
         obstructions=(
             GriddedPerm((0, 1, 2, 3), ((0, 0),) * 4),
             GriddedPerm((0, 1, 2), ((1, 1),) * 3),
         ),
         requirements=(),
         assumptions=(),
     )
     rule = new_strat(t)
     assert rule.children == (t.from_string("1234"),)
def test_no_interleaving():
    strat = SplittingStrategy(interleaving="none")
    rule = strat(t)
    assert len(rule.children) == 1
    child = rule.children[0]
    assert len(child.assumptions) == 2
    assert (TrackingAssumption(
        [GriddedPerm.point_perm((0, 0)),
         GriddedPerm.point_perm((1, 0))]) in child.assumptions)
    assert (TrackingAssumption(
        [GriddedPerm.point_perm((2, 1)),
         GriddedPerm.point_perm((3, 1))]) in child.assumptions)
示例#18
0
 def enum_with_list_req(self):
     t = Tiling(
         obstructions=[
             GriddedPerm((0, 1), ((0, 0), (0, 0))),
             GriddedPerm((0, 1), ((1, 0), (1, 0))),
         ],
         requirements=[[
             GriddedPerm((0, ), ((0, 0), )),
             GriddedPerm((0, ), ((1, 0), )),
         ]],
     )
     return MonotoneTreeEnumeration(t)
示例#19
0
 def test_with_finite_monotone_cell2(self):
     t = Tiling(obstructions=[
         GriddedPerm((0, 1), ((0, 0), ) * 2),
         GriddedPerm((1, 0), ((0, 1), ) * 2),
         GriddedPerm((0, 1), ((0, 1), ) * 2),
         GriddedPerm((1, 0), ((1, 1), ) * 2),
     ])
     enum = MonotoneTreeEnumeration(t)
     print(t)
     assert enum.verified()
     assert (sympy.sympify("x/(1-x)**4 + 1/(1-x)**2") -
             enum.get_genf()).simplify() == 0
示例#20
0
def tiling_simple_trans_row_len2():
    return Tiling(
        obstructions=[
            GriddedPerm(Perm((0, 1)), [(0, 0), (1, 0)]),
            GriddedPerm(Perm((0, 1)), [(1, 0), (2, 0)]),
            GriddedPerm(Perm((0, 1)), [(2, 0), (3, 0)]),
        ],
        requirements=[
            [GriddedPerm(Perm((0,)), [(1, 0)])],
            [GriddedPerm(Perm((0,)), [(2, 0)])],
        ],
    )
示例#21
0
 def enum_with_list_req(self):
     t = Tiling(
         obstructions=[
             GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
             GriddedPerm(Perm((0, 1)), ((1, 0), (1, 0))),
         ],
         requirements=[[
             GriddedPerm(Perm((0, )), ((0, 0), )),
             GriddedPerm(Perm((0, )), ((1, 0), )),
         ]],
     )
     return t
示例#22
0
 def test_ineq_ob(self, simple_trans_col):
     assert simple_trans_col.ineq_ob(((0, 0), (0, 0))) == GriddedPerm(
         (0, ), [(0, 0)])
     assert simple_trans_col.ineq_ob(((0, 0), (1, 0))) == GriddedPerm(
         (1, 0), [(0, 0), (1, 0)])
     assert simple_trans_col.ineq_ob(((1, 0), (0, 0))) == GriddedPerm(
         (0, 1), [(0, 0), (1, 0)])
     assert simple_trans_col.ineq_ob(((0, 0), (0, 1))) == GriddedPerm(
         (1, 0), [(0, 1), (0, 0)])
     assert simple_trans_col.ineq_ob(((0, 1), (0, 0))) == GriddedPerm(
         (0, 1), [(0, 0), (0, 1)])
     with pytest.raises(ValueError):
         simple_trans_col.ineq_ob(((0, 0), (1, 1)))
示例#23
0
 def test_get_genf(self, enum_verified):
     x = sympy.Symbol("x")
     expected_gf = -(sympy.sqrt(-(4 * x**3 - 14 * x**2 + 8 * x - 1) /
                                (2 * x**2 - 4 * x + 1)) - 1) / (
                                    2 * x * (x**2 - 3 * x + 1))
     assert sympy.simplify(enum_verified.get_genf() - expected_gf) == 0
     t = Tiling(obstructions=[
         GriddedPerm((0, 1), ((0, 0), ) * 2),
         GriddedPerm((0, 1), ((1, 0), ) * 2),
     ])
     enum_no_start = MonotoneTreeEnumeration(t)
     expected_gf = -1 / ((x - 1) * (x / (x - 1) + 1))
     assert sympy.simplify(enum_no_start.get_genf() - expected_gf) == 0
示例#24
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
示例#25
0
 def test_genf_with_big_finite_cell(self, strategy):
     t = Tiling(obstructions=[
         GriddedPerm(Perm((0, 1)), ((0, 0), ) * 2),
         GriddedPerm(Perm((0, 1)), ((1, 0), ) * 2),
         GriddedPerm(Perm((3, 2, 1, 0)), ((0, 0), ) * 4),
         GriddedPerm(Perm((3, 2, 1, 0)), ((1, 0), ) * 4),
     ])
     print(t)
     assert strategy.verified(t)
     genf = strategy.get_genf(t).expand()
     x = sympy.var("x")
     assert (genf == 1 + 2 * x + 4 * x**2 + 8 * x**3 + 14 * x**4 +
             20 * x**5 + 20 * x**6)
示例#26
0
 def enum_verified(self):
     return [
         Tiling(
             obstructions=(
                 GriddedPerm(Perm((0, 1)), ((0, 0), (0, 0))),
                 GriddedPerm(Perm((0, 1)), ((0, 0), (1, 0))),
                 GriddedPerm(Perm((0, 1)), ((1, 0), (1, 0))),
                 GriddedPerm(Perm((0, 1)), ((2, 0), (2, 0))),
             ),
             requirements=(),
             assumptions=(),
         )
     ]
示例#27
0
def test_contradictory(simpleob, singlecellob, everycellob):
    assert not simpleob.contradictory()
    assert not singlecellob.contradictory()
    assert not everycellob.contradictory()
    gp = GriddedPerm((0, 1), [(0, 1), (1, 0)])
    assert gp.contradictory()
    gp = GriddedPerm((0, 1), [(1, 0), (0, 0)])
    assert gp.contradictory()
    gp = GriddedPerm((1, 0), [(0, 0), (1, 1)])
    assert gp.contradictory()
示例#28
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
示例#29
0
 def test_genf_with_big_finite_cell(self):
     t = Tiling(obstructions=[
         GriddedPerm((0, 1), ((0, 0), ) * 2),
         GriddedPerm((0, 1), ((1, 0), ) * 2),
         GriddedPerm((3, 2, 1, 0), ((0, 0), ) * 4),
         GriddedPerm((3, 2, 1, 0), ((1, 0), ) * 4),
     ])
     enum = MonotoneTreeEnumeration(t)
     print(t)
     assert enum.verified()
     genf = enum.get_genf().expand()
     x = sympy.var("x")
     assert (genf == 1 + 2 * x + 4 * x**2 + 8 * x**3 + 14 * x**4 +
             20 * x**5 + 20 * x**6)
示例#30
0
def rule1():
    ass1 = TrackingAssumption([GriddedPerm((0, ), ((0, 0), ))])
    ass2 = TrackingAssumption(
        [GriddedPerm((0, ), ((0, 0), )),
         GriddedPerm((0, ), ((1, 0), ))])
    strat = RearrangeAssumptionStrategy(ass2, ass1)
    t1 = Tiling(
        obstructions=[
            GriddedPerm((0, 1), ((0, 0), ) * 2),
            GriddedPerm((0, 1), ((1, 0), ) * 2),
        ],
        assumptions=[ass1, ass2],
    )
    return strat(t1)