Ticket #14790: trac_14790_fpg_names.patch

File trac_14790_fpg_names.patch, 2.4 KB (added by dshurbert, 8 years ago)

Replacement patch, requested changes made, added commit message

  • sage/groups/free_group.py

    # HG changeset patch
    # User Davis Shurbert <dshurbert@pugetsound.edu>
    # Date 1372106620 25200
    # Node ID 935b34f60a9d5cacb3179d5cd66fed513dd78326
    # Parent  7a87b4ee4b2bd89a1ec9657c83a2ea1755e12527
    Python generator for variable names
    
    diff --git a/sage/groups/free_group.py b/sage/groups/free_group.py
    a b  
    9393    """
    9494    return isinstance(x, FreeGroup_class)
    9595
     96def _lexi_gen(zeroes=False):
     97    """
     98    Return a generator object that produces variable names suitable for the
     99    generators of a free group.
     100
     101    INPUT:
     102
     103    - ``zeroes`` -- Boolean defaulting as ``False``. If ``True``, the
     104      integers appended to the output string begin at zero at the
     105      first iteration through the alphabet.
     106
     107    OUTPUT:
     108
     109    Python generator object which outputs a character from the alphabet on each
     110    ``.next()`` call in lexicographical order. The integer `i` is appended
     111    to the output string on the `i^{th}` iteration through the alphabet.
     112   
     113    EXAMPLES::
     114
     115        sage: from sage.groups.free_group import _lexi_gen
     116        sage: itr = _lexi_gen()
     117        sage: F = FreeGroup([itr.next() for i in [1..10]]); F
     118        Free Group on generators {a, b, c, d, e, f, g, h, i, j}
     119        sage: it = _lexi_gen()
     120        sage: [it.next() for i in range(10)]
     121        ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
     122        sage: itt = _lexi_gen(True)
     123        sage: [itt.next() for i in range(10)]
     124        ['a0', 'b0', 'c0', 'd0', 'e0', 'f0', 'g0', 'h0', 'i0', 'j0']
     125        sage: test = _lexi_gen()
     126        sage: ls = [test.next() for i in range(3*26)]
     127        sage: ls[2*26:3*26]
     128        ['a2', 'b2', 'c2', 'd2', 'e2', 'f2', 'g2', 'h2', 'i2', 'j2', 'k2', 'l2', 'm2',
     129         'n2', 'o2', 'p2', 'q2', 'r2', 's2', 't2', 'u2', 'v2', 'w2', 'x2', 'y2', 'z2']
     130
     131    TESTS::
     132       
     133        sage: from sage.groups.free_group import _lexi_gen
     134        sage: test = _lexi_gen()
     135        sage: ls = [test.next() for i in range(500)]
     136        sage: ls[234], ls[260]
     137        ('a9', 'a10')
     138
     139    """
     140    count = Integer(0)
     141    while True:
     142        mwrap, ind  = count.quo_rem(26)
     143        if mwrap == 0 and not(zeroes):
     144            name = ''
     145        else:
     146            name = str(mwrap)
     147        name = chr(ord('a') + ind) + name
     148        yield name
     149        count = count + 1
    96150
    97151class FreeGroupElement(ElementLibGAP):
    98152    """