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

Improve FFE code a bit and add tests #2690

Merged
merged 1 commit into from
Aug 14, 2018
Merged

Conversation

fingolfin
Copy link
Member

@fingolfin fingolfin commented Aug 9, 2018

  • add more FFE test cases, now finfield.c has almost full coverage
  • simplify FuncLOG_FFE_DEFAULT input validation
  • remove some comments pointing out problem when extending FFV to UInt4: we
    don't plan to do that (and it'd be impractical in the current setup anyway),
    and even if: those comments are not really helpful
  • make Z(p,d) stricter about verifying that p is a prime; and fixing an edge
    case on 32 bit systems, where Z(65536,2) lead to an overflow (which luckily
    had no consequences whatsoever)
  • adjust the error message of the kernel function PowFFEFFE (for
    "conjugating" FFE elements) to match those for +, -, *, / in case of
    arguments which have different characteristic.
  • fix bug in RootOfDefiningPolynomial

One change in here might be controversial: I add calls to IsPrimeInt into ZOp for large primes. These could in theory cause a slow down, although, since we cache results of primality checks, usually that should not be noticeable. But it prevents stupid mistakes. So I'd argue it's no problem after all.

@fingolfin fingolfin added kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements topic: tests issues or PRs related to tests release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Aug 9, 2018
@codecov
Copy link

codecov bot commented Aug 10, 2018

Codecov Report

Merging #2690 into master will increase coverage by 0.04%.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##           master    #2690      +/-   ##
==========================================
+ Coverage   75.43%   75.48%   +0.04%     
==========================================
  Files         478      478              
  Lines      241610   241616       +6     
==========================================
+ Hits       182259   182378     +119     
+ Misses      59351    59238     -113
Impacted Files Coverage Δ
hpcgap/lib/ffe.gi 81.6% <100%> (+6.2%) ⬆️
lib/ffe.gi 81.64% <100%> (+5.07%) ⬆️
src/finfield.c 96.83% <100%> (+5.38%) ⬆️
lib/ffeconway.gi 82.53% <83.33%> (-0.02%) ⬇️
hpcgap/lib/ffeconway.gi 61.24% <83.33%> (+1.44%) ⬆️
src/stats.c 89.43% <0%> (-0.2%) ⬇️
lib/numtheor.gi 83.61% <0%> (+0.7%) ⬆️
lib/field.gi 46.55% <0%> (+2.29%) ⬆️
... and 3 more

@fingolfin fingolfin force-pushed the mh/ffe branch 2 times, most recently from 463c674 to d1eddbf Compare August 11, 2018 15:10
@fingolfin fingolfin changed the title More FFE tests and fixes Improve FFE code a bit and add tests Aug 11, 2018
* add more FFE test cases, now finfield.c has almost full coverage
* simplify `FuncLOG_FFE_DEFAULT` input validation
* remove some comments pointing out problem when extending FFV to UInt4: we
  don't plan to do that (and it'd be impractical in the current setup anyway),
  and even if: those comments are not really helpful
* make Z(p,d) stricter about verifying that `p` is a prime; and fixing an edge
  case on 32 bit systems, where Z(65536,2) lead to an overflow (which luckily
  had no consequences whatsoever)
* adjust the error message of the kernel function `PowFFEFFE` (for
  "conjugating" FFE elements) to match those for +, -, *, / in case of
  arguments which have different characteristic.
* fix bug in RootOfDefiningPolynomial
@@ -600,7 +600,7 @@ InstallMethod( RootOfDefiningPolynomial,

coeffs:= ShiftedCoeffs( coeffs[1], coeffs[2] );
p:= Characteristic( F );
d:= ( Length( coeffs ) - 1 ) * DegreeOverPrimeField( F );
d:= DegreeOverPrimeField( F );
Copy link
Member

Choose a reason for hiding this comment

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

Any ideas why this factor was there before?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I dug a bit. That line was added by @ThomasBreuer in a commit from 1998-11-16 (hash 8a81e3cac9f5878891017aa3b6e9d060a0845f0d in the private git history). Looking at the code added there, a large part of it is identical to code in FieldExtension, including the bit computing d -- there, however, F was the base field, while here it is the extension field. So I suspect this was a copy&paste accident. Since this code was never triggered before I added the patches in this PR, we never noticed.

Copy link
Member Author

Choose a reason for hiding this comment

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

One may in fact wonder whether it wouldn't be better to extract the common code into a new helper operationRootOfPolynomial(F, poly). Then the above RootOfDefiningPolynomial method would essentially becomes F -> RootOfPolynomial(PrimeField(F), DefiningPolynomial(F), and the FieldExtension method could also be shortened. And if somebody comes up with a better implementation than "try all field elements" to do this, they'd have to edit only one spot.

@fingolfin fingolfin merged commit 97aec87 into gap-system:master Aug 14, 2018
@fingolfin fingolfin deleted the mh/ffe branch August 14, 2018 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes topic: tests issues or PRs related to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants