Milestone 4 of 9

Hand-check eligibility and exact similarity

Work through intersection, union, exact fractions, threshold cross-products, equality boundaries, and excluded short-document pairs.

Before comparing a corpus, hand-check what a pair is allowed to mean. Empty group sets are excluded under this Project's explicit policy.

Goal

Work through eligibility, exact Jaccard intersection and union, reduced fractions, threshold cross-products, equality, and excluded-pair reasons on small documents.

Inputs

Use primary document group sets and the rational threshold p / q. A pair is eligible only when both documents have at least one unique group. A pair with one or two insufficient_groups documents remains in accounting with an exact reason but receives no similarity or threshold decision. Two empty sets are not treated as identical documents.

For eligible sets A and B:

intersection_count = len(A & B)
union_count = len(A | B)
similarity = intersection_count / union_count

Store integer counts as authoritative. A reduced fractions.Fraction may be used for exact comparison and ordering. A decimal rounded to exactly twelve places is display-only. Flag exactly when:

intersection_count * q >= p * union_count

Equality is included.

Deliverables

Implement hand-check calculations in src/pairs.py or a clearly separated helper. Produce tiny expected records with eligibility status, reason when excluded, exact counts, fraction, decimal display, threshold products, and decision.

Checks

Check exact copies, partial and zero overlap, one empty set, two empty sets, thresholds zero and one, similarity exactly at and just below a threshold, and reduced and unreduced fractions. Verify union is positive for eligible pairs, integer cross-products decide the boundary, and decimal rounding never changes a decision.

Check that an excluded pair has no similarity or threshold decision, remains in pair accounting, and is not called identical merely because both sets are empty. Do not use a floating-point comparison as the authoritative rule.

Workspace

Keep hand-check arithmetic, eligibility, and exact pair metrics in src/pairs.py. Do not generate the full quadratic pair table or selected evidence yet.

Hints

HintCross-multiply the boundary
Compare intersection_count * q with p * union_count. This preserves equality and avoids a rounding edge.
HintRecord the reason
An excluded short document is still a pair input. Save why it has no fraction rather than assigning similarity zero.
HintDisplay is not authority
A twelve-place decimal helps a reader scan the report. Keep the integer counts and exact fraction beside it.

Review

For A = {x, y} and B = {y, z}, calculate both counts and test threshold 1/3. Then repeat with two empty sets. Why are the two cases treated differently?

How to check your work

Checks compare hand calculations with the tiny fixtures. The supplied fixture uses exact counts and cross-products, includes equality, and preserves excluded reasons.

LLM PrimerHand-check eligibility and exact similarityhttps://llmprimer.com/python/projects/find-near-duplicate-documents/hand-check-eligibility-and-exact-similarity© 2026 LLM Primer