def cross_polytope(self, dim_n): """ Return a cross-polytope in dimension ``dim_n``. These are the generalization of the octahedron. INPUT: - ``dim_n`` -- integer. The dimension of the cross-polytope. OUTPUT: A Polyhedron object of the ``dim_n``-dimensional cross-polytope, with exact coordinates. EXAMPLES:: sage: four_cross = polytopes.cross_polytope(4) sage: four_cross.is_simple() False sage: four_cross.n_vertices() 8 """ verts = permutations([0 for i in range(dim_n-1)] + [1]) verts = verts + permutations([0 for i in range(dim_n-1)] + [-1]) return Polyhedron(vertices=verts)
def six_hundred_cell(self): """ Return the standard 600-cell polytope. OUTPUT: A Polyhedron object of the 4-dimensional 600-cell, a regular polytope. In many ways this is an analogue of the icosahedron. The coordinates of this polytope are rational approximations of the true coordinates of the 600-cell, some of which involve the (irrational) golden ratio. EXAMPLES:: sage: p600 = polytopes.six_hundred_cell() # not tested - very long time sage: len(list(p600.bounded_edges())) # not tested - very long time 120 """ verts = [] q12 = QQ(1) / 2 base = [q12, q12, q12, q12] for i in range(2): for j in range(2): for k in range(2): for l in range(2): verts.append([x for x in base]) base[3] = base[3] * (-1) base[2] = base[2] * (-1) base[1] = base[1] * (-1) base[0] = base[0] * (-1) for x in permutations([0, 0, 0, 1]): verts.append(x) for x in permutations([0, 0, 0, -1]): verts.append(x) g = QQ(1618033) / 1000000 # Golden ratio approximation verts = verts + [ i([q12, g / 2, 1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([q12, g / 2, -1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([q12, -g / 2, 1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([q12, -g / 2, -1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([-q12, g / 2, 1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([-q12, g / 2, -1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([-q12, -g / 2, 1 / (g * 2), 0]) for i in AlternatingGroup(4) ] verts = verts + [ i([-q12, -g / 2, -1 / (g * 2), 0]) for i in AlternatingGroup(4) ] return Polyhedron(vertices=verts)
def cross_polytope(self, dim_n): """ Return a cross-polytope in dimension ``dim_n``. These are the generalization of the octahedron. INPUT: - ``dim_n`` -- integer. The dimension of the cross-polytope. OUTPUT: A Polyhedron object of the ``dim_n``-dimensional cross-polytope, with exact coordinates. EXAMPLES:: sage: four_cross = polytopes.cross_polytope(4) sage: four_cross.is_simple() False sage: four_cross.n_vertices() 8 """ verts = permutations([0 for i in range(dim_n - 1)] + [1]) verts = verts + permutations([0 for i in range(dim_n - 1)] + [-1]) return Polyhedron(vertices=verts)
def permutahedron(self, n, project = True): """ The standard permutahedron of (1,...,n) projected into n-1 dimensions. INPUT: - ``n`` -- the numbers ``(1,...,n)`` are permuted - ``project`` -- If ``False`` the polyhedron is left in dimension ``n``. OUTPUT: A Polyhedron object representing the permutahedron. EXAMPLES:: sage: perm4 = polytopes.permutahedron(4) sage: perm4 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices sage: polytopes.permutahedron(5).show() # long time """ verts = range(1,n+1) verts = permutations(verts) if project: verts = [Polytopes.project_1(x) for x in verts] p = Polyhedron(vertices=verts) return p
def hypersimplex(self, dim_n, k, project = True): """ The hypersimplex in dimension dim_n with d choose k vertices, projected into (dim_n - 1) dimensions. INPUT: - ``n`` -- the numbers ``(1,...,n)`` are permuted - ``project`` -- If ``False``, the polyhedron is left in dimension ``n``. OUTPUT: A Polyhedron object representing the hypersimplex. EXAMPLES:: sage: h_4_2 = polytopes.hypersimplex(4,2) # combinatorially equivalent to octahedron sage: h_4_2.n_vertices() 6 sage: h_4_2.n_inequalities() 8 """ vert0 = [0]*(dim_n-k) + [1]*k verts = permutations(vert0) if project: verts = [Polytopes.project_1(x) for x in verts] return Polyhedron(vertices=verts)
def n_simplex(self, dim_n=3, project = True): """ Return a rational approximation to a regular simplex in dimension ``dim_n``. INPUT: - ``dim_n`` -- The dimension of the cross-polytope, a positive integer. - ``project`` -- Optional argument, whether to project orthogonally. Default is True. OUTPUT: A Polyhedron object of the ``dim_n``-dimensional simplex. EXAMPLES:: sage: s5 = polytopes.n_simplex(5) sage: s5.dim() 5 """ verts = permutations([0 for i in range(dim_n)] + [1]) if project: verts = [Polytopes.project_1(x) for x in verts] return Polyhedron(vertices=verts)
def permutahedron(self, n, project=True): """ The standard permutahedron of (1,...,n) projected into n-1 dimensions. INPUT: - ``n`` -- the numbers ``(1,...,n)`` are permuted - ``project`` -- If ``False`` the polyhedron is left in dimension ``n``. OUTPUT: A Polyhedron object representing the permutahedron. EXAMPLES:: sage: perm4 = polytopes.permutahedron(4) sage: perm4 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices sage: polytopes.permutahedron(5).show() # long time """ verts = range(1, n + 1) verts = permutations(verts) if project: verts = [Polytopes.project_1(x) for x in verts] p = Polyhedron(vertices=verts) return p
def hypersimplex(self, dim_n, k, project=True): """ The hypersimplex in dimension dim_n with d choose k vertices, projected into (dim_n - 1) dimensions. INPUT: - ``n`` -- the numbers ``(1,...,n)`` are permuted - ``project`` -- If ``False``, the polyhedron is left in dimension ``n``. OUTPUT: A Polyhedron object representing the hypersimplex. EXAMPLES:: sage: h_4_2 = polytopes.hypersimplex(4,2) # combinatorially equivalent to octahedron sage: h_4_2.n_vertices() 6 sage: h_4_2.n_inequalities() 8 """ vert0 = [0] * (dim_n - k) + [1] * k verts = permutations(vert0) if project: verts = [Polytopes.project_1(x) for x in verts] return Polyhedron(vertices=verts)
def n_simplex(self, dim_n=3, project=True): """ Return a rational approximation to a regular simplex in dimension ``dim_n``. INPUT: - ``dim_n`` -- The dimension of the cross-polytope, a positive integer. - ``project`` -- Optional argument, whether to project orthogonally. Default is True. OUTPUT: A Polyhedron object of the ``dim_n``-dimensional simplex. EXAMPLES:: sage: s5 = polytopes.n_simplex(5) sage: s5.dim() 5 """ verts = permutations([0 for i in range(dim_n)] + [1]) if project: verts = [Polytopes.project_1(x) for x in verts] return Polyhedron(vertices=verts)
def six_hundred_cell(self): """ Return the standard 600-cell polytope. OUTPUT: A Polyhedron object of the 4-dimensional 600-cell, a regular polytope. In many ways this is an analogue of the icosahedron. The coordinates of this polytope are rational approximations of the true coordinates of the 600-cell, some of which involve the (irrational) golden ratio. EXAMPLES:: sage: p600 = polytopes.six_hundred_cell() # not tested - very long time sage: len(list(p600.bounded_edges())) # not tested - very long time 120 """ verts = [] q12 = QQ(1)/2 base = [q12,q12,q12,q12] for i in range(2): for j in range(2): for k in range(2): for l in range(2): verts.append([x for x in base]) base[3] = base[3]*(-1) base[2] = base[2]*(-1) base[1] = base[1]*(-1) base[0] = base[0]*(-1) for x in permutations([0,0,0,1]): verts.append(x) for x in permutations([0,0,0,-1]): verts.append(x) g = QQ(1618033)/1000000 # Golden ratio approximation verts = verts + [i([q12,g/2,1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([q12,g/2,-1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([q12,-g/2,1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([q12,-g/2,-1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([-q12,g/2,1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([-q12,g/2,-1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([-q12,-g/2,1/(g*2),0]) for i in AlternatingGroup(4)] verts = verts + [i([-q12,-g/2,-1/(g*2),0]) for i in AlternatingGroup(4)] return Polyhedron(vertices=verts)
def twenty_four_cell(self): """ Return the standard 24-cell polytope. OUTPUT: A Polyhedron object of the 4-dimensional 24-cell, a regular polytope. The coordinates of this polytope are exact. EXAMPLES:: sage: p24 = polytopes.twenty_four_cell() sage: v = p24.vertex_generator().next() sage: for adj in v.neighbors(): print adj A vertex at (-1/2, -1/2, -1/2, 1/2) A vertex at (-1/2, -1/2, 1/2, -1/2) A vertex at (-1, 0, 0, 0) A vertex at (-1/2, 1/2, -1/2, -1/2) A vertex at (0, -1, 0, 0) A vertex at (0, 0, -1, 0) A vertex at (0, 0, 0, -1) A vertex at (1/2, -1/2, -1/2, -1/2) """ verts = [] q12 = QQ(1)/2 base = [q12,q12,q12,q12] for i in range(2): for j in range(2): for k in range(2): for l in range(2): verts.append([x for x in base]) base[3] = base[3]*(-1) base[2] = base[2]*(-1) base[1] = base[1]*(-1) base[0] = base[0]*(-1) verts = verts + permutations([0,0,0,1]) verts = verts + permutations([0,0,0,-1]) return Polyhedron(vertices=verts)
def twenty_four_cell(self): """ Return the standard 24-cell polytope. OUTPUT: A Polyhedron object of the 4-dimensional 24-cell, a regular polytope. The coordinates of this polytope are exact. EXAMPLES:: sage: p24 = polytopes.twenty_four_cell() sage: v = p24.vertex_generator().next() sage: for adj in v.neighbors(): print adj A vertex at (-1/2, -1/2, -1/2, 1/2) A vertex at (-1/2, -1/2, 1/2, -1/2) A vertex at (-1, 0, 0, 0) A vertex at (-1/2, 1/2, -1/2, -1/2) A vertex at (0, -1, 0, 0) A vertex at (0, 0, -1, 0) A vertex at (0, 0, 0, -1) A vertex at (1/2, -1/2, -1/2, -1/2) """ verts = [] q12 = QQ(1) / 2 base = [q12, q12, q12, q12] for i in range(2): for j in range(2): for k in range(2): for l in range(2): verts.append([x for x in base]) base[3] = base[3] * (-1) base[2] = base[2] * (-1) base[1] = base[1] * (-1) base[0] = base[0] * (-1) verts = verts + permutations([0, 0, 0, 1]) verts = verts + permutations([0, 0, 0, -1]) return Polyhedron(vertices=verts)
def Birkhoff_polytope(self, n): """ Return the Birkhoff polytope with n! vertices. Each vertex is a (flattened) n by n permutation matrix. INPUT: - ``n`` -- a positive integer giving the size of the permutation matrices. EXAMPLES:: sage: b3 = polytopes.Birkhoff_polytope(3) sage: b3.n_vertices() 6 """ perms = permutations(range(1, n + 1)) verts = [] for p in perms: verts += [[Polytopes._pfunc(i, j, p) for j in range(1, n + 1) for i in range(1, n + 1)]] return Polyhedron(vertices=verts)
def Birkhoff_polytope(self, n): """ Return the Birkhoff polytope with n! vertices. Each vertex is a (flattened) n by n permutation matrix. INPUT: - ``n`` -- a positive integer giving the size of the permutation matrices. EXAMPLES:: sage: b3 = polytopes.Birkhoff_polytope(3) sage: b3.n_vertices() 6 """ perms = permutations(range(1,n+1)) verts = [] for p in perms: verts += [ [Polytopes._pfunc(i,j,p) for j in range(1,n+1) for i in range(1,n+1) ] ] return Polyhedron(vertices=verts)