def Origami(r,
            u,
            sparse=False,
            check=True,
            as_tuple=False,
            positions=None,
            name=None):
    r"""
    Constructor for origami

    INPUT:

    - ``r``, ``u`` - two permutations

    - ``sparse`` - boolean (default: False)

    - ``check`` - boolean (default: True) - whether or not check the input

    - ``as_tuple`` - boolean (default: False) - if True, assume that ``r`` and
      ``u`` are tuples on [0,...,N-1] (time efficient)

    - ``positions`` - list of 2-tuples (default: None) - position of the squares
      for drawings

    - ``name`` - an optional name to the origami

    """
    if not as_tuple:
        r = PermutationGroupElement(r, check=check)
        u = PermutationGroupElement(u, check=check)

        r = [i - 1 for i in r.domain()]
        u = [i - 1 for i in u.domain()]

        N = max(len(r), len(u))
        r.extend(xrange(len(r), N))
        u.extend(xrange(len(u), N))

    elif check:
        sr = set(r)
        su = set(u)
        N = len(r)
        if len(u) != N:
            raise ValueError("the two tuples must be of the same length")
        for i in xrange(N):
            if not i in sr:
                raise ValueError("%d is not in r=%s" % (i, str(r)))
            if not i in su:
                raise ValueError("%d is not in u=%s" % (i, str(u)))

    o = Origami_dense_pyx(tuple(r), tuple(u))

    if check and not o.is_connected():
        print "Warning: the origami is not connected"

    if name is not None:
        o.rename(name)
    if positions is not None:
        o.set_positions(positions)
    return o
Exemple #2
0
def Origami(r, u,
        sparse=False,
        check=True,
        as_tuple=False,
        positions=None, name=None):
    r"""
    Constructor for origami

    INPUT:

    - ``r``, ``u`` - two permutations

    - ``sparse`` - boolean (default: False)

    - ``check`` - boolean (default: True) - whether or not check the input

    - ``as_tuple`` - boolean (default: False) - if True, assume that ``r`` and
      ``u`` are tuples on [0,...,N-1] (time efficient)

    - ``positions`` - list of 2-tuples (default: None) - position of the squares
      for drawings

    - ``name`` - an optional name to the origami

    """
    if not as_tuple:
        r = PermutationGroupElement(r, check=check)
        u = PermutationGroupElement(u, check=check)

        r = [i-1 for i in r.domain()]
        u = [i-1 for i in u.domain()]

        N = max(len(r),len(u))
        r.extend(xrange(len(r),N))
        u.extend(xrange(len(u),N))

    elif check:
        sr = set(r)
        su = set(u)
        N = len(r)
        if len(u) != N:
            raise ValueError("the two tuples must be of the same length")
        for i in xrange(N):
            if not i in sr:
                raise ValueError("%d is not in r=%s" %(i,str(r)))
            if not i in su:
                raise ValueError("%d is not in u=%s" %(i,str(u)))

    o = Origami_dense_pyx(tuple(r),tuple(u))

    if check and not o.is_connected():
        print "Warning: the origami is not connected"

    if name is not None:
        o.rename(name)
    if positions is not None:
        o.set_positions(positions)
    return o
    def g(self,i=None):
        r"""
        Return the ``i``-th permutation that defines this pillowcase cover.
        """
        if i is None:
            return self.g(0), self.g(1), self.g(2), self.g(3)

        i = int(i)
        if i < 0 or i > 3:
            raise IndexError("the index i (={}) must be in {{0,1,2,3}}".format(i))

        return PermutationGroupElement([j+1 for j in self.g_tuple(i)], check=False)
def PillowcaseCover(g0, g1, g2, g3=None,
        sparse=False,
        check=True,
        as_tuple=False,
        positions=None, name=None):
    r"""
    Pillowcase cover constructor.
    """
    if not as_tuple:
        g0 = PermutationGroupElement(g0, check=check)
        g1 = PermutationGroupElement(g1, check=check)
        g2 = PermutationGroupElement(g2, check=check)
        if g3 is None:
            g3 = (~g2) * (~g1) * (~g0)
        else:
            g3 = PermutationGroupElement(g3, check=check)

        g0 = [i-1 for i in g0.domain()]
        g1 = [i-1 for i in g1.domain()]
        g2 = [i-1 for i in g2.domain()]
        g3 = [i-1 for i in g3.domain()]

        N = max([len(g0),len(g1),len(g2),len(g3)])
        g0.extend(xrange(len(g0),N))
        g1.extend(xrange(len(g1),N))
        g2.extend(xrange(len(g2),N))
        g3.extend(xrange(len(g3),N))

    elif check:
        s0 = set(g0)
        s1 = set(g1)
        s2 = set(g2)
        s3 = set(g3)
        N = len(g0)
        if len(g1) != N or len(g2) != N or len(g3) != N:
            raise ValueError("the four tuples must be of the same length")
        for i in xrange(N):
            if not i in g0:
                raise ValueError("%d is not in g0=%s" %(i,str(g0)))
            if not i in g1:
                raise ValueError("%d is not in g1=%s" %(i,str(g1)))
            if not i in g2:
                raise ValueError("%d is not in g2=%s"%(i,str(g2)))
            if not i in g3:
                raise ValueError("%d is not in g3=%s"%(i,str(g3)))

    pcc = PillowcaseCover_dense(tuple(g0),tuple(g1),tuple(g2),tuple(g3))

    if name is not None:
        pcc.rename(name)
#    if positions is not None:
#        o.set_positions(positions)
    if check:
        pcc._check()
    return pcc