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

Avoid calling ConvertToVectorRep(v, 0) #4107

Closed

Conversation

frankluebeck
Copy link
Member

The family of finite fields of size >= 256 sets
!.rchar = 0, which leads to calls of 'ConvertToVectorRep'
with second argument 0 in various places.

Added a test which demonstrates the problem.

Description

The problem is described above.

The bug addressed here can be seen in this example:

gap> pol := UnivariatePolynomial(GF(293), Z(293)^0 * ConwayPol(293,8));;
gap> K := AlgebraicExtension(GF(293), pol);;
gap> xinv := 1/PrimitiveElement(K);
Error, <n> must be a positive integer at /export/home/luebeck/gap4/lib/integer.gi:991 called from
LogInt( q, common ) at /export/home/luebeck/gap4/lib/vecmat.gi:1365 called from
ConvertToVectorRepNC( v, f ); at /export/home/luebeck/gap4/lib/vecmat.gi:1530 called from
ImmutableVector( fam!.rchar, rf, true 
 ) at /export/home/luebeck/gap4/lib/algfld.gi:611 called from
InverseOp( elm ) at /export/home/luebeck/gap4/lib/arith.gi:392 called from
<function "InverseSameMutability for an (immutable) object">( <arguments> )
 called from read-eval loop at *stdin*:3
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk> 
gap> c := Random(K);;
Error, <n> must be a positive integer at /export/home/luebeck/gap4/lib/integer.gi:991 called from
LogInt( q, common ) at /export/home/luebeck/gap4/lib/vecmat.gi:1365 called from
ConvertToVectorRepNC( v, f ); at /export/home/luebeck/gap4/lib/vecmat.gi:1530 called from
ImmutableVector( fam!.rchar, l, true 
 ) at /export/home/luebeck/gap4/lib/algfld.gi:910 called from
func( GlobalMersenneTwister, x 
 ) at /export/home/luebeck/gap4/lib/random.gi:299 called from
<function "Random for an algebraic extension">( <arguments> )
 called from read-eval loop at *stdin*:3
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk> 

I'm not sure, if this pull request catches all instances of the problem. It is at least a quick fix which should never be bad.

A better fix would probably try to avoid that for larger finite fields its family has a component !.rchar which is set to 0 (instead of the characteristic of the field).

Text for release notes

A bug in the arithmetic of larger finite fields was fixed.

The family of finite fields of size >= 256 sets
!.rchar = 0, which leads to calls of 'ConvertToVectorRep'
with second argument 0 in various places.

Added a test which demonstrates the problem.
@frankluebeck frankluebeck added the kind: bug: unexpected error Issues describing bugs in which computation unexpectedly encounters an error, and PRs fixing them label Sep 1, 2020
Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever lib/vecmat.gi is modified, the same changes need to be applied to hpcgap/hpcgap/lib/vecmat.gi.

I'll submit an alternative PR.

if f <> 0 then
# method is called with f=0 for finite fields with large characteristic
ConvertToVectorRepNC(v,f);
fi;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should accept 0 here, that's a usage error; instead, the calling code should be fixed; we could insert an assertion here, though, to catch further similar issues in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug: unexpected error Issues describing bugs in which computation unexpectedly encounters an error, and PRs fixing them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants