Skip to content

Commit

Permalink
Implement Union(Rationals,Integers) and more, add tests
Browse files Browse the repository at this point in the history
Resolves #657
  • Loading branch information
fingolfin committed Feb 14, 2018
1 parent e755b88 commit b0d268d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/cyclotom.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2002,8 +2002,8 @@ BindGlobal("CompareCyclotomicCollectionHelper_Filters", [
BindGlobal("CompareCyclotomicCollectionHelper_Proxies", [
[ 1 ], [ 0, 1 ],
[ -1, 0, 1 ], [ -1, 0, 1, E(4) ],
[ -1, 0, 1/2, 1 ], [ -1, 0, 1, 1/2, E(4) ],
[ -1, 0, 1, 1/2, E(4), E(9) ], fail
[ -1, 0, 1/2, 1 ], [ -1, 0, 1/2, 1, E(4), 1/2+E(4) ],
[ -1, 0, 1/2, 1, E(4), 1/2+E(4), E(9) ], fail
] );

if IsHPCGAP then
Expand Down Expand Up @@ -2033,6 +2033,7 @@ function (A,B)
return ab[1] = ab[2];
end );


InstallMethod( IsSubset, "for certain cyclotomic semirings",
[IsCyclotomicCollection and IsSemiringWithOne,
IsCyclotomicCollection and IsSemiringWithOne],
Expand All @@ -2058,6 +2059,20 @@ function (A,B)
end );


InstallMethod( Union2, "for certain cyclotomic semirings",
[IsCyclotomicCollection and IsSemiringWithOne,
IsCyclotomicCollection and IsSemiringWithOne],
function (A,B)
local ab, i;
ab := CompareCyclotomicCollectionHelper(A, B);
# Verify that we recognized both A and B, otherwise give up.
if fail in ab then TryNextMethod(); fi;
i := Position( CompareCyclotomicCollectionHelper_Proxies, Union2( ab[1], ab[2] ) );
if i = fail then TryNextMethod(); fi;
return CompareCyclotomicCollectionHelper_Semirings[i];
end );


#############################################################################
##
#E
Expand Down
29 changes: 29 additions & 0 deletions tst/testinstall/cyclotom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,35 @@ Error, COEFFSCYC: <cyc> must be a cyclotomic (not a boolean or fail)
gap> CycList([1,fail]);
Error, CycList: each entry must be a rational (not a boolean or fail)

#
# Some tests for some operations on certain pre-defined infinite collections
# of cyclotomics, which are implemented using CompareCyclotomicCollectionHelper.
# For the tests, we exploit that the supported collections can be grouped into
# two totally ordered chains.
#
gap> sets:=[ PositiveIntegers, NonnegativeIntegers, Integers, Rationals, GaussianRationals, Cyclotomics ];;
gap> r:=[1..Length(sets)];;
gap> SetX(r, r, {i,j} -> Intersection(sets[i],sets[j]) = sets[Minimum(i,j)]);
[ true ]
gap> SetX(r, r, {i,j} -> Union(sets[i],sets[j]) = sets[Maximum(i,j)]);
[ true ]
gap> SetX(r, r, {i,j} -> IsSubset(sets[i],sets[j]) = (i>=j));
[ true ]
gap> SetX(r, r, {i,j} -> (sets[i]=sets[j]) = (i=j));
[ true ]

#
gap> sets:=[ PositiveIntegers, NonnegativeIntegers, Integers, GaussianIntegers, GaussianRationals, Cyclotomics ];;
gap> r:=[1..Length(sets)];;
gap> SetX(r, r, {i,j} -> Intersection(sets[i],sets[j]) = sets[Minimum(i,j)]);
[ true ]
gap> SetX(r, r, {i,j} -> Union(sets[i],sets[j]) = sets[Maximum(i,j)]);
[ true ]
gap> SetX(r, r, {i,j} -> IsSubset(sets[i],sets[j]) = (i>=j));
[ true ]
gap> SetX(r, r, {i,j} -> (sets[i]=sets[j]) = (i=j));
[ true ]

#
gap> STOP_TEST( "cyclotom.tst", 1);

Expand Down

0 comments on commit b0d268d

Please sign in to comment.