Hi Alex,

By the way, I think this is a good moment to advertise for a very good idea
Nicolas had a few years ago, that is to implement and use the very common and
basic notion of family:

        A Family is an associative container which models a family
        `(f_i)_{i in I}`. Then, f[i] returns the element of the family
        indexed by i. Whenever available, set and EnumeratedSets
        operations (counting, iteration, listing) on the family are induced
        from those of the index set.

> And another example, where I (would like to) follow the example of the
> constructor for multivariate polynomials:
> 
>     sage: FreeGroup('x', 10)
> Expected:
>     Free Group on the Set {x0, x1, x2, x3, x4, x5, x6, x7, x8, x9}
> Got:
>     Free Group on the Set {x8, x9, x2, x3, x0, x1, x6, x7, x4, x5}

Here is my point: Take a random group with a set of generators:

   sage: S3 = SymmetricGroup(3)
   sage: S3.gens()
   [(1,2,3), (1,2)]

Now I want to construct the free group on those generators. Let try to do it
only with FreeMonoid since FreeFroup in not already implemented ;-)

   sage: F = FreeMonoid(2, S3.gens())
   ...
   ValueError: variable names must be alphanumeric, but one is '(1,2,3)' which 
is not.
I currently have to do:

   sage: (gs123, gs12) = S3.gens()
   sage: F = FreeMonoid(2, ['gf123', 'gf12'])
   sage: gf123, gf12 = F.gens()

And to handle the association gf123 <-> gs123 and gf12 <-> gs12 by hand.
Here comes the family. Right now:

   sage: F.gens()
   (gf123, gf12)

But I'd rather F.gens() returns the following Fgens object:

   sage: Fgens = Family({gs123 : gf123, gs12 : gf12})
   sage: Fgens
   Finite family {(1,2,3): gf123, (1,2): gf12}
   sage: tuple(Fgens)   # equivalent to F.gens()
   (gf123, gf12)

Fgens behave has a f.gens() with respect to iteration: 

   sage: for g in Fgens: print(g, g.parent())
   ....: 
   (gf123, Free monoid on 2 generators (gf123, gf12))
   (gf12, Free monoid on 2 generators (gf123, gf12))
   sage: len(Fgens)
   2

Now I can write:

   sage: Fgens[S3((1,2,3))]
   gf123

That is the generator of F are naturally indexed. Note that if you don't know
by what you want to index them Family index automatically the generator by
0, 1,2,... That is the following FgensBis behave as a list:

   sage: FgensBis = Family([gf123, gf12])
   sage: FgensBis
   Family (gf123, gf12)
   sage: FgensBis[0]
   gf123
   sage: len(FgensBis)
   2

We already use It extensively when building the basis in our
CombinatorialFreeModule and I think this should be used everywhere when
building a free object.

Comments and suggestions welcome !

Cheers,

Florent

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to