<Chapter Label="Gens">
<Heading>Farey symbols for congruence subgroups</Heading>

The package &Congruence; provides functions to construct Farey symbols
for finite index subgroups. The algorithm used in the package allows
to construct a Farey symbol for any finite index subgroup of <M>SL_2(&ZZ;)</M> 
for which it is possible to check whether a given matrix belongs to this 
subgroup or not. <P/>

The development of an algorithm to determine the Farey symbol for a
subgroup G of a finite index in <M>SL_2(&ZZ;)</M> was started by Ravi
Kulkarni in <Cite Key="Kulkarni" /> and later it was improved by Mong-Lung Lang,
Chong-Hai Lim and Ser-Peow Tan in <Cite Key="LLT-Hecke" />, <Cite Key="LLT-Algorithm" />.
 
<Section Label="CompFarey">
<Heading>Computation of the Farey symbol for a finite index subgroup</Heading>
            
<ManSection>
  <Attr Name="FareySymbol" 
         Arg="G"  
        Comm="" />
  <Description>
    For a subgroup of a finite index G, this attribute stores one of the 
    Farey symbols corresponding 
    to the congruence subgroup <A>G</A>. The algorithm for its computation will work
for any matrix group for which a membership test is available.
  </Description>
</ManSection>       

<Example>
<![CDATA[
gap> FareySymbol(PrincipalCongruenceSubgroup(8));
[ infinity, 0, 1/4, 1/3, 3/8, 2/5, 1/2, 3/5, 5/8, 2/3, 3/4, 1, 5/4, 4/3, 
  11/8, 7/5, 3/2, 8/5, 13/8, 5/3, 7/4, 2, 9/4, 7/3, 19/8, 12/5, 5/2, 13/5, 
  21/8, 8/3, 11/4, 3, 13/4, 10/3, 27/8, 17/5, 7/2, 18/5, 29/8, 11/3, 15/4, 4, 
  17/4, 13/3, 9/2, 14/3, 19/4, 5, 21/4, 16/3, 11/2, 17/3, 23/4, 6, 25/4, 
  19/3, 13/2, 20/3, 27/4, 7, 29/4, 22/3, 15/2, 23/3, 31/4, 8, infinity ]
[ 1, 17, 10, 26, 32, 18, 19, 27, 30, 5, 2, 2, 13, 28, 26, 20, 21, 29, 27, 7, 
  3, 3, 16, 31, 28, 22, 23, 33, 29, 9, 4, 4, 5, 30, 31, 24, 25, 32, 33, 12, 
  6, 6, 7, 19, 18, 15, 8, 8, 9, 21, 20, 10, 11, 11, 12, 23, 22, 13, 14, 14, 
  15, 25, 24, 16, 17, 1 ]
gap> FareySymbol(CongruenceSubgroupGamma0(20));
[ infinity, 0, 1/5, 1/4, 2/7, 3/10, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1, 
  infinity ]
[ 1, 3, 4, 6, 7, 7, 5, 2, 2, 3, 6, 4, 5, 1 ]  
]]>
</Example>

</Section>

<!-- ********************************************************* -->

<Section Label="CompGens">
<Heading>Computation of generators of a finite index subgroup from its Farey symbol</Heading>
If <A>fs</A> is the Farey symbol for a group <M>G</M> with <M>r_1</M> even
labels, <M>r_2</M> odd labels and <M>r_3</M> pairs of intervals, then <M>G</M> is
generated by <M>r_1+r_2+r_3</M> matrices, which form a set of independent
generators for <M>G</M>. These matrices are constructed as follows:<P/>

for each even interval <M>[x_i, x_{i+1}]</M>, take the matrix
<Alt Only="LaTeX">
  <![CDATA[
  \[
        A=\left( 
           \begin{array}{rr}
              a_{i+1} b_{i+1} + a_i b_i & -a_i^2 - a_{i+1}^2 \\ 
              b_i^2 + b_{i+1}^2   & -a_{i+1} b_{i+1} - a_i b_i
           \end{array} 
        \right)
  \]
  ]]>
