Example #1
0
def best_linear_code_in_guava(n, k, F):
    r"""
    Returns the linear code of length ``n``, dimension ``k`` over field ``F``
    with the maximal minimum distance which is known to the GAP package GUAVA.

    The function uses the tables described in ``bounds_on_minimum_distance_in_guava`` to
    construct this code. This requires the optional GAP package GUAVA.

    INPUT:

    - ``n`` -- the length of the code to look up

    - ``k`` -- the dimension of the code to look up

    - ``F`` -- the base field of the code to look up


    OUTPUT:

    - A :class:`LinearCode` which is a best linear code of the given parameters known to GUAVA.

    EXAMPLES::

        sage: codes.databases.best_linear_code_in_guava(10,5,GF(2))    # long time; optional - gap_packages (Guava package)
        [10, 5] linear code over GF(2)
        sage: gap.eval("C:=BestKnownLinearCode(10,5,GF(2))")           # long time; optional - gap_packages (Guava package)
        'a linear [10,5,4]2..4 shortened code'

    This means that the best possible binary linear code of length 10 and
    dimension 5 is a code with minimum distance 4 and covering radius s somewhere
    between 2 and 4. Use ``bounds_on_minimum_distance_in_guava(10,5,GF(2))``
    for further details.
    """
    if not is_package_installed('gap_packages'):
        raise PackageNotFoundError('gap_packages')
    gap.load_package("guava")
    q = F.order()
    C = gap("BestKnownLinearCode(%s,%s,GF(%s))"%(n,k,q))
    from .linear_code import LinearCode
    return LinearCode(C.GeneratorMat()._matrix_(F))
Example #2
0
def best_linear_code_in_guava(n, k, F):
    r"""
    Returns the linear code of length ``n``, dimension ``k`` over field ``F``
    with the maximal minimum distance which is known to the GAP package GUAVA.

    The function uses the tables described in ``bounds_on_minimum_distance_in_guava`` to
    construct this code. This requires the optional GAP package GUAVA.

    INPUT:

    - ``n`` -- the length of the code to look up

    - ``k`` -- the dimension of the code to look up

    - ``F`` -- the base field of the code to look up


    OUTPUT:

    - A :class:`LinearCode` which is a best linear code of the given parameters known to GUAVA.

    EXAMPLES::

        sage: codes.databases.best_linear_code_in_guava(10,5,GF(2))    # long time; optional - gap_packages (Guava package)
        [10, 5] linear code over GF(2)
        sage: gap.eval("C:=BestKnownLinearCode(10,5,GF(2))")           # long time; optional - gap_packages (Guava package)
        'a linear [10,5,4]2..4 shortened code'

    This means that the best possible binary linear code of length 10 and
    dimension 5 is a code with minimum distance 4 and covering radius s somewhere
    between 2 and 4. Use ``bounds_on_minimum_distance_in_guava(10,5,GF(2))``
    for further details.
    """
    if not is_package_installed('gap_packages'):
        raise PackageNotFoundError('gap_packages')
    gap.load_package("guava")
    q = F.order()
    C = gap("BestKnownLinearCode(%s,%s,GF(%s))" % (n, k, q))
    from .linear_code import LinearCode
    return LinearCode(C.GeneratorMat()._matrix_(F))
