Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
methods disjoint_union and union
Browse files Browse the repository at this point in the history
  • Loading branch information
yuan-zhou committed May 29, 2021
1 parent 27af45a commit cf7698c
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions src/sage/homology/polyhedral_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
:meth:`~PolyhedralComplex.boundary_subcomplex` | Return the boundary subcomplex of this polyhedral complex.
:meth:`~PolyhedralComplex.product` | Return the (Cartesian) product of this polyhedral complex with another one.
:meth:`~PolyhedralComplex.disjoint_union` | Return the disjoint union of this polyhedral complex with another one.
:meth:`~PolyhedralComplex.union` | Return the union of this polyhedral complex with another one.
:meth:`~PolyhedralComplex.join` | Return the join of this polyhedral complex with another one.
:meth:`~PolyhedralComplex.subdivide` | Return a new polyhedral complex (with option ``make_simplicial``) subdividing this one.
Expand Down Expand Up @@ -1613,16 +1614,48 @@ def disjoint_union(self, right):
EXAMPLES::
sage: p1 = Polyhedron(vertices=[(1, 1), (0, 0), (1, 2)])
sage: p2 = Polyhedron(vertices=[(1, 2), (0, 0), (0, 2)])
sage: p3 = Polyhedron(vertices=[(0, 0), (1, 1), (2, 0)])
sage: pc1 = PolyhedralComplex([p1, p3])
sage: pc2 = PolyhedralComplex([p2])
sage: pc = pc1.disjoint_union(pc2)
sage: set(pc.maximal_cell_iterator()) == set([p1, p2, p3])
sage: p1 = Polyhedron(vertices=[(-1, 0), (0, 0), (0, 1)])
sage: p2 = Polyhedron(vertices=[(0, -1), (0, 0), (1, 0)])
sage: p3 = Polyhedron(vertices=[(0, -1), (1, -1), (1, 0)])
sage: pc = PolyhedralComplex([p1]).disjoint_union(PolyhedralComplex([p3]))
sage: set(pc.maximal_cell_iterator()) == set([p1, p3])
True
sage: pc4 = Polyhedron(vertices=[(1, 1), (0, 0), (0, 2)])
sage: pc.disjoint_union(PolyhedralComplex([pc4]))
sage: pc.disjoint_union(PolyhedralComplex([p2]))
Traceback (most recent call last):
...
ValueError: The two complexes are not disjoint
"""
maximal_cells_self = list(self.maximal_cell_iterator())
maximal_cells_right = list(right.maximal_cell_iterator())
for cell in maximal_cells_self:
for cell_right in maximal_cells_right:
if not cell.intersection(cell_right).is_empty():
raise ValueError("The two complexes are not disjoint")
return PolyhedralComplex(maximal_cells_self + maximal_cells_right,
maximality_check=False,
face_to_face_check=False,
is_immutable=(self._is_immutable and
right._is_immutable),
backend=self._backend)

def union(self, right):
"""
The union of this polyhedral complex with another one.
:param right: the other polyhedral complex (the right-hand factor)
EXAMPLES::
sage: p1 = Polyhedron(vertices=[(-1, 0), (0, 0), (0, 1)])
sage: p2 = Polyhedron(vertices=[(0, -1), (0, 0), (1, 0)])
sage: p3 = Polyhedron(vertices=[(0, -1), (1, -1), (1, 0)])
sage: pc = PolyhedralComplex([p1]).union(PolyhedralComplex([p3]))
sage: set(pc.maximal_cell_iterator()) == set([p1, p3])
True
sage: pc.union(PolyhedralComplex([p2]))
Polyhedral complex with 3 maximal cells
sage: p4 = Polyhedron(vertices=[(0, -1), (0, 0), (1, 0), (1, -1)])
sage: pc.union(PolyhedralComplex([p4]))
Traceback (most recent call last):
...
ValueError: The given cells are not face-to-face
Expand Down

0 comments on commit cf7698c

Please sign in to comment.