Skip to content

Commit

Permalink
Trac #28828: Attributes of polyhedra are exposed
Browse files Browse the repository at this point in the history
Currently the f_vector is exposed.

{{{
sage: P = polytopes.simplex()
sage: P.f_vector()[0] = 2
sage: P.f_vector()
(2, 4, 6, 4, 1)
}}}

Same applies for
- incidence matrix,
- vertex-facet graph,
- vertices matrix,
- vertex adjacency matrix,
- facet adjacency matrix,
- gale transform.

Some of the above are probably more relevant than others.

URL: https://trac.sagemath.org/28828
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Laith Rastanawi
  • Loading branch information
Release Manager committed Dec 24, 2019
2 parents cfea7e7 + a7eeece commit 9543202
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
75 changes: 63 additions & 12 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ def set_adjacent(h1, h2):
Hrep = face.ambient_Hrepresentation()
assert(len(Hrep) == codim+2)
set_adjacent(Hrep[-2], Hrep[-1])
M.set_immutable()
return M

def _vertex_adjacency_matrix(self):
Expand Down Expand Up @@ -342,6 +343,7 @@ def set_adjacent(v1, v2):
Vrep = face.ambient_Vrepresentation()
if len(Vrep) == 2:
set_adjacent(Vrep[0], Vrep[1])
M.set_immutable()
return M

def _delete(self):
Expand Down Expand Up @@ -634,10 +636,17 @@ def vertex_facet_graph(self, labels=True):
sage: H = O.vertex_facet_graph()
sage: G.is_isomorphic(H)
False
sage: G.reverse_edges(G.edges())
sage: G.is_isomorphic(H)
sage: G2 = copy(G)
sage: G2.reverse_edges(G2.edges())
sage: G2.is_isomorphic(H)
True
TESTS:
Check that :trac:`28828` is fixed::
sage: G._immutable
True
"""

# We construct the edges and remove the columns that have all 1s;
Expand All @@ -655,7 +664,7 @@ def vertex_facet_graph(self, labels=True):
if any(entry != 1 for entry in column)
for j in range(M.nrows()) if M[j, i] == 1]
G.add_edges(edges)
return G
return G.copy(immutable=True)

def plot(self,
point=None, line=None, polygon=None, # None means unspecified by the user
Expand Down Expand Up @@ -1916,13 +1925,21 @@ def vertices_matrix(self, base_ring=None):
Traceback (most recent call last):
...
TypeError: no conversion of this rational to integer
TESTS:
Check that :trac:`28828` is fixed::
sage: P.vertices_matrix().is_immutable()
True
"""
if base_ring is None:
base_ring = self.base_ring()
m = matrix(base_ring, self.ambient_dim(), self.n_vertices())
for i, v in enumerate(self.vertices()):
for j in range(self.ambient_dim()):
m[j, i] = v[j]
m.set_immutable()
return m

def ray_generator(self):
Expand Down Expand Up @@ -2298,6 +2315,13 @@ def vertex_adjacency_matrix(self):
(0, 1, 0, 0, 1) A vertex at (1, 0)
(0, 0, 0, 0, 1) A ray in the direction (1, 1)
(0, 0, 1, 1, 0) A vertex at (3, 0)
TESTS:
Check that :trac:`28828` is fixed::
sage: P.adjacency_matrix().is_immutable()
True
"""
return self._vertex_adjacency_matrix()

Expand Down Expand Up @@ -2372,6 +2396,13 @@ def facet_adjacency_matrix(self):
[1 1 0 1 1]
[1 1 1 0 1]
[1 1 1 1 0]
TESTS:
Check that :trac:`28828` is fixed::
sage: s4.facet_adjacency_matrix().is_immutable()
True
"""
return self._facet_adjacency_matrix()