Example #3
0
    def solve(self,state, algorithm='default'):
        r"""
        Solves the cube in the ``state``, given as a dictionary
        as in ``legal``. See the ``solve`` method
        of the RubiksCube class for more details.

        This may use GAP's ``EpimorphismFromFreeGroup`` and
        ``PreImagesRepresentative`` as explained below, if
        'gap' is passed in as the algorithm.

        This algorithm

        #. constructs the free group on 6 generators then computes a
           reasonable set of relations which they satisfy

        #. computes a homomorphism from the cube group to this free group
           quotient

        #. takes the cube position, regarded as a group element, and maps
           it over to the free group quotient

        #. using those relations and tricks from combinatorial group theory
           (stabilizer chains), solves the "word problem" for that element.

        #. uses python string parsing to rewrite that in cube notation.

        The Rubik's cube group has about `4.3 \times 10^{19}`
        elements, so this process is time-consuming. See
        http://www.gap-system.org/Doc/Examples/rubik.html for an
        interesting discussion of some GAP code analyzing the Rubik's
        cube.

        EXAMPLES::

            sage: rubik = CubeGroup()
            sage: state = rubik.faces("R")
            sage: rubik.solve(state)
            'R'
            sage: state = rubik.faces("R*U")
            sage: rubik.solve(state, algorithm='gap')       # long time
            'R*U'

        You can also check this another (but similar) way using the
        ``word_problem`` method (eg, G = rubik.group(); g =
        G("(3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28)");
        g.word_problem([b,d,f,l,r,u]), though the output will be less
        intuitive).
        """
        from sage.groups.perm_gps.permgroup import PermutationGroup
        from sage.interfaces.all import gap
        G = self.group()
        try:
            g = self.parse(state)
        except TypeError:
            return "Illegal or syntactically incorrect state. No solution."
        if algorithm != 'gap':
            C = RubiksCube(g)
            return C.solve(algorithm)

        hom = G._gap_().EpimorphismFromFreeGroup()
        soln = hom.PreImagesRepresentative(gap(str(g)))
        # print soln
        sol = str(soln)
        names = self.gen_names()
        for i in range(6):
            sol = sol.replace("x%s" % (i+1), names[i])
        return sol
Example #4
0
    def solve(self, state, algorithm='default'):
        r"""
        Solves the cube in the ``state``, given as a dictionary
        as in ``legal``. See the ``solve`` method
        of the RubiksCube class for more details.

        This may use GAP's ``EpimorphismFromFreeGroup`` and
        ``PreImagesRepresentative`` as explained below, if
        'gap' is passed in as the algorithm.

        This algorithm

        #. constructs the free group on 6 generators then computes a
           reasonable set of relations which they satisfy

        #. computes a homomorphism from the cube group to this free group
           quotient

        #. takes the cube position, regarded as a group element, and maps
           it over to the free group quotient

        #. using those relations and tricks from combinatorial group theory
           (stabilizer chains), solves the "word problem" for that element.

        #. uses python string parsing to rewrite that in cube notation.

        The Rubik's cube group has about `4.3 \times 10^{19}`
        elements, so this process is time-consuming. See
        http://www.gap-system.org/Doc/Examples/rubik.html for an
        interesting discussion of some GAP code analyzing the Rubik's
        cube.

        EXAMPLES::

            sage: rubik = CubeGroup()
            sage: state = rubik.faces("R")
            sage: rubik.solve(state)
            'R'
            sage: state = rubik.faces("R*U")
            sage: rubik.solve(state, algorithm='gap')       # long time
            'R*U'

        You can also check this another (but similar) way using the
        ``word_problem`` method (eg, G = rubik.group(); g =
        G("(3,38,43,19)(5,36,45,21)(8,33,48,24)(25,27,32,30)(26,29,31,28)");
        g.word_problem([b,d,f,l,r,u]), though the output will be less
        intuitive).
        """
        from sage.groups.perm_gps.permgroup import PermutationGroup
        from sage.interfaces.all import gap
        G = self.group()
        try:
            g = self.parse(state)
        except TypeError:
            return "Illegal or syntactically incorrect state. No solution."
        if algorithm != 'gap':
            C = RubiksCube(g)
            return C.solve(algorithm)

        hom = G._gap_().EpimorphismFromFreeGroup()
        soln = hom.PreImagesRepresentative(gap(str(g)))
        # print soln
        sol = str(soln)
        names = self.gen_names()
        for i in range(6):
            sol = sol.replace("x%s" % (i + 1), names[i])
        return sol