</Alt>
<Alt Only="Text,HTML"><Verb><![CDATA[
                       A=  [a_{i+1} b_{i+1} + a_i b_i    -a_i^2 - a_{i+1}^2        ]
                           [b_i^2 +b_{i+1}^2             -a_{i+1} b_{i+1} - a_i b_i]
]]></Verb></Alt>   
<P/>

for each odd interval <M>[x_j,x_{j+1}]</M>, take the matrix
<Alt Only="LaTeX">
  <![CDATA[
  \[
        B=\left( 
           \begin{array}{rr}
              a_{j+1} b_{j+1} + a_j b_{j+1} + a_j b_j & -a_j^2 - a_j a_{j+1} -
a_{j+1}^2 \\ b_j^2 + b_j b_{j+1} + b_{j+1}^2         & -a_{j+1}
b_{j+1} - a_{j+1} b_j - a_j b_j
           \end{array} 
        \right)
  \]
  ]]>
</Alt>
<Alt Only="Text,HTML"><Verb><![CDATA[
                        B=  [a_{j+1} b_{j+1} + a_j b_{j+1} + a_j b_j      -a_j^2 - a_j a_{j+1} -a_{j+1}^2]
                            [ b_j^2 + b_j b_{j+1} + b_{j+1}^2  -a_{j+1}   b_{j+1} - a_{j+1} b_j - a_j b_j]
]]></Verb></Alt>   
<P/>

for each pair of free intervals <M>[x_k,x_{k+1}]</M> and
<M>[x_s,x_{s+1}]</M>, take the matrix
<Alt Only="LaTeX">
  <![CDATA[
  \[
        \left( 
           \begin{array}{rr}
              a_{s+1} b_{k+1} + a_s b_k & -a_s a_k - a_{s+1} a_{k+1} \\ b_s b_k
- b_{s+1} b_{k+1}  & -a_{k+1} b_{s+1} - a_k b_s
           \end{array} 
        \right)
  \]
  ]]>
</Alt>
<Alt Only="Text,HTML"><Verb><![CDATA[
                        C=  [a_{s+1} b_{k+1} + a_s b_k    -a_s a_k - a_{s+1} a_{k+1}]
                            [b_s b_k- b_{s+1} b_{k+1}c    -a_{k+1} b_{s+1} - a_k b_s]
]]></Verb></Alt>   

 
<ManSection>
  <Func Name="MatrixByEvenInterval" 
         Arg="gfs i"  
        Comm="" />
  <Description>
  Returns the matrix corresponding to the even interval i in the generalized Farey sequence <A>gfs</A>.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> H:=CongruenceSubgroupGamma0(5); 
<congruence subgroup CongruenceSubgroupGamma_0(5) in SL_2(Z)>
gap> fs:=FareySymbol(H);
[ infinity, 0, 1/2, 1, infinity ]
[ 1, "even", "even", 1 ]
gap> gfs:=GeneralizedFareySequence(fs);
[ infinity, 0, 1/2, 1, infinity ]
gap> MatrixByEvenInterval(gfs,2);      
[ [ 2, -1 ], [ 5, -2 ] ]
]]>
</Example>


<ManSection>
  <Func Name="MatrixByOddInterval" 
         Arg="gfs i"  
        Comm="" />
  <Description>
  Returns the matrix corresponding to the odd interval i in the generalized Farey sequence <A>gfs</A>.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> fs_oo:=FareySymbolByData([infinity,0,infinity],["odd","odd"]);;
gap> gfs_oo:=GeneralizedFareySequence(fs_oo);
[ infinity, 0, infinity ]
gap> MatrixByOddInterval(gfs_oo,1);
[ [ -1, -1 ], [ 1, 0 ] ]
]]>
</Example>


<ManSection>
  <Func Name="MatrixByFreePairOfIntervals" 
         Arg="gfs k kp"  
        Comm="" />
  <Description>
    Returns the matrix corresponding to the pair of free intervals k and kp in the generalized Farey sequence <A>gfs</A>.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> fs_free:=FareySymbolByData([infinity,0,1,2,infinity],[1,2,2,1]);;
gap> gfs_free:=GeneralizedFareySequence(fs_free);;
gap> MatrixByFreePairOfIntervals(gfs_free,2,3);                                                        
[ [ 3, -2 ], [ 2, -1 ] ]
]]>
</Example>


