Skip to content

Support larger prime power bases in create_galois_field (issue #61)#73

Open
bertcarnell wants to merge 1 commit into
masterfrom
claude/lhs-galois-field-base-61
Open

Support larger prime power bases in create_galois_field (issue #61)#73
bertcarnell wants to merge 1 commit into
masterfrom
claude/lhs-galois-field-base-61

Conversation

@bertcarnell

Copy link
Copy Markdown
Owner

Summary

Fixes #61. create_galois_field() previously failed for prime powers with a base larger than 47:

lhs::create_galois_field(47^2)  # worked
lhs::create_galois_field(53^2)  # Error: GF(2809) = GF(53^2) is not included in this program.

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, so GF(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 bases 53 … 127, one per exponent n ≥ 2 while p^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 entry xtn defines a primitive — hence irreducible — polynomial x^n = xtn[0] + xtn[1]·x + … (mod p).
  • etc/CreatePowerCycle.R — restored the generator script that the xtn.h header references but which was missing from the repo. It searches for the smallest primitive polynomial of each GF(p^n) (using the fact that a primitive polynomial's constant term must be ± a primitive root mod p, which keeps the search fast). Re-run with a larger max_base to 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 constructs GF(53^2), GF(59^2), GF(61^2), checks p/q/n and table dimensions, and spot-checks the additive and multiplicative inverse axioms on sampled elements.

Correctness notes

  • GaloisField.cpp builds the field tables purely from polynomial arithmetic and the OA constructions only use the plus/times/root tables — none of them rely on x being a generator — so irreducibility is sufficient for correctness. I generated primitive polynomials anyway to stay faithful to the existing "power cycle" convention.
  • primes::ipow and q comparisons stay within int range: every entry has p^n < 1e9 < INT_MAX, and ipow uses pow(double,double) which is exact below 2^53.
  • Behavior for unsupported q is unchanged: create_galois_field(2^30) and non-prime-powers still error (verified by the existing tests, which I did not modify).
  • I verified independently (outside R) that the generated xtn vectors for GF(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

GaloisField allocates dense q × q plus/times tables, so memory grows as q² = 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 any n ≥ 3 for these large bases is not practically constructible. The lookup entries are still included for completeness/consistency with the existing table (which already lists similarly large p^n), but the tests deliberately exercise only small n=2 fields. Reducing that memory footprint is out of scope here.

Verification

R is not available in the environment used to prepare this branch, so the testthat suite was not executed here — please run R 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.0 and edits NEWS/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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wish: Increase the upper bound for the base p for prime powers in create_galois_field

2 participants