Exemplo n.º 1
0
def slicing_verified(tiling, **kwargs):
    """The globally verified strategy.

    A tiling is slicing verified if every requirement and obstruction that
    crosses slices is 'simple'. Requirments and obstructions within slices
    do not affect this strategy
    """
    def deflation_type(gp):
        patt = gp._patt
        poss = gp._pos
        if patt == Perm((0, 2, 1)) or patt == Perm((1, 2, 0)):
            if poss[0][1] == poss[2][1] and poss[1][1] > poss[0][1]:
                return True
        if patt == Perm((1, 0, 2)) or patt == Perm((2, 0, 1)):
            if poss[0][1] == poss[2][1] and poss[1][1] < poss[0][1]:
                return True

    if not tiling.dimensions == (1, 1):
        if all(ob.is_single_row() or len(ob) <= 2 or deflation_type(ob)
               for ob in tiling.obstructions):
            if (all(
                    all((r.is_single_row() or len(r) <= 2) for r in req)
                    for req in tiling.requirements)
                    and not possible_tautology(tiling)):
                return VerificationRule(formal_step="Slicing verified.")
    else:
        return subset_verified(tiling, **kwargs)
Exemplo n.º 2
0
def verify_point(tiling, **kwargs):
    """Verify exactly the point tiling."""
    if (tiling.tiling.is_point_tiling()):
        if (isinstance(tiling, Point) or
            isinstance(tiling, SumIndecomposable) or
            isinstance(tiling, SkewDecomposable) or
                isinstance(tiling, All)):
            return VerificationRule("its the point")
Exemplo n.º 3
0
def verify_points(tiling, basis, **kwargs):
    """The verify points strategy.

    A tiling is verified if it is a point or is the empty tiling.
    """
    if tiling.dimensions == (1, 1):
        if (not tiling.requirements and len(tiling.obstructions) == 1 and
                len(tiling.obstructions[0]) == 1):
            return VerificationRule(
                    formal_step="I understand the empty tiling.")
        if (len(tiling.obstructions) == 2 and
                all(len(ob) == 2 for ob in tiling.obstructions) and
                len(tiling.requirements) == 1 and
                len(tiling.requirements[0]) == 1 and
                len(tiling.requirements[0][0]) == 1):
            return VerificationRule(
                    formal_step="I understand points, no really, I do.")
Exemplo n.º 4
0
def verify_short_obstructions(tiling, **kwargs):
    """
    A tiling is verified if it only has obstructions of length at most two.
    """
    if tiling.dimensions == (1, 1):
        return None
    else:
        if all(len(obs) < 3 for obs in tiling.obstructions):
            return VerificationRule(formal_step=(
                "The tiling only has obstructions of length at most two."))
Exemplo n.º 5
0
def subset_verified(tiling, basis, **kwargs):
    """The subset verified strategy.

    A tiling is subset verified if every obstruction and every requirement is
    localized.
    """
    if kwargs.get("no_factors", False):
        if len(tiling.find_factors()) > 1:
            return
    if kwargs.get("no_reqs", False):
        if tiling.requirements:
            return
    if tiling.dimensions == (1, 1):
        if one_by_one_verified(tiling, basis, **kwargs):
            return VerificationRule(
                formal_step="The tiling is a subset of the class.")
    elif (all(ob.is_single_cell() for ob in tiling.obstructions) and all(
            all(r.is_single_cell() for r in req)
            for req in tiling.requirements)):
        return VerificationRule(
            formal_step="The tiling is a subset of the class.")
def globally_verified(tiling, **kwargs):
    """The globally verified strategy.

    A tiling is globally verified if every requirement and obstruction is
    non-interleaving.
    """
    if not tiling.dimensions == (1, 1):
        if all(not ob.is_interleaving() for ob in tiling.obstructions):
            if (all(
                    all(not r.is_interleaving() for r in req)
                    for req in tiling.requirements)
                    and not possible_tautology(tiling)):
                return VerificationRule(formal_step="Globally verified.")
    else:
        return subset_verified(tiling, **kwargs)
def subclass_verified(tiling, basis, **kwargs):
    """The subclass verified strategy.

    A tiling is subclass verified if it only generates permutations in a
    proper subclass of Av(basis).
    """
    if tiling.dimensions == (1, 1):
        return None
    else:
        maxlen = kwargs.get('maxpattlen', 4)
        patterns = set(perm for perm in chain(
            *[Av(basis).of_length(i) for i in range(maxlen + 1)]))
        maxlen += tiling.maximum_length_of_minimum_gridded_perm()
        for i in range(maxlen + 1):
            for g in tiling.objects_of_length(i):
                perm = g.patt
                patterns = set(pattern for pattern in patterns
                               if perm.avoids(pattern))
                if not patterns:
                    return None
        return VerificationRule(formal_step=("The tiling belongs to the "
                                             "subclass obtained by adding"
                                             " the patterns {}."
                                             "".format(Basis(patterns))))
Exemplo n.º 8
0
def verify_letters_and_perms(config, **kwargs):
    if isinstance(config, Letter):
        return VerificationRule("Its a letter.")
    elif config.last_letter is None and len(config.config.slots) == 0:
        return VerificationRule("Its a permutation.")
Exemplo n.º 9
0
def one_by_one_verification(tiling, basis, **kwargs):
    """Return a verification if one-by-one verified."""
    if one_by_one_verified(tiling, basis, **kwargs):
        return VerificationRule(
            formal_step="The tiling is a subclass of the class.")
Exemplo n.º 10
0
def miner_verified(tiling, basis, **kwargs):
    """The Miner verification strategy."""
    # TODO: document all these magic constant scattered all over the function.
    if ((tiling.dimensions[0] is 1 and tiling.dimensions[1] is 2)
            or (tiling.dimensions[0] is 2 and tiling.dimensions[1] is 1)):
        top = []
        bottom = []
        topbool = None
        bottombool = None
        for ob in tiling.obstructions:
            if ob.is_single_cell():
                if ob.pos[0] == (0, 0):
                    bottom.append(ob.patt)
                else:
                    top.append(ob.patt)
            else:
                if topbool is not None or bottombool is not None:
                    return None
                if ob.patt == Perm((0, 1, 2)):
                    if ob.pos[0] == (0, 0) and ob.pos[1] == (0, 0):
                        bottombool = 0
                    else:
                        topbool = 0
                elif ob.patt == Perm((2, 1, 0)):
                    if ob.pos[1] == (0, 0) and ob.pos[2] == (0, 0):
                        bottombool = 1
                    elif ob.pos[0] == (0, 1) and ob.pos[1] == (0, 1):
                        topbool = 1
                    else:
                        return None
                elif ob.patt == Perm((0, 2, 1)):
                    if ob.pos[1] == ob.pos[2]:
                        topbool = 1
                    else:
                        return None
                elif ob.patt == Perm((1, 0, 2)):
                    if ob.pos[0] == ob.pos[1]:
                        bottombool = 1
                    else:
                        return None
                elif ob.patt == Perm((1, 2, 0)):
                    if ob.pos[0] == (0, 0) and ob.pos[1] == (0, 0):
                        bottombool = 0
                    elif ob.pos[0] == (0, 1) and ob.pos[1] == (0, 1):
                        topbool = 0
                    else:
                        return None
                elif ob.patt == Perm((2, 0, 1)):
                    if ob.pos[1] == (0, 0) and ob.pos[2] == (0, 0):
                        bottombool = 0
                    elif ob.pos[1] == (1, 0) and ob.pos[2] == (0, 0):
                        topbool = 0
                    else:
                        return None

                else:
                    return None
        if topbool is not None:
            topbasis = Basis(top)
            if ((topbool == 0 and topbasis == Basis([Perm((0, 1, 2))]))
                    or (topbool == 1 and topbasis == Basis([Perm(
                        (2, 1, 0))]))):
                return VerificationRule("Miner verified!")
        elif bottombool is not None:
            bottombasis = Basis(bottom)
            if ((bottombool == 0 and Basis(bottom) == Basis([Perm(
                (0, 1, 2))])) or
                (bottombool == 1 and bottombasis == Basis([Perm((2, 1, 0))]))):
                return VerificationRule("Miner verified!")