# Ticket #12544: trac_12544_fix_doctests.patch

File trac_12544_fix_doctests.patch, 25.3 KB (added by novoselt, 9 years ago)
• ## sage/geometry/cone.py

```# HG changeset patch
# User Andrey Novoseltsev <novoselt@gmail.com>
# Date 1331088101 25200
# Node ID 6e25398b70096af4aa33f02ab17eec033067bb77
# Parent  f71249f0b399aa5f252d063b70c13a6dc4bf95a5
Adjust doctests to new cone.rays() output.

diff --git a/sage/geometry/cone.py b/sage/geometry/cone.py```
 a Once you have a cone, you can perform numerous operations on it. The most important ones are, probably, ray accessing methods:: sage: halfspace.rays() (N(0, 0, 1), N(0, 1, 0), N(0, -1, 0), N(1, 0, 0), N(-1, 0, 0)) sage: halfspace.ray(3) N(1, 0, 0) sage: halfspace.ray_matrix() sage: rays = halfspace.rays() sage: rays [ 0  0  0  1 -1] [ 0  1 -1  0  0] [ 1  0  0  0  0] sage: halfspace.ray_set() in 3-d lattice N sage: rays.set() frozenset([N(1, 0, 0), N(-1, 0, 0), N(0, 1, 0), N(0, 0, 1), N(0, -1, 0)]) sage: rays.matrix() [ 0  0  0  1 -1] [ 0  1 -1  0  0] [ 1  0  0  0  0] sage: rays(3) [1] [0] [0] in 3-d lattice N sage: rays[3] N(1, 0, 0) sage: halfspace.ray(3) N(1, 0, 0) Note that while we output rays by default as a matrix, the method :meth:`~ConvexRationalPolyhedralCone.rays` returns a :class:`~sage.geometry.point_collection.PointCollection` with `i`-th element being the `i`-th point, i.e. the `i`-th column of the shown matrix, while after explicit conversion to a matrix indexing refers to rows. In the above example requesting the third row will lead to an error:: sage: halfspace.rays().matrix()[3] Traceback (most recent call last): ... IndexError: matrix index out of range If you want to do something with each ray of a cone, you can write :: sage: face 2-d face of 3-d cone in 3-d lattice N sage: face.rays() (N(1, 1, 1), N(1, -1, 1)) [ 1  1] [ 1 -1] [ 1  1] in 3-d lattice N sage: face.ambient_ray_indices() (0, 1) sage: four_rays.rays(face.ambient_ray_indices()) [1, 4, 4, 1] sage: face = L.level_sets()[2][0] sage: face.element.rays() (N(1, 1, 1), N(1, -1, 1)) [ 1  1] [ 1 -1] [ 1  1] in 3-d lattice N sage: L.hasse_diagram().neighbors_in(face) [1-d face of 3-d cone in 3-d lattice N, 1-d face of 3-d cone in 3-d lattice N] sage: quadrant 2-d cone in 2-d lattice N sage: quadrant.rays() (N(1, 0), N(0, 1)) [1 0] [0 1] in 2-d lattice N You may prefer to use :meth:`~IntegralRayCollection.ray_matrix` when you want to take a look at rays, they will be given as columns:: If you give more rays than necessary, the extra ones will be discarded:: sage: Cone([(1,0), (0,1), (1,1), (0,1)]).rays() (N(0, 1), N(1, 0)) [0 1] [1 0] in 2-d lattice N However, this work is not done with ``check=False`` option, so use it carefully! :: sage: Cone([(1,0), (0,1), (1,1), (0,1)], check=False).rays() (N(1, 0), N(0, 1), N(1, 1), N(0, 1)) [1 0 1 0] [0 1 1 1] in 2-d lattice N Even worse things can happen with ``normalize=False`` option:: 1 sage: half_plane = Cone([(1,0), (0,1), (-1,0)]) sage: half_plane.rays() (N(0, 1), N(1, 0), N(-1, 0)) [ 0  1 -1] [ 1  0  0] in 2-d lattice N sage: half_plane.is_strictly_convex() False sage: origin = Cone([(0,0)]) sage: origin.rays() () [] in 2-d lattice N sage: origin.dim() 0 sage: origin.lattice_dim() sage: L = ToricLattice(3, "L") sage: c1 = Cone([(1,0,0),(1,1,1)], lattice=L) sage: c1.rays() (L(1, 0, 0), L(1, 1, 1)) [1 1] [0 1] [0 1] in 3-d lattice L Or you can construct cones from rays of a particular lattice:: sage: ray2 = L(1,1,1) sage: c2 = Cone([ray1, ray2]) sage: c2.rays() (L(1, 0, 0), L(1, 1, 1)) [1 1] [0 1] [0 1] in 3-d lattice L sage: c1 == c2 True TESTS:: sage: Cone([(1,0), (0,1), (1,1), (0,1)]).rays()   # indirect doctest (N(0, 1), N(1, 0)) [0 1] [1 0] in 2-d lattice N """ rays = [] lines = [] Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: c.rays() ((1, 0),) [1] [0] in Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: TestSuite(c).run() """ self._rays = PointCollection(rays, lattice) sage: c.cartesian_product(c)    # indirect doctest 2-d cone in 2-d lattice N+N sage: _.rays() (N+N(1, 0), N+N(0, 1)) [1 0] [0 1] in 2-d lattice N+N """ assert isinstance(other, IntegralRayCollection) if lattice is None: sage: c = Cone([(1,0), (0,1), (-1, 0)]) sage: c.rays() (N(0, 1), N(1, 0), N(-1, 0)) [ 0  1 -1] [ 1  0  0] in 2-d lattice N sage: c.rays([0, 2]) (N(0, 1), N(-1, 0)) """ Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: ac.rays() ((1, 0), (0, 1)) [1 0] [0 1] in Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: ac.ambient() is ac True sage: TestSuite(ac).run() sage: sc = ConvexRationalPolyhedralCone(ambient=ac, ...                         ambient_ray_indices=[1]) sage: sc.rays() ((0, 1),) [0] [1] in Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: sc.ambient() is ac True sage: TestSuite(sc).run() sage: c.cartesian_product(c) 2-d cone in 2-d lattice N+N sage: _.rays() (N+N(1, 0), N+N(0, 1)) [1 0] [0 1] in 2-d lattice N+N """ assert is_Cone(other) rc = super(ConvexRationalPolyhedralCone, self).cartesian_product( sage: cone = Cone([(1,0), (-1,3)]) sage: cone.dual().rays() (M(3, 1), M(0, 1)) [3 0] [1 1] in 2-d lattice M Now let's look at a more complicated case:: sage: cone.dim() 3 sage: cone.dual().rays() (M(7, -18, -2), M(1, -4, 0)) [  7   1] [-18  -4] [ -2   0] in 3-d lattice M sage: cone.dual().dual() is cone True sage: N = ToricLattice(2) sage: Cone([], lattice=N).dual().rays()  # empty cone (M(1, 0), M(-1, 0), M(0, 1), M(0, -1)) [ 1 -1  0  0] [ 0  0  1 -1] in 2-d lattice M sage: Cone([(1,0)], lattice=N).dual().rays()  # ray in 2d (M(1, 0), M(0, 1), M(0, -1)) [ 1  0  0] [ 0  1 -1] in 2-d lattice M sage: Cone([(1,0),(-1,0)], lattice=N).dual().rays()  # line in 2d (M(0, 1), M(0, -1)) [ 0  0] [ 1 -1] in 2-d lattice M sage: Cone([(1,0),(0,1)], lattice=N).dual().rays()  # strictly convex cone (M(1, 0), M(0, 1)) [1 0] [0 1] in 2-d lattice M sage: Cone([(1,0),(-1,0),(0,1)], lattice=N).dual().rays()  # half space (M(0, 1),) [0] [1] in 2-d lattice M sage: Cone([(1,0),(0,1),(-1,-1)], lattice=N).dual().rays()  # whole space () [] in 2-d lattice M """ if "_dual" not in self.__dict__: rays = list(self.facet_normals()) sage: e_ray 1-d face of 3-d cone in 3-d lattice N sage: e_ray.rays() (N(0, -1, 1),) [ 0] [-1] [ 1] in 3-d lattice N sage: e_ray is ray False sage: e_ray.is_equivalent(ray) Now you can look at the actual rays of this face... :: sage: face.rays() (N(1, 0),) [1] [0] in 2-d lattice N ... or you can see indices of the rays of the orginal cone that correspond to the above ray:: sage: face 1-d face of 2-d cone in 2-d lattice N sage: face.rays() (N(1, 0),) [1] [0] in 2-d lattice N sage: face.facets() (0-d face of 2-d cone in 2-d lattice N,) sage: face.facet_of() sage: face.adjacent() (1-d face of 2-d cone in 2-d lattice N,) sage: face.adjacent()[0].rays() (N(0, 1),) [0] [1] in 2-d lattice N Note that if ``cone`` is a face of ``supercone``, then the face lattice of ``cone`` consists of (appropriate) faces of ``supercone``:: Now you can look at the actual rays of this face... :: sage: face.rays() (N(1, 0),) [1] [0] in 2-d lattice N ... or you can see indices of the rays of the orginal cone that correspond to the above ray:: (3-d cone in 4-d lattice N,)) We also ensure that a call to this function does not break :meth:`facets` method (see Trac #9780):: :meth:`facets` method (see :trac:`9780`):: sage: cone = toric_varieties.dP8().fan().generating_cone(0) sage: cone 2-d cone of Rational polyhedral fan in 2-d lattice N sage: [f.rays() for f in cone.facets()] [(N(1, 1),), (N(0, 1),)] sage: for f in cone.facets(): print f.rays() [1] [1] in 2-d lattice N [0] [1] in 2-d lattice N sage: len(cone.faces()) 3 sage: [f.rays() for f in cone.facets()] [(N(1, 1),), (N(0, 1),)] sage: for f in cone.facets(): print f.rays() [1] [1] in 2-d lattice N [0] [1] in 2-d lattice N """ if dim is not None and codim is not None: raise ValueError( sage: cone1 = Cone([(1,0), (-1, 3)]) sage: cone2 = Cone([(-1,0), (2, 5)]) sage: cone1.intersection(cone2).rays() (N(-1, 3), N(2, 5)) [-1  2] [ 3  5] in 2-d lattice N It is OK to intersect cones living in sublattices of the same ambient lattice:: sage: cone3 = Cone([(1,1)], lattice=Ns) sage: I = cone1.intersection(cone3) sage: I.rays() (N(1, 1),) [1] [1] in Sublattice sage: I.lattice() Sublattice ValueError: 2-d lattice N and 2-d lattice M have different ambient lattices! sage: cone1.intersection(Cone(cone1.dual().rays(), N)).rays() (N(3, 1), N(0, 1)) [3 0] [1 1] in 2-d lattice N """ if self._ambient is other._ambient: # Cones of the same ambient cone or fan intersect nicely/quickly. sage: cone1 = Cone([(1,0), (-1, 3)]) sage: cone2 = Cone([(-1,3), (1, 0)]) sage: cone1.rays() (N(1, 0), N(-1, 3)) [ 1 -1] [ 0  3] in 2-d lattice N sage: cone2.rays() (N(-1, 3), N(1, 0)) [-1  1] [ 3  0] in 2-d lattice N sage: cone1 == cone2 False sage: cone1.is_equivalent(cone2) sage: halfplane = Cone([(1,0), (0,1), (-1,0)]) sage: halfplane.lines() (N(1, 0),) [1] [0] in 2-d lattice N sage: fullplane = Cone([(1,0), (0,1), (-1,-1)]) sage: fullplane.lines() (N(0, 1), N(1, 0)) [0 1] [1 0] in 2-d lattice N """ lines = [] for g in self._PPL_cone().minimized_generators(): sage: ssc 1-d cone in 1-d lattice N sage: ssc.rays() (N(1),) [1] in 1-d lattice N sage: line = Cone([(1,0), (-1,0)]) sage: ssc = line.strict_quotient() sage: ssc 0-d cone in 1-d lattice N sage: ssc.rays() () [] in 1-d lattice N """ if "_strict_quotient" not in self.__dict__: if self.is_strictly_convex(): sage: c 2-d cone in 3-d lattice N sage: c.rays() (N(1, 2, 3), N(4, -5, 1)) [ 1  4] [ 2 -5] [ 3  1] in 3-d lattice N sage: c.sublattice() Sublattice sage: c.sublattice(5, -3, 4) sage: cone = Cone([(1,0),(0,1)]) sage: cone.rays() (N(1, 0), N(0, 1)) [1 0] [0 1] in 2-d lattice N sage: cone.Hilbert_coefficients([3,2]) (3, 2)
