Ticket #10977: trac_10977-vector-constructor-doc.patch

File trac_10977-vector-constructor-doc.patch, 2.9 KB (added by rbeezer, 12 years ago)
  • sage/modules/free_module_element.pyx

    # 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  
    157157    INPUT:
    158158
    159159    -  ``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
    161162
    162163    -  ``ring`` - a base ring (or field) for the vector
    163164       space or free module, which contains all of the elements
     
    244245        sage: vector(QQ, 4, [1,1/2,1/3,1/4])
    245246        (1, 1/2, 1/3, 1/4)
    246247
    247 
    248248    But it is an error if the degree and size of the list of entries
    249249    are mismatched::
    250250
     
    346346        (1, 2, 3)
    347347        sage: parent(v)
    348348        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
    352368        sage: x = vector([]); x
    353369        ()
    354370        sage: x.parent()
     
    434450    INPUT:
    435451
    436452    - ``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
    438455    - ``R`` - a ring containing all the entries, possibly given as ``None``
    439456    - ``degree`` -  a requested size for the list when the input is a dictionary,
    440457      otherwise ignored
     
    486503        ...
    487504        TypeError: unable to find a common ring for all elements
    488505
     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
    489513    This checks a bug listed at Trac #10595.  Without good evidence for a ring, the default
    490     is the integers.
     514    is the integers. ::
    491515       
    492516        sage: prepare([], None)
    493517        ([], Integer Ring)