Skip to content

Fix the sign of getLinkingNumber - #79

Merged
mimakaev merged 1 commit into
open2c:masterfrom
teerthsharma:fix/linking-number-sign
Oct 4, 2026
Merged

mimakaev merged 1 commit into
open2c:masterfrom
teerthsharma:fix/linking-number-sign

Conversation

@teerthsharma

Copy link
Copy Markdown
Contributor

Description

Closes #78.

_getLinkingNumberCpp sums signed projected crossings into L and returns -L/2. intersectValue already uses the standard crossing sign, so the negation makes getLinkingNumber return the opposite of the Gauss linking number, and of its own docstring, on every linked pair.

This change returns L/2. It also releases the new[] buffers in intersectValue and _getLinkingNumberCpp with delete[] instead of free(), and releases data, which leaked. test_hopf_link_sign pins the sign: -1 for the test's Hopf link, +1 with one ring reversed. The existing test_hopf_link only checked abs(L) == 1. mutualSimplify, simplifyPolymer and the Python signatures are unchanged.

Validation

From this branch on master at 1e9ac0f, in-place build on Ubuntu (WSL2), g++ 15.2.0, Python 3.14.4, openmm 8.6.1:

  • Compiled getLinkingNumber vs a Gauss–Legendre double integral, 11 pairs (Hopf link in four orientations, T(2,2), T(2,4), T(2,6) in both chiralities, unlinked rings): 1/11 agree on master, 11/11 with this change.
  • pytest tests: 64/64 passed on master, 65/65 with this change.
  • test_hopf_link_sign with master's __polymer_math.cpp: fails, 1 failed and 1 passed of the two Hopf tests.
  • valgrind on a 30-point Hopf link: 16 Mismatched free() / delete / delete [] contexts on master, 0 with this change. Definitely lost: 3,192 bytes on master, 2,712 with this change.
  • black -l 120 --check .: 40 files unchanged. isort --check-only .: clean. flake8 tests/test_polymer_math.py: clean.

Limits

Every non-zero result changes sign, so analyses run against master since #75 that kept the sign will invert. Results from v0.1.0 keep their sign and halve.

PR Checklist

  • apply "black" to the whole codebase (black .)
  • apply isort to the codebase (isort .)
  • fun flake8 and try to resolve all the issues (work in progress!)

_getLinkingNumberCpp returned -L/2, but intersectValue already uses the
standard crossing sign, so L = 2 * lk and the result was the negative of
the Gauss linking number. Return L/2 and pin the Hopf link's sign in
test_hopf_link_sign.

Release the new[] buffers in intersectValue and _getLinkingNumberCpp
with delete[] instead of free(), and release data, which leaked.

Fixes open2c#78
@mimakaev
mimakaev merged commit 11a870c into open2c:master Oct 4, 2026
teerthsharma pushed a commit to teerthsharma/teerthsharma that referenced this pull request Oct 11, 2026
The profile linked its website to teerthsharma.github.io and its 3D
portfolio to teerthfolio.vercel.app. teerthsharma.github.io now serves from
teerth.dev, which GitHub redirects to with a 301 for the user site and every
project site; teerthfolio.vercel.app 308-redirects to www.evilseal.si. The
Website, 3D portfolio and Caustic results links point at the new addresses
directly, so none of the three passes through a redirect.

open2c/polychrom#79, merged 2026-10-04, joins the landings table, the link
row under the ticker and commits.svg as a twelfth slide. getLinkingNumber
returned the negated Gauss linking number on every linked pair; the fix
brings agreement with a Gauss-Legendre double integral from 1/11 pairs to
11/11. The ticker's alt text and footer now say twelve, eleven of them in
production ML infrastructure, since polychrom is a chromosome-simulation
library. gen.py reproduces the previously committed commits.svg and
systems.svg byte-for-byte before this change, and the new slide passes its
width guard.

The resume carries the same link changes and an open2c block in the
Experience section's existing per-org shape. The added block overflowed A4
by two lines; the Caustic and OpenCLAW-P2P entries each lose one clause and
Education fits on one line, so the render stays one page (125,023 bytes,
against 121,354 before). The Experience entries above open2c are unchanged.
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.

getLinkingNumber returns the negative of the Gauss linking number

2 participants