Skip to content

feat(math): add dual code and syndrome operations using SymPy (#1851) - #2026

Open
morluto wants to merge 1 commit into
mainfrom
agent/coding-theory-1851
Open

feat(math): add dual code and syndrome operations using SymPy (#1851)#2026
morluto wants to merge 1 commit into
mainfrom
agent/coding-theory-1851

Conversation

@morluto

@morluto morluto commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Summary

Add two operations to the existing domain, partially addressing #1851.

Operations

  • code.dual_code.compute — Compute the parity check matrix (dual code) from a generator matrix over GF(p), using SymPy's exact null space computation. Returns the code dimension, length, and dual dimension.
  • code.syndrome.compute — Compute the syndrome vector H*r^T mod p for a received word under a parity check matrix over GF(p).

Library choice

SymPy's provides exact rational null space computation, which we reduce modulo the prime field to get the parity check matrix. This avoids hand-rolling a custom null space algorithm and leverages a mature, tested implementation.

Tests

5 known-answer tests covering:

  • [7,4] Hamming code dual code (dimension 3, length 7)
  • Identity matrix dual code (trivial null space)
  • Zero syndrome (valid codeword)
  • Non-zero syndrome over GF(2)
  • Syndrome over GF(3) (modular arithmetic verification)

Continue this on Linzumi

Add two operations to the code_theory domain:

- code.dual_code.compute: compute the parity check matrix (dual code)
  from a generator matrix over GF(p), using SymPy's exact null
  space computation.
- code.syndrome.compute: compute the syndrome vector H*r^T mod p
  for a received word under a parity check matrix.

Partially addresses #1851.
@morluto morluto added feature epic: execute Execute: math.run honesty, results, verify path domain: coding-theory Error-correcting codes and finite code structures request: math-operation Request to add or extend a user-facing mathematical operation labels Aug 18, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto morluto left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review verdict: blocked — the dual is computed over the wrong field

Matrix(rows).nullspace() is ordinary SymPy matrix nullspace over characteristic zero, not over GF(p). Reducing its entries afterward does not convert a rational kernel basis into a finite-field kernel basis.

Two concrete failures:

p = 3
G = ((2, 1),)

SymPy returns the rational basis vector (-1/2, 1). This code applies int(-1/2) == 0 and returns parity row (0, 1), but G * H^T == 1 (mod 3), so the advertised parity check is simply false.

p = 2
G = ((1,1,0), (1,0,1), (0,1,1))

The determinant is -2, so the matrix is nonsingular over QQ but singular over GF(2). The code returns a trivial dual, while (1,1,1) is a nonzero finite-field null vector.

Use modular row reduction/nullspace over an actual GF(p) domain (for example SymPy's domain-matrix finite-field machinery), and verify G H^T = 0 mod p as a postcondition/property test.

There is a second dimension bug: code_dimension=k uses the number of supplied rows, but a generator matrix may have dependent rows. Either require full row rank over GF(p) or report the modular rank; then dual_dimension must equal n-rank(G). A duplicate-row regression should cover this.

Finally, SyndromeRequest validates received-word residues but not parity-check entries. Normalize or require canonical residues consistently.

morluto commented Aug 18, 2026

Copy link
Copy Markdown
Owner Author

Deep review summary

Verdict: REQUEST CHANGES — the dual code is computed over characteristic zero, not over GF(p).

Matrix(rows).nullspace() computes the ordinary rational nullspace. Reducing its entries afterward does not turn a QQ kernel basis into a finite-field kernel basis.

Concrete failures:

p = 3
G = ((2, 1),)

SymPy returns (-1/2, 1). The implementation applies int(-1/2) == 0 and emits (0, 1), but G H^T = 1 mod 3, so the advertised parity check is false.

p = 2
G = ((1,1,0), (1,0,1), (0,1,1))

This matrix has determinant -2, hence is nonsingular over QQ but singular over GF(2). The implementation returns a trivial dual, although (1,1,1) is a nonzero finite-field null vector.

Use modular row reduction or nullspace over an actual GF(p) domain and property-test the postcondition G H^T = 0 mod p.

There is also a dimension bug: code_dimension is the supplied row count, but generator rows may be dependent. Require full modular row rank or report rank_GF(p)(G); then dual_dimension must be n - rank(G). Add a duplicate-row regression.

Finally, SyndromeRequest validates received-word residues but not parity-check entries. Normalize or require canonical residues consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: coding-theory Error-correcting codes and finite code structures epic: execute Execute: math.run honesty, results, verify path feature request: math-operation Request to add or extend a user-facing mathematical operation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant