Skip to content

Commit

Permalink
Sync some changes from lib/ to hpcgap/lib/ (#5642)
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored Feb 19, 2024
1 parent 3cf365f commit 4bdb789
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
29 changes: 19 additions & 10 deletions hpcgap/lib/basis.gd
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,11 @@ DeclareOperation( "RelativeBasisNC", [ IsBasis, IsHomogeneousList ] );
## (see&nbsp;<Ref Sect="Vector Spaces Handled By Nice Bases"/>).
## <P/>
## <A>name</A> must be a string,
## a filter <M>f</M> with this name is created, and
## a logical implication from <M>f</M> to <Ref Filt="IsHandledByNiceBasis"/>
## is installed.
## a filter <M>f</M> with this name is created which implies
## <Ref Filt="IsFreeLeftModule"/>, and
## a logical implication from the join of <M>f</M> with
## <Ref Filt="IsAttributeStoringRep"/> to
## <Ref Filt="IsHandledByNiceBasis"/> is installed.
## <P/>
## <A>record</A> must be a record with the following components.
## <List>
Expand All @@ -805,28 +807,34 @@ DeclareOperation( "RelativeBasisNC", [ IsBasis, IsHomogeneousList ] );
## </Item>
## <Mark><C>NiceFreeLeftModuleInfo</C> </Mark>
## <Item>
## the <C>NiceFreeLeftModuleInfo</C> method for left modules in <M>f</M>,
## the <Ref Attr="NiceFreeLeftModuleInfo"/> method for left modules in
## <M>f</M>,
## </Item>
## <Mark><C>NiceVector</C> </Mark>
## <Item>
## the <C>NiceVector</C> method for left modules <M>V</M> in <M>f</M>;
## the <Ref Oper="NiceVector"/> method for left modules <M>V</M> in
## <M>f</M>;
## called with <M>V</M> and a vector <M>v \in V</M>, this function returns the
## nice vector <M>r</M> associated with <M>v</M>, and
## </Item>
## <Mark><C>UglyVector</C></Mark>
## <Item>
## the <Ref Oper="UglyVector"/> method for left modules <M>V</M> in <M>f</M>;
## called with <M>V</M> and a vector <M>r</M> in the <C>NiceFreeLeftModule</C> value
## of <M>V</M>, this function returns the vector <M>v \in V</M> to which <M>r</M> is
## the <Ref Oper="UglyVector"/> method for left modules <M>V</M> in
## <M>f</M>;
## called with <M>V</M> and a vector <M>r</M> in the
## <Ref Attr="NiceFreeLeftModule"/> value of <M>V</M>,
## this function returns the vector <M>v \in V</M> to which <M>r</M> is
## associated.
## </Item>
## </List>
## <P/>
## The idea is that all one has to do for implementing a new kind of free
## left modules handled by the mechanism of nice bases is to call
## <C>DeclareHandlingByNiceBasis</C> and <C>InstallHandlingByNiceBasis</C>,
## <Ref Func="DeclareHandlingByNiceBasis"/> and
## <Ref Func="InstallHandlingByNiceBasis"/>,
## which causes the installation of the necessary methods and adds the pair
## <M>[ f, </M><C><A>record</A>.detect</C><M> ]</M> to the global list <C>NiceBasisFiltersInfo</C>.
## <M>[ f, </M><A>record</A><C>.detect</C><M> ]</M> to the global list
## <Ref Var="NiceBasisFiltersInfo"/>.
## The <Ref Oper="LeftModuleByGenerators"/> methods call
## <Ref Func="CheckForHandlingByNiceBasis"/>, which sets the appropriate filter
## for the desired left module if applicable.
Expand Down Expand Up @@ -889,6 +897,7 @@ InstallGlobalFunction( "DeclareHandlingByNiceBasis", function( name, info )
local entry;
atomic readwrite NiceBasisFiltersInfo do
DeclareFilter( name );
InstallTrueMethod( IsFreeLeftModule, ValueGlobal( name ) );
entry := [ ValueGlobal( name ), info ];
MigrateObj( entry, NiceBasisFiltersInfo );
Add( NiceBasisFiltersInfo, entry, 1 );
Expand Down
10 changes: 6 additions & 4 deletions hpcgap/lib/basis.gi
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,16 @@ InstallGlobalFunction( "InstallHandlingByNiceBasis",
filter:= ValueGlobal( name );

# Install the detection of the filter.
# The mechanism is safe only if the domain can store
# its nice variant, thus we will install it only for cases where
# 'IsAttributeStoringRep' is guaranteed.
atomic readwrite NiceBasisFiltersInfo do
entry:= First( NiceBasisFiltersInfo,
x -> IsIdenticalObj( filter, x[1] ) );
entry[3] := record.detect;
od;

filter:= filter and IsAttributeStoringRep;
InstallTrueMethod( IsHandledByNiceBasis, filter );
filter:= IsFreeLeftModule and filter;

# Install the methods.
InstallMethod( NiceFreeLeftModuleInfo,
Expand Down Expand Up @@ -1078,7 +1080,7 @@ InstallMethod( IsCanonicalBasis,
##
#M Basis( <V> ) . . . . . . . . . . . for free module handled by nice basis
##
BasisForFreeModuleByNiceBasis:= function( V )
BindGlobal( "BasisForFreeModuleByNiceBasis", function( V )
local B;
B:= Objectify( NewType( FamilyObj( V ),
IsFiniteBasisDefault
Expand All @@ -1087,7 +1089,7 @@ BasisForFreeModuleByNiceBasis:= function( V )
rec() );
SetUnderlyingLeftModule( B, V );
return B;
end;
end );

InstallMethod( Basis,
"for free module that is handled by a nice basis",
Expand Down
1 change: 0 additions & 1 deletion hpcgap/lib/helpbase.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1442,4 +1442,3 @@ atomic readwrite HELP_REGION do
fi;
od; # end atomic
end);

10 changes: 5 additions & 5 deletions hpcgap/lib/polyconw.gi
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ end);

## list of all cases with less than 100*10^9 compatible polynomials, sorted
## w.r.t. this number
ConwayCandidates := function()
BindGlobal( "ConwayCandidates", function()
local cand, p, i;
# read data
for p in [2,113,1009] do
Expand All @@ -211,7 +211,7 @@ ConwayCandidates := function()
Sort(cand);
cand := Filtered(cand, a-> not IsBound(CONWAYPOLDATA[a[2]][a[3]]));
return cand;
end;
end );

##
##
Expand Down Expand Up @@ -502,15 +502,15 @@ InstallGlobalFunction( IsCheapConwayPolynomial, function( p, n )
fi;
# this is not very precise, hopefully good enough for the moment
if p < 41 then
if n < 100 and IsPrimeInt(n) then
if n < 100 and (n = 1 or IsPrimeInt(n)) then
return true;
fi;
elif p < 100 then
if n < 40 and IsPrimeInt(n) then
if n < 40 and (n = 1 or IsPrimeInt(n)) then
return true;
fi;
elif p < 1000 then
if n < 14 and IsPrimeInt(n) then
if n < 14 and (n = 1 or IsPrimeInt(n)) then
return true;
fi;
elif p < 2^48 then
Expand Down
36 changes: 24 additions & 12 deletions hpcgap/lib/ratfun.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,20 @@ function( left, right )
return SumCoefPolynomial(left, right);
end);

# divide by constant polynomials

InstallMethod(\/,"constant denominator poly",IsIdenticalObj,
[IsPolynomial,IsPolynomial],0,
function(num,den)
local e;
e:=ExtRepNumeratorRatFun(den);
if Length(e)=0 then Error("Division by zero");
elif Length(e)>2 or Length(e[1])>0 then TryNextMethod();fi;
e:=Inverse(e[2]);
if e=fail then TryNextMethod();fi;
return e*num;
end);

InstallGlobalFunction( QuotientPolynomialsExtRep,QUOTIENT_POLYNOMIALS_EXT);

#############################################################################
Expand All @@ -1090,9 +1104,7 @@ InstallMethod(HeuristicCancelPolynomialsExtRep,"ignore",true,
[IsRationalFunctionsFamily,IsList,IsList],
# fallback: lower than default for the weakest conditions
-1,
function(f,a,b)
return fail; # can't do anything
end);
ReturnFail);

InstallGlobalFunction(TryGcdCancelExtRepPolynomials,TRY_GCD_CANCEL_EXTREP_POL);

Expand Down Expand Up @@ -1129,7 +1141,7 @@ local fam,t,num,tt,den;
ExtRepPolynomialRatFun(left),
ExtRepDenominatorRatFun(right));
num:=ZippedProduct(t[1],ExtRepNumeratorRatFun(right),
fam!.zeroCoefficient,fam!.zippedProduct);
fam!.zeroCoefficient,fam!.zippedProduct);
if Length(t[2])=2 and t[2][1]=[] and t[2][2]=fam!.oneCoefficient then
return PolynomialByExtRepNC(fam,num);
else
Expand All @@ -1140,7 +1152,7 @@ local fam,t,num,tt,den;
ExtRepPolynomialRatFun(right),
ExtRepDenominatorRatFun(left));
num:=ZippedProduct(t[1],ExtRepNumeratorRatFun(left),
fam!.zeroCoefficient,fam!.zippedProduct);
fam!.zeroCoefficient,fam!.zippedProduct);
if Length(t[2])=2 and t[2][1]=[] and t[2][2]=fam!.oneCoefficient then
return PolynomialByExtRepNC(fam,num);
else
Expand All @@ -1152,9 +1164,9 @@ local fam,t,num,tt,den;
tt:=TryGcdCancelExtRepPolynomials(fam,
ExtRepNumeratorRatFun(right),ExtRepDenominatorRatFun(left));
num:=ZippedProduct(t[1],tt[1],fam!.zeroCoefficient,
fam!.zippedProduct);
fam!.zippedProduct);
den:=ZippedProduct(t[2],tt[2],fam!.zeroCoefficient,
fam!.zippedProduct);
fam!.zippedProduct);
if Length(den)=2 and den[1]=[] and den[2]=fam!.oneCoefficient then
return PolynomialByExtRepNC(fam,num);
else
Expand Down Expand Up @@ -1219,14 +1231,14 @@ local fam,num,den,lnum,rnum,lden,rden,t,tmp,tmpp,i;
# same denominator: add numerators
num:=ZippedSum(lnum,rnum,fam!.zeroCoefficient,fam!.zippedSum);
if Length(num)=0 then
return Zero(fam);
return Zero(fam);
fi;
t:=TryGcdCancelExtRepPolynomials(fam,num,lden);
if Length(t[2])=2 and Length(t[2][1])=0 and t[2][2]=fam!.oneCoefficient
then
return PolynomialByExtRepNC(fam,t[1]);
return PolynomialByExtRepNC(fam,t[1]);
else
return RationalFunctionByExtRepNC(fam,t[1],t[2]);
return RationalFunctionByExtRepNC(fam,t[1],t[2]);
fi;
else
t:=TryGcdCancelExtRepPolynomials(fam,lden,rden);
Expand All @@ -1236,9 +1248,9 @@ local fam,num,den,lnum,rnum,lden,rden,t,tmp,tmpp,i;
fam!.zippedProduct);
num:=ZippedSum(tmp,tmpp,fam!.zeroCoefficient,fam!.zippedSum);
if Length(t)=3 then
tmp:=t[3];
tmp:=t[3];
else
tmp:=QuotientPolynomialsExtRep(fam,rden,t[2]);
tmp:=QuotientPolynomialsExtRep(fam,rden,t[2]);
fi;
tmpp:=TryGcdCancelExtRepPolynomials(fam,num,tmp);
den:=ZippedProduct(tmpp[2],t[1],fam!.zeroCoefficient,
Expand Down

0 comments on commit 4bdb789

Please sign in to comment.