GAP (ResClasses) - Chapter 1: Unions of Residue Classes

Goto Chapter: | Top | 1 | 2 | 3 | 4 | Bib | Ind

### 1. Unions of Residue Classes

#### 1.1 Entering residue classes and unions thereof

##### 1.1-1 ResidueClass

`> ResidueClass`( R, m, r ) | ( function )

`> ResidueClass`( m, r ) | ( function )

`> ResidueClass`( r, m ) | ( function )

Returns: In the three-argument form the residue class r mod m of the ring R, and in the two-argument form the residue class r mod m of the integers.

In the two-argument case, r and m must not be negative, and r is assumed to lie in the range `[0..m-1]`. The latter is used to decide which of the two arguments is the modulus m and which is the residue r. For convenience, in the two-argument case it is permitted to enclose the argument list in list brackets.

Residue classes have the property `IsResidueClass`. Rings are regarded as residue class 0 (mod 1), and therefore have this property. There are operations `Modulus` and `Residue` to retrieve the modulus m resp. residue r of a residue class.

    gap> ResidueClass(2,3);
    The residue class 2(3) of Z
    gap> ResidueClass(Z_pi([2,5]),2,1);
    The residue class 1(2) of Z_( 2, 5 )
    gap> R := PolynomialRing(GF(2),1);;
    gap> x := Indeterminate(GF(2),1);; SetName(x,"x");
    gap> ResidueClass(R,x+One(R),Zero(R));
    The residue class 0*Z(2) ( mod x+Z(2)^0 ) of GF(2)[x]

##### 1.1-2 ResidueClassUnion

`> ResidueClassUnion`( R, m, r ) | ( function )

`> ResidueClassUnion`( R, m, r, included, excluded ) | ( function )

Returns: The union of the residue classes r[i] mod m of the ring R, plus / minus finite sets included and excluded of elements of R.

    gap> ResidueClassUnion(Integers,6,[2,4]);
    Union of the residue classes 2(6) and 4(6) of Z
    gap> ResidueClassUnion(Integers,5,[1,2],[3,8],[-4,1]);
    (Union of the residue classes 1(5) and 2(5) of Z) U [ 3, 8 ] \ [ -4, 1 ]
    gap> ResidueClassUnion(Z_pi([2,3]),8,[3,5]);
    <union of 2 residue classes (mod 8) of Z_( 2, 3 )>
    gap> ResidueClassUnion(R,x^2,[One(R),x],[Zero(R)],[One(R)]);
    <union of 2 residue classes (mod x^2) of GF(2)[x]> U [ 0*Z(2) ] \ [ Z(2)^0 ]

For extracting the components of a residue class union as passed as arguments to `ResidueClassUnion`, there are operations `Modulus`, `Residues`, `IncludedElements` and `ExcludedElements`.

The user has the choice between a longer and more descriptive and a shorter and less bulky output format for residue classes and unions thereof:

    gap> ResidueClassUnionViewingFormat("short");
    gap> ResidueClassUnion(Integers,12,[0,1,4,7,8]);
    0(4) U 1(6)
    gap> ResidueClassUnionViewingFormat("long");
    gap> ResidueClassUnion(Integers,12,[0,1,4,7,8]);
    Union of the residue classes 0(4) and 1(6) of Z

##### 1.1-3 AllResidueClassesModulo

`> AllResidueClassesModulo`( R, m ) | ( function )

`> AllResidueClassesModulo`( m ) | ( function )

Returns: A sorted list of all residue classes (mod m) of the ring R.

If the argument R is omitted it defaults to the default ring of m -- cp. the documentation of `DefaultRing` in the GAP reference manual. A transversal for the residue classes (mod m) can be obtained by the operation `AllResidues(R,m)`, and their number can be determined by the operation `NumberOfResidues(R,m)`.

    gap> AllResidueClassesModulo(Integers,2);
    [ The residue class 0(2) of Z, The residue class 1(2) of Z ]
    gap> AllResidueClassesModulo(Z_pi(2),2);
    [ The residue class 0(2) of Z_( 2 ), The residue class 1(2) of Z_( 2 ) ]
    gap> AllResidueClassesModulo(R,x);
    [ The residue class 0*Z(2) ( mod x ) of GF(2)[x],
      The residue class Z(2)^0 ( mod x ) of GF(2)[x] ]
    gap> AllResidues(Integers,6);
    [ 0 .. 5 ]
    gap> AllResidues(R,x^3);
    [ 0*Z(2), Z(2)^0, x, x+Z(2)^0, x^2, x^2+Z(2)^0, x^2+x, x^2+x+Z(2)^0 ]

#### 1.2 Methods for unions of residue classes

There are methods for `Print`, `String` and `Display` which are applicable to unions of residue classes. There is a method for `in` which tests whether some ring element lies in a given union of residue classes.

    gap> Print(ResidueClass(1,2),"\n");
    ResidueClassUnion( Integers, 2, [ 1 ] )
    gap> 1 in ResidueClass(1,2);
    true

There are methods for `Union`, `Intersection`, `Difference` and `IsSubset` available for unions of residue classes. They also accept finite subsets of the base ring as arguments.

    gap> S := Union(ResidueClass(0,2),ResidueClass(0,3));
    Z \ Union of the residue classes 1(6) and 5(6) of Z
    gap> Intersection(S,ResidueClass(0,7));
    Union of the residue classes 0(14) and 21(42) of Z
    gap> Difference(S,ResidueClass(2,4));
    Union of the residue classes 0(4) and 3(6) of Z
    gap> IsSubset(ResidueClass(0,2),ResidueClass(4,8));
    true
    gap> Union(S,[1..10]);
    (Union of the residue classes 0(2) and 3(6) of Z) U [ 1, 5, 7 ]
    gap> Intersection(S,[1..10]);
    [ 2, 3, 4, 6, 8, 9, 10 ]
    gap> Difference(S,[1..10]);
    (Union of the residue classes 0(2) and 3(6) of Z) \ [ 2, 3, 4, 6, 8, 9, 10 ]
    gap> Difference(Integers,[1..10]);
    Z \ <set of cardinality 10>
    gap> IsSubset(S,[1..10]);
    false

