Support larger prime power bases in create_galois_field (issue #61)#73
Open
bertcarnell wants to merge 1 commit into
Open
Support larger prime power bases in create_galois_field (issue #61)#73bertcarnell wants to merge 1 commit into
bertcarnell wants to merge 1 commit into
Conversation
The Galois field power-cycle table (src/xtn.h) previously only covered prime power bases up to 47, so create_galois_field(53^2) and larger prime powers failed with 'GF(...) is not included in this program'. Extend the table to cover prime bases up to 127, adding primitive-polynomial entries for each base and exponent while p^n < 1e9 (the same threshold used for the original entries). Existing entries are left byte-for-byte unchanged. The generated polynomials are primitive (hence irreducible); only irreducibility is required by GaloisField.cpp, which builds the field tables without relying on x being a generator. Also restore the generator script (etc/CreatePowerCycle.R, referenced in the xtn.h header but missing from the repository) so the table can be regenerated and extended further, and add tests that build GF(53^2), GF(59^2), and GF(61^2) and spot-check the field axioms. Reported by U. Groemping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #61.
create_galois_field()previously failed for prime powers with a base larger than 47:The limit lived in the generated lookup table
src/xtn.h, which only contained power-cycle (primitive-polynomial) representations for prime bases up to 47. This PR extends the table to cover prime bases up to 127, soGF(53^2),GF(59^2), … now work, comfortably covering the ~120 requested in the issue.How
src/xtn.h— appended 51 new entries for prime bases53 … 127, one per exponentn ≥ 2whilep^n < 1e9(the same threshold that produced the original entries). Existing entries are left byte-for-byte unchanged (the only edit to pre-existing content is fixing a filename typo in the header comment). For each entryxtndefines a primitive — hence irreducible — polynomialx^n = xtn[0] + xtn[1]·x + … (mod p).etc/CreatePowerCycle.R— restored the generator script that thextn.hheader references but which was missing from the repo. It searches for the smallest primitive polynomial of eachGF(p^n)(using the fact that a primitive polynomial's constant term must be±a primitive root modp, which keeps the search fast). Re-run with a largermax_baseto extend the table further (e.g. for the covering-array work mentioned in the issue).tests/testthat/test-galois_field.R— added a test that constructsGF(53^2),GF(59^2),GF(61^2), checksp/q/nand table dimensions, and spot-checks the additive and multiplicative inverse axioms on sampled elements.Correctness notes
GaloisField.cppbuilds the field tables purely from polynomial arithmetic and the OA constructions only use theplus/times/roottables — none of them rely onxbeing a generator — so irreducibility is sufficient for correctness. I generated primitive polynomials anyway to stay faithful to the existing "power cycle" convention.primes::ipowandqcomparisons stay withinintrange: every entry hasp^n < 1e9 < INT_MAX, andipowusespow(double,double)which is exact below2^53.qis unchanged:create_galois_field(2^30)and non-prime-powers still error (verified by the existing tests, which I did not modify).xtnvectors forGF(53^2),GF(59^2),GF(61^2)produce complete inverse tables — i.e. every non-zero element has a reciprocal — so construction will not throw.A caveat worth flagging
GaloisFieldallocates denseq × qplus/timestables, so memory grows asq² = p^(2n).GF(53^2)(q=2809) is ~31 MB per table and fine, but e.g.GF(113^2)/GF(127^2)(q≈12.8k/16.1k) need ~0.7–1 GB per table, and anyn ≥ 3for these large bases is not practically constructible. The lookup entries are still included for completeness/consistency with the existing table (which already lists similarly largep^n), but the tests deliberately exercise only smalln=2fields. Reducing that memory footprint is out of scope here.Verification
R is not available in the environment used to prepare this branch, so the
testthatsuite was not executed here — please runR CMD check/devtools::test()before merging. The new table entries and their field validity were verified with an independent script.Coordination
Like the other two feature branches, this bumps the version to
1.4.0and editsNEWS/DESCRIPTION. Only those metadata files would conflict if multiple are merged; the code changes are disjoint. Happy to rebase/renumber as you prefer.https://claude.ai/code/session_01JNVgdYk9zNB8B4hLSn8rzj
Generated by Claude Code