def pack(self, comb_class: Tiling) -> StrategyPack:
     try:
         return InsertionEncodingVerificationStrategy().pack(comb_class)
     except StrategyDoesNotApply:
         pass
     if self.no_factors:
         raise InvalidOperationError("Cannot get a simpler specification")
     if (
         any(isinstance(ass, ComponentAssumption) for ass in comb_class.assumptions)
         and len(comb_class.find_factors()) == 1
     ):
         raise InvalidOperationError(
             "Can't find generating function with component assumption."
         )
     return StrategyPack(
         initial_strats=[FactorFactory()],
         inferral_strats=[],
         expansion_strats=[],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
             LocalVerificationStrategy(no_factors=True),
         ],
         name="factor pack",
     )
Beispiel #2
0
 def pack(self, tiling: Tiling) -> StrategyPack:
     if any(
             isinstance(ass, ComponentAssumption)
             for ass in tiling.assumptions):
         raise InvalidOperationError(
             "Can't find generating function with component assumption.")
     try:
         return InsertionEncodingVerificationStrategy().pack(tiling)
     except StrategyDoesNotApply:
         pass
     if self.no_factors:
         raise InvalidOperationError(
             "Cannot get a specification for a tiling in the database")
     return StrategyPack(
         initial_strats=[FactorFactory()],
         inferral_strats=[],
         expansion_strats=[],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
         ],
         name="factor pack",
     )
Beispiel #3
0
def get_word_searcher(avoid, alphabet):
    pack = StrategyPack(
        initial_strats=[RemoveFrontOfPrefix()],
        inferral_strats=[],
        expansion_strats=[[ExpansionStrategy()]],
        ver_strats=[AtomStrategy()],
        name=(
            "Finding specification for words avoiding consecutive patterns."),
    )
    start_class = AvoidingWithPrefix("", avoid, alphabet)
    searcher = CombinatorialSpecificationSearcher(start_class, pack)
    return searcher
 def _pack_for_shift(comb_class: Tiling) -> StrategyPack:
     if any(isinstance(ass, ComponentAssumption) for ass in comb_class.assumptions):
         raise InvalidOperationError(
             "Can't find generating function with component assumption."
         )
     return StrategyPack(
         name="LocallyFactorable",
         initial_strats=[FactorFactory(), RequirementCorroborationFactory()],
         inferral_strats=[],
         expansion_strats=[[FactorInsertionFactory()]],
         ver_strats=[
             BasicVerificationStrategy(),
             OneByOneVerificationStrategy(),
             InsertionEncodingVerificationStrategy(),
             MonotoneTreeVerificationStrategy(no_factors=True),
             LocalVerificationStrategy(no_factors=True),
         ],
     )
Beispiel #5
0
        yield DecompositionRule("Removing last letter.", [
            Letter(av_config.last_letter),
            Suffixes(av_config.config, av_config.basis)
        ])


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.")


pack = StrategyPack(initial_strats=[remove_letter, equivalent],
                    inferral_strats=[],
                    expansion_strats=[[expansion]],
                    ver_strats=[verify_letters_and_perms],
                    name=("Finding regular insertion encodings"))

if __name__ == "__main__":
    from permuta.permutils import is_insertion_encodable_maximum

    basis = input("Enter comma separated permutations: ")
    basis = [Perm.to_standard(p) for p in basis.split(',')]

    if is_insertion_encodable_maximum(basis):
        start_class = Suffixes(Configuration(Perm(), (0, )), basis)
        print(Configuration(Perm((0, )), (0, )))
        searcher = CombinatorialSpecificationSearcher(start_class,
                                                      pack,
                                                      debug=True)
Beispiel #6
0
        break


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")


pack = StrategyPack(initial_strats=[factor, list_cleanup,
                                    all_factor_insertions],
                    inferral_strats=[],
                    expansion_strats=[[expansion]],
                    ver_strats=[verify_point],
                    name=("substition_decomposition"))


if __name__ == "__main__":
    basis = input("Enter comma separated permutations: ")
    basis = [Perm.to_standard(p) for p in basis.split(',')]

    start_class = All(basis)
    searcher = CombinatorialSpecificationSearcher(start_class, pack,
                                                  debug=True)
    tree = searcher.auto_search(status_update=30)

    tree.get_min_poly(solve=True)
Beispiel #7
0
    @classmethod
    def from_dict(cls, d):
        return cls()

    def __str__(self) -> str:
        return self.formal_step()

    def __repr__(self) -> str:
        return self.__class__.__name__ + "()"


pack = StrategyPack(
    initial_strats=[RemoveFrontOfPrefix()],
    inferral_strats=[],
    expansion_strats=[[ExpansionStrategy()]],
    ver_strats=[AtomStrategy()],
    name=("Finding specification for words avoiding consecutive patterns."),
)

if __name__ == "__main__":
    example_alphabet = input(
        ("Input the alphabet (letters should be separated by a"
         " comma):")).split(",")
    example_patterns = tuple(
        map(
            Word,
            input(("Input the patterns to be avoided (patterns should be "
                   "separated by a comma):")).split(","),
        ))