Skip to content

Commit

Permalink
Fix bug in MeetOfPartialPerms
Browse files Browse the repository at this point in the history
Previously if the argument was empty or of length 1, then this function
would return an error. This commit fixes this, and adds tests.
  • Loading branch information
james-d-mitchell authored and markuspf committed Dec 23, 2016
1 parent 77ae12c commit 4ff9b38
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/pperm.gi
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,23 @@ end);

InstallGlobalFunction(MeetOfPartialPerms,
function(arg)
local meet, i;

if IsPartialPermCollection(arg[1]) then
local meet, i, empty;
if Length(arg) = 1 and IsPartialPermCollection(arg[1]) then
return CallFuncList(MeetOfPartialPerms, AsList(arg[1]));
elif not IsPartialPermCollection(arg) then
Error("usage: the argument should be a collection of partial perms,");
Error("usage: the argument should be a collection of partial perms, ");
return;
fi;

meet:=arg[1]; i:=1;
repeat
i:=i+1;
meet:=MEET_PPERMS(meet, arg[i]);
until i=Length(arg) or meet=EmptyPartialPerm();
meet := arg[1];
i := 1;
empty := EmptyPartialPerm();

while i < Length(arg) and meet <> empty do
i := i + 1;
meet := MEET_PPERMS(meet, arg[i]);
od;

return meet;
end);
Expand Down
12 changes: 12 additions & 0 deletions tst/testinstall/pperm.tst
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,18 @@ gap> g:=PartialPermNC([100001,2,3,4,5]);
[1,100001](2)(3)(4)(5)
gap> MeetOfPartialPerms(f,g);
<identity partial perm on [ 2, 3, 4, 5 ]>
gap> MeetOfPartialPerms(PartialPerm([1]));
<identity partial perm on [ 1 ]>
gap> MeetOfPartialPerms(PartialPerm([1]), PartialPerm([2]));
<empty partial perm>
gap> MeetOfPartialPerms(PartialPerm([1]), PartialPerm([1, 2]));
<identity partial perm on [ 1 ]>
gap> MeetOfPartialPerms([]);
Error, usage: the argument should be a collection of partial perms,
gap> MeetOfPartialPerms([PartialPerm([1]), PartialPerm([1, 2])]);
<identity partial perm on [ 1 ]>
gap> MeetOfPartialPerms(SymmetricInverseMonoid(3));
<empty partial perm>

# RestrictedPartialPerm
gap> f:=PartialPermNC([100000,2,3,4,5]);
Expand Down

0 comments on commit 4ff9b38

Please sign in to comment.