Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/cyclotom.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,31 @@ function (A,B)
end );


InstallMethod( IsSubset, "for a cyclotomic semiring and a range",
[IsCyclotomicCollection and IsSemiringWithOne,
IsRange],
function (D, R)
local lo;
if IsEmpty( R ) then return true; fi;
# Ranges contain only integers.
if IsPositiveIntegers( D ) then
# PositiveIntegers contains all integers >= 1
lo := Minimum( R[1], R[Length(R)] );
return lo >= 1;
elif IsNonnegativeIntegers( D ) then
# NonnegativeIntegers contains all integers >= 0
lo := Minimum( R[1], R[Length(R)] );
return lo >= 0;
elif IsIntegers( D ) or IsRationals( D )
or IsGaussianIntegers( D ) or IsGaussianRationals( D )
or (HasIsWholeFamily( D ) and IsWholeFamily( D )) then
# These domains contain all integers, so any range is a subset
return true;
fi;
TryNextMethod();
end );


InstallMethod( Intersection2, "for certain cyclotomic semirings",
[IsCyclotomicCollection and IsSemiringWithOne,
IsCyclotomicCollection and IsSemiringWithOne],
Expand Down
40 changes: 40 additions & 0 deletions tst/testinstall/cyclotom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,45 @@ gap> SetX(r, r, {i,j} -> IsSubset(sets[i],sets[j]) = (i>=j));
gap> SetX(r, r, {i,j} -> (sets[i]=sets[j]) = (i=j));
[ true ]

#
# IsSubset for cyclotomic semirings and ranges
#
gap> IsSubset(Integers, [1..10^15]);
true
gap> IsSubset(Integers, [-10..10]);
true
gap> IsSubset(Rationals, [1..10^15]);
true
gap> IsSubset(GaussianIntegers, [1..10^15]);
true
gap> IsSubset(GaussianRationals, [1..10^15]);
true
gap> IsSubset(PositiveIntegers, [1..10^15]);
true
gap> IsSubset(PositiveIntegers, [0..10]);
false
gap> IsSubset(PositiveIntegers, [-5..5]);
false
gap> IsSubset(NonnegativeIntegers, [0..10^15]);
true
gap> IsSubset(NonnegativeIntegers, [-1..10]);
false
gap> IsSubset(NonnegativeIntegers, [1..10]);
true

# descending ranges
gap> IsSubset(PositiveIntegers, [10,9..1]);
true
gap> IsSubset(PositiveIntegers, [10,9..0]);
false
gap> IsSubset(NonnegativeIntegers, [10,9..0]);
true
gap> IsSubset(NonnegativeIntegers, [5,3..-1]);
false

# empty ranges
gap> IsSubset(PositiveIntegers, [1..0]);
true

#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I wrote that I'd suggest to keep the tests for ranges and lists apart, my idea was to insert something like this, here below the ranges tests:

Suggested change
#
#
gap> lists:=[ [-2,-1], [], [-1,0,1], [0,1], [1,2], [-b,-1], [-b,0], [-b,1], [-1,b], [0,b], [1,b], [-b,b]];;
#
gap> SetX(ranges, lists, {r,s} -> IsSubset(s,r) = (IsEmpty(r) or (First(r) in s and Last(r) in s)));
[ true ]
gap> SetX(ranges, lists, {r,s} -> not IsSubset(r,s));
[ true ]

gap> STOP_TEST("cyclotom.tst");
Loading