• ## sage/geometry/fan.py

`diff --git a/sage/geometry/fan.py b/sage/geometry/fan.py`
 a Given such "automatic" fans, you may wonder what are their rays and cones:: sage: fan1.rays() (N(1, 0, 0), N(0, 1, 0), N(0, 0, 1), N(-1, 0, 0), N(0, -1, 0), N(0, 0, -1)) [ 1  0  0 -1  0  0] [ 0  1  0  0 -1  0] [ 0  0  1  0  0 -1] in 3-d lattice N sage: fan1.ray_matrix() [ 1  0  0 -1  0  0] [ 0  1  0  0 -1  0] The last output is not very illuminating. Let's try to improve it:: sage: for cone in fan1: print cone.rays() (N(1, 0, 0), N(0, 1, 0), N(0, 0, -1)) (N(0, 1, 0), N(-1, 0, 0), N(0, 0, -1)) (N(1, 0, 0), N(0, -1, 0), N(0, 0, -1)) (N(-1, 0, 0), N(0, -1, 0), N(0, 0, -1)) (N(1, 0, 0), N(0, 1, 0), N(0, 0, 1)) (N(0, 1, 0), N(0, 0, 1), N(-1, 0, 0)) (N(1, 0, 0), N(0, 0, 1), N(0, -1, 0)) (N(0, 0, 1), N(-1, 0, 0), N(0, -1, 0)) [ 1  0  0] [ 0  1  0] [ 0  0 -1] in 3-d lattice N [ 0 -1  0] [ 1  0  0] [ 0  0 -1] in 3-d lattice N [ 1  0  0] [ 0 -1  0] [ 0  0 -1] in 3-d lattice N [-1  0  0] [ 0 -1  0] [ 0  0 -1] in 3-d lattice N [1 0 0] [0 1 0] [0 0 1] in 3-d lattice N [ 0  0 -1] [ 1  0  0] [ 0  1  0] in 3-d lattice N [ 1  0  0] [ 0  0 -1] [ 0  1  0] in 3-d lattice N [ 0 -1  0] [ 0  0 -1] [ 1  0  0] in 3-d lattice N You can also do :: sage: cone = cone.element sage: cone.rays() (N(1, 0, 0), N(0, 1, 0)) [1 0] [0 1] [0 0] in 3-d lattice N You can check how "good" a fan is:: [ 1  0 -1  0] [ 0  1  0 -1] sage: for cone in P1xP1: print cone.rays() (N(1, 0), N(0, -1)) (N(-1, 0), N(0, -1)) (N(1, 0), N(0, 1)) (N(0, 1), N(-1, 0)) [ 1  0] [ 0 -1] in 2-d lattice N [-1  0] [ 0 -1] in 2-d lattice N [1 0] [0 1] in 2-d lattice N [ 0 -1] [ 1  0] in 2-d lattice N """ if any(d <= 0 for d in polytope.distances([0]*polytope.dim())): raise ValueError("face fans are defined only for polytopes containing" [ 1  0 -1  0] [ 0  1  0 -1] sage: for cone in P1xP1: print cone.rays() (N(1, 0), N(0, -1)) (N(-1, 0), N(0, -1)) (N(1, 0), N(0, 1)) (N(0, 1), N(-1, 0)) [ 1  0] [ 0 -1] in 2-d lattice N [-1  0] [ 0 -1] in 2-d lattice N [1 0] [0 1] in 2-d lattice N [ 0 -1] [ 1  0] in 2-d lattice N """ rays = (polytope.facet_normal(i) for i in range(polytope.nfacets())) cones = (vertex.facets() for vertex in polytope.faces(dim=0)) sage: f = sage.geometry.fan.RationalPolyhedralFan( ...                         [(0,)], [v], None) sage: f.rays() ((0, 1),) [0] [1] in Ambient free module of rank 2 over the principal ideal domain Integer Ring sage: TestSuite(f).run() sage: f = Fan([(0,)], [(0,1)]) sage: TestSuite(f).run() ...           rays=[(1,0), (0,1), (-1, 0)], ...           check=False) sage: for cone in f: print cone.rays() (N(1, 0), N(0, 1)) (N(0, 1), N(-1, 0)) [1 0] [0 1] in 2-d lattice N [ 0 -1] [ 1  0] in 2-d lattice N """ return iter(self.generating_cones()) sage: cone2 = Cone([(1,0), (0,1)]) sage: f = Fan([cone1, cone2]) sage: f.rays() (N(0, 1), N(0, -1), N(1, 0)) [ 0  0  1] [ 1 -1  0] in 2-d lattice N sage: f.cone_containing(0)  # ray index 1-d cone of Rational polyhedral fan in 2-d lattice N sage: f.cone_containing(0, 1) # ray indices sage: fan = Fan(cones=[(0,1,2,3), (0,1,4)], ...       rays=[(1,1,1), (1,-1,1), (1,-1,-1), (1,1,-1), (0,0,1)]) sage: fan.cone_containing(0).rays() (N(1, 1, 1),) [1] [1] [1] in 3-d lattice N """ if not points: return self.cones(dim=0)[0] sage: e_ray 1-d cone of Rational polyhedral fan in 3-d lattice N sage: e_ray.rays() (N(0, -1, 1),) [ 0] [-1] [ 1] in 3-d lattice N sage: e_ray is ray False sage: e_ray.is_equivalent(ray) sage: fan.is_smooth(codim=1) True sage: fan.generating_cone(0).rays() (N(-1, 1), N(-1, -1)) [-1 -1] [ 1 -1] in 2-d lattice N sage: fan.generating_cone(0).ray_matrix().det() 2 """
• ## sage/geometry/triangulation/element.py

`diff --git a/sage/geometry/triangulation/element.py b/sage/geometry/triangulation/element.py`
 a 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)) [1 1 1 1 1 1 1 1] [1 3 2 0 1 1 2 2] [0 1 3 2 1 2 1 2] in 3-d lattice N """ from sage.geometry.fan import Fan if origin is None: sage: N = triangulation.normal_cone();  N 4-d cone in 4-d lattice sage: N.rays() ((-1, 0, 0, 0), (1, 0, 1, 0), (-1, 0, -1, 0), (1, 0, 0, -1), (-1, 0, 0, 1), (1, 1, 0, 0), (-1, -1, 0, 0)) [-1  1 -1  1 -1  1 -1] [ 0  0  0  0  0  1 -1] [ 0  1 -1  0  0  0  0] [ 0  0  0 -1  1  0  0] in Ambient free module of rank 4 over the principal ideal domain Integer Ring sage: N.dual().rays() ((-1, 1, 1, -1),) [-1] [ 1] [ 1] [-1] in Ambient free module of rank 4 over the principal ideal domain Integer Ring TESTS::
• ## sage/schemes/generic/fano_toric_variety.py

`diff --git a/sage/schemes/generic/fano_toric_variety.py b/sage/schemes/generic/fano_toric_variety.py`
 a sage: P1xP2 = P1.cartesian_product(P2); P1xP2 3-d CPR-Fano toric variety covered by 6 affine patches sage: P1xP2.fan().rays() (N+N(1, 0, 0), N+N(-1, 0, 0), N+N(0, 1, 0), N+N(0, 0, 1), N+N(0, -1, -1)) [ 1 -1  0  0  0] [ 0  0  1  0 -1] [ 0  0  0  1 -1] in 3-d lattice N+N sage: P1xP2.Delta_polar() A lattice polytope: 3-dimensional, 5 vertices. """
• ## sage/schemes/generic/toric_divisor.py

`diff --git a/sage/schemes/generic/toric_divisor.py b/sage/schemes/generic/toric_divisor.py`
 a sage: Kc = dP6.Kaehler_cone(); Kc 4-d cone in 4-d lattice sage: Kc.rays() (Divisor class [0, 1, 1, 0], Divisor class [0, 0, 1, 1], Divisor class [1, 1, 0, 0], Divisor class [1, 1, 1, 0], Divisor class [0, 1, 1, 1]) [0 0 1 1 0] [1 0 1 1 1] [1 1 0 1 1] [0 1 0 0 1] in The toric rational divisor class group of a 2-d CPR-Fano toric variety covered by 6 affine patches sage: Kc.ray(1).lift() V(y) + V(v) sage: X.rational_class_group().dimension() 4 sage: X.Kaehler_cone().rays() (Divisor class [1, 0, 0, 0],) [1] [0] [0] [0] in The toric rational divisor class group of a 3-d toric variety covered by 7 affine patches sage: antiK = -X.K() sage: antiK.divisor_class() Divisor class [2, 0, 0, 0]
• ## sage/schemes/generic/toric_morphism.py

`diff --git a/sage/schemes/generic/toric_morphism.py b/sage/schemes/generic/toric_morphism.py`
 a sage: A2_Z2 = toric_varieties.A2_Z2() sage: A2_Z2.fan().rays() (N(1, 0), N(1, 2)) [1 1] [0 2] in 2-d lattice N sage: O2_P1 = A2_Z2.resolve(new_rays=[(1,1)]) sage: blowup = O2_P1.hom(identity_matrix(2), A2_Z2) sage: blowup.as_polynomial_map()
