本文整理汇总了Python中sage.modules.all.vector函数的典型用法代码示例。如果您正苦于以下问题:Python vector函数的具体用法?Python vector怎么用?Python vector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
def plot(self):
"""
Plot the lattice polygon.
OUTPUT:
A graphics object.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL
sage: P = LatticePolytope_PPL((1,0), (0,1), (0,0), (2,2))
sage: P.plot()
Graphics object consisting of 6 graphics primitives
sage: LatticePolytope_PPL([0], [1]).plot()
Graphics object consisting of 3 graphics primitives
sage: LatticePolytope_PPL([0]).plot()
Graphics object consisting of 2 graphics primitives
"""
from sage.plot.point import point2d
from sage.plot.polygon import polygon2d
vertices = self.ordered_vertices()
points = self.integral_points()
if self.space_dimension() == 1:
vertices = [vector(ZZ, (v[0], 0)) for v in vertices]
points = [vector(ZZ, (p[0], 0)) for p in points]
point_plot = sum(point2d(p, pointsize=100, color='red')
for p in points)
polygon_plot = polygon2d(vertices, alpha=0.2, color='green',
zorder=-1, thickness=2)
return polygon_plot + point_plot
示例2: _split_hyperbolic
def _split_hyperbolic(L) :
cur_cor = 2
Lcor = L + cur_cor * identity_matrix(L.nrows())
while not is_positive_definite(Lcor) :
cur_cor += 2
Lcor = L + cur_cor * identity_matrix(L.nrows())
a = FreeModule(ZZ, L.nrows()).gen(0)
if a * L * a >= 0 :
Lcor_length_inc = max(3, a * L * a)
cur_Lcor_length = Lcor_length_inc
while True :
short_vectors = flatten(QuadraticForm(Lcor).short_vector_list_up_to_length( a * Lcor * a )[cur_Lcor_length - Lcor_length_inc: cur_Lcor_length], max_level = 1)
for a in short_vectors :
if a * L * a < 0 :
break
else :
continue
break
n = -a * L * a // 2
short_vectors = E8.short_vector_list_up_to_length(n + 1)[-1]
for v in short_vectors :
for w in short_vectors :
if v * E8_gram * w == 2 * n - 1 :
LE8_mat = L.block_sum(E8_gram)
v_form = vector( list(a) + list(v) ) * LE8_mat
w_form = vector( list(a) + list(w) ) * LE8_mat
Lred_basis = matrix(ZZ, [v_form, w_form]).right_kernel().basis_matrix().transpose()
Lred_basis = matrix(ZZ, Lred_basis)
return Lred_basis.transpose() * LE8_mat * Lred_basis
示例3: _eval_restriction_vector
def _eval_restriction_vector(R, s, r, reduction_function) :
r"""
For each list rs in R compute the multiplicity of s r' = r, r' in rs.
INPUT:
- `R` -- A list of lists of vectors.
- `s` -- A vector of the same length.
- `r` -- An integer.
- ``reduction_function`` -- A function that takes a tuple representing an element in `L^\#`
and returs a pair of a reduced element in `L^\#` and a sign.
OUTPUT:
- A vector with integer entries that correspond to the elements
of R in the given order.
"""
if reduction_function is None :
return vector([ len([ rp for rp in rs if s.dot_product(rp) == r ])
for rs in R ])
else :
return vector([ sum( reduction_function(rp)[1] for rp in rs if s.dot_product(rp) == r )
for rs in R ])
示例4: get_homology_kernel
def get_homology_kernel(self, hecke_data = None):
verbose('Entering get_homology_kernel...')
verb = get_verbose()
set_verbose(0)
if hecke_data is None:
hecke_data = []
wp = self.wp()
Gn = self.large_group()
B = ArithHomology(self, ZZ**1, trivial_action = True)
C = HomologyGroup(Gn, ZZ**1, trivial_action = True)
group = B.group()
Bsp = B.space()
def phif(x):
ans = C(0)
for g, v in zip(group.gens(), x.values()):
if not self.use_shapiro():
ans += C((Gn(g), v))
else:
for a, ti in zip(v.values(), self.coset_reps()):
# We are considering a * (g tns t_i)
g0, _ = self.get_coset_ti( set_immutable(ti * g.quaternion_rep ))
ans += C((Gn(g0), a))
return ans
f = Bsp.hom([vector(C(phif(o))) for o in B.gens()])
def phig(x):
ans = C(0)
for g, v in zip(group.gens(), x.values()):
if not self.use_shapiro():
ans += C((Gn(wp**-1 * g.quaternion_rep * wp), v))
else:
for a, ti in zip(v.values(), self.coset_reps()):
# We are considering a * (g tns t_i)
g0, _ = self.get_coset_ti( set_immutable(ti * g.quaternion_rep ))
ans += C((Gn(wp**-1 * g0 * wp), a))
return ans
g = Bsp.hom([vector(C(phig(o))) for o in B.gens()])
maplist = [f, g]
for ell, T in hecke_data:
Aq = B.hecke_matrix(ell, with_torsion = True)
tmap = Bsp.hom([sum([ZZ(a) * o for a, o in zip(col, Bsp.gens())]) for col in T.charpoly()(Aq).columns()])
maplist.append(tmap)
fg = direct_sum_of_maps(maplist)
ker = fg.kernel()
try:
kerV = ker.V()
good_ker = [o.lift() for o,inv in zip(ker.gens(), ker.invariants()) if inv == 0]
except AttributeError:
kerV = ker
try:
good_ker = [kerV.lift(o) for o in ker.gens()]
except AttributeError:
good_ker = ker.gens()
kerVZ_amb = ZZ**(kerV.ambient_module().dimension())
kerVZ = kerVZ_amb.submodule([kerVZ_amb(o.denominator() * o) for o in kerV.basis()])
good_ker = kerVZ.span_of_basis([kerVZ((o.denominator() * o).change_ring(ZZ)) for o in good_ker])
good_ker = [B(o.denominator() * o) for o in good_ker.LLL().rows()]
set_verbose(verb)
verbose('Done with get_homology_kernel')
return good_ker
示例5: sector
def sector(ray1, ray2, **extra_options):
r"""
Plot a sector between ``ray1`` and ``ray2`` centered at the origin.
.. NOTE::
This function was intended for plotting strictly convex cones, so it
plots the smaller sector between ``ray1`` and ``ray2`` and, therefore,
they cannot be opposite. If you do want to use this function for bigger
regions, split them into several parts.
.. NOTE::
As of version 4.6 Sage does not have a graphic primitive for sectors in
3-dimensional space, so this function will actually approximate them
using polygons (the number of vertices used depends on the angle
between rays).
INPUT:
- ``ray1``, ``ray2`` -- rays in 2- or 3-dimensional space of the same
length;
- ``extra_options`` -- a dictionary of options that should be passed to
lower level plotting functions.
OUTPUT:
- a plot.
EXAMPLES::
sage: from sage.geometry.toric_plotter import sector
sage: sector((1,0), (0,1))
Graphics object consisting of 1 graphics primitive
sage: sector((3,2,1), (1,2,3))
Graphics3d Object
"""
ray1 = vector(RDF, ray1)
ray2 = vector(RDF, ray2)
r = ray1.norm()
if len(ray1) == 2:
# Plot an honest sector
phi1 = arctan2(ray1[1], ray1[0])
phi2 = arctan2(ray2[1], ray2[0])
if phi1 > phi2:
phi1, phi2 = phi2, phi1
if phi2 - phi1 > pi:
phi1, phi2 = phi2, phi1 + 2 * pi
return disk((0,0), r, (phi1, phi2), **extra_options)
else:
# Plot a polygon, 30 vertices per radian.
vertices_per_radian = 30
n = ceil(arccos(ray1 * ray2 / r**2) * vertices_per_radian)
dr = (ray2 - ray1) / n
points = (ray1 + i * dr for i in range(n + 1))
points = [r / pt.norm() * pt for pt in points]
points.append(vector(RDF, 3))
return polygon(points, **extra_options)
示例6: homogenize
def homogenize(inhomog, degree):
e = tuple(hom._A * vector(ZZ,[inhomog[x], inhomog[y]]) + degree * hom._b)
result = list(inhomog)
for i, var in enumerate(variables):
result[R.gens().index(var)] = e[i]
result = vector(ZZ, result)
result.set_immutable()
return result
示例7: fan
def fan(self, origin=None):
r"""
Construct the fan of cones over the simplices of the triangulation.
INPUT:
- ``origin`` -- ``None`` (default) or coordinates of a
point. The common apex of all cones of the fan. If ``None``,
the triangulation must be a star triangulation and the
distinguished central point is used as the origin.
OUTPUT:
A :class:`~sage.geometry.fan.RationalPolyhedralFan`. The
coordinates of the points are shifted so that the apex of the
fan is the origin of the coordinate system.
.. note:: If the set of cones over the simplices is not a fan, a
suitable exception is raised.
EXAMPLES::
sage: pc = PointConfiguration([(0,0), (1,0), (0,1), (-1,-1)], star=0, fine=True)
sage: triangulation = pc.triangulate()
sage: fan = triangulation.fan(); fan
Rational polyhedral fan in 2-d lattice N
sage: fan.is_equivalent( toric_varieties.P2().fan() )
True
Toric diagrams (the `\ZZ_5` hyperconifold)::
sage: vertices=[(0, 1, 0), (0, 3, 1), (0, 2, 3), (0, 0, 2)]
sage: interior=[(0, 1, 1), (0, 1, 2), (0, 2, 1), (0, 2, 2)]
sage: points = vertices+interior
sage: pc = PointConfiguration(points, fine=True)
sage: triangulation = pc.triangulate()
sage: fan = triangulation.fan( (-1,0,0) )
sage: fan
Rational polyhedral fan in 3-d lattice N
sage: fan.rays()
N(1, 1, 0),
N(1, 3, 1),
N(1, 2, 3),
N(1, 0, 2),
N(1, 1, 1),
N(1, 1, 2),
N(1, 2, 1),
N(1, 2, 2)
in 3-d lattice N
"""
from sage.geometry.fan import Fan
if origin is None:
origin = self.point_configuration().star_center()
R = self.base_ring()
origin = vector(R, origin)
points = self.point_configuration().points()
return Fan(self, (vector(R, p) - origin for p in points))
示例8: set_rays
def set_rays(self, generators):
r"""
Set up rays and their ``generators`` to be used by plotting functions.
As an alternative to using this method, you can pass ``generators`` to
:class:`ToricPlotter` constructor.
INPUT:
- ``generators`` - a list of primitive non-zero ray generators.
OUTPUT:
- none.
EXAMPLES::
sage: from sage.geometry.toric_plotter import ToricPlotter
sage: tp = ToricPlotter(dict(), 2)
sage: tp.adjust_options()
sage: tp.plot_rays()
Traceback (most recent call last):
...
AttributeError: 'ToricPlotter' object has no attribute 'rays'
sage: tp.set_rays([(0,1)])
sage: tp.plot_rays()
Graphics object consisting of 2 graphics primitives
"""
d = self.dimension
if d == 1:
generators = [vector(RDF, 2, (gen[0], 0)) for gen in generators]
else:
generators = [vector(RDF, d, gen) for gen in generators]
self.generators = generators
if self.mode == "box":
rays = []
bounds = [self.__dict__[bound]
for bound in ["xmin", "xmax", "ymin", "ymax", "zmin", "zmax"]]
bounds = bounds[:2 * d]
for gen in generators:
factors = []
for i, gen_i in enumerate(gen):
factors.append(gen_i / bounds[2 * i])
factors.append(gen_i / bounds[2 * i + 1])
rays.append(gen / max(factors))
elif self.mode == "generators":
rays = generators
elif self.mode == "round":
r = self.radius
rays = [r * gen / gen.norm() for gen in generators]
self.rays = rays
示例9: reduce_r
def reduce_r(self, r) :
for rred in map(lambda rs: rs[0], self._r_representatives) :
r_rred = vector(r) - vector(rred)
if r_rred in self.__L_span :
break
else :
raise RuntimeError( "Could not find reduced r" )
if rred in self._r_reduced_representatives :
s = 1
else :
rred = tuple(map(operator.neg, rred))
s = -1
return (rred, s)
示例10: weil_representation
def weil_representation(self) :
r"""
OUTPUT:
- A pair of matrices corresponding to T and S.
"""
disc_bilinear = lambda a, b: (self._dual_basis * vector(QQ, a.lift())) * self._L * (self._dual_basis * vector(QQ, b.lift()))
disc_quadratic = lambda a: disc_bilinear(a, a) / ZZ(2)
zeta_order = ZZ(lcm([8, 12, prod(self.invariants())] + map(lambda ed: 2 * ed, self.invariants())))
K = CyclotomicField(zeta_order); zeta = K.gen()
R = PolynomialRing(K, 'x'); x = R.gen()
# sqrt2s = (x**2 - 2).factor()
# if sqrt2s[0][0][0].complex_embedding().real() > 0 :
# sqrt2 = sqrt2s[0][0][0]
# else :
# sqrt2 = sqrt2s[0][1]
Ldet_rts = (x**2 - prod(self.invariants())).factor()
if Ldet_rts[0][0][0].complex_embedding().real() > 0 :
Ldet_rt = Ldet_rts[0][0][0]
else :
Ldet_rt = Ldet_rts[0][0][0]
Tmat = diagonal_matrix( K, [zeta**(zeta_order*disc_quadratic(a)) for a in self] )
Smat = zeta**(zeta_order / 8 * self._L.nrows()) / Ldet_rt \
* matrix( K, [ [ zeta**ZZ(-zeta_order * disc_bilinear(gamma,delta))
for delta in self ]
for gamma in self ])
return (Tmat, Smat)
示例11: _unpivot_ray
def _unpivot_ray(self, ray):
"""
Undo the pivoting to go back to the original inequalities
containing a linear subspace.
INPUT:
- ``ray`` -- ray in the pivoted coordinates.
OUTPUT:
Ray in the original coordinates.
EXAMPLES::
sage: from sage.geometry.polyhedron.double_description_inhomogeneous \
....: import PivotedInequalities
sage: piv = PivotedInequalities(QQ, 2)
sage: piv._pivot_inequalities(matrix([(1,1,3), (5,5,7)]))
[1 3]
[5 7]
sage: piv._unpivot_ray([1, 3])
(1, 0, 3)
"""
result = [self.base_ring.zero()] * (self.dim + 1)
for r, i in zip(ray, self._pivots):
result[i] = r
return vector(self.base_ring, result)
示例12: __call__
def __call__(self, v):
"""
Apply the affine transformation to ``v``.
INPUT:
- ``v`` -- a multivariate polynomial, a vector, or anything
that can be converted into a vector.
OUTPUT:
The image of ``v`` under the affine group element.
EXAMPLES::
sage: G = AffineGroup(2, QQ)
sage: g = G([0,1,-1,0],[2,3]); g
[ 0 1] [2]
x |-> [-1 0] x + [3]
sage: v = vector([4,5])
sage: g(v)
(7, -1)
sage: R.<x,y> = QQ[]
sage: g(x), g(y)
(y + 2, -x + 3)
sage: p = x^2 + 2*x*y + y + 1
sage: g(p)
-2*x*y + y^2 - 5*x + 10*y + 20
The action on polynomials is such that it intertwines with
evaluation. That is::
sage: p(*g(v)) == g(p)(*v)
True
Test that the univariate polynomial ring is covered::
sage: H = AffineGroup(1, QQ)
sage: h = H([2],[3]); h
x |-> [2] x + [3]
sage: R.<z> = QQ[]
sage: h(z+1)
3*z + 2
"""
from sage.rings.polynomial.polynomial_element import is_Polynomial
from sage.rings.polynomial.multi_polynomial import is_MPolynomial
parent = self.parent()
if is_Polynomial(v) and parent.degree() == 1:
ring = v.parent()
return ring([self._A[0, 0], self._b[0]])
if is_MPolynomial(v) and parent.degree() == v.parent().ngens():
ring = v.parent()
from sage.modules.all import vector
image_coords = self._A * vector(ring, ring.gens()) + self._b
return v(*image_coords)
v = parent.vector_space()(v)
return self._A * v + self._b
示例13: gkz_phi
def gkz_phi(self):
r"""
Calculate the GKZ phi vector of the triangulation.
The phi vector is a vector of length equals to the number of
points in the point configuration. For a fixed triangulation
`T`, the entry corresponding to the `i`-th point `p_i` is
.. math::
\phi_T(p_i) = \sum_{t\in T, t\owns p_i} Vol(t)
that is, the total volume of all simplices containing `p_i`.
See also [GKZ]_ page 220 equation 1.4.
OUTPUT:
The phi vector of self.
EXAMPLES::
sage: p = PointConfiguration([[0,0],[1,0],[2,1],[1,2],[0,1]])
sage: p.triangulate().gkz_phi()
(3, 1, 5, 2, 4)
sage: p.lexicographic_triangulation().gkz_phi()
(1, 3, 4, 2, 5)
"""
vec = vector(ZZ, self.point_configuration().n_points())
for simplex in self:
vol = self.point_configuration().volume(simplex)
for i in simplex:
vec[i] = vec[i] + vol
return vec
示例14: vertices
def vertices(self):
r"""
Return the vertices as a tuple of `\ZZ`-vectors.
OUTPUT:
A tuple of `\ZZ`-vectors. Each entry is the coordinate vector
of an integral points of the lattice polytope.
EXAMPLES::
sage: from sage.geometry.polyhedron.ppl_lattice_polytope import LatticePolytope_PPL
sage: p = LatticePolytope_PPL((-9,-6,-1,-1),(0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0))
sage: p.vertices()
((-9, -6, -1, -1), (0, 0, 0, 1), (0, 0, 1, 0), (0, 1, 0, 0), (1, 0, 0, 0))
sage: p.minimized_generators()
Generator_System {point(-9/1, -6/1, -1/1, -1/1), point(0/1, 0/1, 0/1, 1/1),
point(0/1, 0/1, 1/1, 0/1), point(0/1, 1/1, 0/1, 0/1), point(1/1, 0/1, 0/1, 0/1)}
"""
d = self.space_dimension()
v = vector(ZZ, d)
points = []
for g in self.minimized_generators():
for i in range(0,d):
v[i] = g.coefficient(Variable(i))
v_copy = copy.copy(v)
v_copy.set_immutable()
points.append(v_copy)
return tuple(points)
示例15: coleman_integral_S_to_Q
def coleman_integral_S_to_Q(self, w, S, Q):
r"""
Computes the Coleman integral $\int_S^Q w$
**one should be able to feed $S,Q$ into coleman_integral,
but currently that segfaults**
INPUT:
- w: a differential
- S: a point with coordinates in an extension of $\Q_p$
- Q: a non-Weierstrass point defined over $\Q_p$
OUTPUT:
the Coleman integral $\int_S^Q w$
EXAMPLES::
sage: R.<x> = QQ['x']
sage: H = HyperellipticCurve(x^3-10*x+9)
sage: K = Qp(5,6)
sage: HK = H.change_ring(K)
sage: J.<a> = K.extension(x^20-5)
sage: HJ = H.change_ring(J)
sage: x,y = HK.monsky_washnitzer_gens()
sage: P = HK(1,0)
sage: Q = HK(0,3)
sage: S = HK.get_boundary_point(HJ,P)
sage: P_to_S = HK.coleman_integral_P_to_S(y.diff(),P,S)
sage: S_to_Q = HJ.coleman_integral_S_to_Q(y.diff(),S,Q)
sage: P_to_S + S_to_Q
3 + O(a^119)
sage: HK.coleman_integral(y.diff(),P,Q)
3 + O(5^6)
AUTHOR:
- Jennifer Balakrishnan
"""
import sage.schemes.hyperelliptic_curves.monsky_washnitzer as monsky_washnitzer
K = self.base_ring()
R = monsky_washnitzer.SpecialHyperellipticQuotientRing(self, K)
MW = monsky_washnitzer.MonskyWashnitzerDifferentialRing(R)
w = MW(w)
f, vec = w.reduce_fast()
g = self.genus()
const = f(Q[0], Q[1]) - f(S[0], S[1])
if vec == vector(2 * g * [0]):
return const
else:
basis_values = self.S_to_Q(S, Q)
dim = len(basis_values)
dot = sum([vec[i] * basis_values[i] for i in range(dim)])
return const + dot