Skip to content

Commit

Permalink
Replace basic membership test
Browse files Browse the repository at this point in the history
Tries to address #72
  • Loading branch information
pedritomelenas authored Aug 5, 2022
1 parent 5adaf87 commit 84204b7
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions gap/basics.gi
Original file line number Diff line number Diff line change
Expand Up @@ -673,21 +673,27 @@ InstallMethod( BelongsToNumericalSemigroup,
fi;

##########################
# the desperate method
belongs:=function(x,gen)
if gen=[] then
return false;
fi;

if x=0 then
return true;
fi;

if x<0 then
return false;
fi;

return belongs(x-gen[1],gen) or belongs(x,gen{[2..Length(gen)]});
# the desperate method, inspired in the code of NrRestrictedPartitions
# the old version caused some recursion depth problems
belongs:=function(n,set)
local p,m,l;
p := [];
for m in [1..n+1] do
if (m-1) mod set[1] = 0 then
p[m] := 1;
else
p[m] := 0;
fi;
od;
for l in set{ [2..Length(set)] } do
for m in [l+1..n+1] do
p[m] := p[m] + p[m-l];
od;
if p[n+1]>0 then
return true;
fi;
od;
return p[n+1]<>0;
end;

return belongs(n,gen);
Expand Down

0 comments on commit 84204b7

Please sign in to comment.