• ## sage/schemes/generic/toric_variety.py

`diff --git a/sage/schemes/generic/toric_variety.py b/sage/schemes/generic/toric_variety.py`
 a sage: Kc 2-d cone in 2-d lattice sage: Kc.rays() (Divisor class [0, 1], Divisor class [1, 0]) [0 1] [1 0] in The toric rational divisor class group of a 2-d toric variety covered by 4 affine patches sage: [ divisor_class.lift() for divisor_class in Kc.rays() ] [V(z1), V(z0)] sage: Kc.lattice() sage: P4_11169.Mori_cone() 2-d cone in 7-d lattice sage: P4_11169.Mori_cone().rays() ((0, 0, 1, 1, 1, -3, 0), (3, 2, 0, 0, 0, 1, -6)) [ 0  3] [ 0  2] [ 1  0] [ 1  0] [ 1  0] [-3  1] [ 0 -6] in Ambient free module of rank 7 over the principal ideal domain Integer Ring """ if "_Mori_cone" not in self.__dict__: # Ideally, self.Kaehler_cone().dual() should be it, but sage: P1xP1 = P1.cartesian_product(P1); P1xP1 2-d toric variety covered by 4 affine patches sage: P1xP1.fan().rays() (N+N(-1, 0), N+N(1, 0), N+N(0, -1), N+N(0, 1)) [-1  1  0  0] [ 0  0 -1  1] in 2-d lattice N+N """ return ToricVariety(self.fan().cartesian_product(other.fan()), coordinate_names, coordinate_indices,