Skip to content

Fix compositions count freqs target - #65

Merged
jwood000 merged 3 commits into
mainfrom
fix-compositions-count-freqs-target
Jun 7, 2026
Merged

Fix compositions count freqs target#65
jwood000 merged 3 commits into
mainfrom
fix-compositions-count-freqs-target

Conversation

@jwood000

@jwood000 jwood000 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

This PR fixes a counting bug in compositionsCount() for multiset inputs with repeated frequencies, a fixed length, and a target constraint when the input does not include zero.

Previously, the following equivalent counting paths returned different results:

permuteCount(
    1:15, 8,
    freqs = rep(5:1, each = 3),
    constraintFun = "sum",
    comparisonFun = "==",
    limitConstraints = 40
)
# 12527578

compositionsCount(
    1:15, 8,
    freqs = rep(5:1, each = 3),
    target = 40
)
# previously 3262902
# now 12527578

The fix updates the multiset composition/partition counting path so the weak-counting flag is set correctly when zero is not included, or when the count is explicitly weak.

Changes

  • Fixed the affected multiset counting condition.
  • Added a regression test covering the mismatch above.
  • Updated internal AI helper scripts to use the newer default model and omit unsupported temperature parameters.

Notes

No API changes are introduced. Existing code remains source-compatible, but counts for affected cases may change from the previous incorrect value to the corrected value.

jwood000 added 3 commits June 6, 2026 18:57
Pass `!includeZero || isWeak` to `CountPartsMultiset` so zero-exclusion
is respected, and add a regression test for sum constraints with
frequencies.
Use gpt-5.5 as the default review model across helpers, allow
AI_REVIEW_MODEL overrides for news and PR summaries, and omit
temperature from response requests.
Extract the zero-counting flag to document how padded zeros are handled
in composition multiset counts.

@jwood000 jwood000 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed the fix. The change is intentionally narrow: CountPartsMultiset() already has the correct counting behavior once the final flag reflects whether zeros should participate in the permutation count.

The previous call passed part.isWeak directly, which undercounted non-weak composition cases where zero was not part of the input but appeared internally as padding. The updated condition, !part.includeZero || part.isWeak, preserves the existing weak behavior while ensuring fixed-length compositions over positive inputs are counted correctly.

The added regression test covers the reported mismatch between permuteCount() and compositionsCount().

@jwood000
jwood000 merged commit 128a699 into main Jun 7, 2026
14 checks passed
@jwood000
jwood000 deleted the fix-compositions-count-freqs-target branch June 7, 2026 00:26
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