-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
small bug with PartitionsGreatestLE(0,n); #5548
Comments
Looking at the code, i can see this was an intentional design decision, not just an accident, see ( lib/combinat.gi:1987) : That doesn't mean it can't be changed, or better documented, or course, but given this is such old code I'd be worried about changing it in case someone else's code depends on this behaviour?
|
OK. No idea what the reasoning behind this convention was. |
Looking at the manual, "partition of Since the behavior is not specified, it is difficult to reverse engineer what the intent behind the current behavior of First, one might of course try to extrapolate from the definition in the manual. E.g. one could argue that 0 can be decomposed into a "sum" with zero summands, and then Next I'd also expect the following relations to hold, no matter what the exact definition is:
All of these are violated here. The minimal "fix" to support this would indeed be to let So let's go back to the git history of this function. It was never really changed since it was added by Max N. back in August 2001 (for anyone with access to the "private" history, it is in commit 6007aab576230b6869dfe83198f027bba9685d18 there). Back then the old InstallGlobalFunction( PartitionsGreatestLE,
function(n,m)
local parts;
if not(IsInt(n) and IsInt(m)) then
ErrorNoReturn("usage: PartitionsGreatestLE( <n>, <m> )");
elif n < 0 or m < 0 then
parts := [];
else
if n = 0 then
if m = 0 then
parts := [ [ ] ];
else
parts := [ ];
fi;
else
if m = 0 then
parts := [ ];
else
parts := GPartitionsGreatestLE( n, m );
fi;
fi;
fi;
return parts;
end); Now, I can't help but notice the striking similarity to the code in InstallGlobalFunction(PartitionsRecursively,function ( n, arg... )
local parts, k;
if Length(arg) = 0 then
parts := PartitionsA( n, n, [], 1 );
elif Length(arg) = 1 then
k := arg[1];
if n = 0 then
if k = 0 then
parts := [ [ ] ];
else
parts := [ ];
fi;
else
if k = 0 then
parts := [ ];
else
parts := PartitionsK( n, n, k, [], 1 );
fi;
fi;
else
Error("usage: Partitions( <n> [, <k>] )");
fi;
return parts;
end); I can't help but notice how strikingly similar that code is (also There are no calls to |
That sounds reasonable to me. @rtange , would you be interested in writing some better documentation, and tests as well to check all these cases (which is probably more work than the actual fix itself)? If you don't fancy that let me know, but I thought I'd suggest it as you've most recently thought about this :) |
It seems to me that the documentation (i.e. the manual) matches the proposed new version better than the old one. I can do the testing, provided I can just paste in the new combinat.gi file and not redo an installation. I wonder whether PartitionsRecursively should also be adapted, since it has the same issue. |
Observed behaviour
PartitionsGreatestLE(0,n);
gives[[]]
for n=0 and[]
for n>0Expected behaviour
It should be
[[]]
for all n>=0This can be awkward when you need the union of the
PartitionsGreatestLE(i,n)
for all i>=0 and n fixed.Copy and paste GAP banner (to tell us about your setup)
The text was updated successfully, but these errors were encountered: