# HG changeset patch
# User Rob Beezer <beezer@ups.edu>
# Date 1300750668 25200
# Node ID f93ce2361cc19bcad14c7fbc4309814069633488
# Parent 63144922ed6cda164915a2da7d6629f426de9b60
10977: vector constructor documentation addition
diff -r 63144922ed6c -r f93ce2361cc1 sage/modules/free_module_element.pyx
a
|
b
|
|
157 | 157 | INPUT: |
158 | 158 | |
159 | 159 | - ``object`` - a list, dictionary, or other |
160 | | iterable containing the entries of the vector |
| 160 | iterable containing the entries of the vector, including |
| 161 | any object that is palatable to the ``Sequence`` constructor |
161 | 162 | |
162 | 163 | - ``ring`` - a base ring (or field) for the vector |
163 | 164 | space or free module, which contains all of the elements |
… |
… |
|
244 | 245 | sage: vector(QQ, 4, [1,1/2,1/3,1/4]) |
245 | 246 | (1, 1/2, 1/3, 1/4) |
246 | 247 | |
247 | | |
248 | 248 | But it is an error if the degree and size of the list of entries |
249 | 249 | are mismatched:: |
250 | 250 | |
… |
… |
|
346 | 346 | (1, 2, 3) |
347 | 347 | sage: parent(v) |
348 | 348 | Ambient free module of rank 3 over the principal ideal domain Integer Ring |
349 | | |
350 | | Am empty list, without a ring given, will default to the integers. :: |
351 | | |
| 349 | |
| 350 | Complex numbers can be converted naturally to a sequence of length 2. And |
| 351 | then to a vector. :: |
| 352 | |
| 353 | sage: c = CDF(2 + 3*I) |
| 354 | sage: v = vector(c); v |
| 355 | (2.0, 3.0) |
| 356 | |
| 357 | A generator, or other iterable, may also be supplied as input. Anything |
| 358 | that can be converted to a :class:`~sage.structure.sequence.Sequence` is |
| 359 | a possible input. :: |
| 360 | |
| 361 | sage: type(i^2 for i in range(3)) |
| 362 | <type 'generator'> |
| 363 | sage: v = vector(i^2 for i in range(3)); v |
| 364 | (0, 1, 4) |
| 365 | |
| 366 | An empty list, without a ring given, will default to the integers. :: |
| 367 | |
352 | 368 | sage: x = vector([]); x |
353 | 369 | () |
354 | 370 | sage: x.parent() |
… |
… |
|
434 | 450 | INPUT: |
435 | 451 | |
436 | 452 | - ``v`` - a dictionary with non-negative integers as keys, |
437 | | or a list or other object that can be converted to Sequence |
| 453 | or a list or other object that can be converted by the ``Sequence`` |
| 454 | constructor |
438 | 455 | - ``R`` - a ring containing all the entries, possibly given as ``None`` |
439 | 456 | - ``degree`` - a requested size for the list when the input is a dictionary, |
440 | 457 | otherwise ignored |
… |
… |
|
486 | 503 | ... |
487 | 504 | TypeError: unable to find a common ring for all elements |
488 | 505 | |
| 506 | Some objects can be converted to sequences even if they are not always |
| 507 | thought of as sequences. :: |
| 508 | |
| 509 | sage: c = CDF(2+3*I) |
| 510 | sage: prepare(c, None) |
| 511 | ([2.0, 3.0], Real Double Field) |
| 512 | |
489 | 513 | This checks a bug listed at Trac #10595. Without good evidence for a ring, the default |
490 | | is the integers. |
| 514 | is the integers. :: |
491 | 515 | |
492 | 516 | sage: prepare([], None) |
493 | 517 | ([], Integer Ring) |