hspZ v0.0.4

F. Entropy correction

Recount composition only in the score band where low-complexity correction can change acceptance.

Entropy is deferred until exact endpoints are known and only for scores in `[K, 3K]`. This keeps KegAlign's result on every tested input (the logarithm is an independent implementation, within 3.4e-14 relative error) while removing composition bookkeeping from the common path.

F.1 — Enter the narrow entropy bandStep 1 of 3

WHAT GOES IN: Exact X-drop total score, threshold K, and the `--noentropy` setting. WHAT HAPPENS: Scores from K through 3K enter entropy correction; higher scores bypass it and lower scores fail. WHAT COMES OUT: A direct decision or one interval requiring composition counts. INVARIANT: The band is closed at both K and 3K, matching KegAlign.

Readable journey

Step 1

F.1 — Enter the narrow entropy band

what goes in
Exact X-drop total score, threshold K, and the `--noentropy` setting.
what happens
Scores from K through 3K enter entropy correction; higher scores bypass it and lower scores fail.
what comes out
A direct decision or one interval requiring composition counts.
invariant
The band is closed at both K and 3K, matching KegAlign.
  1. Total score → Band check: score + K + setting
  2. Band check → Direct accept/reject: below K or above 3K
  3. Band check → Entropy recount: K through 3K
Step 2

F.2 — Recount matching unambiguous bases

what goes in
The closed HSP interval selected by the X-drop maxima.
what happens
The warp revisits the interval and counts matching A, C, G, and T pairs in four packed fields.
what comes out
Four base-composition counts and their total.
invariant
Mismatches, ambiguous symbols, softmask symbols, and positions beyond either maximum do not count.
  1. Closed HSP → Warp recount: start through start + len
  2. Warp recount → Warp recount: keep equal unambiguous pairs
  3. Warp recount → Packed A/C/G/T counts: one reduced count vector
Step 3

F.3 — Reproduce KegAlign's float boundary

what goes in
Total score, composition counts, and `logf(4)` widened to double.
what happens
With at least 20 counted bases, normalized entropy scales the score (with fewer, the score stands), then the result follows KegAlign's conversion points before comparison with K.
what comes out
An accepted entropy-adjusted score or rejection.
invariant
Replacing widened `logf(4)` or the score conversions with mathematically cleaner doubles can change boundary cases.
  1. Base counts → Normalized entropy: -sum(p ln p) / widened logf(4)
  2. Normalized entropy → Scaled score: score × entropy
  3. Scaled score → Threshold K: KegAlign conversion + compare