If the underlying ring has a residue class ring of a given cardinality t, then a residue class can be written as a disjoint union of t residue classes with equal moduli:

##### 1.2-1 SplittedClass

`> SplittedClass`( cl, t ) | ( operation )

Returns: A partition of the residue class cl into t residue classes with equal moduli, provided that such a partition exists. Otherwise `fail`.

    gap> SplittedClass(ResidueClass(1,2),2);
    [ The residue class 1(4) of Z, The residue class 3(4) of Z ]
    gap> SplittedClass(ResidueClass(Z_pi(3),3,0),2);
    fail

Often one needs a partition of a given union of residue classes into "few" residue classes. Ensuring to get always a partition of minimal possible length seems to be algorithmically difficult. The following operation finds usually "reasonably short" partitions:

##### 1.2-2 AsUnionOfFewClasses

`> AsUnionOfFewClasses`( U ) | ( operation )

Returns: A set of disjoint residue classes whose union is U.

As the name of the operation suggests, it is taken care that the number of residue classes in the returned list is kept "reasonably small". It is not necessarily minimal. No care is taken of `IncludedElements` and `ExcludedElements`.

    gap> AsUnionOfFewClasses(Difference(Integers,ResidueClass(0,12)));
    [ The residue class 1(2) of Z, The residue class 2(4) of Z,
      The residue class 4(12) of Z, The residue class 8(12) of Z ]

One can compute the sets of sums, differences, products and quotients of the elements of a union of residue classes and an element of the base ring:

    gap> ResidueClass(0,2) + 1;
    The residue class 1(2) of Z
    gap> ResidueClass(0,2) - 2 = ResidueClass(0,2);
    true
    gap> 3 * ResidueClass(0,2);
    The residue class 0(6) of Z
    gap> ResidueClass(0,2)/2;
    Integers

##### 1.2-3 Density

`> Density`( U ) | ( operation )

Returns: The natural density of U as a subset of the underlying ring.

The natural density of a residue class r(m) of a ring R is defined by 1/|R/mR|, and the natural density of a union U of finitely many residue classes is defined by the sum of the densities of the elements of a partition of U into finitely many residue classes.

    gap> Density(ResidueClass(0,2));
    1/2
    gap> Density(Difference(Integers,ResidueClass(0,5)));
    4/5

##### 1.2-4 RandomPartitionIntoResidueClasses

`> RandomPartitionIntoResidueClasses`( R, length, primes ) | ( operation )

Returns: A "random" partition of the ring R into length residue classes whose moduli have only prime factors in primes, resp. `fail` if no such partition exists.

    gap> ResidueClassUnionViewingFormat("short");
    gap> RandomPartitionIntoResidueClasses(Integers,30,[2,3,5,7]);
    [ 2(7), 3(7), 4(7), 5(7), 6(7), 1(35), 8(35), 14(35), 21(35), 22(35), 28(35),
      29(35), 7(105), 15(105), 42(105), 50(105), 77(105), 85(105), 70(175),
      105(175), 35(350), 210(350), 0(525), 140(525), 315(525), 350(525),
      490(525), 175(1575), 700(1575), 1225(1575) ]
    gap> Union(last);
    Integers
    gap> Sum(List(last2,Density));
    1

For looping over unions of residue classes of the integers, there are methods for the operations `Iterator` and `NextIterator`.

#### 1.3 The categories and families of unions of residue classes

##### 1.3-1 IsUnionOfResidueClasses

`> IsUnionOfResidueClasses`( U ) | ( filter )

`> IsUnionOfResidueClassesOfZ`( U ) | ( filter )

`> IsUnionOfResidueClassesOfZ_pi`( U ) | ( filter )

`> IsUnionOfResidueClassesOfGFqx`( U ) | ( filter )

Returns: `true` if U is a union of residue classes resp. a union of residue classes of the ring of integers resp. a union of residue classes of a semilocalization of the ring of integers resp. a union of residue classes of a polynomial ring in one variable over a finite field, and `false` otherwise.

Often the same methods can be used for residue classes of the ring of integers and of its semilocalizations. For this reason there is a category `IsUnionOfResidueClassesOfZorZ_pi` which is the union of `IsUnionOfResidueClassesOfZ` and `IsUnionOfResidueClassesOfZ_pi`. The internal representation of unions of residue classes is called `IsResidueClassUnionSparseRep`.

##### 1.3-2 ResidueClassUnionsFamily

`> ResidueClassUnionsFamily`( R ) | ( function )

`> ResidueClassUnionsFamily`( R, fixedreps ) | ( function )

Returns: The family of unions of residue classes resp. the family of unions of residue classes with fixed representatives of the ring R, depending on whether fixedreps is present and `true`.

The ring R can be retrieved as `UnderlyingRing(ResidueClassUnionsFamily(R))`. Unions of residue classes with fixed representatives are described in the next chapter.

Top of Book | Previous Chapter | Next Chapter

Goto Chapter: | Top | 1 | 2 | 3 | 4 | Bib | Ind

generated by GAPDoc2HTML