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

ENHANCE: RootFFE as 3-argument function with field first. #761

Merged
merged 1 commit into from
Apr 22, 2016
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
7 changes: 4 additions & 3 deletions lib/ffe.gd
Original file line number Diff line number Diff line change
Expand Up @@ -659,18 +659,19 @@ DeclareAttribute( "AsInternalFFE", IsFFE);
##
## <#GAPDoc Label="RootFFE">
## <ManSection>
## <Oper Name="RootFFE" Arg='z, k'/>
## <Oper Name="RootFFE" Arg='F, z, k'/>
##
## <Description>
## <Ref Func="RootFFE"/> returns a finite field element
## <A>r</A> whose <A>k</A>-th power is <A>z</A>. If no such element exists
## <A>r</A> from <F> whose <A>k</A>-th power is <A>z</A>.
## If no such element exists
## then
## <K>fail</K> is returned.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "RootFFE", [ IsFFE, IsObject ] );
DeclareOperation( "RootFFE", [ IsObject, IsFFE, IsObject ] );


#############################################################################
Expand Down
34 changes: 25 additions & 9 deletions lib/ffe.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1149,17 +1149,33 @@ end);
##
#M RootFFE( <z>, <k> )
##
InstallMethod( RootFFE, "use LogFFE",true,[IsFFE,IsPosInt],
function(z,k)
local q,e;
q:=Characteristic(z)^DegreeFFE(z);
InstallMethod(RootFFE,"use field order",IsCollsElmsX,
[IsField,IsFFE,IsPosInt],0,
function(F,z,k)
return RootFFE(Size(F),z,k);
end);

InstallOtherMethod(RootFFE,"use LogFFE",true,[IsPosInt,IsFFE,IsPosInt],
function(q,z,k)
local e,m,p,a;
if IsZero(z) or IsOne(z) then return z;fi;
m:=q-1;
e:=LogFFE(z,Z(q));
e:=e/k;
if Gcd(DenominatorRat(e),q-1)=1 then
return Z(q)^(e mod (q-1));
else
return fail;
p:=GcdInt(m,e); #power for subgroup it is in
k:=k mod m;
a:=GcdInt(m,k); # power for subgroup we want
if p mod a<>0 then
return fail; # element does not lie in subgroup of a-th powers
fi;
# k/a is coprime to order of elts in subgroup and elt is an a-th power
a:=(e*(a/k mod (m/p))/a mod m);
return Z(q)^a;
end);

InstallOtherMethod(RootFFE,"without field",true,
[IsFFE,IsPosInt],0,
function(z,k)
return RootFFE(Characteristic(z)^DegreeFFE(z),z,k);
end);


Expand Down
20 changes: 16 additions & 4 deletions lib/zmodnz.gi
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,28 @@ InstallMethod( LogFFE,
##
#M RootFFE( <z>, <k> ) . . . . . . . . . . . . . . . . . . for `IsZmodpZObj'
##
InstallMethod(RootFFE,"for modulus rep, using RootMod",true,
[IsZmodpZObj and IsModulusRep,IsPosInt],
function( z, k )
InstallOtherMethod(RootFFE,"for modulus rep, using RootMod",true,
[IsPosInt,IsZmodpZObj and IsModulusRep,IsPosInt],
function( A, z, k )
local r,fam;
fam:=FamilyObj(z);
r:=RootMod(z![1],k,fam!.Characteristic);
if A<>fam!.Characteristic then
TryNextMethod();
fi;
if k=1 or z![1]=0 or z![1]=1 then return z;fi;
r:=RootMod(z![1],k,A);
if r=fail then return r;fi;
return ZmodnZObj(fam,r);
end );

InstallOtherMethod(RootFFE,"for modulus rep",true,
[IsZmodpZObj and IsModulusRep,IsPosInt],
function(z,k)
return RootFFE(FamilyObj(z)!.Characteristic,z,k);
end);




#############################################################################
##
Expand Down
17 changes: 17 additions & 0 deletions tst/testinstall/ffe.tst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ gap> Subfields( GF(81) );
[ GF(3), GF(3^2), GF(3^4) ]
gap> Subfields( GF(2^6) );
[ GF(2), GF(2^2), GF(2^3), GF(2^6) ]

# RootFFE
gap> Rochambeau:=function(F)
> local e,i,p,a,r;
> e:=Elements(F);
> for i in [1..2*Size(F)] do
> p:=Set(List(e,x->x^i));
> for a in e do
> r:=RootFFE(F,a,i);
> if a in p and r=fail then Error("-1"); return -1;fi;
> if r<>fail and a<>r^i then Error("1");return 1;fi;
> od;
> od;
> return 0;
> end;;
gap> ForAll(Filtered([1..256],IsPrimePowerInt),x->Rochambeau(GF(x))=0);
true
gap> STOP_TEST( "ffe.tst", 470000);

#############################################################################
Expand Down