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

Commit

Permalink
removed translation from direct sum
Browse files Browse the repository at this point in the history
  • Loading branch information
jplab committed Mar 2, 2018
1 parent b063975 commit d0242f3
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3123,61 +3123,55 @@ def subdirect_sum(self, other):

def direct_sum(self, other):
"""
Return the direct sum of ``self`` and ``other``. The direct sum of two
polyhedron is the subdirect sum of the two, when they have the origin
in their interior.
Return the direct sum of ``self`` and ``other``.
The direct sum of two polyhedron is the subdirect sum of the two, when
they have the origin in their interior. To avoid checking if the origin
is contained in both, we place the affine subspace containing ``other``
at the center of ``self``.
INPUT:
- ``other`` -- a :class:`Polyhedron_base`.
OUTPUT:
The direct sum of ``self`` and ``other`` with a suitable base ring to
encompass the two.
EXAMPLES::
sage: P1 = Polyhedron([[1],[2]], base_ring=ZZ)
sage: P2 = Polyhedron([[3],[4]], base_ring=QQ)
sage: ds = P1.direct_sum(P2);ds
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4
vertices
A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 4 vertices
sage: ds.vertices()
(A vertex at (-1/2, 0),
A vertex at (0, -1/2),
A vertex at (0, 1/2),
A vertex at (1/2, 0))
(A vertex at (1, 0),
A vertex at (2, 0),
A vertex at (3/2, -1/2),
A vertex at (3/2, 1/2))
.. SEEALSO::
:meth:`join`
:meth:`subdirect_sum`
"""
translated_self = self - self.center()
translated_other = other - other.center()

try:
new_ring = translated_self.parent()._coerce_base_ring(translated_other)
new_ring = self.parent()._coerce_base_ring(other)
except TypeError:
raise TypeError("no common canonical parent for objects with parents: " + str(translated_self.parent())
+ " and " + str(translated_other.parent()))
raise TypeError("no common canonical parent for objects with parents: " + str(self.parent())
+ " and " + str(other.parent()))

dim_self = translated_self.ambient_dim()
dim_other = translated_other.ambient_dim()
dim_self = self.ambient_dim()
dim_other = other.ambient_dim()

new_vertices = [list(x)+[0]*dim_other for x in translated_self.vertex_generator()] + \
[[0]*dim_self+list(x) for x in translated_other.vertex_generator()]
new_vertices = [list(x) + [0]*dim_other for x in self.vertex_generator()] + \
[list(self.center()) + list(x.vector() - other.center()) for x in other.vertex_generator()]
new_rays = []
new_rays.extend( [ r+[0]*dim_other
for r in translated_self.ray_generator() ] )
new_rays.extend( [ [0]*dim_self+r
for r in translated_other.ray_generator() ] )
new_rays.extend( [ r + [0]*dim_other
for r in self.ray_generator() ] )
new_rays.extend( [ [0]*dim_self + r
for r in other.ray_generator() ] )
new_lines = []
new_lines.extend( [ l+[0]*dim_other
for l in translated_self.line_generator() ] )
new_lines.extend( [ [0]*dim_self+l
for l in translated_other.line_generator() ] )
new_lines.extend( [ l + [0]*dim_other
for l in self.line_generator() ] )
new_lines.extend( [ [0]*dim_self + l
for l in other.line_generator() ] )
return Polyhedron(vertices=new_vertices,
rays=new_rays, lines=new_lines,
base_ring=new_ring)
Expand Down

0 comments on commit d0242f3

Please sign in to comment.