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

Commit

Permalink
First version of linear transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
jplab authored and Jonathan Kliem committed Jan 24, 2020
1 parent dde78cb commit a521ca7
Showing 1 changed file with 61 additions and 2 deletions.
63 changes: 61 additions & 2 deletions src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import itertools
import six
from sage.structure.element import Element, coerce_binop, is_Vector
from sage.structure.element import Element, coerce_binop, is_Vector, is_Matrix
from sage.structure.richcmp import rich_to_bool, op_NE
from sage.cpython.string import bytes_to_str

Expand Down Expand Up @@ -4270,6 +4270,61 @@ def dilation(self, scalar):
parent = self.parent().base_extend(scalar)
return parent.element_class(parent, [new_vertices, new_rays, new_lines], None)

def linear_transformation(self, linear_transf):
"""
Return the linear transformation of ``self``.
INPUT:
- ``linear_transf`` -- a matrix, not necessarily in :meth:`base_ring`
OUTPUT:
The polyhedron transformed by that matrix, possibly coerced to a
bigger base ring.
EXAMPLES::
sage: b3 = polytopes.Birkhoff_polytope(3)
sage: proj_mat=matrix([[0,1,0,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0],[0,0,0,0,0,1,0,0,0],[0,0,0,0,0,0,0,1,0]])
sage: b3_proj = proj_mat * b3; b3_proj
A 3-dimensional polyhedron in ZZ^4 defined as the convex hull of 5 vertices
sage: square = polytopes.regular_polygon(4)
sage: square.vertices_list()
[[0, -1], [1, 0], [-1, 0], [0, 1]]
sage: transf = matrix([[1,1],[0,1]])
sage: sheared = transf * square
sage: sheared.vertices_list()
[[-1, 0], [-1, -1], [1, 1], [1, 0]]
sage: sheared == square.linear_transformation(transf)
True
TESTS:
Linear transformation respects backend::
sage: P = polytopes.simplex(backend='field')
sage: t = matrix([[1,1,1,1],[0,1,1,1],[0,0,1,1],[0,0,0,1]])
sage: P.linear_transformation(t).backend()
'field'
"""
if not linear_transf.is_zero():
new_vertices = [ list(linear_transf*v.vector()) for v in self.vertex_generator() ]
new_rays = [ list(linear_transf*r.vector()) for r in self.ray_generator() ]
new_lines = [ list(linear_transf*l.vector()) for l in self.line_generator() ]
else:
new_vertices = [ self.ambient_space().zero() for v in self.vertex_generator() ]
new_rays = []
new_lines = []

par = self.parent()
new_dim = linear_transf.nrows()
new_br = par.base_extend(linear_transf.base_ring()).base_ring()
new_parent = par.parent()(new_br,new_dim,self.backend())

return new_parent.element_class(new_parent, [new_vertices, new_rays, new_lines], None)

def _acted_upon_(self, actor, self_on_left):
"""
Implement the multiplicative action by scalars or other polyhedra.
Expand All @@ -4296,11 +4351,15 @@ def _acted_upon_(self, actor, self_on_left):
True
sage: p + vector(ZZ,[1,2,3]) == p.translation([1,2,3])
True
sage: matrix(ZZ,[[1,2,3]]) * p
A 1-dimensional polyhedron in ZZ^1 defined as the convex hull of 2 vertices
"""
if is_Polyhedron(actor):
return self.product(actor)
if is_Vector(actor):
elif is_Vector(actor):
return self.translation(actor)
elif is_Matrix(actor):
return self.linear_transformation(actor)
else:
return self.dilation(actor)

Expand Down

0 comments on commit a521ca7

Please sign in to comment.