Expand Down Expand Up @@ -2467,6 +2498,13 @@ def incidence_matrix(self):
[1 0 1]
[0 1 0]
[0 0 1]
TESTS:
Check that :trac:`28828` is fixed::
sage: R.incidence_matrix().is_immutable()
True
"""
incidence_matrix = matrix(ZZ, self.n_Vrepresentation(),
self.n_Hrepresentation(), 0)
Expand All @@ -2492,6 +2530,7 @@ def incidence_matrix(self):
if self._is_zero(Hvec*Vvec):
incidence_matrix[Vindex, Hindex] = 1

incidence_matrix.set_immutable()
return incidence_matrix

def base_ring(self):
Expand Down Expand Up @@ -3285,7 +3324,7 @@ def gale_transform(self):
sage: p = Polyhedron(vertices = [[0,0],[0,1],[1,0]])
sage: p2 = p.prism()
sage: p2.gale_transform()
[(1, 0), (0, 1), (-1, -1), (-1, 0), (0, -1), (1, 1)]
((1, 0), (0, 1), (-1, -1), (-1, 0), (0, -1), (1, 1))
REFERENCES:
Expand All @@ -3305,7 +3344,7 @@ def gale_transform(self):
[ [1]+x for x in self.vertex_generator()])
A = A.transpose()
A_ker = A.right_kernel()
return A_ker.basis_matrix().transpose().rows()
return tuple(A_ker.basis_matrix().transpose().rows())

@cached_method
def normal_fan(self, direction='inner'):
Expand Down Expand Up @@ -5535,6 +5574,13 @@ def f_vector(self):
(A vertex at (1, 0), A vertex at (-1, 0))
sage: P.f_vector()
(1, 0, 2, 1)
TESTS:
Check that :trac:`28828` is fixed::
sage: P.f_vector().is_immutable()
True
"""
return self.combinatorial_polyhedron().f_vector()

Expand Down Expand Up @@ -7515,10 +7561,7 @@ def combinatorial_automorphism_group(self, vertex_graph_only=False):
G = self.graph()
else:
G = self.vertex_facet_graph()
group = G.automorphism_group(edge_labels=True)
self._combinatorial_automorphism_group = group

return self._combinatorial_automorphism_group
return G.automorphism_group(edge_labels=True)

@cached_method
def restricted_automorphism_group(self, output="abstract"):
Expand Down Expand Up @@ -7668,14 +7711,14 @@ def restricted_automorphism_group(self, output="abstract"):
Permutation Group with generators [(1,2)]
sage: G = P.restricted_automorphism_group(output="matrixlist")
sage: G
[
(
[1 0 0 0 0 0] [ -87/55 -82/55 -2/5 38/55 98/55 12/11]
[0 1 0 0 0 0] [-142/55 -27/55 -2/5 38/55 98/55 12/11]
[0 0 1 0 0 0] [-142/55 -82/55 3/5 38/55 98/55 12/11]
[0 0 0 1 0 0] [-142/55 -82/55 -2/5 93/55 98/55 12/11]
[0 0 0 0 1 0] [-142/55 -82/55 -2/5 38/55 153/55 12/11]
[0 0 0 0 0 1], [ 0 0 0 0 0 1]
]
)
sage: g = AffineGroup(5, QQ)(G[1])
sage: g
[ -87/55 -82/55 -2/5 38/55 98/55] [12/11]
Expand Down Expand Up @@ -7746,6 +7789,11 @@ def restricted_automorphism_group(self, output="abstract"):
Traceback (most recent call last):
...
ValueError: unknown output 'foobar', valid values are ('abstract', 'permutation', 'matrix', 'matrixlist')
Check that :trac:`28828` is fixed::
sage: P.restricted_automorphism_group(output="matrixlist")[0].is_immutable()
True
"""
# The algorithm works as follows:
#
Expand Down Expand Up @@ -7860,8 +7908,11 @@ def edge_label(i, j, c_ij):
A = sum(V[perm(i)].column() * Vplus[i].row() for i in range(len(V)))
matrices.append(A + W)

for mat in matrices:
mat.set_immutable()

if output == "matrixlist":
return matrices
return tuple(matrices)
else:
return MatrixGroup(matrices)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,9 @@ cdef class CombinatorialPolyhedron(SageObject):
raise ValueError("could not determine f_vector")
from sage.modules.free_module_element import vector
from sage.rings.all import ZZ
return vector(ZZ, self._f_vector)
f_vector = vector(ZZ, self._f_vector)
f_vector.set_immutable()
return f_vector

def face_iter(self, dimension=None, dual=None):
r"""
Expand Down

0 comments on commit 9543202

Please sign in to comment.