Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sums with negative RHS. #3793

Merged
merged 1 commit into from
Oct 13, 2023
Merged

Fix sums with negative RHS. #3793

merged 1 commit into from
Oct 13, 2023

Conversation

TimSheard
Copy link
Contributor

@TimSheard TimSheard commented Oct 13, 2023

When solving for a variable (like 'N') that appears on the right-hand-side of a summation constraint like this

SumsTo (Right (Coin 1)) ₳ 15 <= ∑ sum Map{34 -> ₳ 5 | size = 15, sum = ₳ 125} + sum N

There is a problem with the current algorithm, if the type of the variable 'N' does not support negative values.
The current algorithm solves this by subtracting the the constants on the right (125) from the constants on the left (15), resulting in (-110) <= N, which has a solution N is at Least (-109). But since N cannot be negative we must settle for a solution N is at Least 0.

We add special code to consider this case. And also made a few error messages more precise.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

Copy link
Contributor

@lehins lehins left a comment

Choose a reason for hiding this comment

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

👍

@lehins lehins enabled auto-merge October 13, 2023 15:37
@lehins lehins merged commit a792fbf into master Oct 13, 2023
13 of 16 checks passed
@iohk-bors iohk-bors bot deleted the ts-fixsum-negativeLHS branch October 13, 2023 16:00
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.

None yet

2 participants