Ticket #14684: 14684_free_group_conversion.patch

File 14684_free_group_conversion.patch, 1.4 KB (added by mmarco, 8 years ago)
  • sage/groups/free_group.py

    # HG changeset patch
    # User Miguel Marco <mmarco@unizar.es>
    # Date 1370308306 -7200
    # Node ID b28218dc998d26b57fffab53e10194fa45f947ad
    # Parent  7c96167d6f4c42f067dd7e5aa8b645b0750df8a9
    Trac #14684: make conversion between free groups aware of generator names
    
    diff --git a/sage/groups/free_group.py b/sage/groups/free_group.py
    a b  
    552552            a
    553553            sage: type(_)
    554554            <class 'sage.groups.free_group.FreeGroup_class_with_category.element_class'>
     555           
     556            sage: F.<a,b>=FreeGroup()
     557            sage: G.<b,a>=FreeGroup()
     558            sage: a.parent()
     559            Free Group on generators {b, a}
     560            sage: F(a)
     561            a
     562
    555563        """
    556564        if len(args)!=1:
    557565            return self.element_class(*args, parent=self, **kwds)
     
    565573        if hasattr(P, '_freegroup_'):
    566574            if P.FreeGroup() is self:
    567575                return self.element_class(x.Tietze(), parent=self, **kwds)
     576        if isinstance(P, FreeGroup_class):
     577            names=set([P._names[abs(i)-1] for i in x.Tietze()])
     578            if names.issubset(self._names):
     579                return self( [ i.sign()*(self._names.index(P._names[abs(i)-1])+1) for i in x.Tietze() ] )
     580            else:
     581                raise ValueError('generators of %s not in the group'%x)
    568582        return self.element_class(x, parent=self, **kwds)
    569583
    570584    def abelian_invariants(self):