Skip to content

feat(math): add nonlinear binary code operations - #2124

Merged
morluto merged 4 commits into
mainfrom
feat/code-nonlinear-1785
Aug 21, 2026
Merged

feat(math): add nonlinear binary code operations#2124
morluto merged 4 commits into
mainfrom
feat/code-nonlinear-1785

Conversation

@morluto

@morluto morluto commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

Add four new operations to the domain and create the missing for catalog registration (issue #1785).

Operations Added

Operation Description
Exact Hamming distance between two equal-length binary words with differing coordinates, weights, and support intersection
Complete distance profile: weight distribution, minimum/maximum pairwise Hamming distance, distance histogram, extremal pairs witnesses
Profile of a constant-weight binary code using support-intersection distances d(x,y) = 2(w -
Map codewords to support subsets on coordinate labels

Design

  • Word distance: Direct bitwise comparison with exact support intersection count.
  • Explicit profile: Brute-force pairwise enumeration for small codes, returning a compact distance histogram plus extremal witnesses pairs.
  • Constant-weight profile: Uses the constant-weight identity d(x,y) = 2(w - |supp(x) ∩ supp(y)|) for efficient distance computation.
  • Set system: Maps each binary word to its support (positions of 1s), producing a set-system representation compatible with existing incidence structure operations.
  • Fail-closed binding: Result models re-run the kernel to verify exactness.
  • Catalog registration: Created the missing file that was preventing the domain from being discovered by the catalog.

Testing

  • 12 tests covering: word distance (identical, complementary, partial overlap), explicit profile (simple code, single codeword, distance histogram), constant-weight profile (weight-2 code, disjoint supports), set system (standard, zero word), distance profile, constant-weight generation
  • All tests pass

Issue

Part of #1785 — coding theory: nonlinear binary code and constant-weight distance-profile operations.

Continue this on Linzumi

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/jacobian/math/code_nonlinear/_tools.py
Comment thread src/jacobian/math/code_nonlinear/_models.py Outdated
Comment thread src/jacobian/math/code_nonlinear/_operations.py Outdated
Comment thread src/jacobian/math/code_nonlinear/_admission.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +14 to +16
"code.nonlinear.distance_profile.compute",
AdmissionDecision.KEEP,
"exact minimum Hamming distance and weight profile by brute-force enumeration",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +123 to +124
if m_count == 1:
min_dist = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +153 to +155
if self.distance_histogram != profile["distance_histogram"]:
raise ValueError("distance_histogram must be exact")
return self

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +198 to +202
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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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.
@morluto
morluto force-pushed the feat/code-nonlinear-1785 branch from 3be21ae to d4d47a6 Compare August 21, 2026 01:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +133 to +134
length: int = Field(ge=1)
cardinality: int = Field(ge=1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@morluto
morluto merged commit dbc40df into main Aug 21, 2026
26 checks passed
@morluto
morluto deleted the feat/code-nonlinear-1785 branch August 21, 2026 02:04
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.

1 participant