Skip to content
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

Make permutations remember their inverses (cleanup of #1772) #1831

Merged
merged 5 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions doc/ref/permutat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Permutations in ⪆ are entered and displayed in cycle notation,
such as <C>(1,2,3)(4,5)</C>.
<P/>
The preimage of the point <M>i</M> under the permutation <M>p</M> can be
computed as <M>i</M><C>/</C><M>p</M>,
without constructing the inverse of <M>p</M>.
computed as <M>i</M><C>/</C><M>p</M>, see <Ref Var="PERM_INVERSE_THRESHOLD"/>.
<P/>
For arithmetic operations for permutations and their precedence,
see&nbsp;<Ref Sect="Arithmetic Operations for Elements"/>.
Expand All @@ -47,6 +46,7 @@ the category test function for permutations is <Ref Func="IsPerm"/>.
<#Include Label="IsPerm">
<#Include Label="IsPermCollection">
<#Include Label="PermutationsFamily">
<#Include Label="PERM_INVERSE_THRESHOLD">

</Section>

Expand Down
4 changes: 2 additions & 2 deletions lib/dicthf.gi
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function(d,pe)
if IsPerm4Rep(p) then
# is it a proper 4byte perm?
if l>65536 then
return HashKeyBag(p,255,0,4*l);
return HashKeyBag(p,255,GAPInfo.BytesPerVariable,4*l);
else
# the permutation does not require 4 bytes. Trim in two
# byte representation (we need to do this to get consistent
Expand All @@ -217,7 +217,7 @@ function(d,pe)
fi;
fi;
# now we have a Perm2Rep:
return HashKeyBag(p,255,0,2*l);
return HashKeyBag(p,255,GAPInfo.BytesPerVariable,2*l);
end;
end);

Expand Down
23 changes: 23 additions & 0 deletions lib/permutat.g
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,29 @@ InstallMethod( DistancePerms, "for general permutations",
function(x,y)
return NrMovedPoints(x/y); end);

#############################################################################
##
#V PERM_INVERSE_THRESHOLD . . . . cut off for when inverses are computed
## eagerly
##
## <#GAPDoc Label="PERM_INVERSE_THRESHOLD">
## <ManSection>
## <Var Name="PERM_INVERSE_THRESHOLD"/>
##
## <Description>
## For permutations of degree up to <C>PERM_INVERSE_THRESHOLD</C> whenever
## the inverse image of a point under a permutations is needed, the entire
## inverse is computed and stored. Otherwise, if the inverse is not stored,
## the point is traced around the cycle it is part of to find the inverse
## image. This takes time when it happens, and uses memory, but saves time
## on a variety of subsequent computations. This threshold can be adjusted
## by simply assigning to the variable. The default is 10000.
## </Description>
## </ManSection>
## <#/GAPDoc>

PERM_INVERSE_THRESHOLD := 10000;



#############################################################################
Expand Down
12 changes: 6 additions & 6 deletions src/exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,10 @@ Obj EvalPermExpr (
c, MAX_DEG_PERM4);

/* if necessary resize the permutation */
if ( SIZE_OBJ(perm)/sizeof(UInt4) < c ) {
ResizeBag( perm, (c + 1023) / 1024 * 1024 * sizeof(UInt4) );
ptr4 = ADDR_PERM4( perm );
for ( k = m+1; k <= SIZE_OBJ(perm)/sizeof(UInt4); k++ ) {
if (DEG_PERM4(perm) < c) {
ResizeBag(perm, SIZEBAG_PERM4((c + 1023) / 1024 * 1024));
ptr4 = ADDR_PERM4(perm);
for (k = m + 1; k <= DEG_PERM4(perm); k++) {
ptr4[k-1] = k-1;
}
}
Expand Down Expand Up @@ -911,12 +911,12 @@ Obj EvalPermExpr (
ptr2[k-1] = ptr4[k-1];
};
RetypeBag( perm, T_PERM2 );
ResizeBag( perm, m * sizeof(UInt2) );
ResizeBag(perm, SIZEBAG_PERM2(m));
}

/* otherwise just shorten the permutation */
else {
ResizeBag( perm, m * sizeof(UInt4) );
ResizeBag(perm, SIZEBAG_PERM4(m));
}

/* return the permutation */
Expand Down
10 changes: 5 additions & 5 deletions src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1984,10 +1984,10 @@ void IntrPermCycle (
c, MAX_DEG_PERM4);

/* if necessary resize the permutation */
if ( SIZE_OBJ(perm)/sizeof(UInt4) < c ) {
ResizeBag( perm, (c + 1023) / 1024 * 1024 * sizeof(UInt4) );
if (DEG_PERM4(perm) < c) {
ResizeBag(perm, SIZEBAG_PERM4((c + 1023) / 1024 * 1024));
ptr4 = ADDR_PERM4( perm );
for ( k = m+1; k <= SIZE_OBJ(perm)/sizeof(UInt4); k++ ) {
for (k = m + 1; k <= DEG_PERM4(perm); k++) {
ptr4[k-1] = k-1;
}
}
Expand Down Expand Up @@ -2057,12 +2057,12 @@ void IntrPerm (
ptr2[k-1] = ptr4[k-1];
};
RetypeBag( perm, T_PERM2 );
ResizeBag( perm, m * sizeof(UInt2) );
ResizeBag(perm, SIZEBAG_PERM2(m));
}

/* otherwise just shorten the permutation */
else {
ResizeBag( perm, m * sizeof(UInt4) );
ResizeBag(perm, SIZEBAG_PERM4(m));
}

}
Expand Down
Loading