<ManSection>
  <Func Name="GeneratorsByFareySymbol" 
         Arg="fs"  
        Comm="" />
  <Description>
  Returns a set of matrices constructed as above.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> fs_eo:=FareySymbolByData([infinity,0,infinity],["even","odd"]);;
gap> GeneratorsByFareySymbol(last);                                  
[ [ [ 0, -1 ], [ 1, 0 ] ], [ [ 0, -1 ], [ 1, -1 ] ] ]
gap> GeneratorsByFareySymbol(fs); 
[ [ [ 1, 1 ], [ 0, 1 ] ], [ [ 2, -1 ], [ 5, -2 ] ], [ [ 3, -2 ], [ 5, -3 ] ] ]
gap> GeneratorsByFareySymbol(fs_oo);
[ [ [ -1, -1 ], [ 1, 0 ] ], [ [ 0, -1 ], [ 1, -1 ] ] ]
gap> GeneratorsByFareySymbol(fs_free);                                                        
[ [ [ 1, 2 ], [ 0, 1 ] ], [ [ 3, -2 ], [ 2, -1 ] ] ]
]]>
</Example>


<ManSection>
  <Func Name="GeneratorsOfGroup" 
         Arg="G"  
        Comm="" />
  <Description>
  Returns a set of generators for the finite index group G in <M>SL_2(Z)</M>.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> G:=PrincipalCongruenceSubgroup(2);
<principal congruence subgroup of level 2 in SL_2(Z)>
gap> FareySymbol(G);
[ infinity, 0, 1, 2, infinity ]
[ 2, 1, 1, 2 ]
gap> GeneratorsOfGroup(G);
#I  Using the Congruence package for GeneratorsOfGroup ...
[ [ [ 1, 2 ], [ 0, 1 ] ], [ [ 3, -2 ], [ 2, -1 ] ] ]
gap> H:=CongruenceSubgroupGamma0(5);        
<congruence subgroup CongruenceSubgroupGamma_0(5) in SL_2(Z)>
gap> GeneratorsOfGroup(H);
#I  Using the Congruence package for GeneratorsOfGroup ...
[ [ [ 1, 1 ], [ 0, 1 ] ], [ [ 2, -1 ], [ 5, -2 ] ], [ [ 3, -2 ], [ 5, -3 ] ] ]
gap> I:=IntersectionOfCongruenceSubgroups(PrincipalCongruenceSubgroup(2),CongruenceSubgroupGamma0(3));
<intersection of congruence subgroups of resulting level 6 in SL_2(Z)>
gap> FareySymbol(I);
[ infinity, 0, 1/3, 1/2, 2/3, 1, 4/3, 3/2, 5/3, 2, infinity ]
[ 1, 5, 4, 3, 2, 2, 3, 4, 5, 1 ]
gap> GeneratorsOfGroup(I);                                                          
#I  Using the Congruence package for GeneratorsOfGroup ...
[ [ [ 1, 2 ], [ 0, 1 ] ], [ [ 11, -2 ], [ 6, -1 ] ], 
  [ [ 19, -8 ], [ 12, -5 ] ], [ [ 17, -10 ], [ 12, -7 ] ], 
  [ [ 7, -6 ], [ 6, -5 ] ] ]
]]>
</Example>

</Section>

<!-- ********************************************************* -->

<Section Label="CompOther">
<Heading>Other properties derived from Farey symbols</Heading>

<ManSection>
  <Func Name="IndexInPSL2ZByFareySymbol" 
         Arg="fs"  
        Comm="" />
  <Description>
By Proposition 7.2 in [Kulkarni], for the Farey symbol with underlying
generalized Farey sequence [infinity, x0, x1, ..., xn, infinity], the
index in <M>PSL_2(Z)</M> is given by the formula d = 3*n + e3, where e3 is the 
number of odd intervals.
  </Description>
</ManSection> 

<Example>
<![CDATA[
gap> IndexInPSL2ZByFareySymbol(fs);
6
gap> IndexInPSL2ZByFareySymbol(fs_oo);
2
gap> IndexInPSL2ZByFareySymbol(fs_free);
6
]]>
</Example>

</Section>
 
</Chapter>
