Ticket #5631: trac_5631_rebased.patch
File trac_5631_rebased.patch, 9.5 KB (added by , 14 years ago) |
---|
-
sage/schemes/generic/affine_space.py
# HG changeset patch # User Alexandru Ghitza <aghitza@alum.mit.edu> # Date 1239351644 -36000 # Node ID b1949e0776d6498eaddee808815ffbde94959357 # Parent 470a0a0e9a2c89bdace62f0d5e2051c43f6b0747 trac 5631: improve doctest coverage of affine_space.py diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/affine_space.py
a b 55 55 56 56 def AffineSpace(n, R=None, names='x'): 57 57 r""" 58 Return affine space of dimension `n` over the ring 59 `R`. 58 Return affine space of dimension `n` over the ring `R`. 60 59 61 60 EXAMPLES: The dimension and ring can be given in either order. 62 61 … … 85 84 sage: AffineSpace(5, names='x') 86 85 Affine Space of dimension 5 over Integer Ring 87 86 88 There is also an affine space associated each polynomial ring.87 There is also an affine space associated to each polynomial ring. 89 88 90 89 :: 91 90 … … 158 157 Affine Space of dimension 0 over Integer Ring 159 158 """ 160 159 def __init__(self, n, R, names): 160 """ 161 EXAMPLES:: 162 163 sage: AffineSpace(3, Zp(5), 'y') 164 Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20 165 """ 161 166 names = normalize_names(n, names) 162 167 ambient_space.AmbientSpace.__init__(self, n, R) 163 168 self._assign_names(names) … … 204 209 i += 1 205 210 206 211 def ngens(self): 212 """ 213 Return the number of generators of self, i.e. the number of 214 variables in the coordinate ring of self. 215 216 EXAMPLES:: 217 218 sage: AffineSpace(3, QQ).ngens() 219 3 220 sage: AffineSpace(7, ZZ).ngens() 221 7 222 """ 207 223 return self.dimension_relative() 208 224 209 225 def rational_points(self, F=None): 226 """ 227 Return the list of `F`-rational points on the affine space self, 228 where `F` is a given finite field, or the base ring of self. 229 230 EXAMPLES:: 231 232 sage: A = AffineSpace(1, GF(3)) 233 sage: A.rational_points() 234 [(0), (1), (2)] 235 sage: A.rational_points(GF(3^2, 'b')) 236 [(0), (2*b), (b + 1), (b + 2), (2), (b), (2*b + 2), (2*b + 1), (1)] 237 238 sage: AffineSpace(2, ZZ).rational_points(GF(2)) 239 [(0, 0), (1, 0), (0, 1), (1, 1)] 240 241 TESTS:: 242 243 sage: AffineSpace(2, QQ).rational_points() 244 Traceback (most recent call last): 245 ... 246 TypeError: Base ring (= Rational Field) must be a finite field. 247 sage: AffineSpace(1, GF(3)).rational_points(ZZ) 248 Traceback (most recent call last): 249 ... 250 TypeError: Second argument (= Integer Ring) must be a finite field. 251 """ 210 252 if F == None: 211 253 if not is_FiniteField(self.base_ring()): 212 254 raise TypeError, "Base ring (= %s) must be a finite field."%self.base_ring() 213 255 return [ P for P in self ] 214 256 elif not is_FiniteField(F): 215 257 raise TypeError, "Second argument (= %s) must be a finite field."%F 216 return [ P for P in self (F) ]258 return [ P for P in self.base_extend(F) ] 217 259 218 260 def _point_morphism_class(self, *args, **kwds): 219 261 return morphism.SchemeMorphism_on_points_affine_space(*args, **kwds) … … 236 278 237 279 def _latex_(self): 238 280 r""" 281 Return a LaTeX representation of this affine space. 282 239 283 EXAMPLES:: 240 284 241 285 sage: print latex(AffineSpace(1, ZZ, 'x')) 242 286 \mathbf{A}_{\mathbf{Z}}^1 287 288 TESTS:: 289 290 sage: AffineSpace(3, Zp(5), 'y')._latex_() 291 '\\mathbf{A}_{\\mathbf{Z}_{5}}^3' 243 292 """ 244 293 return "\\mathbf{A}_{%s}^%s"%(latex(self.base_ring()), self.dimension_relative()) 245 294 … … 253 302 return morphism.SchemeMorphism_affine_coordinates(*args, **kwds) 254 303 255 304 def _repr_(self): 305 """ 306 Return a string representation of this affine space. 307 308 EXAMPLES:: 309 310 sage: AffineSpace(1, ZZ, 'x') 311 Affine Space of dimension 1 over Integer Ring 312 313 TESTS:: 314 315 sage: AffineSpace(3, Zp(5), 'y')._repr_() 316 'Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20' 317 """ 256 318 return "Affine Space of dimension %s over %s"%(self.dimension_relative(), self.base_ring()) 257 319 258 320 def _repr_generic_point(self, polys=None): 321 """ 322 Return a string representation of the generic point 323 corresponding to the list of polys on this affine space. 324 325 If polys is None, the representation of the generic point of 326 the affine space is returned. 327 328 EXAMPLES:: 329 330 sage: A.<x, y> = AffineSpace(2, ZZ) 331 sage: A._repr_generic_point([y-x^2]) 332 '(-x^2 + y)' 333 sage: A._repr_generic_point() 334 '(x, y)' 335 """ 259 336 if polys is None: 260 337 polys = self.gens() 261 338 return '(%s)'%(", ".join([str(f) for f in polys])) 262 339 263 340 def _latex_generic_point(self, v=None): 341 """ 342 Return a LaTeX representation of the generic point 343 corresponding to the list of polys on this affine space. 344 345 If polys is None, the representation of the generic point of 346 the affine space is returned. 347 348 EXAMPLES:: 349 350 sage: A.<x, y> = AffineSpace(2, ZZ) 351 sage: A._latex_generic_point([y-x^2]) 352 '\\left(- x^{2} + y\\right)' 353 sage: A._latex_generic_point() 354 '\\left(x, y\\right)' 355 """ 264 356 if v is None: 265 357 v = self.gens() 266 358 return '\\left(%s\\right)'%(", ".join([str(latex(f)) for f in v])) … … 280 372 281 373 def coordinate_ring(self): 282 374 """ 283 Return the coordinate ring of this scheme, if defined. Otherwise 284 raise a ValueError. 375 Return the coordinate ring of this scheme, if defined. 285 376 286 377 EXAMPLES:: 287 378 … … 410 501 0 411 502 """ 412 503 return algebraic_scheme.AlgebraicScheme_subscheme_affine(self, X) 413 414 def subscheme_complement(self, X, Y):415 X = self.subscheme(X)416 Y = self.subscheme(Y)417 return algebraic_scheme.AlgebraicScheme_quasi(X, Y) -
sage/schemes/generic/algebraic_scheme.py
diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/algebraic_scheme.py
a b 195 195 """ 196 196 An algebraic scheme presented as a closed subscheme is defined by 197 197 explicit polynomial equations. This is as opposed to a general 198 scheme, which could, e.g., b ythe Neron model of some object, and198 scheme, which could, e.g., be the Neron model of some object, and 199 199 for which we do not want to give explicit equations. 200 200 201 201 INPUT: … … 427 427 raise ValueError, "other (=%s) must be in the same ambient space as self"%other 428 428 return A.subscheme(self.defining_ideal() + other.defining_ideal()) 429 429 430 def exclude(self, other): 430 431 def complement(self, other): 431 432 """ 432 Return the scheme-theoretic complement self - other. 433 434 EXAMPLES: HERE 433 Return the scheme-theoretic complement self - other, where 434 self and other are both closed algebraic subschemes of the 435 same ambient space. 436 EXAMPLES:: 437 438 sage: A.<x, y, z> = AffineSpace(3, ZZ) 439 sage: X = A.subscheme([x+y-z]) 440 sage: Y = A.subscheme([x-y+z]) 441 sage: X.complement(Y) 442 Quasi-affine scheme X - Y, where: 443 X: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by: 444 x + y - z 445 Y: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by: 446 x - y + z 447 448 sage: P.<x, y, z> = ProjectiveSpace(2, QQ) 449 sage: X = P.subscheme([x^2+y^2+z^2]) 450 sage: Y = P.subscheme([x*y+y*z+z*x]) 451 sage: X.complement(Y) 452 Quasi-projective scheme X - Y, where: 453 X: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by: 454 x^2 + y^2 + z^2 455 Y: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by: 456 x*y + x*z + y*z 435 457 """ 436 458 if not isinstance(other, AlgebraicScheme_subscheme): 437 459 raise TypeError, \ … … 439 461 A = self.ambient_space() 440 462 if other.ambient_space() != A: 441 463 raise ValueError, "other (=%s) must be in the same ambient space as self"%other 442 return A.subscheme_complement( 443 self.defining_ideal(), self.defining_ideal() + other.defining_ideal()) 464 return AlgebraicScheme_quasi(self, other) 444 465 445 466 def rational_points(self, F=None, bound=0): 446 467 """ -
sage/schemes/generic/projective_space.py
diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/projective_space.py
a b 299 299 """ 300 300 return algebraic_scheme.AlgebraicScheme_subscheme_projective(self, X) 301 301 302 def subscheme_complement(self, X, Y):303 return algebraic_scheme.AlgebraicScheme_quasi(self, X, Y)304 305 302 def affine_patch(self, i): 306 303 r""" 307 304 Return the `i^{th}` affine patch of this projective space.