def _get_action_(self, other, op, self_is_left): """ EXAMPLES:: sage: A = FormalSums(RR).get_action(RR); A # indirect doctest Right scalar multiplication by Real Field with 53 bits of precision on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision sage: A = FormalSums(ZZ).get_action(QQ); A Right scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field with precomposition on left by Conversion map: From: Abelian Group of all Formal Finite Sums over Integer Ring To: Abelian Group of all Formal Finite Sums over Rational Field sage: A = FormalSums(QQ).get_action(ZZ); A Right scalar multiplication by Integer Ring on Abelian Group of all Formal Finite Sums over Rational Field """ if op is operator.mul and isinstance(other, Parent): extended = self.base_extend(other) if self_is_left: action = RightModuleAction(other, extended) if extended is not self: action = PrecomposedAction( action, extended._internal_coerce_map_from(self), None) else: action = LeftModuleAction(other, extended) if extended is not self: action = PrecomposedAction( action, None, extended._internal_coerce_map_from(self)) return action
def get_action_impl(self, other, op, self_is_left): """ EXAMPLES:: sage: A = FormalSums(RR).get_action(RR); A Right scalar multiplication by Real Field with 53 bits of precision on Abelian Group of all Formal Finite Sums over Real Field with 53 bits of precision sage: A = FormalSums(ZZ).get_action(QQ); A Right scalar multiplication by Rational Field on Abelian Group of all Formal Finite Sums over Rational Field with precomposition on left by Call morphism: From: Abelian Group of all Formal Finite Sums over Integer Ring To: Abelian Group of all Formal Finite Sums over Rational Field sage: A = FormalSums(QQ).get_action(ZZ); A Right scalar multiplication by Integer Ring on Abelian Group of all Formal Finite Sums over Rational Field """ import operator from sage.structure.coerce import LeftModuleAction, RightModuleAction from sage.categories.action import PrecomposedAction if op is operator.mul and isinstance(other, Parent): extended = self.base_extend(other) if self_is_left: action = RightModuleAction(other, extended) if extended is not self: action = PrecomposedAction(action, extended.coerce_map_from(self), None) else: action = LeftModuleAction(other, extended) if extended is not self: action = PrecomposedAction(action, None, extended.coerce_map_from(self)) return action
def _get_action_(self, other, op, self_is_left): """ Register actions with the coercion model. The monoid actions are Minkowski sum and Cartesian product. In addition, we want multiplication by a scalar to be dilation and addition by a vector to be translation. This is implemented as an action in the coercion model. INPUT: - ``other`` -- a scalar or a vector. - ``op`` -- the operator. - ``self_is_left`` -- boolean. Whether ``self`` is on the left of the operator. OUTPUT: An action that is used by the coercion model. EXAMPLES:: sage: from sage.geometry.polyhedron.parent import Polyhedra sage: PZZ2 = Polyhedra(ZZ, 2) sage: PZZ2.get_action(ZZ) # indirect doctest Right action by Integer Ring on Polyhedra in ZZ^2 sage: PZZ2.get_action(QQ) Right action by Rational Field on Polyhedra in QQ^2 with precomposition on left by Conversion map: From: Polyhedra in ZZ^2 To: Polyhedra in QQ^2 with precomposition on right by Identity endomorphism of Rational Field sage: PQQ2 = Polyhedra(QQ, 2) sage: PQQ2.get_action(ZZ) Right action by Integer Ring on Polyhedra in QQ^2 sage: PQQ2.get_action(QQ) Right action by Rational Field on Polyhedra in QQ^2 sage: Polyhedra(ZZ,2).an_element() * 2 A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: Polyhedra(ZZ,2).an_element() * (2/3) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: Polyhedra(QQ,2).an_element() * 2 A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: Polyhedra(QQ,2).an_element() * (2/3) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: 2 * Polyhedra(ZZ,2).an_element() A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: (2/3) * Polyhedra(ZZ,2).an_element() A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: 2 * Polyhedra(QQ,2).an_element() A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: (2/3) * Polyhedra(QQ,2).an_element() A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices sage: from sage.geometry.polyhedron.parent import Polyhedra sage: PZZ2.get_action(ZZ^2, op=operator.add) Right action by Ambient free module of rank 2 over the principal ideal domain Integer Ring on Polyhedra in ZZ^2 with precomposition on left by Identity endomorphism of Polyhedra in ZZ^2 with precomposition on right by Generic endomorphism of Ambient free module of rank 2 over the principal ideal domain Integer Ring """ import operator from sage.structure.coerce_actions import ActedUponAction from sage.categories.action import PrecomposedAction if op is operator.add and is_FreeModule(other): base_ring = self._coerce_base_ring(other) extended_self = self.base_extend(base_ring) extended_other = other.base_extend(base_ring) action = ActedUponAction(extended_other, extended_self, not self_is_left) if self_is_left: action = PrecomposedAction( action, extended_self._internal_coerce_map_from(self).__copy__(), extended_other._internal_coerce_map_from(other).__copy__()) else: action = PrecomposedAction( action, extended_other._internal_coerce_map_from(other).__copy__(), extended_self._internal_coerce_map_from(self).__copy__()) return action if op is operator.mul and is_CommutativeRing(other): ring = self._coerce_base_ring(other) if ring is self.base_ring(): return ActedUponAction(other, self, not self_is_left) extended = self.base_extend(ring) action = ActedUponAction(ring, extended, not self_is_left) if self_is_left: action = PrecomposedAction( action, extended._internal_coerce_map_from(self).__copy__(), ring._internal_coerce_map_from(other).__copy__()) else: action = PrecomposedAction( action, ring._internal_coerce_map_from(other).__copy__(), extended._internal_coerce_map_from(self).__copy__()) return action