feat(math): add nonlinear binary code operations - #2124
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3de9a606ed
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9737fecf90
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "code.nonlinear.distance_profile.compute", | ||
| AdmissionDecision.KEEP, | ||
| "exact minimum Hamming distance and weight profile by brute-force enumeration", |
There was a problem hiding this comment.
Reject singleton inputs before admitting distance profiles
When a caller supplies a one-word code, which BinaryCodeRequest permits, the newly public code.nonlinear.distance_profile.compute reports that word's Hamming weight as minimum_distance; there is no distinct pair whose distance realizes that value, and isometric singleton codes such as {000} and {101} consequently produce different alleged minima. The explicit-profile singleton fix does not cover this separately admitted legacy operation, so narrow its request contract or explicitly represent the undefined minimum before marking it KEEP.
AGENTS.md reference: AGENTS.md:L74-L77
Useful? React with 👍 / 👎.
| if m_count == 1: | ||
| min_dist = 0 |
There was a problem hiding this comment.
Reject singleton constant-weight profiles
For a one-word constant-weight code, this branch returns minimum_distance=0 even though the advertised pairwise profile has no distinct pair and therefore no exact minimum. The final tree rejects this degenerate case only for ExplicitProfileRequest, while ConstantWeightProfileRequest still accepts it; reject singleton inputs here as well or make the undefined extremum explicit.
AGENTS.md reference: AGENTS.md:L74-L77
Useful? React with 👍 / 👎.
| """Domain operation ownership.""" | ||
|
|
||
| __all__: list[str] = [] | ||
| from jacobian.math.code_nonlinear._operations import compute_to_set_system as to_set_system |
There was a problem hiding this comment.
Expose a domain-value set-system function
The advertised native to_set_system symbol is only an alias for the wire adapter: calling it with the natural domain value, such as a tuple of binary codewords, raises AttributeError when compute_to_set_system accesses request.codewords, and a successful call returns a wire ToSetSystemResult envelope rather than the mathematical support value. Define a direct native function accepting codewords and keep the request-model adapter separate.
AGENTS.md reference: AGENTS.md:L98-L101
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89b5fc76f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ), | ||
| OperationAdmission( | ||
| "code.binary.explicit.profile.compute", | ||
| AdmissionDecision.KEEP, |
There was a problem hiding this comment.
Reclassify the redundant explicit-profile operation
For every non-singleton request accepted by code.nonlinear.distance_profile.compute, this newly kept operation already returns the same minimum distance and echoes the codewords from which the legacy operation's ordered weight profile is derived. Publishing both IDs therefore creates overlapping discovery intents rather than filling a distinct operation gap; retain one public profile contract and reclassify the redundant candidate.
AGENTS.md reference: AGENTS.md:L69-L71
Useful? React with 👍 / 👎.
| if self.distance_histogram != profile["distance_histogram"]: | ||
| raise ValueError("distance_histogram must be exact") | ||
| return self |
There was a problem hiding this comment.
Validate the extremal witness pairs
When an ExplicitProfileResult is deserialized or revalidated, arbitrary witnesses such as min_distance_pair=(0, 0) or out-of-range max_distance_pair=(99, 99) are accepted as long as the scalar profile fields match, because this validator returns without comparing either pair to _explicit_profile. That allows the result contract to certify invalid extremal witnesses; bind both fields to the computed profile just like the histogram and extrema.
AGENTS.md reference: AGENTS.md:L105-L114
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3be21ae41e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| profile = _constant_weight_profile(self.codewords) | ||
| if self.minimum_distance != profile["minimum_distance"]: | ||
| raise ValueError("minimum_distance must be exact") | ||
| if self.distance_histogram != profile["distance_histogram"]: | ||
| raise ValueError("distance_histogram must be exact") |
There was a problem hiding this comment.
Bind all profile metadata to the source codewords
When a serialized ConstantWeightProfileResult is revalidated, this validator accepts length=1, weight=0, and cardinality=99 alongside two length-4, weight-2 codewords, because it checks only the minimum distance and histogram. This permits a purported exact profile to carry false source metadata; recompute and validate these three fields from codewords as part of the defining invariant.
AGENTS.md reference: AGENTS.md:L156-L157
Useful? React with 👍 / 👎.
…ile, and set-system operations to nonlinear binary codes Add four new operations to the code_nonlinear domain and create the missing _admission.py for catalog registration (issue #1785): - code.binary.word_distance.compute: exact Hamming distance with differing coordinates, weights, and support intersection - code.binary.explicit.profile.compute: complete distance profile with weight distribution, distance histogram, and extremal pair witnesses - code.binary.constant_weight.profile.compute: profile of a constant-weight code using support-intersection distances d(x,y) = 2(w - |supp(x) ∩ supp(y)|) - code.binary.explicit.to_set_system.compute: map codewords to support subsets on coordinate labels Also register the two existing operations (distance_profile and constant_weight) via the newly created _admission.py.
3be21ae to
d4d47a6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d4d47a60b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| """Profile of a constant-weight binary code.""" | ||
|
|
||
| codewords: tuple[tuple[int, ...], ...] = Field( | ||
| min_length=1, max_length=MAX_CODEWORDS |
There was a problem hiding this comment.
Align the generator and profile cardinality bounds
For the schema-valid generator request {"length": 16, "weight": 8}, code.nonlinear.constant_weight.compute returns all C(16,8) = 12,870 codewords, but this newly published consumer rejects the generated codewords above 1,024; BinaryCodeRequest and ExplicitProfileRequest impose the same cap. Consequently, even the codewords field of an exact generator result cannot be supplied to any profile operation for valid generator inputs, so either restrict generation according to its output cardinality or align the consumer/work contract.
AGENTS.md reference: AGENTS.md:L95-L97
Useful? React with 👍 / 👎.
| length: int = Field(ge=1) | ||
| cardinality: int = Field(ge=1) |
There was a problem hiding this comment.
Bind explicit-profile metadata to its codewords
When an ExplicitProfileResult is deserialized or revalidated, two length-2 codewords can be paired with values such as length=99 and cardinality=1 and still pass as long as the distributions and extrema are exact, because bind_profile never compares these metadata fields with codewords. This permits an authoritative profile to report a false ambient length and source cardinality; validate both fields against the source codewords.
AGENTS.md reference: AGENTS.md:L156-L157
Useful? React with 👍 / 👎.
Summary
Add four new operations to the domain and create the missing for catalog registration (issue #1785).
Operations Added
Design
Testing
Issue
Part of #1785 — coding theory: nonlinear binary code and constant-weight distance-profile operations.
Continue this on Linzumi