[GAP Forum] Re: Replacing in GAP

Nikos Apostolakis nikos.ap at gmail.com
Mon Mar 19 15:50:42 GMT 2007


"AHMET ARIKAN" writes:
>
> Let  y=(a_1,a_2,...,a_k) be a cycle of length k where a_i is a
> natural number for each i. Is there a way in GAP to replace some
> determined components with some other natural numbers (for example
> replace a_{i_1},..., a_{i_t} with some different natural
> numbers). Of course it can be done manually, but it is not helpful
> for him.
>

The following function converts a list to a cycle. So for example
list2cycle([1,2,3]);
 => (1,2,3)

----- 8<  Cut here 8< -----
list2cycle := function(c)                                   
    local cycle, shift;                                       

    shift:= [2..Length(c)];  
    Add(shift, 1);                       
    cycle:= [1..Maximum(c)];  
    cycle{c}:= c{shift};                

    return PermList(cycle);                                   
end;    
----- 8<  Cut here 8< -----

I found this function in some older post in this forum.  Using this
function you can define a conjugating permutation to do the
replacement you want.  For example to replace in the cycle c
the elements of list1 with the elments of list2 you can do

pairs := List( [1..Length(list1)], i -> [ list1[i], list2[i] ]);
conj := Product( List(pairs, list2cycle));
c^conj;

assuming ofcourse that everything above makes sence (i.e.  list1 and
list2 have the same length etc).  This is basically Alastair's
solution in a form that can easily bundled into a function.

HTH,
Nikos



More information about the Forum mailing list